Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Unified Diff: LayoutTests/fast/selectors/element-closest.html

Issue 704733002: Adding Element.closest() API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/selectors/element-closest-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/selectors/element-closest.html
diff --git a/LayoutTests/fast/selectors/element-closest.html b/LayoutTests/fast/selectors/element-closest.html
new file mode 100644
index 0000000000000000000000000000000000000000..3b56b7c7f3ef385a3bb706a5ece82417f2a321ff
--- /dev/null
+++ b/LayoutTests/fast/selectors/element-closest.html
@@ -0,0 +1,124 @@
+<!doctype html>
+<script src="../../resources/js-test.js"></script>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+<body>
+<tribe>
+
+ <realm>
+ <throne></throne>
+ <ancestor id="doe" name="young" class="classic">
+ <target id="anotherTarget"></target>
+ </ancestor>
+ </realm>
+
+ <ancestor id="john" name="old" class="classic">
+ <sibling></sibling>
+ <target id="theTarget" webkit="fast"></target>
+ </ancestor>
+
+</tribe>
+
+<foo>
+ <bar>
+ <a id="a">
+ <b id="b">
+ <c id="c">
+ <d id="d">
+ <lemon id="sour"></lemon>
+ </d>
+ <c/>
+ </b>
+ </a>
+ </bar>
+</foo>
+</body>
+<script>
+description('This test makes sure the closest() API works correctly');
+
+var theTarget = document.getElementById('theTarget');
+var ancestor = document.getElementById('john');
+var sour = document.getElementById('sour');
+var sibling = document.getElementById('sibling');
+var a = document.getElementById('a');
+var b = document.getElementById('b');
+var c = document.getElementById('c');
+var d = document.getElementById('d');
+
+shouldBe('theTarget.closest("#theTarget")', 'theTarget');
+shouldBe('theTarget.closest("ancestor")', 'ancestor');
+shouldBe('theTarget.closest("tribe ancestor")', 'ancestor');
+shouldBe('theTarget.closest("tribe ancestor sibling")', 'sibling');
+shouldBe('theTarget.closest("tribe > ancestor")', 'ancestor');
+shouldBe('theTarget.closest("realm + ancestor")', 'ancestor');
+shouldBe('theTarget.closest("realm ~ ancestor")', 'ancestor');
+shouldBe('theTarget.closest("tribe, ancestor")', 'ancestor');
+shouldBe('theTarget.closest("ancestor, tribe")', 'ancestor');
+
+shouldBeNull('theTarget.closest("tribe realm")');
+shouldBeNull('theTarget.closest("tribe realm throne")');
+shouldBeNull('theTarget.closest("tribe realm ancestor")');
+shouldBeNull('theTarget.closest("realm > ancestor")');
+shouldBeNull('theTarget.closest("throne + ancestor")');
+shouldBeNull('theTarget.closest("throne ~ ancestor")');
+
+shouldBe('theTarget.closest(".classic")', 'ancestor');
+shouldBe('theTarget.closest("#john")', 'ancestor');
+shouldBeNull('theTarget.closest("doe")');
+shouldBe('theTarget.closest("ancestor[name=old]")', 'ancestor');
+shouldBeNull('theTarget.closest("ancestor[name=young]")', 'ancestor');
+
+shouldBeNull('theTarget.closest(null)');
+shouldBeNull('theTarget.closest(undefined)');
+
+shouldBe('sour.closest("lemon")', 'sour');
+
+shouldBe('sour.closest("a, b, c, d")', 'd');
+shouldBe('sour.closest("a, b, c")', 'c');
+shouldBe('sour.closest("a, b")', 'b');
+shouldBe('sour.closest("d, c, b, a")', 'd');
+shouldBe('sour.closest("c, b, a")', 'c');
+shouldBe('sour.closest("b, a")', 'b');
+shouldBe('sour.closest("a")', 'a');
+
+shouldBe('document.closest', 'undefined');
+shouldThrow('document.closest()');
+shouldThrow('theTarget.closest()');
+shouldThrow('theTarget.closest("")');
+shouldThrow('theTarget.closest(".123")');
+shouldThrow('theTarget.closest(" ")');
+shouldThrow('theTarget.closest(")")');
+shouldThrow('theTarget.closest("(")');
+shouldThrow('theTarget.closest("()")');
+shouldThrow('theTarget.closest("^_^")');
+shouldThrow('theTarget.closest("{")');
+shouldThrow('theTarget.closest("}")');
+shouldThrow('theTarget.closest("{}")');
+
+shouldBe('theTarget.closest(":scope")', 'theTarget');
+shouldBe('theTarget.closest(":not(:scope)")', 'ancestor');
+shouldBe('theTarget.closest("ancestor :scope")', 'theTarget');
+shouldBe('theTarget.closest("ancestor > :scope")', 'theTarget');
+shouldBeNull('theTarget.closest("ancestor:scope")');
+
+shouldBe('theTarget.closest("sibling + :scope")', 'theTarget');
+shouldBe('theTarget.closest("sibling ~ :scope")', 'theTarget');
+
+shouldBe('theTarget.closest("#theTarget:scope")', 'theTarget');
+shouldBe('theTarget.closest(":scope#theTarget")', 'theTarget');
+
+shouldBe('theTarget.closest("[webkit]:scope#theTarget")', 'theTarget');
+shouldBeNull('theTarget.closest(":not([webkit=fast]):scope#theTarget")');
+
+shouldBeNull('theTarget.closest(":scope target")');
+shouldBeNull('theTarget.closest(":scope > target")');
+shouldBeNull('theTarget.closest(":scope + target")');
+shouldBeNull('theTarget.closest(":scope ~ target")');
+
+shouldBeNull('theTarget.closest(":scope *")');
+shouldBeNull('theTarget.closest(":scope > *")');
+shouldBeNull('theTarget.closest(":scope + *")');
+shouldBeNull('theTarget.closest(":scope ~ *")');
+</script>
« no previous file with comments | « no previous file | LayoutTests/fast/selectors/element-closest-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698