From: <mgu...@us...> - 2013-01-28 10:49:45
|
Revision: 8043 http://sourceforge.net/p/htmlunit/code/8043 Author: mguillem Date: 2013-01-28 10:49:41 +0000 (Mon, 28 Jan 2013) Log Message: ----------- - added @BuggyWebDriver to mark tests that are not running in real browser through WebDriver but are working fine when run manually - command "JustifyFull" is supported by FF17 - made HTMLDocumentTest working for FF17 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -312,10 +312,6 @@ /** Was originally .isFirefox(). */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) - GENERATED_165, - - /** Was originally .isFirefox(). */ - @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) GENERATED_167, /** Was originally .isFirefox(). */ @@ -971,6 +967,10 @@ @BrowserFeature(@WebBrowser(IE)) JS_PARENT_PROTO_PROPERTIES, + /** Indicates that document.queryCommandSupported(..) is only available in design mode. */ + @BrowserFeature(@WebBrowser(value = FF, maxVersion = 3.6f)) + JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE, + /** Javascript script.text(...) reexecutes the script (IE). */ @BrowserFeature(@WebBrowser(IE)) JS_SCRIPT_ALWAYS_REEXECUTE_ON_SET_TEXT, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Document.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -463,8 +463,10 @@ public Object createElementNS(final String namespaceURI, final String qualifiedName) { final org.w3c.dom.Element element; final BrowserVersion browserVersion = getBrowserVersion(); - if (browserVersion.hasFeature(XUL_SUPPORT) - && "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { + if ("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) { + if (!browserVersion.hasFeature(XUL_SUPPORT)) { + throw Context.reportRuntimeError("XUL not available"); + } // simple hack, no need to implement the XUL objects (at least in a first time) element = new HtmlDivision(namespaceURI, qualifiedName, getPage(), null); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -19,7 +19,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_160; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_161; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_164; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_165; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_51; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_53; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_55; @@ -27,7 +26,6 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_59; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_60; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_61; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.GENERATED_63; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLCOLLECTION_OBJECT_DETECTION; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_CHARSET_LOWERCASE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLDOCUMENT_COLOR; @@ -39,6 +37,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_SETTING_DOMAIN_THROWS_FOR_ABOUT_BLANK; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_ELEMENT_BY_ID_ALSO_BY_NAME_IN_QUICKS_MODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_GET_ELEMENT_BY_ID_CASE_SENSITIVE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_TREEWALKER_EXPAND_ENTITY_REFERENCES_FALSE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; @@ -174,7 +173,7 @@ */ private static final Map<String, Class<? extends Event>> SUPPORTED_EVENT_TYPE_MAP; - private static final List<String> EXECUTE_CMDS_IE = Arrays.asList(new String[] { + private static final List<String> EXECUTE_CMDS_IE = Arrays.asList( "2D-Position", "AbsolutePosition", "BackColor", "BackgroundImageCache" /* Undocumented */, "BlockDirLTR", "BlockDirRTL", "Bold", "BrowseMode", "ClearAuthenticationCache", "Copy", "CreateBookmark", "CreateLink", "Cut", "Delete", "DirLTR", "DirRTL", @@ -191,18 +190,23 @@ "SizeToControl", "SizeToControlHeight", "SizeToControlWidth", "Stop", "StopImage", "StrikeThrough", "Subscript", "Superscript", "UnBookmark", "Underline", "Undo", "Unlink", "Unselect" - }); + ); /** https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla#Executing_Commands */ - private static final List<String> EXECUTE_CMDS_FF = Arrays.asList(new String[] { + private static final List<String> EXECUTE_CMDS_FF = Arrays.asList( "backColor", "bold", "contentReadOnly", "copy", "createLink", "cut", "decreaseFontSize", "delete", "fontName", "fontSize", "foreColor", "formatBlock", "heading", "hiliteColor", "increaseFontSize", "indent", "insertHorizontalRule", "insertHTML", "insertImage", "insertOrderedList", "insertUnorderedList", "insertParagraph", "italic", "justifyCenter", "justifyLeft", "justifyRight", "outdent", "paste", "redo", "removeFormat", "selectAll", "strikeThrough", "subscript", "superscript", "underline", "undo", "unlink", "useCSS", "styleWithCSS" - }); + ); + private static final List<String> EXECUTE_CMDS_FF17 = new ArrayList<String>(EXECUTE_CMDS_FF) { { + add("JustifyFull"); + } + }; + /** * Static counter for {@link #uniqueID_}. */ @@ -1855,16 +1859,24 @@ */ @JsxFunction public boolean queryCommandSupported(final String cmd) { - final boolean ff = getBrowserVersion().hasFeature(GENERATED_165); - final String mode = getDesignMode(); - if (!ff) { + if (getBrowserVersion().hasFeature(JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE)) { + final String mode = getDesignMode(); + if (!"on".equals(mode)) { + final String msg = "queryCommandSupported() called while document.designMode='" + mode + "'."; + throw Context.reportRuntimeError(msg); + } + } + return hasCommand(cmd); + } + + private boolean hasCommand(final String cmd) { + if (getBrowserVersion().isIE()) { return containsCaseInsensitive(EXECUTE_CMDS_IE, cmd); } - if (!"on".equals(mode)) { - final String msg = "queryCommandSupported() called while document.designMode='" + mode + "'."; - throw Context.reportRuntimeError(msg); + else if ("FF3.6".equals(getBrowserVersion().getNickname())) { + return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); } - return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); + return containsCaseInsensitive(EXECUTE_CMDS_FF17, cmd); } /** @@ -1875,16 +1887,14 @@ */ @JsxFunction public boolean queryCommandEnabled(final String cmd) { - final boolean ff = getBrowserVersion().hasFeature(GENERATED_165); - final String mode = getDesignMode(); - if (!ff) { - return containsCaseInsensitive(EXECUTE_CMDS_IE, cmd); + if (getBrowserVersion().hasFeature(JS_QUERYCOMMAND_SUPPORTED_ONLY_DESIGNMODE)) { + final String mode = getDesignMode(); + if (!"on".equals(mode)) { + final String msg = "queryCommandEnabled() called while document.designMode='" + mode + "'."; + throw Context.reportRuntimeError(msg); + } } - if (!"on".equals(mode)) { - final String msg = "queryCommandEnabled() called while document.designMode='" + mode + "'."; - throw Context.reportRuntimeError(msg); - } - return containsCaseInsensitive(EXECUTE_CMDS_FF, cmd); + return hasCommand(cmd); } /** @@ -1897,12 +1907,8 @@ */ @JsxFunction public boolean execCommand(final String cmd, final boolean userInterface, final Object value) { - final BrowserVersion browser = getBrowserVersion(); - final boolean ie = browser.hasFeature(GENERATED_63); - if ((ie && !containsCaseInsensitive(EXECUTE_CMDS_IE, cmd)) - || (!ie && !containsCaseInsensitive(EXECUTE_CMDS_FF, cmd))) { - - if (browser.hasFeature(EXECCOMMAND_THROWS_ON_WRONG_COMMAND)) { + if (!hasCommand(cmd)) { + if (getBrowserVersion().hasFeature(EXECCOMMAND_THROWS_ON_WRONG_COMMAND)) { throw Context.reportRuntimeError("document.execCommand(): invalid command '" + cmd + "'"); } return false; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserRunner.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -276,6 +276,15 @@ } /** + * Indicates that the test runs manually in a real browser but not when using WebDriver to driver the browser. + * @see Browser + */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public static @interface BuggyWebDriver { + } + + /** * The number of tries that test will be executed. * The test will fail if and only if all trials failed. */ Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/BrowserVersionClassRunner.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -39,6 +39,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.BrowserRunner.Tries; @@ -164,6 +165,9 @@ else if (isExpectedToFail(method)) { prefix = "(failure expected) "; } + else if (realBrowser_ && isBuggyWebDriver(method)) { + prefix = "(buggy) "; + } String browserString = browserVersion_.getNickname(); if (realBrowser_) { @@ -320,7 +324,7 @@ final int tries; if (testCase instanceof WebDriverTestCase && realBrowser_) { - notYetImplemented = false; + notYetImplemented = isBuggyWebDriver(method); tries = 1; } else { @@ -375,6 +379,11 @@ return notYetImplementedBrowsers != null && isDefinedIn(notYetImplementedBrowsers.value()); } + private boolean isBuggyWebDriver(final FrameworkMethod method) { + final BuggyWebDriver buggyWebDriver = method.getAnnotation(BuggyWebDriver.class); + return buggyWebDriver != null; + } + private int getTries(final FrameworkMethod method) { final Tries tries = method.getAnnotation(Tries.class); return tries != null ? tries.value() : 1; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-28 09:11:32 UTC (rev 8042) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2013-01-28 10:49:41 UTC (rev 8043) @@ -29,6 +29,7 @@ import java.util.Date; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.openqa.selenium.By; @@ -38,6 +39,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.BuggyWebDriver; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.WebWindow; @@ -299,7 +301,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = "exception", FF = "Hello", FF10 = "exception") + @Alerts(DEFAULT = "exception", FF3_6 = "Hello", FF = "exception") public void createDocumentNS_xul() throws Exception { final String html = "<html><body>\n" + "<script>\n" @@ -669,6 +671,7 @@ * @throws Exception if an error occurs */ @Test + @BuggyWebDriver // tested with FF8, FF17, FF18 @Alerts(FF = { "1", "[object HTMLBodyElement]" }, CHROME = { "0", "exception" }, IE = "exception") public void designMode_selectionRange_empty() throws Exception { designMode_selectionRange(""); @@ -678,6 +681,7 @@ * @throws Exception if an error occurs */ @Test + @BuggyWebDriver // tested with FF8, FF17, FF18 @Alerts(FF = { "1", "[object Text]" }, CHROME = { "0", "exception" }, IE = "exception") public void designMode_selectionRange_text() throws Exception { designMode_selectionRange("hello"); @@ -834,25 +838,56 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "exception", "0 commands supported" }, - IE = { "Not supported: foo", "Not supported: 123", "78 commands supported" }) - public void queryCommandSupported() throws Exception { + @Alerts(FF3_6 = { "exception", "0 commands supported" }, + FF17 = { "32 commands supported", "not supported: foo, 123" }, + IE = { "32 commands supported", "not supported: foo, 123" }) + public void queryCommandSupported_common() throws Exception { + final String[] commands = {"BackColor", "Bold", + "Copy", "CreateLink", "Cut", "Delete", + "FontName", "FontSize", "ForeColor", "FormatBlock", + "Indent", "InsertHorizontalRule", "InsertImage", "InsertOrderedList", + "InsertParagraph", "InsertUnorderedList", "Italic", + "JustifyCenter", "JustifyFull", "JustifyLeft", "JustifyRight", + "Outdent", "Paste", "Redo", "RemoveFormat", + "SelectAll", "StrikeThrough", "Subscript", "Superscript", + "Underline", "Undo", "Unlink", + "foo", "123" }; + queryCommandSupported(commands); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(FF3_6 = { "exception", "0 commands supported" }, + DEFAULT = { "0 commands supported" }, + IE = { "46 commands supported" }) + public void queryCommandSupported_disctinct() throws Exception { + final String[] commands = {"2D-Position", "AbsolutePosition", + "BlockDirLTR", "BlockDirRTL", "BrowseMode", + "ClearAuthenticationCache", "CreateBookmark", + "DirLTR", "DirRTL", "EditMode", + "InlineDirLTR", "InlineDirRTL", "InsertButton", "InsertFieldset", + "InsertIFrame", "InsertInputButton", "InsertInputCheckbox", "InsertInputFileUpload", + "InsertInputHidden", "InsertInputImage", "InsertInputPassword", "InsertInputRadio", + "InsertInputReset", "InsertInputSubmit", "InsertInputText", "InsertMarquee", + "InsertSelectDropdown", "InsertSelectListbox", "InsertTextArea", + "JustifyNone", + "LiveResize", "MultipleSelection", "Open", "OverWrite", + "PlayImage", "Print", "Refresh", "RemoveParaFormat", + "SaveAs", "SizeToControl", "SizeToControlHeight", "SizeToControlWidth", "Stop", "StopImage", + "UnBookmark", "Unselect"}; + + queryCommandSupported(commands); + } + + private void queryCommandSupported(final String... commands) throws Exception { + final String jsCommandArray = "['" + StringUtils.join(commands, "', '") + "']"; final String html = "<html><head><title>Test</title><script>\n" + "function doTest() {\n" - + " var cmds = ['2D-Position', 'AbsolutePosition', 'BackColor', 'BlockDirLTR', 'BlockDirRTL', 'Bold', " - + "'BrowseMode', 'ClearAuthenticationCache', 'Copy', 'CreateBookmark', 'CreateLink', 'Cut', 'Delete', " - + "'DirLTR', 'DirRTL', 'EditMode', 'FontName', 'FontSize', 'ForeColor', 'FormatBlock', 'Indent', " - + "'InlineDirLTR', 'InlineDirRTL', 'InsertButton', 'InsertFieldset', 'InsertHorizontalRule', " - + "'InsertIFrame', 'InsertImage', 'InsertInputButton', 'InsertInputCheckbox', 'InsertInputFileUpload', " - + "'InsertInputHidden', 'InsertInputImage', 'InsertInputPassword', 'InsertInputRadio', " - + "'InsertInputReset', 'InsertInputSubmit', 'InsertInputText', 'InsertMarquee', 'InsertOrderedList', " - + "'InsertParagraph', 'InsertSelectDropdown', 'InsertSelectListbox', 'InsertTextArea', " - + "'InsertUnorderedList', 'Italic', 'JustifyCenter', 'JustifyFull', 'JustifyLeft', 'JustifyNone', " - + "'JustifyRight', 'LiveResize', 'MultipleSelection', 'Open', 'Outdent', 'OverWrite', 'Paste', " - + "'PlayImage', 'Print', 'Redo', 'Refresh', 'RemoveFormat', 'RemoveParaFormat', 'SaveAs', 'SelectAll', " - + "'SizeToControl', 'SizeToControlHeight', 'SizeToControlWidth', 'Stop', 'StopImage', 'StrikeThrough', " - + "'Subscript', 'Superscript', 'UnBookmark', 'Underline', 'Undo', 'Unlink', 'Unselect', 'foo', 123];\n" + + " var cmds = " + jsCommandArray + ";\n" + " var nbSupported = 0;\n" + + " var cmdsNotSupported = [];\n" + " try {\n" + " for (var i=0; i<cmds.length; ++i) {\n" + " var cmd = cmds[i];" @@ -860,10 +895,12 @@ + " if (b)\n" + " nbSupported++;\n" + " else\n" - + " alert('Not supported: ' + cmd);\n" + + " cmdsNotSupported[cmdsNotSupported.length] = cmd;\n" + " }" + " } catch (e) { alert('exception'); }\n" + " alert(nbSupported + ' commands supported');\n" + + " if (nbSupported != 0 && cmdsNotSupported.length > 0)\n" + + " alert('not supported: ' + cmdsNotSupported.join(', '));\n" + "}\n" + "</script></head><body onload='doTest()'>\n" + "<div id='log'></div>\n" @@ -1358,7 +1395,8 @@ @Alerts(IE = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#000000" }, // IE9 = {"#800080", "", "#0000aa", "#0000aa", "#000000", "#0" }, FF3_6 = {"", "", "#0000aa", "#0000aa", "#000000", "#000000" }, - FF = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }) + FF10 = {"#800080", "", "#0000aa", "#0000aa", "x", "x" }, + FF17 = {"", "", "#0000aa", "#0000aa", "x", "x" }) public void vlinkColor() throws Exception { final String html = "<html>\n" |