OLD | NEW |
| (Empty) |
1 /* | |
2 * Check that the matches() method exists on the given Node | |
3 */ | |
4 function interfaceCheckMatches(type, obj) { | |
5 if (obj.nodeType === obj.ELEMENT_NODE) { | |
6 test(function() { | |
7 assert_idl_attribute(obj, "matches", type + " supports matches"); | |
8 }, type + " supports matches") | |
9 } | |
10 } | |
11 | |
12 function runSpecialMatchesTests(type, element) { | |
13 test(function() { // 1 | |
14 if (element.tagName.toLowerCase() === "null") { | |
15 assert_true(element.matches(null), "An element with the tag name '" + elem
ent.tagName.toLowerCase() + "' should match."); | |
16 } else { | |
17 assert_false(element.matches(null), "An element with the tag name '" + ele
ment.tagName.toLowerCase() + "' should not match."); | |
18 } | |
19 }, type + ".matches(null)") | |
20 | |
21 test(function() { // 2 | |
22 if (element.tagName.toLowerCase() === "undefined") { | |
23 assert_true(element.matches(undefined), "An element with the tag name '" +
element.tagName.toLowerCase() + "' should match."); | |
24 } else { | |
25 assert_false(element.matches(undefined), "An element with the tag name '"
+ element.tagName.toLowerCase() + "' should not match."); | |
26 } | |
27 }, type + ".matches(undefined)") | |
28 | |
29 test(function() { // 3 | |
30 assert_throws(TypeError(), function() { | |
31 element.matches(); | |
32 }, "This should throw a TypeError.") | |
33 }, type + ".matches no parameter") | |
34 } | |
35 | |
36 /* | |
37 * Execute queries with the specified invalid selectors for matches() | |
38 * Only run these tests when errors are expected. Don't run for valid selector t
ests. | |
39 */ | |
40 function runInvalidSelectorTestMatches(type, root, selectors) { | |
41 if (root.nodeType === root.ELEMENT_NODE) { | |
42 for (var i = 0; i < selectors.length; i++) { | |
43 var s = selectors[i]; | |
44 var n = s["name"]; | |
45 var q = s["selector"]; | |
46 | |
47 test(function() { | |
48 assert_throws("SyntaxError", function() { | |
49 root.matches(q) | |
50 }) | |
51 }, type + ".matches: " + n + ": " + q); | |
52 } | |
53 } | |
54 } | |
55 | |
56 function runMatchesTest(type, root, selectors, docType) { | |
57 var nodeType = getNodeType(root); | |
58 | |
59 for (var i = 0; i < selectors.length; i++) { | |
60 var s = selectors[i]; | |
61 var n = s["name"]; | |
62 var q = s["selector"]; | |
63 var e = s["expect"]; | |
64 var u = s["unexpected"]; | |
65 | |
66 var ctx = s["ctx"]; | |
67 var ref = s["ref"]; | |
68 | |
69 if ((!s["exclude"] || (s["exclude"].indexOf(nodeType) === -1 && s["exclude"]
.indexOf(docType) === -1)) | |
70 && (s["testType"] & TEST_MATCH) ) { | |
71 | |
72 if (ctx && !ref) { | |
73 test(function() { | |
74 var j, element, refNode; | |
75 for (j = 0; j < e.length; j++) { | |
76 element = root.querySelector("#" + e[j]); | |
77 refNode = root.querySelector(ctx); | |
78 assert_true(element.matches(q, refNode), "The element #" + e[j] + "
should match the selector.") | |
79 } | |
80 | |
81 if (u) { | |
82 for (j = 0; j < u.length; j++) { | |
83 element = root.querySelector("#" + u[j]); | |
84 refNode = root.querySelector(ctx); | |
85 assert_false(element.matches(q, refNode), "The element #" + u[j] +
" should not match the selector.") | |
86 } | |
87 } | |
88 }, type + " Element.matches: " + n + " (with refNode Element): " + q); | |
89 } | |
90 | |
91 if (ref) { | |
92 test(function() { | |
93 var j, element, refNodes; | |
94 for (j = 0; j < e.length; j++) { | |
95 element = root.querySelector("#" + e[j]); | |
96 refNodes = root.querySelectorAll(ref); | |
97 assert_true(element.matches(q, refNodes), "The element #" + e[j] + "
should match the selector.") | |
98 } | |
99 | |
100 if (u) { | |
101 for (j = 0; j < u.length; j++) { | |
102 element = root.querySelector("#" + u[j]); | |
103 refNodes = root.querySelectorAll(ref); | |
104 assert_false(element.matches(q, refNodes), "The element #" + u[j]
+ " should not match the selector.") | |
105 } | |
106 } | |
107 }, type + " Element.matches: " + n + " (with refNodes NodeList): " + q); | |
108 } | |
109 | |
110 if (!ctx && !ref) { | |
111 test(function() { | |
112 for (var j = 0; j < e.length; j++) { | |
113 var element = root.querySelector("#" + e[j]); | |
114 assert_true(element.matches(q), "The element #" + e[j] + " should ma
tch the selector.") | |
115 } | |
116 | |
117 if (u) { | |
118 for (j = 0; j < u.length; j++) { | |
119 element = root.querySelector("#" + u[j]); | |
120 assert_false(element.matches(q), "The element #" + u[j] + " should
not match the selector.") | |
121 } | |
122 } | |
123 }, type + " Element.matches: " + n + " (with no refNodes): " + q); | |
124 } | |
125 } | |
126 } | |
127 } | |
OLD | NEW |