From: <asa...@us...> - 2012-12-12 10:54:00
|
Revision: 7861 http://sourceforge.net/p/htmlunit/code/7861 Author: asashour Date: 2012-12-12 10:53:56 +0000 (Wed, 12 Dec 2012) Log Message: ----------- CodeStyle: "two empty lines" is already part of checkstyle Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-12 10:13:44 UTC (rev 7860) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-12 10:53:56 UTC (rev 7861) @@ -8,7 +8,7 @@ <body> <release version="2.12" date="???" description="Bugfixes"> - <action type="fix" dev="asashour" issue="1456 "> + <action type="fix" dev="asashour" issue="1456"> JavaScript: fix the value of "(i in x)" for NodeList, HTMLCollection and CSSRuleList. </action> <action type="update" dev="asashour"> Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2012-12-12 10:13:44 UTC (rev 7860) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2012-12-12 10:53:56 UTC (rev 7861) @@ -109,7 +109,6 @@ lineBetweenMethods(lines, relativePath); svnProperties(file, relativePath); runWith(lines, relativePath); - twoEmptyLines(lines, relativePath); vs85aspx(lines, relativePath); deprecated(lines, relativePath); staticJSMethod(lines, relativePath); @@ -384,19 +383,6 @@ } /** - * Verifies that no two empty contiguous lines. - */ - private void twoEmptyLines(final List<String> lines, final String relativePath) { - for (int i = 1; i < lines.size(); i++) { - final String previousLine = lines.get(i - 1); - final String line = lines.get(i); - if (StringUtils.isBlank(previousLine) && StringUtils.isBlank(line)) { - addFailure("Two empty contiguous lines at " + relativePath + ", line: " + (i + 1)); - } - } - } - - /** * Verifies that no "(VS.85).aspx" token exists (which is sometimes used in MSDN documentation). */ private void vs85aspx(final List<String> lines, final String relativePath) { |
From: <asa...@us...> - 2012-12-16 08:41:38
|
Revision: 7867 http://sourceforge.net/p/htmlunit/code/7867 Author: asashour Date: 2012-12-16 08:41:35 +0000 (Sun, 16 Dec 2012) Log Message: ----------- CSS: fix DirectAdjacentSelector (E + F) Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-15 13:08:47 UTC (rev 7866) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-16 08:41:35 UTC (rev 7867) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="fix" dev="asashour"> + CSS: fix DirectAdjacentSelector (E + F). + </action> <action type="fix" dev="asashour" issue="1456"> JavaScript: fix the value of "(i in x)" for NodeList, HTMLCollection and CSSRuleList. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-15 13:08:47 UTC (rev 7866) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-16 08:41:35 UTC (rev 7867) @@ -371,7 +371,10 @@ return HtmlHtml.TAG_NAME.equalsIgnoreCase(element.getTagName()); case Selector.SAC_DIRECT_ADJACENT_SELECTOR: final SiblingSelector ss = (SiblingSelector) selector; - final DomNode prev = element.getPreviousSibling(); + DomNode prev = element.getPreviousSibling(); + while (prev != null && !(prev instanceof HtmlElement)) { + prev = prev.getPreviousSibling(); + } return prev instanceof HtmlElement && selects(browserVersion, ss.getSelector(), (HtmlElement) prev) && selects(browserVersion, ss.getSiblingSelector(), element); @@ -827,6 +830,9 @@ case Selector.SAC_CHILD_SELECTOR: final DescendantSelector ds = (DescendantSelector) selector; return isValidSelector(ds.getAncestorSelector()) && isValidSelector(ds.getSimpleSelector()); + case Selector.SAC_DIRECT_ADJACENT_SELECTOR: + final SiblingSelector ss = (SiblingSelector) selector; + return isValidSelector(ss.getSelector()) && isValidSelector(ss.getSiblingSelector()); default: LOG.warn("Unhandled CSS selector type '" + selector.getSelectorType() + "'. Accepting it silently."); return true; // at least in a first time to break less stuff Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-15 13:08:47 UTC (rev 7866) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-16 08:41:35 UTC (rev 7867) @@ -81,4 +81,30 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "1", "ul2" }) + public void directAdjacentSelector() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var list = document.querySelectorAll('p+ul');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='ul1'></ul>\n" + + " <p></p>\n" + + " <ul id='ul2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } } |
From: <asa...@us...> - 2012-12-18 07:35:15
|
Revision: 7871 http://sourceforge.net/p/htmlunit/code/7871 Author: asashour Date: 2012-12-18 07:35:12 +0000 (Tue, 18 Dec 2012) Log Message: ----------- JavaScript: add document.charset, .characterSet, .defaultCharset and .inputEncoding Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-18 06:26:11 UTC (rev 7870) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-18 07:35:12 UTC (rev 7871) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="add" dev="asashour"> + JavaScript: add document.charset, .characterSet, .defaultCharset and .inputEncoding. + </action> <action type="fix" dev="asashour"> CSS: fix DirectAdjacentSelector (E + F). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-12-18 06:26:11 UTC (rev 7870) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-12-18 07:35:12 UTC (rev 7871) @@ -576,6 +576,10 @@ @BrowserFeature(@WebBrowser(IE)) HTMLDOCUMENT_COLOR, + /** Is document.charset lower-case (and defaultCharset is 'windows-1252'). */ + @BrowserFeature(@WebBrowser(IE)) + HTMLDOCUMENT_CHARSET_LOWERCASE, + /** Allows invalid 'align' values. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTMLELEMENT_ALIGN_INVALID, Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2012-12-18 06:26:11 UTC (rev 7870) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Node.java 2012-12-18 07:35:12 UTC (rev 7871) @@ -424,8 +424,7 @@ } // if parentNode is null in IE, create a DocumentFragment to be the parentNode - if (domNode.getParentNode() == null - && getWindow().getWebWindow().getWebClient().getBrowserVersion() + if (domNode.getParentNode() == null && getBrowserVersion() .hasFeature(JS_APPEND_CHILD_CREATE_DOCUMENT_FRAGMENT_PARENT)) { final DomDocumentFragment fragment = domNode.getPage().createDomDocumentFragment(); fragment.appendChild(domNode); 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 2012-12-18 06:26:11 UTC (rev 7870) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2012-12-18 07:35:12 UTC (rev 7871) @@ -28,6 +28,7 @@ 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; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_ANCHORS_REQUIRES_NAME_OR_ID; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_DOCUMENT_APPEND_CHILD_SUPPORTED; @@ -79,6 +80,7 @@ import com.gargoylesoftware.htmlunit.ElementNotFoundException; import com.gargoylesoftware.htmlunit.ScriptResult; import com.gargoylesoftware.htmlunit.StringWebResponse; +import com.gargoylesoftware.htmlunit.TextUtil; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.WebResponse; import com.gargoylesoftware.htmlunit.WebWindow; @@ -870,6 +872,49 @@ } /** + * Returns a string representing the encoding under which the document was parsed. + * @return a string representing the encoding under which the document was parsed + */ + @JsxGetter({ @WebBrowser(FF), @WebBrowser(CHROME) }) + public String getInputEncoding() { + return getHtmlPage().getPageEncoding(); + } + + /** + * Returns the character encoding of the current document. + * @return the character encoding of the current document + */ + @JsxGetter({ @WebBrowser(FF), @WebBrowser(CHROME) }) + public String getCharacterSet() { + return getHtmlPage().getPageEncoding(); + } + + /** + * Retrieves the character set used to encode the document. + * @return the character set used to encode the document + */ + @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) + public String getCharset() { + String charset = getHtmlPage().getPageEncoding(); + if (getBrowserVersion().hasFeature(HTMLDOCUMENT_CHARSET_LOWERCASE)) { + charset = charset.toLowerCase(); + } + return charset; + } + + /** + * Gets the default character set from the current regional language settings. + * @return the default character set from the current regional language settings + */ + @JsxGetter({ @WebBrowser(IE), @WebBrowser(CHROME) }) + public String getDefaultCharset() { + if (getBrowserVersion().hasFeature(HTMLDOCUMENT_CHARSET_LOWERCASE)) { + return "windows-1252"; + } + return TextUtil.DEFAULT_CHARSET; + } + + /** * Returns the value of the "URL" property. * @return the value of the "URL" property */ 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 2012-12-18 06:26:11 UTC (rev 7870) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-18 07:35:12 UTC (rev 7871) @@ -1453,10 +1453,9 @@ * @throws Exception if the test fails */ @Test - @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1256" }, + @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) - @NotYetImplemented public void encoding() throws Exception { final String html = "<html>\n" + "<head>\n" |
From: <asa...@us...> - 2012-12-18 11:49:56
|
Revision: 7876 http://sourceforge.net/p/htmlunit/code/7876 Author: asashour Date: 2012-12-18 11:49:54 +0000 (Tue, 18 Dec 2012) Log Message: ----------- Fixing build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-12-18 11:31:21 UTC (rev 7875) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-12-18 11:49:54 UTC (rev 7876) @@ -572,14 +572,14 @@ @BrowserFeature(@WebBrowser(IE)) HTMLCONDITIONAL_COMMENTS, + /** Is document.charset lower-case (and defaultCharset is 'windows-1252'). */ + @BrowserFeature(@WebBrowser(IE)) + HTMLDOCUMENT_CHARSET_LOWERCASE, + /** Do document.bgColor/.alinkColor/.vlinkColor/.linkColor have value by default. */ @BrowserFeature(@WebBrowser(IE)) HTMLDOCUMENT_COLOR, - /** Is document.charset lower-case (and defaultCharset is 'windows-1252'). */ - @BrowserFeature(@WebBrowser(IE)) - HTMLDOCUMENT_CHARSET_LOWERCASE, - /** Allows invalid 'align' values. */ @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) HTMLELEMENT_ALIGN_INVALID, Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2012-12-18 11:31:21 UTC (rev 7875) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebDriverTestCase.java 2012-12-18 11:49:54 UTC (rev 7876) @@ -78,11 +78,11 @@ ff17.bin=/usr/bin/firefox [Unix-like] chrome.bin=/path/to/chromedriver [Unix-like] * </pre> - * The file should contain four properties: "browsers", "ff3.bin", "ff3.6.bin", and "chrome.bin". + * The file should contain four properties: "browsers", "ff3.6.bin", "ff3.17.bin", and "chrome.bin". * <ul> * <li>browsers: is a comma separated list contains any combination of "hu" (for HtmlUnit with all browser versions), * "hu-ie6", "hu-ie7", "hu-ie8", "hu-ie9", "hu-ff3.6", "hu-ff17", - * "ff3.6", "ie6", "ie7", "ie8", "ie9", "chrome", which will be used to driver real browsers, + * "ff3.6", "ff17", "ie6", "ie7", "ie8", "ie9", "chrome", which will be used to driver real browsers, * note that you can't define more than one IE as there is no standard way * to have multiple IEs on the same machine</li> * <li>ff3.6.bin: is the location of the FF3.6 binary, in Windows use double back-slashes</li> |
From: <mgu...@us...> - 2012-12-18 13:55:33
|
Revision: 7879 http://sourceforge.net/p/htmlunit/code/7879 Author: mguillem Date: 2012-12-18 13:55:30 +0000 (Tue, 18 Dec 2012) Log Message: ----------- Fixed typo in method names of com.gargoylesoftware.htmlunit.WebConsole.Formatter. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebConsole.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-18 13:42:43 UTC (rev 7878) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-18 13:55:30 UTC (rev 7879) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="fix" dev="mguillem"> + Fixed typo in method names of com.gargoylesoftware.htmlunit.WebConsole.Formatter. + </action> <action type="add" dev="asashour"> JavaScript: add document.charset, .characterSet, .defaultCharset and .inputEncoding. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebConsole.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebConsole.java 2012-12-18 13:42:43 UTC (rev 7878) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebConsole.java 2012-12-18 13:55:30 UTC (rev 7879) @@ -95,7 +95,7 @@ * @param o object to be printed using string format specifiers * @return a string representation of the passed object */ - String paramterAsString(Object o); + String parameterAsString(Object o); /** * Function that is used to print an object as integer using @@ -103,7 +103,7 @@ * @param o object to be printed using integer format specifiers * @return a string representation of the passed object */ - String paramterAsInteger(Object o); + String parameterAsInteger(Object o); /** * Function that is used to print an object as float using @@ -111,7 +111,7 @@ * @param o object to be printed using float format specifiers * @return a string representation of the passed object */ - String paramterAsFloat(Object o); + String parameterAsFloat(Object o); } private Formatter formatter_ = new DefaultFormatter(); @@ -220,14 +220,14 @@ switch (ch) { case 'o': case 's': - replacement = formatter.paramterAsString(pop(args)); + replacement = formatter.parameterAsString(pop(args)); break; case 'd': case 'i': - replacement = formatter.paramterAsInteger(pop(args)); + replacement = formatter.parameterAsInteger(pop(args)); break; case 'f': - replacement = formatter.paramterAsFloat(pop(args)); + replacement = formatter.parameterAsFloat(pop(args)); break; default: replacement = group; @@ -263,11 +263,11 @@ private static class DefaultFormatter implements Formatter { public String printObject(final Object o) { - return paramterAsString(o); + return parameterAsString(o); } @Override - public String paramterAsString(final Object o) { + public String parameterAsString(final Object o) { if (o != null) { return o.toString(); } @@ -275,7 +275,7 @@ } @Override - public String paramterAsInteger(final Object o) { + public String parameterAsInteger(final Object o) { if (o instanceof Number) { return Integer.toString(((Number) o).intValue()); } @@ -291,7 +291,7 @@ } @Override - public String paramterAsFloat(final Object o) { + public String parameterAsFloat(final Object o) { if (o instanceof Number) { return Float.toString(((Number) o).floatValue()); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 13:42:43 UTC (rev 7878) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 13:55:30 UTC (rev 7879) @@ -458,7 +458,7 @@ } @Override - public String paramterAsString(final Object o) { + public String parameterAsString(final Object o) { if (o instanceof NativeArray) { final StringBuffer sb = new StringBuffer(); for (int i = 0; i < ((NativeArray) o).size(); i++) { @@ -473,7 +473,7 @@ } @Override - public String paramterAsInteger(final Object o) { + public String parameterAsInteger(final Object o) { if (o instanceof Number) { return Integer.toString(((Number) o).intValue()); } @@ -489,7 +489,7 @@ } @Override - public String paramterAsFloat(final Object o) { + public String parameterAsFloat(final Object o) { if (o instanceof Number) { return Float.toString(((Number) o).floatValue()); } |
From: <mgu...@us...> - 2012-12-18 14:42:28
|
Revision: 7880 http://sourceforge.net/p/htmlunit/code/7880 Author: mguillem Date: 2012-12-18 14:42:25 +0000 (Tue, 18 Dec 2012) Log Message: ----------- window.console is first defined in FF4 and (probably) in IE9 but is defined for Chrome Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-18 14:42:25 UTC (rev 7880) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="update" dev="mguillem"> + JavaScript: adjust availability of window.console (Firefox 4+, IE9+ and Chrome). + </action> <action type="fix" dev="mguillem"> Fixed typo in method names of com.gargoylesoftware.htmlunit.WebConsole.Formatter. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Console.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -14,6 +14,10 @@ */ package com.gargoylesoftware.htmlunit.javascript.host; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.CHROME; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.FF; +import static com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName.IE; + import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -35,6 +39,7 @@ import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxFunction; +import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; /** * A JavaScript object for a console. This implementation simulates Firefox's console, which utilizes FireBug API. @@ -42,7 +47,8 @@ * @version $Revision$ * @author Andrea Martino */ -@JsxClass +@JsxClass(browsers = { @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public class Console extends SimpleScriptable { private static final Map<String, Long> TIMERS = new HashMap<String, Long>(); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/Window.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -605,7 +605,8 @@ * Returns the console property. * @return the console property */ - @JsxGetter(@WebBrowser(FF)) + @JsxGetter({ @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public ScriptableObject getConsole() { return console_; } @@ -614,7 +615,8 @@ * Sets the console. * @param console the console */ - @JsxSetter(@WebBrowser(FF)) + @JsxSetter({ @WebBrowser(value = FF, minVersion = 4), @WebBrowser(value = IE, minVersion = 9), + @WebBrowser(CHROME) }) public void setConsole(final ScriptableObject console) { console_ = console; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java 2012-12-18 13:55:30 UTC (rev 7879) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/ConsoleTest.java 2012-12-18 14:42:25 UTC (rev 7880) @@ -20,68 +20,98 @@ import java.util.List; import org.junit.Test; +import org.junit.experimental.runners.Enclosed; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; import com.gargoylesoftware.htmlunit.WebConsole; import com.gargoylesoftware.htmlunit.WebConsole.Logger; +import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** * Tests for {@link Console}. * * @version $Revision$ * @author Ahmed Ashour + * @author Marc Guillemot */ -@RunWith(BrowserRunner.class) -public class ConsoleTest extends SimpleWebTestCase { +@RunWith(Enclosed.class) +public class ConsoleTest { + /** + * The tests running through WebDriver. + */ + @RunWith(BrowserRunner.class) + public static class WebdriverBasedTests extends WebDriverTestCase { + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(DEFAULT = "false", + FF3_6 = "true", IE6 = "true", IE7 = "true", IE8 = "true") + public void undefined() throws Exception { + final String html + = "<html><body><script>\n" + + "alert(window.console == undefined)\n" + + "</script></body></html>"; + loadPageWithAlerts2(html); + } + } + /** - * @throws Exception if the test fails + * The tests NOT running through WebDriver. */ - @Test - @Browsers(FF) - public void log() throws Exception { - final WebConsole console = getWebClient().getWebConsole(); - final List<String> messages = new ArrayList<String>(); - console.setLogger(new Logger() { + @RunWith(BrowserRunner.class) + public static class SimpleTests extends SimpleWebTestCase { + /** + * @throws Exception if the test fails + */ + @Test + @Browsers(FF) + public void log() throws Exception { + final WebConsole console = getWebClient().getWebConsole(); + final List<String> messages = new ArrayList<String>(); + console.setLogger(new Logger() { - @Override - public void warn(final Object message) { - } + @Override + public void warn(final Object message) { + } - @Override - public void trace(final Object message) { - } + @Override + public void trace(final Object message) { + } - @Override - public void info(final Object message) { - messages.add("info: " + message); - } + @Override + public void info(final Object message) { + messages.add("info: " + message); + } - @Override - public void error(final Object message) { - } + @Override + public void error(final Object message) { + } - @Override - public void debug(final Object message) { - } - }); + @Override + public void debug(final Object message) { + } + }); - final String html - = "<html><head><title>foo</title><script>\n" - + "function test() {\n" - + " if (window.console) {\n" - + " var arr = ['one', 'two', 'three', document.body.children];\n" - + " window.console.log(arr);\n" - + " window.dump('hello');\n" - + " }\n" - + "}\n" - + "</script></head><body onload='test()'></body></html>"; + final String html + = "<html><head><title>foo</title><script>\n" + + "function test() {\n" + + " if (window.console) {\n" + + " var arr = ['one', 'two', 'three', document.body.children];\n" + + " window.console.log(arr);\n" + + " window.dump('hello');\n" + + " }\n" + + "}\n" + + "</script></head><body onload='test()'></body></html>"; - loadPage(html); - assertEquals("info: [\"one\", \"two\", \"three\", ({})]", messages.get(0)); - assertEquals("info: hello", messages.get(1)); + loadPage(html); + assertEquals("info: [\"one\", \"two\", \"three\", ({})]", messages.get(0)); + assertEquals("info: hello", messages.get(1)); + } } } |
From: <mgu...@us...> - 2012-12-18 17:03:53
|
Revision: 7886 http://sourceforge.net/p/htmlunit/code/7886 Author: mguillem Date: 2012-12-18 17:03:49 +0000 (Tue, 18 Dec 2012) Log Message: ----------- offsetHeight of most empty elements seems to be 0. It looks like it makes JQuery test 107 green for FF3_6 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCellElementTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2012-12-18 16:48:15 UTC (rev 7885) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/ComputedCSSStyleDeclaration.java 2012-12-18 17:03:49 UTC (rev 7886) @@ -15,8 +15,8 @@ package com.gargoylesoftware.htmlunit.javascript.host.css; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CAN_INHERIT_CSS_PROPERTY_VALUES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DEFAULT_ELEMENT_HEIGHT_MARKS_MIN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DEFAULT_ELEMENT_HEIGHT_15; -import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DEFAULT_ELEMENT_HEIGHT_MARKS_MIN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DEFAULT_WIDTH_AUTO; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_DISPLAY_DEFAULT; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_FONT_STRECH_DEFAULT_NORMAL; @@ -51,6 +51,8 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLBodyElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLCanvasElement; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLIFrameElement; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLTextAreaElement; /** * A JavaScript object for a ComputedCSSStyleDeclaration. @@ -1644,10 +1646,24 @@ final boolean explicitHeightSpecified = super.getHeight().length() > 0; - int defaultHeight = 20; - if (getBrowserVersion().hasFeature(CSS_DEFAULT_ELEMENT_HEIGHT_15)) { + final int defaultHeight; + if (getElement().getFirstChild() == null) { + if (getElement() instanceof HTMLIFrameElement) { + defaultHeight = 154; + } + else if (getElement() instanceof HTMLTextAreaElement) { + defaultHeight = 49; + } + else { + defaultHeight = 0; + } + } + else if (getBrowserVersion().hasFeature(CSS_DEFAULT_ELEMENT_HEIGHT_15)) { defaultHeight = 15; } + else { + defaultHeight = 20; + } final int defaultValue = getElement() instanceof HTMLCanvasElement ? 150 : windowHeight; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCellElementTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCellElementTest.java 2012-12-18 16:48:15 UTC (rev 7885) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLTableCellElementTest.java 2012-12-18 17:03:49 UTC (rev 7886) @@ -15,6 +15,7 @@ package com.gargoylesoftware.htmlunit.javascript.host.html; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import org.junit.Test; import org.junit.runner.RunWith; @@ -22,6 +23,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.BrowserRunner.Browsers; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -479,4 +481,25 @@ + "</html>"; loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "0", IE = { "1" }) + @NotYetImplemented(IE) + public void offsetHeight() throws Exception { + final String html = + "<html><body>\n" + + "<table><tr>\n" + + "<td style='padding:0' id='it'></td>\n" + + "<td style='display: none'>t</td>" + + "</tr></table>\n" + + "<script>\n" + + "var it = document.getElementById('it');\n" + + "alert(it.offsetHeight);\n" + + "</script>\n" + + "</body></html>"; + loadPageWithAlerts2(html); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-12-18 16:48:15 UTC (rev 7885) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/libraries/JQuery182Test.java 2012-12-18 17:03:49 UTC (rev 7886) @@ -16,9 +16,12 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF3_6; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF10; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF17; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE6; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE7; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.CHROME; import static org.junit.Assert.fail; import org.eclipse.jetty.server.Server; @@ -1093,7 +1096,7 @@ @Alerts(FF3_6 = "support: Verify that the support tests resolve as expected per browser (0, 30, 30)", FF10 = "data: expando (0, 1, 1)", CHROME = "data: expando (0, 1, 1)", IE = "support: Verify that the support tests resolve as expected per browser (6, 24, 30)") - @NotYetImplemented + @NotYetImplemented({ FF10, FF17, IE, CHROME }) public void test_107() throws Exception { runTest(107); } |
From: <asa...@us...> - 2012-12-19 05:37:13
|
Revision: 7889 http://sourceforge.net/p/htmlunit/code/7889 Author: asashour Date: 2012-12-19 05:37:11 +0000 (Wed, 19 Dec 2012) Log Message: ----------- Upper-case the charset detected from "meta" tag. Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-19 04:57:47 UTC (rev 7888) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-19 05:37:11 UTC (rev 7889) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="update" dev="asashour"> + Upper-case the charset detected from "meta" tag. + </action> <action type="update" dev="mguillem"> JavaScript: adjust availability of window.console (Firefox 4+, IE9+ and Chrome). </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-19 04:57:47 UTC (rev 7888) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-19 05:37:11 UTC (rev 7889) @@ -365,6 +365,7 @@ if (charset == null) { continue; } + charset = charset.toUpperCase(); } if (UTF16_BE.equalsIgnoreCase(charset) || UTF16_LE.equalsIgnoreCase(charset)) { charset = UTF8; 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 2012-12-19 04:57:47 UTC (rev 7888) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-19 05:37:11 UTC (rev 7889) @@ -1505,7 +1505,6 @@ @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) - @NotYetImplemented(FF) public void encoding3() throws Exception { final String html = "<html>\n" + "<head>\n" |
From: <asa...@us...> - 2012-12-19 06:52:55
|
Revision: 7890 http://sourceforge.net/p/htmlunit/code/7890 Author: asashour Date: 2012-12-19 06:52:52 +0000 (Wed, 19 Dec 2012) Log Message: ----------- Upper-case the charset detected from "meta" tag. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-19 05:37:11 UTC (rev 7889) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-19 06:52:52 UTC (rev 7890) @@ -365,12 +365,12 @@ if (charset == null) { continue; } - charset = charset.toUpperCase(); } if (UTF16_BE.equalsIgnoreCase(charset) || UTF16_LE.equalsIgnoreCase(charset)) { charset = UTF8; } if (isSupportedCharset(charset)) { + charset = charset.toUpperCase(); if (LOG.isDebugEnabled()) { LOG.debug("Encoding found in meta tag: '" + charset + "'."); } 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 2012-12-19 05:37:11 UTC (rev 7889) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-19 06:52:52 UTC (rev 7890) @@ -1551,4 +1551,32 @@ final WebDriver driver = loadPage2(html, URL_FIRST, "text/html;charset=UTF-8", "ISO-8859-1"); verifyAlerts(DEFAULT_WAIT_TIME, expectedAlerts, driver); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + FF = { "UTF-8", "UTF-8", "undefined", "undefined" }, + CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }) + public void encoding5() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + "<meta charset='UTF-8'>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.inputEncoding);\n" + + " alert(document.characterSet);\n" + + " alert(document.charset);\n" + + " alert(document.defaultCharset);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + " <a id='myId' href='test?è=è'>test</a>" + + "</body></html>"; + + final String[] expectedAlerts = getExpectedAlerts(); + final WebDriver driver = loadPage2(html, URL_FIRST, "text/html", "UTF-8"); + verifyAlerts(DEFAULT_WAIT_TIME, expectedAlerts, driver); + } } |
From: <asa...@us...> - 2012-12-20 03:12:30
|
Revision: 7892 http://sourceforge.net/p/htmlunit/code/7892 Author: asashour Date: 2012-12-20 03:12:25 +0000 (Thu, 20 Dec 2012) Log Message: ----------- Upper-case the charset detected from "meta" tag. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponse2Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlForm.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -230,7 +230,7 @@ */ private String getSubmitCharset() { if (getAcceptCharsetAttribute().length() > 0) { - return SUBMIT_CHARSET_PATTERN.matcher(getAcceptCharsetAttribute().trim()).replaceAll(""); + return SUBMIT_CHARSET_PATTERN.matcher(getAcceptCharsetAttribute().trim()).replaceAll("").toUpperCase(); } return getPage().getPageEncoding(); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/EncodingSniffer.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -295,6 +295,7 @@ final String value = pair.getValue(); encoding = extractEncodingFromContentType(value); if (encoding != null) { + encoding = encoding.toUpperCase(); break; } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponse2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponse2Test.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebResponse2Test.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -40,7 +40,7 @@ + "<body>foo</body>\n" + "</html>"; final HtmlPage page = loadPage(html); - assertEquals("utf-8", page.getWebResponse().getContentCharsetOrNull()); + assertEquals("UTF-8", page.getWebResponse().getContentCharsetOrNull()); assertEquals(html, page.getWebResponse().getContentAsString()); } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlFormTest.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -1149,12 +1149,12 @@ */ @Test public void submitRequestCharset() throws Exception { - submitRequestCharset("utf-8", null, null, "utf-8"); - submitRequestCharset(null, "utf-8", null, "utf-8"); - submitRequestCharset("iso-8859-1", null, "utf-8", "utf-8"); - submitRequestCharset("iso-8859-1", null, "utf-8, iso-8859-1", "utf-8"); - submitRequestCharset("utf-8", null, "iso-8859-1 utf-8", "iso-8859-1"); - submitRequestCharset("iso-8859-1", null, "utf-8, iso-8859-1", "utf-8"); + submitRequestCharset("utf-8", null, null, "UTF-8"); + submitRequestCharset(null, "utf-8", null, "UTF-8"); + submitRequestCharset("iso-8859-1", null, "utf-8", "UTF-8"); + submitRequestCharset("iso-8859-1", null, "utf-8, iso-8859-1", "UTF-8"); + submitRequestCharset("utf-8", null, "iso-8859-1 utf-8", "ISO-8859-1"); + submitRequestCharset("iso-8859-1", null, "utf-8, iso-8859-1", "UTF-8"); } /** @@ -1207,7 +1207,7 @@ webConnection.setDefaultResponse(html, 200, "ok", contentType); final HtmlPage page = client.getPage(getDefaultUrl()); - final String firstPageEncoding = StringUtils.defaultString(metaCharset, headerCharset); + final String firstPageEncoding = StringUtils.defaultString(metaCharset, headerCharset).toUpperCase(); assertEquals(firstPageEncoding, page.getPageEncoding()); final HtmlForm form = page.getFormByName("form1"); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPage3Test.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -24,6 +24,7 @@ import org.openqa.selenium.WebElement; import com.gargoylesoftware.htmlunit.BrowserRunner; +import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; import com.gargoylesoftware.htmlunit.WebDriverTestCase; /** @@ -93,4 +94,36 @@ Assert.assertEquals("js", input.getAttribute("addedBy")); Assert.assertEquals("js", input.getAttribute("addedby")); } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "undefined", "undefined", "iso-8859-1", "windows-1252" }, + FF = { "ISO-8859-1", "ISO-8859-1", "undefined", "undefined" }, + CHROME = { "ISO-8859-1", "ISO-8859-1", "ISO-8859-1", "ISO-8859-1" }) + public void getPageEncoding() throws Exception { + final String htmlContent = "<html><head>\n" + + " <title>foo</title>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=Shift_JIS'>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.inputEncoding);\n" + + " alert(document.characterSet);\n" + + " alert(document.charset);\n" + + " alert(document.defaultCharset);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + + "<table><tr><td>\n" + + "<meta name=vs_targetSchema content=\"http://schemas.microsoft.com/intellisense/ie5\">\n" + + "<form name='form1'>\n" + + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n" + + " <input type='text' name='textfield2' id='textfield2'/>\n" + + "</form>\n" + + "</td></tr></table>\n" + + "</body></html>"; + loadPageWithAlerts2(htmlContent); + } + } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlPageTest.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -607,28 +607,6 @@ } /** - * @throws Exception if the test fails - */ - @Test - public void testGetPageEncoding() throws Exception { - final String htmlContent = "<html><head>\n" - + "<title>foo</title>\n" - + "<meta http-equiv='Content-Type' content='text/html ;charset=Shift_JIS'>\n" - + "</head><body>\n" - + "<table><tr><td>\n" - + "<meta name=vs_targetSchema content=\"http://schemas.microsoft.com/intellisense/ie5\">\n" - + "<form name='form1'>\n" - + " <input type='text' name='textfield1' id='textfield1' value='foo' />\n" - + " <input type='text' name='textfield2' id='textfield2'/>\n" - + "</form>\n" - + "</td></tr></table>\n" - + "</body></html>"; - final HtmlPage page = loadPage(htmlContent); - - assertEquals("shift_jis", page.getPageEncoding()); - } - - /** * Verifies that an empty charset in a content-type meta tag is ignored. See bug 2484753. * @throws Exception if an error occurs */ 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 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -1562,7 +1562,7 @@ public void encoding5() throws Exception { final String html = "<html>\n" + "<head>\n" - + "<meta charset='UTF-8'>\n" + + " <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\n" + " <script>\n" + " function test() {\n" + " alert(document.inputEncoding);\n" @@ -1572,6 +1572,33 @@ + " }\n" + " </script>\n" + "</head><body onload='test()'>\n" + + "</body></html>"; + + final String[] expectedAlerts = getExpectedAlerts(); + final WebDriver driver = loadPage2(html, URL_FIRST, "text/html;charset=utf-8", "ISO-8859-1"); + verifyAlerts(DEFAULT_WAIT_TIME, expectedAlerts, driver); + } + + /** + * @throws Exception if the test fails + */ + @Test + @Alerts(IE = { "undefined", "undefined", "utf-8", "windows-1252" }, + FF = { "UTF-8", "UTF-8", "undefined", "undefined" }, + CHROME = { "UTF-8", "UTF-8", "UTF-8", "ISO-8859-1" }) + public void encoding6() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + " <meta charset='UTF-8'>\n" + + " <script>\n" + + " function test() {\n" + + " alert(document.inputEncoding);\n" + + " alert(document.characterSet);\n" + + " alert(document.charset);\n" + + " alert(document.defaultCharset);\n" + + " }\n" + + " </script>\n" + + "</head><body onload='test()'>\n" + " <a id='myId' href='test?è=è'>test</a>" + "</body></html>"; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java 2012-12-19 17:55:04 UTC (rev 7891) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/EncodingSnifferTest.java 2012-12-20 03:12:25 UTC (rev 7892) @@ -41,8 +41,8 @@ testHeader(null, "foo", "bar"); testHeader(null, "Content-Type", "blah"); testHeader(null, "Content-Type", "text/html;charset=blah"); - testHeader("utf-8", "Content-Type", "text/html;charset=utf-8"); - testHeader("utf-8", "Content-Type", "text/html;charset=utf-8;"); + testHeader("UTF-8", "Content-Type", "text/html;charset=utf-8"); + testHeader("UTF-8", "Content-Type", "text/html;charset=utf-8;"); } private void testHeader(final String expectedEncoding, final String headerName, final String headerValue) { @@ -72,10 +72,10 @@ testMeta(null, "<meta a='b'"); testMeta(null, "<meta a='b' c=d e=\"f\"/>"); testMeta(null, "<meta a='b' c=d e=\"f\" content='text/html; charset=blah' />"); - testMeta("utf-8", "<meta a='b' c=d e=\"f\" content='text/html; charset=utf-8' />"); - testMeta("utf-8", "abc <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>"); - testMeta("utf-8", "abc <meta http-equiv='Content-Type' content='text/html; CHARSET=UTF-8'/>"); - testMeta("utf-8", "abc <meta http-equiv='Content-Type' content='text/html; chArsEt=UtF-8'/>"); + testMeta("UTF-8", "<meta a='b' c=d e=\"f\" content='text/html; charset=utf-8' />"); + testMeta("UTF-8", "abc <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>"); + testMeta("UTF-8", "abc <meta http-equiv='Content-Type' content='text/html; CHARSET=UTF-8'/>"); + testMeta("UTF-8", "abc <meta http-equiv='Content-Type' content='text/html; chArsEt=UtF-8'/>"); } private void testMeta(final String expectedEncoding, final String content) { |
From: <asa...@us...> - 2012-12-21 18:55:51
|
Revision: 7897 http://sourceforge.net/p/htmlunit/code/7897 Author: asashour Date: 2012-12-21 18:55:47 +0000 (Fri, 21 Dec 2012) Log Message: ----------- CSS3: support prefix/suffix/substring attributes and GeneralAdjacentSibling selectors Issue 1466 Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-21 18:17:44 UTC (rev 7896) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-21 18:55:47 UTC (rev 7897) @@ -69,7 +69,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLHtmlElement; import com.steadystate.css.dom.CSSValueImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS21; +import com.steadystate.css.parser.SACParserCSS3; /** * A JavaScript object for a CSSStyleDeclaration. @@ -5607,7 +5607,7 @@ final InputSource source = new InputSource(new StringReader(styleAttribute)); source.setURI(uri); final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); try { styleDeclaration_ = parser.parseStyleDeclaration(source); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-21 18:17:44 UTC (rev 7896) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-21 18:55:47 UTC (rev 7897) @@ -93,9 +93,13 @@ import com.steadystate.css.dom.CSSStyleRuleImpl; import com.steadystate.css.dom.CSSStyleSheetImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS21; +import com.steadystate.css.parser.SACParserCSS3; import com.steadystate.css.parser.SelectorListImpl; +import com.steadystate.css.parser.selectors.GeneralAdjacentSelectorImpl; +import com.steadystate.css.parser.selectors.PrefixAttributeConditionImpl; import com.steadystate.css.parser.selectors.PseudoClassConditionImpl; +import com.steadystate.css.parser.selectors.SubstringAttributeConditionImpl; +import com.steadystate.css.parser.selectors.SuffixAttributeConditionImpl; /** * A JavaScript object for a Stylesheet. @@ -331,6 +335,17 @@ */ public static boolean selects(final BrowserVersion browserVersion, final Selector selector, final DomElement element) { + if (selector instanceof GeneralAdjacentSelectorImpl) { + final SiblingSelector ss = (SiblingSelector) selector; + for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) { + if (prev instanceof HtmlElement + && selects(browserVersion, ss.getSelector(), (HtmlElement) prev) + && selects(browserVersion, ss.getSiblingSelector(), element)) { + return true; + } + } + return false; + } switch (selector.getSelectorType()) { case Selector.SAC_ANY_NODE_SELECTOR: return true; @@ -402,6 +417,18 @@ * @return <tt>true</tt> if it does apply, <tt>false</tt> if it doesn't apply */ static boolean selects(final BrowserVersion browserVersion, final Condition condition, final DomElement element) { + if (condition instanceof PrefixAttributeConditionImpl) { + final AttributeCondition ac = (AttributeCondition) condition; + return element.getAttribute(ac.getLocalName()).startsWith(ac.getValue()); + } + if (condition instanceof SuffixAttributeConditionImpl) { + final AttributeCondition ac = (AttributeCondition) condition; + return element.getAttribute(ac.getLocalName()).endsWith(ac.getValue()); + } + if (condition instanceof SubstringAttributeConditionImpl) { + final AttributeCondition ac = (AttributeCondition) condition; + return element.getAttribute(ac.getLocalName()).contains(ac.getValue()); + } switch (condition.getConditionType()) { case Condition.SAC_ID_CONDITION: final AttributeCondition ac4 = (AttributeCondition) condition; @@ -578,7 +605,7 @@ org.w3c.dom.css.CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } @@ -605,7 +632,7 @@ SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); // in case of error parseSelectors returns null Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-21 18:17:44 UTC (rev 7896) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-21 18:55:47 UTC (rev 7897) @@ -34,7 +34,7 @@ public class CSSSelectorTest extends WebDriverTestCase { /** - * Test for bug 1287: CSS3 selector is not yet supported. + * Test for bug 1287. * * @throws Exception if an error occurs */ @@ -163,4 +163,109 @@ loadPageWithAlerts2(html); } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "1", "thing1" }) + public void prefixAttribute() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var list = document.querySelectorAll('[id^=\"thing\"]');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing1'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "1", "something" }) + public void suffixAttribute() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var list = document.querySelectorAll('[id$=\"thing\"]');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "2", "something", "thing2" }) + public void substringAttribute() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var list = document.querySelectorAll('[id*=\"thing\"]');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " alert(list[1].id);\n" + + " } catch(e) {alert('exception')}\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <ul id='something'></ul>\n" + + " <p></p>\n" + + " <ul id='thing2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts({ "1", "ul2" }) + public void generalAdjacentSelector() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " try {\n" + + " var list = document.querySelectorAll('div~ul');\n" + + " alert(list.length);\n" + + " alert(list[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <div></div>\n" + + " <p></p>\n" + + " <ul id='ul2'></ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } |
From: <asa...@us...> - 2012-12-22 06:13:09
|
Revision: 7898 http://sourceforge.net/p/htmlunit/code/7898 Author: asashour Date: 2012-12-22 06:13:04 +0000 (Sat, 22 Dec 2012) Log Message: ----------- Revert: CSS3, as it seems SACParserCSS3 has issues. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-21 18:55:47 UTC (rev 7897) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-22 06:13:04 UTC (rev 7898) @@ -59,7 +59,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS3; +import com.steadystate.css.parser.SACParserCSS21; /** * Base class for nodes in the HTML DOM tree. This class is modeled after the @@ -1558,7 +1558,7 @@ errorOccured.set(true); } }; - final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); final SelectorList selectorList = parser.parseSelectors(new InputSource(new StringReader(selectors))); // in case of error parseSelectors returns null Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-21 18:55:47 UTC (rev 7897) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-22 06:13:04 UTC (rev 7898) @@ -69,7 +69,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLHtmlElement; import com.steadystate.css.dom.CSSValueImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS3; +import com.steadystate.css.parser.SACParserCSS21; /** * A JavaScript object for a CSSStyleDeclaration. @@ -5607,7 +5607,7 @@ final InputSource source = new InputSource(new StringReader(styleAttribute)); source.setURI(uri); final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); try { styleDeclaration_ = parser.parseStyleDeclaration(source); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-21 18:55:47 UTC (rev 7897) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-22 06:13:04 UTC (rev 7898) @@ -93,7 +93,7 @@ import com.steadystate.css.dom.CSSStyleRuleImpl; import com.steadystate.css.dom.CSSStyleSheetImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS3; +import com.steadystate.css.parser.SACParserCSS21; import com.steadystate.css.parser.SelectorListImpl; import com.steadystate.css.parser.selectors.GeneralAdjacentSelectorImpl; import com.steadystate.css.parser.selectors.PrefixAttributeConditionImpl; @@ -605,7 +605,7 @@ org.w3c.dom.css.CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } @@ -632,7 +632,7 @@ SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); // in case of error parseSelectors returns null Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-21 18:55:47 UTC (rev 7897) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-22 06:13:04 UTC (rev 7898) @@ -19,6 +19,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -40,6 +41,7 @@ */ @Test @Alerts("li2") + @NotYetImplemented public void nth_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -88,6 +90,7 @@ */ @Test @Alerts({ "li1", "li4", "li7", "li10" }) + @NotYetImplemented public void nth_child_equation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -169,6 +172,7 @@ */ @Test @Alerts({ "1", "thing1" }) + @NotYetImplemented public void prefixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -195,6 +199,7 @@ */ @Test @Alerts({ "1", "something" }) + @NotYetImplemented public void suffixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -221,6 +226,7 @@ */ @Test @Alerts({ "2", "something", "thing2" }) + @NotYetImplemented public void substringAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -248,6 +254,7 @@ */ @Test @Alerts({ "1", "ul2" }) + @NotYetImplemented public void generalAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" |
From: <asa...@us...> - 2012-12-22 11:32:03
|
Revision: 7899 http://sourceforge.net/p/htmlunit/code/7899 Author: asashour Date: 2012-12-22 11:31:58 +0000 (Sat, 22 Dec 2012) Log Message: ----------- - Fix the encoding of clicked links to match the enclosing page (FF). - UrlUtils: deprecate encodeUrl(URL, boolean). Issue 1402 Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-22 11:31:58 UTC (rev 7899) @@ -9,6 +9,12 @@ <body> <release version="2.12" date="???" description="Bugfixes"> <action type="update" dev="asashour"> + UrlUtils: deprecate encodeUrl(URL, boolean). + </action> + <action type="fix" dev="asashour" issue="1402"> + Fix the encoding of clicked links to match the enclosing page (FF). + </action> + <action type="update" dev="asashour"> Upper-case the charset detected from "meta" tag. </action> <action type="update" dev="mguillem"> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/HttpWebConnection.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -241,7 +241,7 @@ // URLs; because of this we allow some Unicode chars in URLs. However, at this point we're // handing things over the HttpClient, and HttpClient will blow up if we leave these Unicode // chars in the URL. - final URL url = UrlUtils.encodeUrl(webRequest.getUrl(), false); + final URL url = UrlUtils.encodeUrl(webRequest.getUrl(), false, webRequest.getCharset()); final String charset = webRequest.getCharset(); // URIUtils.createURI is deprecated but as of httpclient-4.2.1, URIBuilder doesn't work here as it encodes path Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebClient.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -1422,7 +1422,8 @@ WebAssert.notNull("method", method); WebAssert.notNull("parameters", parameters); - url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING)); + url = UrlUtils.encodeUrl(url, getBrowserVersion().hasFeature(URL_MINIMAL_QUERY_ENCODING), + webRequest.getCharset()); webRequest.setUrl(url); if (LOG.isDebugEnabled()) { Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlAnchor.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -116,6 +116,7 @@ } final WebRequest webRequest = new WebRequest(url); + webRequest.setCharset(page.getPageEncoding()); webRequest.setAdditionalHeader("Referer", page.getUrl().toExternalForm()); if (LOG.isDebugEnabled()) { LOG.debug( Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/util/UrlUtils.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -22,6 +22,7 @@ import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.net.URLCodec; +import com.gargoylesoftware.htmlunit.TextUtil; import com.gargoylesoftware.htmlunit.WebAssert; /** @@ -203,8 +204,25 @@ * @param url the URL to encode * @param minimalQueryEncoding whether or not to perform minimal query encoding, like IE does * @return the encoded URL + * @deprecated as of 2.12, please use {@link #encodeUrl(URL, boolean, String)} instead */ + @Deprecated public static URL encodeUrl(final URL url, final boolean minimalQueryEncoding) { + return encodeUrl(url, minimalQueryEncoding, TextUtil.DEFAULT_CHARSET); + } + + /** + * <p>Encodes illegal characters in the specified URL's path, query string and anchor according to the URL + * encoding rules observed in real browsers.</p> + * + * <p>For example, this method changes <tt>"http://first/?a=b c"</tt> to <tt>"http://first/?a=b%20c"</tt>.</p> + * + * @param url the URL to encode + * @param minimalQueryEncoding whether or not to perform minimal query encoding, like IE does + * @param charset the charset + * @return the encoded URL + */ + public static URL encodeUrl(final URL url, final boolean minimalQueryEncoding, final String charset) { final String p = url.getProtocol(); if ("javascript".equalsIgnoreCase(p) || "about".equalsIgnoreCase(p) || "data".equalsIgnoreCase(p)) { // Special exception. @@ -213,7 +231,7 @@ try { String path = url.getPath(); if (path != null) { - path = encode(path, PATH_ALLOWED_CHARS, "utf-8"); + path = encode(path, PATH_ALLOWED_CHARS, "UTF-8"); } String query = url.getQuery(); if (query != null) { @@ -221,12 +239,12 @@ query = org.apache.commons.lang3.StringUtils.replace(query, " ", "%20"); } else { - query = encode(query, QUERY_ALLOWED_CHARS, "windows-1252"); + query = encode(query, QUERY_ALLOWED_CHARS, charset); } } String anchor = url.getRef(); if (anchor != null) { - anchor = encode(anchor, ANCHOR_ALLOWED_CHARS, "utf-8"); + anchor = encode(anchor, ANCHOR_ALLOWED_CHARS, "UTF-8"); } return createNewUrl(url.getProtocol(), url.getHost(), url.getPort(), path, anchor, query); } @@ -244,7 +262,7 @@ */ public static String encodeAnchor(String anchor) { if (anchor != null) { - anchor = encode(anchor, ANCHOR_ALLOWED_CHARS, "utf-8"); + anchor = encode(anchor, ANCHOR_ALLOWED_CHARS, "UTF-8"); } return anchor; } 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 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -1606,4 +1606,30 @@ final WebDriver driver = loadPage2(html, URL_FIRST, "text/html", "UTF-8"); verifyAlerts(DEFAULT_WAIT_TIME, expectedAlerts, driver); } + + /** + * @throws Exception if the test fails + */ + @Test + public void encoding7() throws Exception { + final String html = "<html>\n" + + "<head>\n" + + "<meta charset='UTF-8'>\n" + + "</head><body>\n" + + " <a id='myId' href='test?\u00E8=\u00E8'>test</a>" + + "</body></html>"; + + final WebDriver driver = loadPage2(html, URL_FIRST, "text/html", "UTF-8"); + driver.findElement(By.id("myId")).click(); + String actualQuery = driver.getCurrentUrl(); + actualQuery = actualQuery.substring(actualQuery.indexOf('?')); + final String expectedQuery; + if (getBrowserVersion().isIE()) { + expectedQuery = "?\u00E8=\u00E8"; + } + else { + expectedQuery = "?%C3%A8=%C3%A8"; + } + assertTrue(actualQuery.endsWith(expectedQuery)); + } } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java 2012-12-22 06:13:04 UTC (rev 7898) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/util/UrlUtilsTest.java 2012-12-22 11:31:58 UTC (rev 7899) @@ -19,6 +19,7 @@ import org.junit.Test; import com.gargoylesoftware.htmlunit.SimpleWebTestCase; +import com.gargoylesoftware.htmlunit.TextUtil; /** * Tests for {@link UrlUtils}. @@ -230,7 +231,8 @@ @Test public void percent() throws Exception { final URL url = new URL("http://localhost/bug%21.html"); - assertEquals("http://localhost/bug%21.html", UrlUtils.encodeUrl(url, false).toExternalForm()); + assertEquals("http://localhost/bug%21.html", + UrlUtils.encodeUrl(url, false, TextUtil.DEFAULT_CHARSET).toExternalForm()); } /** |
From: <asa...@us...> - 2012-12-25 04:58:51
|
Revision: 7912 http://sourceforge.net/p/htmlunit/code/7912 Author: asashour Date: 2012-12-25 04:58:47 +0000 (Tue, 25 Dec 2012) Log Message: ----------- trivial docs Modified Paths: -------------- trunk/htmlunit/src/site/xdoc/gettingStarted.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java Modified: trunk/htmlunit/src/site/xdoc/gettingStarted.xml =================================================================== --- trunk/htmlunit/src/site/xdoc/gettingStarted.xml 2012-12-24 08:02:25 UTC (rev 7911) +++ trunk/htmlunit/src/site/xdoc/gettingStarted.xml 2012-12-25 04:58:47 UTC (rev 7912) @@ -55,7 +55,7 @@ <source><![CDATA[ @Test public void homePage_Firefox() throws Exception { - final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10); + final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_17); final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net"); Assert.assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText()); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2012-12-24 08:02:25 UTC (rev 7911) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebClientTest.java 2012-12-25 04:58:47 UTC (rev 7912) @@ -820,11 +820,9 @@ final String htmlContent = "<html><head><title>foo</title></head><body></body></html>"; final File currentDirectory = new File((new File("")).getAbsolutePath()); final File tmpFile = File.createTempFile("test", ".html", currentDirectory); - System.out.println("Temporary file created: " + tmpFile.getAbsolutePath()); tmpFile.deleteOnExit(); final String encoding = (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding(); FileUtils.writeStringToFile(tmpFile, htmlContent, encoding); - System.out.println("Temporary file exists: " + tmpFile.exists()); // Test a normal file URL. |
From: <asa...@us...> - 2012-12-25 05:52:10
|
Revision: 7913 http://sourceforge.net/p/htmlunit/code/7913 Author: asashour Date: 2012-12-25 05:52:06 +0000 (Tue, 25 Dec 2012) Log Message: ----------- Fix URL handling of local files in windows, if they have folders starting with dot, thanks to Hudson Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-25 04:58:47 UTC (rev 7912) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-25 05:52:06 UTC (rev 7913) @@ -8,6 +8,9 @@ <body> <release version="2.12" date="???" description="Bugfixes"> + <action type="fix" dev="asashour"> + Fix URL handling of local files in windows, if they have folders starting with dot. + </action> <action type="add" dev="asashour"> JavaScript: add document.implementation.createDocument for Chrome. </action> Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2012-12-25 04:58:47 UTC (rev 7912) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2012-12-25 05:52:06 UTC (rev 7913) @@ -185,6 +185,9 @@ if (url.getRef() != null) { newFile += '#' + url.getRef(); } + if ("file".equals(url.getProtocol()) && url.getAuthority().endsWith(":")) { + newFile = ":" + newFile; + } url = new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile); } catch (final Exception e) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 04:58:47 UTC (rev 7912) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 05:52:06 UTC (rev 7913) @@ -175,4 +175,14 @@ final URL expected = new URL("http://xn--wgbh1c.com/" + internationalized); assertEquals(expected, request.getUrl()); } + + /** + * @throws Exception if the test fails + */ + @Test + public void hiddenFileInWindows() throws Exception { + final URL url = new URL("file://c:/testing/.hidden/folder"); + final WebRequest request = new WebRequest(url); + assertEquals(url.toExternalForm(), request.getUrl().toExternalForm()); + } } |
From: <asa...@us...> - 2012-12-25 06:59:29
|
Revision: 7914 http://sourceforge.net/p/htmlunit/code/7914 Author: asashour Date: 2012-12-25 06:59:26 +0000 (Tue, 25 Dec 2012) Log Message: ----------- Fix NPE Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2012-12-25 05:52:06 UTC (rev 7913) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/WebRequest.java 2012-12-25 06:59:26 UTC (rev 7914) @@ -185,7 +185,7 @@ if (url.getRef() != null) { newFile += '#' + url.getRef(); } - if ("file".equals(url.getProtocol()) && url.getAuthority().endsWith(":")) { + if ("file".equals(url.getProtocol()) && url.getAuthority() != null && url.getAuthority().endsWith(":")) { newFile = ":" + newFile; } url = new URL(url.getProtocol(), url.getHost(), url.getPort(), newFile); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 05:52:06 UTC (rev 7913) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 06:59:26 UTC (rev 7914) @@ -185,4 +185,13 @@ final WebRequest request = new WebRequest(url); assertEquals(url.toExternalForm(), request.getUrl().toExternalForm()); } + /** + * @throws Exception if the test fails + */ + @Test + public void hiddenFileInWindows2() throws Exception { + final URL url = new URL("file:/c:/testing/.hidden/folder"); + final WebRequest request = new WebRequest(url); + assertEquals(url.toExternalForm(), request.getUrl().toExternalForm()); + } } |
From: <asa...@us...> - 2012-12-25 07:04:01
|
Revision: 7915 http://sourceforge.net/p/htmlunit/code/7915 Author: asashour Date: 2012-12-25 07:03:58 +0000 (Tue, 25 Dec 2012) Log Message: ----------- checkstyle Modified Paths: -------------- trunk/htmlunit/src/changes/changes.xml trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java Modified: trunk/htmlunit/src/changes/changes.xml =================================================================== --- trunk/htmlunit/src/changes/changes.xml 2012-12-25 06:59:26 UTC (rev 7914) +++ trunk/htmlunit/src/changes/changes.xml 2012-12-25 07:03:58 UTC (rev 7915) @@ -9,7 +9,7 @@ <body> <release version="2.12" date="???" description="Bugfixes"> <action type="fix" dev="asashour"> - Fix URL handling of local files in windows, if they have folders starting with dot. + Fix URL handling of local files in Windows, if they have folders starting with dot. </action> <action type="add" dev="asashour"> JavaScript: add document.implementation.createDocument for Chrome. Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 06:59:26 UTC (rev 7914) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/WebRequestTest.java 2012-12-25 07:03:58 UTC (rev 7915) @@ -185,6 +185,7 @@ final WebRequest request = new WebRequest(url); assertEquals(url.toExternalForm(), request.getUrl().toExternalForm()); } + /** * @throws Exception if the test fails */ |
From: <rb...@us...> - 2012-12-27 17:21:53
|
Revision: 7916 http://sourceforge.net/p/htmlunit/code/7916 Author: rbri Date: 2012-12-27 17:21:50 +0000 (Thu, 27 Dec 2012) Log Message: ----------- % next try switching to the new CSS3 parser Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSFontFaceRule.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSRule.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -59,7 +59,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS21; +import com.steadystate.css.parser.SACParserCSS3; /** * Base class for nodes in the HTML DOM tree. This class is modeled after the @@ -1558,7 +1558,7 @@ errorOccured.set(true); } }; - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); final SelectorList selectorList = parser.parseSelectors(new InputSource(new StringReader(selectors))); // in case of error parseSelectors returns null Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSFontFaceRule.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSFontFaceRule.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSFontFaceRule.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -16,6 +16,8 @@ import java.util.regex.Pattern; +import org.apache.commons.lang3.StringUtils; + import com.gargoylesoftware.htmlunit.javascript.configuration.BrowserName; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass; import com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter; @@ -32,7 +34,7 @@ public class CSSFontFaceRule extends CSSRule { private static final Pattern REPLACEMENT_1 = Pattern.compile("font-family: ([^;]*);"); - private static final Pattern REPLACEMENT_2 = Pattern.compile("src: ([^;]*);"); + private static final Pattern REPLACEMENT_2 = Pattern.compile("src: url\\(([^;]*)\\);"); /** * Creates a new instance. JavaScript objects must have a default constructor. @@ -47,7 +49,7 @@ * @param stylesheet the Stylesheet of this rule. * @param rule the wrapped rule */ - protected CSSFontFaceRule(final CSSStyleSheet stylesheet, final org.w3c.dom.css.CSSRule rule) { + protected CSSFontFaceRule(final CSSStyleSheet stylesheet, final org.w3c.dom.css.CSSFontFaceRule rule) { super(stylesheet, rule); } @@ -61,9 +63,9 @@ @JsxGetter(@WebBrowser(BrowserName.FF)) public String getCssText() { String cssText = super.getCssText(); - cssText = cssText.replace("{ ", "{\n "); - cssText = cssText.replace("; }", ";\n}"); - cssText = cssText.replace("; ", ";\n "); + cssText = StringUtils.replace(cssText, "{", "{\n "); + cssText = StringUtils.replace(cssText, "}", ";\n}"); + cssText = StringUtils.replace(cssText, "; ", ";\n "); cssText = REPLACEMENT_1.matcher(cssText).replaceFirst("font-family: \"$1\";"); cssText = REPLACEMENT_2.matcher(cssText).replaceFirst("src: url(\"$1\");"); return cssText; Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSRule.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSRule.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSRule.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -92,10 +92,6 @@ case FONT_FACE_RULE: return new CSSFontFaceRule(stylesheet, (org.w3c.dom.css.CSSFontFaceRule) rule); default: - if (rule.getCssText().startsWith("@font-face")) { - // hack for the lack of support for @font-face in the SACParserCSS21 we currently use - return new CSSFontFaceRule(stylesheet, rule); - } throw new UnsupportedOperationException("CSSRule " + rule.getClass().getName() + " is not yet supported:" + rule.getCssText()); } Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleDeclaration.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -69,7 +69,7 @@ import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLHtmlElement; import com.steadystate.css.dom.CSSValueImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS21; +import com.steadystate.css.parser.SACParserCSS3; /** * A JavaScript object for a CSSStyleDeclaration. @@ -5607,7 +5607,7 @@ final InputSource source = new InputSource(new StringReader(styleAttribute)); source.setURI(uri); final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); try { styleDeclaration_ = parser.parseStyleDeclaration(source); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -93,7 +93,7 @@ import com.steadystate.css.dom.CSSStyleRuleImpl; import com.steadystate.css.dom.CSSStyleSheetImpl; import com.steadystate.css.parser.CSSOMParser; -import com.steadystate.css.parser.SACParserCSS21; +import com.steadystate.css.parser.SACParserCSS3; import com.steadystate.css.parser.SelectorListImpl; import com.steadystate.css.parser.selectors.GeneralAdjacentSelectorImpl; import com.steadystate.css.parser.selectors.PrefixAttributeConditionImpl; @@ -605,7 +605,7 @@ org.w3c.dom.css.CSSStyleSheet ss; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); ss = parser.parseStyleSheet(source, null, null); } @@ -632,7 +632,7 @@ SelectorList selectors; try { final ErrorHandler errorHandler = getWindow().getWebWindow().getWebClient().getCssErrorHandler(); - final CSSOMParser parser = new CSSOMParser(new SACParserCSS21()); + final CSSOMParser parser = new CSSOMParser(new SACParserCSS3()); parser.setErrorHandler(errorHandler); selectors = parser.parseSelectors(source); // in case of error parseSelectors returns null Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-25 07:03:58 UTC (rev 7915) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-27 17:21:50 UTC (rev 7916) @@ -19,6 +19,7 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -41,7 +42,7 @@ */ @Test @Alerts("li2") - @NotYetImplemented + @NotYetImplemented(Browser.IE) public void nth_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -90,7 +91,7 @@ */ @Test @Alerts({ "li1", "li4", "li7", "li10" }) - @NotYetImplemented + @NotYetImplemented(Browser.IE) public void nth_child_equation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -172,7 +173,6 @@ */ @Test @Alerts({ "1", "thing1" }) - @NotYetImplemented public void prefixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -199,7 +199,6 @@ */ @Test @Alerts({ "1", "something" }) - @NotYetImplemented public void suffixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -226,7 +225,6 @@ */ @Test @Alerts({ "2", "something", "thing2" }) - @NotYetImplemented public void substringAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -254,7 +252,6 @@ */ @Test @Alerts({ "1", "ul2" }) - @NotYetImplemented public void generalAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" |
From: <asa...@us...> - 2012-12-29 06:13:12
|
Revision: 7918 http://sourceforge.net/p/htmlunit/code/7918 Author: asashour Date: 2012-12-29 06:13:09 +0000 (Sat, 29 Dec 2012) Log Message: ----------- CSS3: nth_child selector Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.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 2012-12-29 05:18:30 UTC (rev 7917) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2012-12-29 06:13:09 UTC (rev 7918) @@ -97,7 +97,7 @@ * Indicates that the pseudo classes 'root', 'enabled', 'disabled' * and 'checked' are supported. */ - @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME) }) + @BrowserFeature({ @WebBrowser(FF), @WebBrowser(CHROME), @WebBrowser(value = IE, minVersion = 9) }) CSS_SPECIAL_PSEUDO_CLASSES, /** Internet Explorer versions 5 and later support the behavior property. The behavior property lets 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 2012-12-29 05:18:30 UTC (rev 7917) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2012-12-29 06:13:09 UTC (rev 7918) @@ -1880,7 +1880,7 @@ * @param selectors the selectors * @return the static node list */ - @JsxFunction({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(FF) }) + @JsxFunction({ @WebBrowser(value = IE, minVersion = 9), @WebBrowser(FF) }) public StaticNodeList querySelectorAll(final String selectors) { try { final List<Node> nodes = new ArrayList<Node>(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 05:18:30 UTC (rev 7917) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 06:13:09 UTC (rev 7918) @@ -19,8 +19,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.Browser; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -41,13 +39,14 @@ * @throws Exception if an error occurs */ @Test - @Alerts("li2") - @NotYetImplemented(Browser.IE) + @Alerts(DEFAULT = "li2", IE8 = { }) public void nth_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " alert(document.querySelectorAll('li:nth-child(2)')[0].id);\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('li:nth-child(2)')[0].id);\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" @@ -90,15 +89,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "li1", "li4", "li7", "li10" }) - @NotYetImplemented(Browser.IE) + @Alerts(DEFAULT = { "li1", "li4", "li7", "li10" }, IE8 = { }) public void nth_child_equation() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " var list = document.querySelectorAll('li:nth-child(3n+1)');\n" - + " for (var i = 0 ; i < list.length; i++) {\n" - + " alert(list[i].id);\n" + + " if (document.querySelectorAll) {\n" + + " var list = document.querySelectorAll('li:nth-child(3n+1)');\n" + + " for (var i = 0 ; i < list.length; i++) {\n" + + " alert(list[i].id);\n" + + " }\n" + " }\n" + "}\n" + "</script></head>\n" @@ -146,16 +146,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "1", "ul2" }) + @Alerts(DEFAULT = { "1", "ul2" }, IE8 = { }) public void directAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " try {\n" + + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('p+ul');\n" + " alert(list.length);\n" + " alert(list[0].id);\n" - + " } catch(e) {alert('exception')}\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" @@ -172,16 +172,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "1", "thing1" }) + @Alerts(DEFAULT = { "1", "thing1" }, IE8 = { }) public void prefixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " try {\n" + + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('[id^=\"thing\"]');\n" + " alert(list.length);\n" + " alert(list[0].id);\n" - + " } catch(e) {alert('exception')}\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" @@ -198,16 +198,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "1", "something" }) + @Alerts(DEFAULT = { "1", "something" }, IE8 = { }) public void suffixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " try {\n" + + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('[id$=\"thing\"]');\n" + " alert(list.length);\n" + " alert(list[0].id);\n" - + " } catch(e) {alert('exception')}\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" @@ -224,17 +224,17 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "2", "something", "thing2" }) + @Alerts(DEFAULT = { "2", "something", "thing2" }, IE8 = { }) public void substringAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " try {\n" + + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('[id*=\"thing\"]');\n" + " alert(list.length);\n" + " alert(list[0].id);\n" + " alert(list[1].id);\n" - + " } catch(e) {alert('exception')}\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" @@ -251,16 +251,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts({ "1", "ul2" }) + @Alerts(DEFAULT = { "1", "ul2" }, IE8 = { }) public void generalAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + "function test() {\n" - + " try {\n" + + " if (document.querySelectorAll) {\n" + " var list = document.querySelectorAll('div~ul');\n" + " alert(list.length);\n" + " alert(list[0].id);\n" - + " } catch(e) {alert('exception')}\n" + + " }\n" + "}\n" + "</script></head>\n" + "<body onload='test()'>\n" 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 2012-12-29 05:18:30 UTC (rev 7917) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-29 06:13:09 UTC (rev 7918) @@ -859,9 +859,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "3", "div1" }, - IE = "undefined", - IE8 = { "3", "div1" }) + @Alerts(DEFAULT = { "3", "div1" }, IE8 = "undefined") public void querySelectorAll() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Test</title>\n" + "<style>\n" |
From: <asa...@us...> - 2012-12-29 07:44:47
|
Revision: 7919 http://sourceforge.net/p/htmlunit/code/7919 Author: asashour Date: 2012-12-29 07:44:37 +0000 (Sat, 29 Dec 2012) Log Message: ----------- document.querySelectorAll seems to be used by Prototype, but not in real IE8, for further investigations. Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 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 2012-12-29 06:13:09 UTC (rev 7918) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocument.java 2012-12-29 07:44:37 UTC (rev 7919) @@ -1880,7 +1880,7 @@ * @param selectors the selectors * @return the static node list */ - @JsxFunction({ @WebBrowser(value = IE, minVersion = 9), @WebBrowser(FF) }) + @JsxFunction({ @WebBrowser(value = IE, minVersion = 8), @WebBrowser(FF) }) public StaticNodeList querySelectorAll(final String selectors) { try { final List<Node> nodes = new ArrayList<Node>(); Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 06:13:09 UTC (rev 7918) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 07:44:37 UTC (rev 7919) @@ -14,11 +14,14 @@ */ package com.gargoylesoftware.htmlunit.javascript.host.css; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; + import org.junit.Test; import org.junit.runner.RunWith; import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; +import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -40,6 +43,7 @@ */ @Test @Alerts(DEFAULT = "li2", IE8 = { }) + @NotYetImplemented(IE8) public void nth_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -147,6 +151,7 @@ */ @Test @Alerts(DEFAULT = { "1", "ul2" }, IE8 = { }) + @NotYetImplemented(IE8) public void directAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -173,6 +178,7 @@ */ @Test @Alerts(DEFAULT = { "1", "thing1" }, IE8 = { }) + @NotYetImplemented(IE8) public void prefixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -199,6 +205,7 @@ */ @Test @Alerts(DEFAULT = { "1", "something" }, IE8 = { }) + @NotYetImplemented(IE8) public void suffixAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -225,6 +232,7 @@ */ @Test @Alerts(DEFAULT = { "2", "something", "thing2" }, IE8 = { }) + @NotYetImplemented(IE8) public void substringAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -252,6 +260,7 @@ */ @Test @Alerts(DEFAULT = { "1", "ul2" }, IE8 = { }) + @NotYetImplemented(IE8) public void generalAdjacentSelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" 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 2012-12-29 06:13:09 UTC (rev 7918) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-29 07:44:37 UTC (rev 7919) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.FF3_6; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE; +import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.IE8; import static com.gargoylesoftware.htmlunit.BrowserRunner.Browser.NONE; import static com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.EMPTY_COOKIE_NAME; import static com.gargoylesoftware.htmlunit.util.StringUtils.parseHttpDate; @@ -860,6 +861,7 @@ */ @Test @Alerts(DEFAULT = { "3", "div1" }, IE8 = "undefined") + @NotYetImplemented(IE8) public void querySelectorAll() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Test</title>\n" + "<style>\n" |
From: <asa...@us...> - 2012-12-29 09:03:26
|
Revision: 7920 http://sourceforge.net/p/htmlunit/code/7920 Author: asashour Date: 2012-12-29 09:03:23 +0000 (Sat, 29 Dec 2012) Log Message: ----------- More CSS3 selectors Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-29 07:44:37 UTC (rev 7919) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-29 09:03:23 UTC (rev 7920) @@ -131,7 +131,9 @@ private String uri_; private static final Collection<String> PSEUDO_CLASSES = Arrays.asList("link", "visited", "hover", "active", - "focus", "target", "lang", "disabled", "checked", "indeterminated", "root", "nth-child()"); + "focus", "target", "lang", "disabled", "enabled", "checked", "indeterminated", "root", + "nth-child()", "nth-last-child()", "nth-of-type()", "nth-last-of-type()", + "first-child", "last-child", "first-of-type", "last-of-type", "only-child", "only-of-type", "empty"); /** * Creates a new empty stylesheet. @@ -546,6 +548,40 @@ return (element instanceof HtmlCheckBoxInput && ((HtmlCheckBoxInput) element).isChecked()) || (element instanceof HtmlRadioButtonInput && ((HtmlRadioButtonInput) element).isChecked()); } + else if ("first-child".equals(value)) { + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("last-child".equals(value)) { + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("first-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } + else if ("last-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } else if (value.startsWith("nth-child(")) { final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); int index = 0; @@ -556,6 +592,65 @@ } return getNth(nth, index); } + else if (value.startsWith("nth-last-child(")) { + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + index++; + } + } + return getNth(nth, index); + } + else if (value.startsWith("nth-of-type(")) { + final String type = element.getNodeName(); + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + index++; + } + } + return getNth(nth, index); + } + else if (value.startsWith("nth-last-of-type(")) { + final String type = element.getNodeName(); + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + index++; + } + } + return getNth(nth, index); + } + else if ("only-child".equals(value)) { + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement) { + return false; + } + } + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("only-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 07:44:37 UTC (rev 7919) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 09:03:23 UTC (rev 7920) @@ -281,4 +281,246 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "li3", IE8 = { }) + @NotYetImplemented(IE8) + public void nth_last_child() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('li:nth-last-child(1)')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<ul>\n" + + " <li id='li1'></li>\n" + + " <li id='li2'></li>\n" + + " <li id='li3'></li>\n" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id3", IE8 = { }) + @NotYetImplemented(IE8) + public void nth_of_type() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('p:nth-of-type(2)')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <h1 id='id11'></h1>\n" + + " <p id='id2'></p>\n" + + " <p id='id3'></p>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id3", IE8 = { }) + @NotYetImplemented(IE8) + public void nth_last_of_type() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('p:nth-last-of-type(1)')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <h1 id='id1'></h1>\n" + + " <p id='id2'></p>\n" + + " <p id='id3'></p>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "li1", IE8 = { }) + @NotYetImplemented(IE8) + public void first_child() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('li:first-child')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<ul>\n" + + " <li id='li1'></li>\n" + + " <li id='li2'></li>\n" + + " <li id='li3'></li>\n" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "li3", IE8 = { }) + @NotYetImplemented(IE8) + public void last_child() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('li:last-child')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<ul>\n" + + " <li id='li1'></li>\n" + + " <li id='li2'></li>\n" + + " <li id='li3'></li>\n" + + "</ul>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id2", IE8 = { }) + @NotYetImplemented(IE8) + public void first_of_type() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('p:first-of-type')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <h1 id='id1'></h1>\n" + + " <p id='id2'></p>\n" + + " <h1 id='id3'></h1>\n" + + " <p id='id4'></p>\n" + + " <h1 id='id5'></h1>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id4", IE8 = { }) + @NotYetImplemented(IE8) + public void last_of_type() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('p:last-of-type')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <h1 id='id1'></h1>\n" + + " <p id='id2'></p>\n" + + " <h1 id='id3'></h1>\n" + + " <p id='id4'></p>\n" + + " <h1 id='id5'></h1>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id3", IE8 = { }) + @NotYetImplemented(IE8) + public void only_child() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('h1:only-child')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <h1 id='id1'></h1>\n" + + " <p id='id2'></p>\n" + + "</section>\n" + + "<section>\n" + + " <h1 id='id3'></h1>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id3", IE8 = { }) + @NotYetImplemented(IE8) + public void only_of_type() throws Exception { + final String html + = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " alert(document.querySelectorAll('p:only-of-type')[0].id);\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + "<section>\n" + + " <p id='id1'></p>\n" + + " <p id='id2'></p>\n" + + "</section>\n" + + "<section>\n" + + " <p id='id3'></p>\n" + + "</section>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } |
From: <asa...@us...> - 2012-12-30 05:13:32
|
Revision: 7921 http://sourceforge.net/p/htmlunit/code/7921 Author: asashour Date: 2012-12-30 05:13:27 +0000 (Sun, 30 Dec 2012) Log Message: ----------- Revert: more CSS3 selectors Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-29 09:03:23 UTC (rev 7920) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-30 05:13:27 UTC (rev 7921) @@ -131,9 +131,7 @@ private String uri_; private static final Collection<String> PSEUDO_CLASSES = Arrays.asList("link", "visited", "hover", "active", - "focus", "target", "lang", "disabled", "enabled", "checked", "indeterminated", "root", - "nth-child()", "nth-last-child()", "nth-of-type()", "nth-last-of-type()", - "first-child", "last-child", "first-of-type", "last-of-type", "only-child", "only-of-type", "empty"); + "focus", "target", "lang", "disabled", "checked", "indeterminated", "root", "nth-child()"); /** * Creates a new empty stylesheet. @@ -548,40 +546,6 @@ return (element instanceof HtmlCheckBoxInput && ((HtmlCheckBoxInput) element).isChecked()) || (element instanceof HtmlRadioButtonInput && ((HtmlRadioButtonInput) element).isChecked()); } - else if ("first-child".equals(value)) { - for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { - if (n instanceof DomElement) { - return false; - } - } - return true; - } - else if ("last-child".equals(value)) { - for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { - if (n instanceof DomElement) { - return false; - } - } - return true; - } - else if ("first-of-type".equals(value)) { - final String type = element.getNodeName(); - for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - return false; - } - } - return true; - } - else if ("last-of-type".equals(value)) { - final String type = element.getNodeName(); - for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - return false; - } - } - return true; - } else if (value.startsWith("nth-child(")) { final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); int index = 0; @@ -592,65 +556,6 @@ } return getNth(nth, index); } - else if (value.startsWith("nth-last-child(")) { - final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); - int index = 0; - for (DomNode n = element; n != null; n = n.getNextSibling()) { - if (n instanceof DomElement) { - index++; - } - } - return getNth(nth, index); - } - else if (value.startsWith("nth-of-type(")) { - final String type = element.getNodeName(); - final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); - int index = 0; - for (DomNode n = element; n != null; n = n.getPreviousSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - index++; - } - } - return getNth(nth, index); - } - else if (value.startsWith("nth-last-of-type(")) { - final String type = element.getNodeName(); - final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); - int index = 0; - for (DomNode n = element; n != null; n = n.getNextSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - index++; - } - } - return getNth(nth, index); - } - else if ("only-child".equals(value)) { - for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { - if (n instanceof DomElement) { - return false; - } - } - for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { - if (n instanceof DomElement) { - return false; - } - } - return true; - } - else if ("only-of-type".equals(value)) { - final String type = element.getNodeName(); - for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - return false; - } - } - for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { - if (n instanceof DomElement && n.getNodeName().equals(type)) { - return false; - } - } - return true; - } return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-29 09:03:23 UTC (rev 7920) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-30 05:13:27 UTC (rev 7921) @@ -286,7 +286,7 @@ */ @Test @Alerts(DEFAULT = "li3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void nth_last_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -312,7 +312,7 @@ */ @Test @Alerts(DEFAULT = "id3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void nth_of_type() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -338,7 +338,7 @@ */ @Test @Alerts(DEFAULT = "id3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void nth_last_of_type() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -364,7 +364,7 @@ */ @Test @Alerts(DEFAULT = "li1", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void first_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -390,7 +390,7 @@ */ @Test @Alerts(DEFAULT = "li3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void last_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -416,7 +416,7 @@ */ @Test @Alerts(DEFAULT = "id2", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void first_of_type() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -444,7 +444,7 @@ */ @Test @Alerts(DEFAULT = "id4", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void last_of_type() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -472,7 +472,7 @@ */ @Test @Alerts(DEFAULT = "id3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void only_child() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" @@ -500,7 +500,7 @@ */ @Test @Alerts(DEFAULT = "id3", IE8 = { }) - @NotYetImplemented(IE8) + @NotYetImplemented public void only_of_type() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>First</title><script>\n" 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 2012-12-29 09:03:23 UTC (rev 7920) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLDocumentTest.java 2012-12-30 05:13:27 UTC (rev 7921) @@ -1002,7 +1002,7 @@ */ @Test @Alerts(DEFAULT = { "div1", "null" }, - IE = "undefined", IE8 = { "div1", "null" }) + IE6 = "undefined", IE7 = "undefined") public void querySelector() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>Test</title>\n" + "<style>\n" |
From: <asa...@us...> - 2012-12-31 05:02:45
|
Revision: 7924 http://sourceforge.net/p/htmlunit/code/7924 Author: asashour Date: 2012-12-31 05:02:39 +0000 (Mon, 31 Dec 2012) Log Message: ----------- Fixing build Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-30 13:57:46 UTC (rev 7923) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-31 05:02:39 UTC (rev 7924) @@ -16,6 +16,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_SELECTOR_LANG; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.CSS_SPECIAL_PSEUDO_CLASSES; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_EXPANDURL; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_STYLE_EMPTY; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_STYLE_NULL; @@ -86,6 +87,7 @@ import com.gargoylesoftware.htmlunit.javascript.configuration.WebBrowser; import com.gargoylesoftware.htmlunit.javascript.host.Element; import com.gargoylesoftware.htmlunit.javascript.host.Window; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.gargoylesoftware.htmlunit.util.UrlUtils; import com.steadystate.css.dom.CSSImportRuleImpl; @@ -531,6 +533,11 @@ if (!browserVersion.hasFeature(CSS_SPECIAL_PSEUDO_CLASSES)) { return false; } + if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS) + && ((HTMLDocument) ((Window) element.getScriptObject().getParentScope()).getDocument()) + .getDocumentMode() < 9) { + return false; + } final String value = condition.getValue(); if ("root".equals(value)) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2012-12-30 13:57:46 UTC (rev 7923) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/CodeStyleTest.java 2012-12-31 05:02:39 UTC (rev 7924) @@ -543,7 +543,8 @@ private void browserVersion_isIE(final List<String> lines, final String relativePath) { if (relativePath.replace('\\', '/').contains("src/main/java") && !relativePath.contains("JavaScriptConfiguration") - && !relativePath.contains("BrowserVersionFeatures")) { + && !relativePath.contains("BrowserVersionFeatures") + && !relativePath.contains("HTMLDocument")) { int index = 1; for (final String line : lines) { if ((line.contains(".isIE()") || line.contains(".isFirefox()"))) { Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java 2012-12-30 13:57:46 UTC (rev 7923) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/html/HTMLElement2Test.java 2012-12-31 05:02:39 UTC (rev 7924) @@ -868,8 +868,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(FF = { "3", "div1" }, - IE = "undefined", IE8 = { "3", "div1" }) + @Alerts(FF = { "3", "div1" }, IE = "undefined") public void querySelectorAll() throws Exception { final String html = "<html><head><title>Test</title>\n" + "<style>\n" @@ -901,9 +900,7 @@ * @throws Exception if the test fails */ @Test - @Alerts(DEFAULT = { "1", "p1" }, - IE6 = "undefined", - IE7 = "undefined") + @Alerts(DEFAULT = { "1", "p1" }, IE = "undefined") public void querySelectorAllOnDisconnectedElement() throws Exception { final String html = "<html><head><title>Test</title>\n" + "<script>\n" |
From: <asa...@us...> - 2012-12-31 06:54:55
|
Revision: 7927 http://sourceforge.net/p/htmlunit/code/7927 Author: asashour Date: 2012-12-31 06:54:50 +0000 (Mon, 31 Dec 2012) Log Message: ----------- - IE handles CSS3 only when the corresponding documentMode allows - More CSS3 selectors Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-31 05:39:24 UTC (rev 7926) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2012-12-31 06:54:50 UTC (rev 7927) @@ -17,6 +17,7 @@ import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DISPLAYED_COLLAPSE; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.DOM_NORMALIZE_REMOVE_CHILDREN; import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.NODE_APPEND_CHILD_SELF_IGNORE; +import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS; import java.io.IOException; import java.io.PrintWriter; @@ -55,8 +56,10 @@ import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.xpath.XPathUtils; import com.gargoylesoftware.htmlunit.javascript.SimpleScriptable; +import com.gargoylesoftware.htmlunit.javascript.host.Window; import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleDeclaration; import com.gargoylesoftware.htmlunit.javascript.host.css.CSSStyleSheet; +import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument; import com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement; import com.steadystate.css.parser.CSSOMParser; import com.steadystate.css.parser.SACParserCSS3; @@ -1566,9 +1569,17 @@ throw new CSSException("Invalid selectors: " + selectors); } if (null != selectorList) { - CSSStyleSheet.validateSelectors(selectorList); + final BrowserVersion browserVersion = webClient.getBrowserVersion(); + final int documentMode; + if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS)) { + documentMode = ((HTMLDocument) ((Window) getScriptObject().getParentScope()).getDocument()) + .getDocumentMode(); + } + else { + documentMode = 9; + } + CSSStyleSheet.validateSelectors(selectorList, documentMode); - final BrowserVersion browserVersion = webClient.getBrowserVersion(); for (final HtmlElement child : getHtmlElementDescendants()) { for (int i = 0; i < selectorList.getLength(); i++) { final Selector selector = selectorList.item(i); Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-31 05:39:24 UTC (rev 7926) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-31 06:54:50 UTC (rev 7927) @@ -29,6 +29,7 @@ import java.io.StringReader; import java.net.MalformedURLException; import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -131,9 +132,18 @@ /** This stylesheet's URI (used to resolved contained @import rules). */ private String uri_; - private static final Collection<String> PSEUDO_CLASSES = Arrays.asList("link", "visited", "hover", "active", - "focus", "target", "lang", "disabled", "checked", "indeterminated", "root", "nth-child()"); + private static final Collection<String> CSS2_PSEUDO_CLASSES = Arrays.asList("link", "visited", "hover", "active", + "focus", "lang", "first-child"); + private static final Collection<String> CSS3_PSEUDO_CLASSES = new ArrayList<String>(Arrays.asList( + "checked", "disabled", "indeterminated", "root", "target", + "nth-child()", "nth-last-child()", "nth-of-type()", "nth-last-of-type()", + "last-child", "first-of-type", "last-of-type", "only-child", "only-of-type", "empty")); + + static { + CSS3_PSEUDO_CLASSES.addAll(CSS2_PSEUDO_CLASSES); + } + /** * Creates a new empty stylesheet. */ @@ -531,7 +541,7 @@ final AttributeCondition condition, final DomElement element) { if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS) && ((HTMLDocument) ((Window) element.getScriptObject().getParentScope()).getDocument()) - .getDocumentMode() < 9) { + .getDocumentMode() < 8) { return false; } @@ -549,6 +559,40 @@ return (element instanceof HtmlCheckBoxInput && ((HtmlCheckBoxInput) element).isChecked()) || (element instanceof HtmlRadioButtonInput && ((HtmlRadioButtonInput) element).isChecked()); } + else if ("first-child".equals(value)) { + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("last-child".equals(value)) { + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("first-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } + else if ("last-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } else if (value.startsWith("nth-child(")) { final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); int index = 0; @@ -559,6 +603,65 @@ } return getNth(nth, index); } + else if (value.startsWith("nth-last-child(")) { + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + index++; + } + } + return getNth(nth, index); + } + else if (value.startsWith("nth-of-type(")) { + final String type = element.getNodeName(); + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + index++; + } + } + return getNth(nth, index); + } + else if (value.startsWith("nth-last-of-type(")) { + final String type = element.getNodeName(); + final String nth = value.substring(value.indexOf('(') + 1, value.length() - 1); + int index = 0; + for (DomNode n = element; n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + index++; + } + } + return getNth(nth, index); + } + else if ("only-child".equals(value)) { + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement) { + return false; + } + } + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement) { + return false; + } + } + return true; + } + else if ("only-of-type".equals(value)) { + final String type = element.getNodeName(); + for (DomNode n = element.getPreviousSibling(); n != null; n = n.getPreviousSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + for (DomNode n = element.getNextSibling(); n != null; n = n.getNextSibling()) { + if (n instanceof DomElement && n.getNodeName().equals(type)) { + return false; + } + } + return true; + } return false; } @@ -883,42 +986,53 @@ /** * Validates the list of selectors. * @param selectorList the selectors + * @param documentMode see {@link HTMLDocument#getDocumentMode()} * @throws CSSException if a selector is invalid */ - public static void validateSelectors(final SelectorList selectorList) throws CSSException { + public static void validateSelectors(final SelectorList selectorList, final int documentMode) throws CSSException { for (int i = 0; i < selectorList.getLength(); ++i) { final Selector item = selectorList.item(i); - if (!isValidSelector(item)) { + if (!isValidSelector(item, documentMode)) { throw new CSSException("Invalid selector: " + item); } } } - private static boolean isValidSelector(final Selector selector) { + /** + * @param documentMode see {@link HTMLDocument#getDocumentMode()} + */ + private static boolean isValidSelector(final Selector selector, final int documentMode) { switch (selector.getSelectorType()) { case Selector.SAC_ELEMENT_NODE_SELECTOR: return true; case Selector.SAC_CONDITIONAL_SELECTOR: final ConditionalSelector conditional = (ConditionalSelector) selector; - return isValidSelector(conditional.getSimpleSelector()) && isValidSelector(conditional.getCondition()); + return isValidSelector(conditional.getSimpleSelector(), documentMode) + && isValidSelector(conditional.getCondition(), documentMode); case Selector.SAC_DESCENDANT_SELECTOR: case Selector.SAC_CHILD_SELECTOR: final DescendantSelector ds = (DescendantSelector) selector; - return isValidSelector(ds.getAncestorSelector()) && isValidSelector(ds.getSimpleSelector()); + return isValidSelector(ds.getAncestorSelector(), documentMode) + && isValidSelector(ds.getSimpleSelector(), documentMode); case Selector.SAC_DIRECT_ADJACENT_SELECTOR: final SiblingSelector ss = (SiblingSelector) selector; - return isValidSelector(ss.getSelector()) && isValidSelector(ss.getSiblingSelector()); + return isValidSelector(ss.getSelector(), documentMode) + && isValidSelector(ss.getSiblingSelector(), documentMode); default: LOG.warn("Unhandled CSS selector type '" + selector.getSelectorType() + "'. Accepting it silently."); return true; // at least in a first time to break less stuff } } - private static boolean isValidSelector(final Condition condition) { + /** + * @param documentMode see {@link HTMLDocument#getDocumentMode()} + */ + private static boolean isValidSelector(final Condition condition, final int documentMode) { switch (condition.getConditionType()) { case Condition.SAC_AND_CONDITION: final CombinatorCondition cc1 = (CombinatorCondition) condition; - return isValidSelector(cc1.getFirstCondition()) && isValidSelector(cc1.getSecondCondition()); + return isValidSelector(cc1.getFirstCondition(), documentMode) + && isValidSelector(cc1.getSecondCondition(), documentMode); case Condition.SAC_ATTRIBUTE_CONDITION: case Condition.SAC_ID_CONDITION: case Condition.SAC_CLASS_CONDITION: @@ -932,7 +1046,10 @@ } value = value.substring(0, value.indexOf('(') + 1) + ')'; } - return PSEUDO_CLASSES.contains(value); + if (documentMode < 9) { + return CSS2_PSEUDO_CLASSES.contains(value); + } + return CSS3_PSEUDO_CLASSES.contains(value); default: LOG.warn("Unhandled CSS condition type '" + condition.getConditionType() + "'. Accepting it silently."); return true; Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-31 05:39:24 UTC (rev 7926) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-31 06:54:50 UTC (rev 7927) @@ -19,7 +19,6 @@ import com.gargoylesoftware.htmlunit.BrowserRunner; import com.gargoylesoftware.htmlunit.BrowserRunner.Alerts; -import com.gargoylesoftware.htmlunit.BrowserRunner.NotYetImplemented; import com.gargoylesoftware.htmlunit.WebDriverTestCase; import com.gargoylesoftware.htmlunit.html.HtmlPageTest; @@ -40,10 +39,10 @@ * @throws Exception if an error occurs */ @Test - @Alerts(DEFAULT = "li2", IE = "exception") + @Alerts(DEFAULT = "li2", IE8 = "exception") public void nth_child() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" @@ -285,15 +284,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("li3") - @NotYetImplemented + @Alerts(DEFAULT = "li3", IE8 = "exception") public void nth_last_child() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('li:nth-last-child(1)')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('li:nth-last-child(1)')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -312,15 +312,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id3") - @NotYetImplemented + @Alerts(DEFAULT = "id3", IE8 = "exception") public void nth_of_type() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('p:nth-of-type(2)')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('p:nth-of-type(2)')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -339,15 +340,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id3") - @NotYetImplemented + @Alerts(DEFAULT = "id3", IE8 = "exception") public void nth_last_of_type() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('p:nth-last-of-type(1)')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('p:nth-last-of-type(1)')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -367,7 +369,6 @@ */ @Test @Alerts("li1") - @NotYetImplemented public void first_child() throws Exception { final String html = "<html><head><title>First</title>\n" + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" @@ -393,15 +394,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("li3") - @NotYetImplemented + @Alerts(DEFAULT = "li3", IE8 = "exception") public void last_child() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('li:last-child')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('li:last-child')[0].id);\n" + + " } catch (e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -420,15 +422,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id2") - @NotYetImplemented + @Alerts(DEFAULT = "id2", IE8 = "exception") public void first_of_type() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('p:first-of-type')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('p:first-of-type')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -449,15 +452,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id4") - @NotYetImplemented + @Alerts(DEFAULT = "id4", IE8 = "exception") public void last_of_type() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('p:last-of-type')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('p:last-of-type')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -478,15 +482,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id3") - @NotYetImplemented + @Alerts(DEFAULT = "id3", IE8 = "exception") public void only_child() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('h1:only-child')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('h1:only-child')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" @@ -507,15 +512,16 @@ * @throws Exception if an error occurs */ @Test - @Alerts("id3") - @NotYetImplemented + @Alerts(DEFAULT = "id3", IE8 = "exception") public void only_of_type() throws Exception { final String html = "<html><head><title>First</title>\n" - + "<meta http-equiv='X-UA-Compatible' content='IE=8'>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + "<script>\n" + "function test() {\n" + " if (document.querySelectorAll) {\n" - + " alert(document.querySelectorAll('p:only-of-type')[0].id);\n" + + " try {\n" + + " alert(document.querySelectorAll('p:only-of-type')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + " }\n" + "}\n" + "</script></head>\n" |
From: <asa...@us...> - 2012-12-31 08:08:02
|
Revision: 7928 http://sourceforge.net/p/htmlunit/code/7928 Author: asashour Date: 2012-12-31 08:07:59 +0000 (Mon, 31 Dec 2012) Log Message: ----------- CSS3 selector "empty" Modified Paths: -------------- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java =================================================================== --- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-31 06:54:50 UTC (rev 7927) +++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2012-12-31 08:07:59 UTC (rev 7928) @@ -662,6 +662,9 @@ } return true; } + else if ("empty".equals(value)) { + return element.getFirstChild() == null; + } return false; } Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java =================================================================== --- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-31 06:54:50 UTC (rev 7927) +++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSSelectorTest.java 2012-12-31 08:07:59 UTC (rev 7928) @@ -538,4 +538,29 @@ loadPageWithAlerts2(html); } + /** + * @throws Exception if an error occurs + */ + @Test + @Alerts(DEFAULT = "id1", IE8 = "exception") + public void empty() throws Exception { + final String html = "<html><head><title>First</title>\n" + + "<meta http-equiv='X-UA-Compatible' content='IE=9'>\n" + + "<script>\n" + + "function test() {\n" + + " if (document.querySelectorAll) {\n" + + " try {\n" + + " alert(document.querySelectorAll('p:empty')[0].id);\n" + + " } catch(e) {alert('exception')}\n" + + " }\n" + + "}\n" + + "</script></head>\n" + + "<body onload='test()'>\n" + + " <p id='id1'></p>\n" + + " <p id='id2'>Hello, World!</p>\n" + + "</body></html>"; + + loadPageWithAlerts2(html); + } + } |