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