OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <script src="../../resources/js-test.js"></script> |
| 3 <script> |
| 4 if (window.testRunner) |
| 5 testRunner.dumpAsText(); |
| 6 </script> |
| 7 <body> |
| 8 <tribe> |
| 9 |
| 10 <realm> |
| 11 <throne></throne> |
| 12 <ancestor id="doe" name="young" class="classic"> |
| 13 <target id="anotherTarget"></target> |
| 14 </ancestor> |
| 15 </realm> |
| 16 |
| 17 <ancestor id="john" name="old" class="classic"> |
| 18 <sibling></sibling> |
| 19 <target id="theTarget" webkit="fast"></target> |
| 20 </ancestor> |
| 21 |
| 22 </tribe> |
| 23 |
| 24 <foo> |
| 25 <bar> |
| 26 <a id="a"> |
| 27 <b id="b"> |
| 28 <c id="c"> |
| 29 <d id="d"> |
| 30 <lemon id="sour"></lemon> |
| 31 </d> |
| 32 <c/> |
| 33 </b> |
| 34 </a> |
| 35 </bar> |
| 36 </foo> |
| 37 </body> |
| 38 <script> |
| 39 description('This test makes sure the closest() API works correctly'); |
| 40 |
| 41 var theTarget = document.getElementById('theTarget'); |
| 42 var ancestor = document.getElementById('john'); |
| 43 var sour = document.getElementById('sour'); |
| 44 var sibling = document.getElementById('sibling'); |
| 45 var a = document.getElementById('a'); |
| 46 var b = document.getElementById('b'); |
| 47 var c = document.getElementById('c'); |
| 48 var d = document.getElementById('d'); |
| 49 |
| 50 shouldBe('theTarget.closest("#theTarget")', 'theTarget'); |
| 51 shouldBe('theTarget.closest("ancestor")', 'ancestor'); |
| 52 shouldBe('theTarget.closest("tribe ancestor")', 'ancestor'); |
| 53 shouldBe('theTarget.closest("tribe ancestor sibling")', 'sibling'); |
| 54 shouldBe('theTarget.closest("tribe > ancestor")', 'ancestor'); |
| 55 shouldBe('theTarget.closest("realm + ancestor")', 'ancestor'); |
| 56 shouldBe('theTarget.closest("realm ~ ancestor")', 'ancestor'); |
| 57 shouldBe('theTarget.closest("tribe, ancestor")', 'ancestor'); |
| 58 shouldBe('theTarget.closest("ancestor, tribe")', 'ancestor'); |
| 59 |
| 60 shouldBeNull('theTarget.closest("tribe realm")'); |
| 61 shouldBeNull('theTarget.closest("tribe realm throne")'); |
| 62 shouldBeNull('theTarget.closest("tribe realm ancestor")'); |
| 63 shouldBeNull('theTarget.closest("realm > ancestor")'); |
| 64 shouldBeNull('theTarget.closest("throne + ancestor")'); |
| 65 shouldBeNull('theTarget.closest("throne ~ ancestor")'); |
| 66 |
| 67 shouldBe('theTarget.closest(".classic")', 'ancestor'); |
| 68 shouldBe('theTarget.closest("#john")', 'ancestor'); |
| 69 shouldBeNull('theTarget.closest("doe")'); |
| 70 shouldBe('theTarget.closest("ancestor[name=old]")', 'ancestor'); |
| 71 shouldBeNull('theTarget.closest("ancestor[name=young]")', 'ancestor'); |
| 72 |
| 73 shouldBeNull('theTarget.closest(null)'); |
| 74 shouldBeNull('theTarget.closest(undefined)'); |
| 75 |
| 76 shouldBe('sour.closest("lemon")', 'sour'); |
| 77 |
| 78 shouldBe('sour.closest("a, b, c, d")', 'd'); |
| 79 shouldBe('sour.closest("a, b, c")', 'c'); |
| 80 shouldBe('sour.closest("a, b")', 'b'); |
| 81 shouldBe('sour.closest("d, c, b, a")', 'd'); |
| 82 shouldBe('sour.closest("c, b, a")', 'c'); |
| 83 shouldBe('sour.closest("b, a")', 'b'); |
| 84 shouldBe('sour.closest("a")', 'a'); |
| 85 |
| 86 shouldBe('document.closest', 'undefined'); |
| 87 shouldThrow('document.closest()'); |
| 88 shouldThrow('theTarget.closest()'); |
| 89 shouldThrow('theTarget.closest("")'); |
| 90 shouldThrow('theTarget.closest(".123")'); |
| 91 shouldThrow('theTarget.closest(" ")'); |
| 92 shouldThrow('theTarget.closest(")")'); |
| 93 shouldThrow('theTarget.closest("(")'); |
| 94 shouldThrow('theTarget.closest("()")'); |
| 95 shouldThrow('theTarget.closest("^_^")'); |
| 96 shouldThrow('theTarget.closest("{")'); |
| 97 shouldThrow('theTarget.closest("}")'); |
| 98 shouldThrow('theTarget.closest("{}")'); |
| 99 |
| 100 shouldBe('theTarget.closest(":scope")', 'theTarget'); |
| 101 shouldBe('theTarget.closest(":not(:scope)")', 'ancestor'); |
| 102 shouldBe('theTarget.closest("ancestor :scope")', 'theTarget'); |
| 103 shouldBe('theTarget.closest("ancestor > :scope")', 'theTarget'); |
| 104 shouldBeNull('theTarget.closest("ancestor:scope")'); |
| 105 |
| 106 shouldBe('theTarget.closest("sibling + :scope")', 'theTarget'); |
| 107 shouldBe('theTarget.closest("sibling ~ :scope")', 'theTarget'); |
| 108 |
| 109 shouldBe('theTarget.closest("#theTarget:scope")', 'theTarget'); |
| 110 shouldBe('theTarget.closest(":scope#theTarget")', 'theTarget'); |
| 111 |
| 112 shouldBe('theTarget.closest("[webkit]:scope#theTarget")', 'theTarget'); |
| 113 shouldBeNull('theTarget.closest(":not([webkit=fast]):scope#theTarget")'); |
| 114 |
| 115 shouldBeNull('theTarget.closest(":scope target")'); |
| 116 shouldBeNull('theTarget.closest(":scope > target")'); |
| 117 shouldBeNull('theTarget.closest(":scope + target")'); |
| 118 shouldBeNull('theTarget.closest(":scope ~ target")'); |
| 119 |
| 120 shouldBeNull('theTarget.closest(":scope *")'); |
| 121 shouldBeNull('theTarget.closest(":scope > *")'); |
| 122 shouldBeNull('theTarget.closest(":scope + *")'); |
| 123 shouldBeNull('theTarget.closest(":scope ~ *")'); |
| 124 </script> |
OLD | NEW |