Quantcast

[HtmlUnit] SVN: [13807] trunk/htmlunit/src

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[HtmlUnit] SVN: [13807] trunk/htmlunit/src

asashour-2
Revision: 13807
          http://sourceforge.net/p/htmlunit/code/13807
Author:   asashour
Date:     2017-03-17 17:55:18 +0000 (Fri, 17 Mar 2017)
Log Message:
-----------
Fixing build

Modified Paths:
--------------
    trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java
    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/CSSStyleSheet2Test.java

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-03-17 17:48:47 UTC (rev 13806)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/BrowserVersionFeatures.java 2017-03-17 17:55:18 UTC (rev 13807)
@@ -1437,6 +1437,10 @@
     @BrowserFeature(@WebBrowser(IE))
     QUERYSELECTORALL_NOT_IN_QUIRKS,
 
+    /** Indicates {@code .querySelectorAll()} ignores {@code :target} condition. */
+    @BrowserFeature(@WebBrowser(CHROME))
+    QUERYSELECTORALL_NO_TARGET,
+
     /** IE throws a syntax error if a css3 pseudo selector is used on an detached node. */
     @BrowserFeature(@WebBrowser(IE))
     QUERYSELECTOR_CSS3_PSEUDO_REQUIRE_ATTACHED_NODE,

Modified: trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java
===================================================================
--- trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2017-03-17 17:48:47 UTC (rev 13806)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/html/DomNode.java 2017-03-17 17:55:18 UTC (rev 13807)
@@ -1876,7 +1876,7 @@
                 for (final DomElement child : getDomElementDescendants()) {
                     for (int i = 0; i < selectorList.getLength(); i++) {
                         final Selector selector = selectorList.item(i);
-                        if (CSSStyleSheet.selects(browserVersion, selector, child)) {
+                        if (CSSStyleSheet.selects(browserVersion, selector, child, null, true)) {
                             elements.add(child);
                             break;
                         }

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 2017-03-17 17:48:47 UTC (rev 13806)
+++ trunk/htmlunit/src/main/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet.java 2017-03-17 17:55:18 UTC (rev 13807)
@@ -16,6 +16,7 @@
 
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLLINK_CHECK_TYPE_FOR_STYLESHEET;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NOT_IN_QUIRKS;
+import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTORALL_NO_TARGET;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.QUERYSELECTOR_CSS3_PSEUDO_REQUIRE_ATTACHED_NODE;
 import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.STYLESHEET_HREF_EMPTY_IS_NULL;
 import static com.gargoylesoftware.htmlunit.html.DomElement.ATTRIBUTE_NOT_DEFINED;
@@ -260,7 +261,7 @@
                 final SelectorList selectors = styleRule.getSelectors();
                 for (int j = 0; j < selectors.getLength(); j++) {
                     final Selector selector = selectors.item(j);
-                    final boolean selected = selects(browser, selector, e, pseudoElement);
+                    final boolean selected = selects(browser, selector, e, pseudoElement, false);
                     if (selected) {
                         final org.w3c.dom.css.CSSStyleDeclaration dec = styleRule.getStyle();
                         style.applyStyleFromSelector(dec, selector);
@@ -406,38 +407,15 @@
     /**
      * Returns {@code true} if the specified selector selects the specified element.
      *
-     * @param selector the selector to test
-     * @param element the element to test
-     * @return {@code true} if it does apply, {@code false} if it doesn't apply
-     */
-    boolean selects(final Selector selector, final DomElement element) {
-        return selects(getBrowserVersion(), selector, element);
-    }
-
-    /**
-     * Returns {@code true} if the specified selector selects the specified element.
-     *
      * @param browserVersion the browser version
      * @param selector the selector to test
      * @param element the element to test
-     * @return {@code true} if it does apply, {@code false} if it doesn't apply
-     */
-    public static boolean selects(final BrowserVersion browserVersion, final Selector selector,
-            final DomElement element) {
-        return selects(browserVersion, selector, element, null);
-    }
-
-    /**
-     * Returns {@code true} if the specified selector selects the specified element.
-     *
-     * @param browserVersion the browser version
-     * @param selector the selector to test
-     * @param element the element to test
      * @param pseudoElement the pseudo element to match, (can be {@code null})
+     * @param fromQuerySelectorAll whether this is called from {@link DomNode#querySelectorAll(String)
      * @return {@code true} if it does apply, {@code false} if it doesn't apply
      */
     public static boolean selects(final BrowserVersion browserVersion, final Selector selector,
-            final DomElement element, final String pseudoElement) {
+            final DomElement element, final String pseudoElement, final boolean fromQuerySelectorAll) {
         switch (selector.getSelectorType()) {
             case Selector.SAC_ANY_NODE_SELECTOR:
                 if (selector instanceof GeneralAdjacentSelectorImpl) {
@@ -446,8 +424,10 @@
                     final SimpleSelector ssSiblingSelector = ss.getSiblingSelector();
                     for (DomNode prev = element.getPreviousSibling(); prev != null; prev = prev.getPreviousSibling()) {
                         if (prev instanceof HtmlElement
-                            && selects(browserVersion, ssSelector, (HtmlElement) prev)
-                            && selects(browserVersion, ssSiblingSelector, element)) {
+                            && selects(browserVersion, ssSelector, (HtmlElement) prev,
+                                    pseudoElement, fromQuerySelectorAll)
+                            && selects(browserVersion, ssSiblingSelector, element,
+                                    pseudoElement, fromQuerySelectorAll)) {
                             return true;
                         }
                     }
@@ -464,12 +444,13 @@
                     return false; // for instance parent is a DocumentFragment
                 }
                 final DescendantSelector cs = (DescendantSelector) selector;
-                return selects(browserVersion, cs.getSimpleSelector(), element)
-                    && selects(browserVersion, cs.getAncestorSelector(), (HtmlElement) parentNode);
+                return selects(browserVersion, cs.getSimpleSelector(), element, pseudoElement, fromQuerySelectorAll)
+                    && selects(browserVersion, cs.getAncestorSelector(), (HtmlElement) parentNode,
+                            pseudoElement, fromQuerySelectorAll);
             case Selector.SAC_DESCENDANT_SELECTOR:
                 final DescendantSelector ds = (DescendantSelector) selector;
                 final SimpleSelector simpleSelector = ds.getSimpleSelector();
-                if (selects(browserVersion, simpleSelector, element, pseudoElement)) {
+                if (selects(browserVersion, simpleSelector, element, pseudoElement, fromQuerySelectorAll)) {
                     DomNode ancestor = element;
                     if (simpleSelector.getSelectorType() != Selector.SAC_PSEUDO_ELEMENT_SELECTOR) {
                         ancestor = ancestor.getParentNode();
@@ -476,7 +457,8 @@
                     }
                     final Selector dsAncestorSelector = ds.getAncestorSelector();
                     while (ancestor instanceof HtmlElement) {
-                        if (selects(browserVersion, dsAncestorSelector, (HtmlElement) ancestor, pseudoElement)) {
+                        if (selects(browserVersion, dsAncestorSelector, (HtmlElement) ancestor, pseudoElement,
+                                fromQuerySelectorAll)) {
                             return true;
                         }
                         ancestor = ancestor.getParentNode();
@@ -486,8 +468,9 @@
             case Selector.SAC_CONDITIONAL_SELECTOR:
                 final ConditionalSelector conditional = (ConditionalSelector) selector;
                 final SimpleSelector simpleSel = conditional.getSimpleSelector();
-                return (simpleSel == null || selects(browserVersion, simpleSel, element))
-                    && selects(browserVersion, conditional.getCondition(), element);
+                return (simpleSel == null || selects(browserVersion, simpleSel, element,
+                        pseudoElement, fromQuerySelectorAll))
+                    && selects(browserVersion, conditional.getCondition(), element, fromQuerySelectorAll);
             case Selector.SAC_ELEMENT_NODE_SELECTOR:
                 final ElementSelector es = (ElementSelector) selector;
                 final String name = es.getLocalName();
@@ -501,11 +484,12 @@
                     prev = prev.getPreviousSibling();
                 }
                 return prev != null
-                    && selects(browserVersion, ss.getSelector(), (HtmlElement) prev)
-                    && selects(browserVersion, ss.getSiblingSelector(), element);
+                    && selects(browserVersion, ss.getSelector(), (HtmlElement) prev,
+                            pseudoElement, fromQuerySelectorAll)
+                    && selects(browserVersion, ss.getSiblingSelector(), element, pseudoElement, fromQuerySelectorAll);
             case Selector.SAC_NEGATIVE_SELECTOR:
                 final NegativeSelector ns = (NegativeSelector) selector;
-                return !selects(browserVersion, ns.getSimpleSelector(), element);
+                return !selects(browserVersion, ns.getSimpleSelector(), element, pseudoElement, fromQuerySelectorAll);
             case Selector.SAC_PSEUDO_ELEMENT_SELECTOR:
                 if (pseudoElement != null && !pseudoElement.isEmpty() && pseudoElement.charAt(0) == ':') {
                     final String pseudoName = ((ElementSelector) selector).getLocalName();
@@ -529,9 +513,11 @@
      * @param browserVersion the browser version
      * @param condition the condition to test
      * @param element the element to test
+     * @param fromQuerySelectorAll whether this is called from {@link DomNode#querySelectorAll(String)
      * @return {@code true} if it does apply, {@code false} if it doesn't apply
      */
-    static boolean selects(final BrowserVersion browserVersion, final Condition condition, final DomElement element) {
+    static boolean selects(final BrowserVersion browserVersion, final Condition condition, final DomElement element,
+            final boolean fromQuerySelectorAll) {
         if (condition instanceof PrefixAttributeConditionImpl) {
             final AttributeCondition ac = (AttributeCondition) condition;
             final String value = ac.getValue();
@@ -561,8 +547,8 @@
                 return selectsWhitespaceSeparated(v3, a3);
             case Condition.SAC_AND_CONDITION:
                 final CombinatorCondition cc1 = (CombinatorCondition) condition;
-                return selects(browserVersion, cc1.getFirstCondition(), element)
-                    && selects(browserVersion, cc1.getSecondCondition(), element);
+                return selects(browserVersion, cc1.getFirstCondition(), element, fromQuerySelectorAll)
+                    && selects(browserVersion, cc1.getSecondCondition(), element, fromQuerySelectorAll);
             case Condition.SAC_ATTRIBUTE_CONDITION:
                 final AttributeCondition ac1 = (AttributeCondition) condition;
                 if (ac1.getSpecified()) {
@@ -586,11 +572,11 @@
                 return selects(v2, a2, ' ');
             case Condition.SAC_OR_CONDITION:
                 final CombinatorCondition cc2 = (CombinatorCondition) condition;
-                return selects(browserVersion, cc2.getFirstCondition(), element)
-                    || selects(browserVersion, cc2.getSecondCondition(), element);
+                return selects(browserVersion, cc2.getFirstCondition(), element, fromQuerySelectorAll)
+                    || selects(browserVersion, cc2.getSecondCondition(), element, fromQuerySelectorAll);
             case Condition.SAC_NEGATIVE_CONDITION:
                 final NegativeCondition nc = (NegativeCondition) condition;
-                return !selects(browserVersion, nc.getCondition(), element);
+                return !selects(browserVersion, nc.getCondition(), element, fromQuerySelectorAll);
             case Condition.SAC_ONLY_CHILD_CONDITION:
                 return element.getParentNode().getChildNodes().getLength() == 1;
             case Condition.SAC_CONTENT_CONDITION:
@@ -612,7 +598,7 @@
                 final String tagName = element.getTagName();
                 return ((HtmlPage) element.getPage()).getElementsByTagName(tagName).getLength() == 1;
             case Condition.SAC_PSEUDO_CLASS_CONDITION:
-                return selectsPseudoClass(browserVersion, (AttributeCondition) condition, element);
+                return selectsPseudoClass(browserVersion, (AttributeCondition) condition, element, fromQuerySelectorAll);
             case Condition.SAC_POSITIONAL_CONDITION:
                 return false;
             default:
@@ -683,7 +669,7 @@
     }
 
     private static boolean selectsPseudoClass(final BrowserVersion browserVersion,
-            final AttributeCondition condition, final DomElement element) {
+            final AttributeCondition condition, final DomElement element, final boolean fromQuerySelectorAll) {
         if (browserVersion.hasFeature(QUERYSELECTORALL_NOT_IN_QUIRKS)) {
             final Object sobj = element.getPage().getScriptableObject();
             if (sobj instanceof HTMLDocument && ((HTMLDocument) sobj).getDocumentMode() < 8) {
@@ -792,6 +778,9 @@
                 return isEmpty(element);
 
             case "target":
+                if (fromQuerySelectorAll && browserVersion.hasFeature(QUERYSELECTORALL_NO_TARGET)) {
+                    return false;
+                }
                 final String ref = element.getPage().getUrl().getRef();
                 return StringUtils.isNotBlank(ref) && ref.equals(element.getId());
 
@@ -871,7 +860,8 @@
 
                         validateSelectors(selectorList, 9, element);
 
-                        return !CSSStyleSheet.selects(browserVersion, selectorList.item(0), element);
+                        return !CSSStyleSheet.selects(browserVersion, selectorList.item(0), element,
+                                null, fromQuerySelectorAll);
                     }
                     catch (final IOException e) {
                         throw new CSSException("Error parsing CSS selectors from '" + selectors + "': "

Modified: trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2Test.java
===================================================================
--- trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2Test.java 2017-03-17 17:48:47 UTC (rev 13806)
+++ trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/javascript/host/css/CSSStyleSheet2Test.java 2017-03-17 17:55:18 UTC (rev 13807)
@@ -23,6 +23,7 @@
 import org.w3c.dom.NodeList;
 
 import com.gargoylesoftware.htmlunit.BrowserRunner;
+import com.gargoylesoftware.htmlunit.BrowserVersion;
 import com.gargoylesoftware.htmlunit.SimpleWebTestCase;
 import com.gargoylesoftware.htmlunit.html.DomElement;
 import com.gargoylesoftware.htmlunit.html.HtmlElement;
@@ -65,6 +66,7 @@
         final HtmlInput input2 = (HtmlInput) page.getElementsByName("i2").get(0);
         final DomElement button1 = page.getElementsByName("b1").get(0);
         final DomElement button2 = page.getElementsByName("b2").get(0);
+        final BrowserVersion browserVersion = getBrowserVersion();
 
         final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
         final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
@@ -71,16 +73,17 @@
         final CSSStyleSheet sheet = host.getSheet();
 
         Selector selector = parseSelector(sheet, "*.yui-log input");
-        assertFalse(sheet.selects(selector, body));
-        assertFalse(sheet.selects(selector, form));
-        assertTrue(sheet.selects(selector, input1));
-        assertTrue(sheet.selects(selector, input2));
-        assertFalse(sheet.selects(selector, button1));
-        assertFalse(sheet.selects(selector, button2));
+        
+        assertFalse(CSSStyleSheet.selects(browserVersion, selector, body, null, false));
+        assertFalse(CSSStyleSheet.selects(browserVersion, selector, form, null, false));
+        assertTrue(CSSStyleSheet.selects(browserVersion, selector, input1, null, false));
+        assertTrue(CSSStyleSheet.selects(browserVersion, selector, input2, null, false));
+        assertFalse(CSSStyleSheet.selects(browserVersion, selector, button1, null, false));
+        assertFalse(CSSStyleSheet.selects(browserVersion, selector, button2, null, false));
 
         selector = parseSelector(sheet, "#m1");
-        assertTrue(sheet.selects(selector, input1));
-        assertFalse(sheet.selects(selector, input2));
+        assertTrue(CSSStyleSheet.selects(browserVersion, selector, input1, null, false));
+        assertFalse(CSSStyleSheet.selects(browserVersion, selector, input2, null, false));
     }
 
     private static Selector parseSelector(final CSSStyleSheet sheet, final String rule) {
@@ -150,13 +153,14 @@
         final HtmlPage page = loadPage(html);
         final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
         final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
+        final BrowserVersion browserVersion = getBrowserVersion();
         final CSSStyleSheet sheet = host.getSheet();
 
         Selector selector = sheet.parseSelectors(new InputSource(new StringReader("#d\\:e"))).item(0);
-        assertTrue(sheet.selects(selector, page.getHtmlElementById("d:e")));
+        assertTrue(CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d:e"), null, false));
 
         selector = sheet.parseSelectors(new InputSource(new StringReader("#d-e"))).item(0);
-        assertTrue(sheet.selects(selector, page.getHtmlElementById("d-e")));
+        assertTrue(CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d-e"), null, false));
     }
 
     /**
@@ -207,13 +211,17 @@
             + "  </body>\n"
             + "</html>";
         final HtmlPage page = loadPage(html);
+        final BrowserVersion browserVersion = getBrowserVersion();
         final HtmlStyle node = (HtmlStyle) page.getElementsByTagName("style").item(0);
         final HTMLStyleElement host = (HTMLStyleElement) node.getScriptableObject();
         final CSSStyleSheet sheet = host.getSheet();
         final Selector selector = sheet.parseSelectors(new InputSource(new StringReader(css))).item(0);
-        assertEquals(selectBody, sheet.selects(selector, page.getHtmlElementById("b")));
-        assertEquals(selectDivD, sheet.selects(selector, page.getHtmlElementById("d")));
-        assertEquals(selectSpanS, sheet.selects(selector, page.getHtmlElementById("s")));
+        assertEquals(selectBody,
+                CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("b"), null, false));
+        assertEquals(selectDivD,
+                CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("d"), null, false));
+        assertEquals(selectSpanS,
+                CSSStyleSheet.selects(browserVersion, selector, page.getHtmlElementById("s"), null, false));
     }
 
     /**


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
HtmlUnit-develop mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-develop
Loading...