| OLD | NEW |
| (Empty) | |
| 1 <!DOCTYPE html> |
| 2 <meta charset="UTF-8"> |
| 3 <title>Selectors-API Test Suite: HTML</title> |
| 4 <script src="/resources/testharness.js"></script> |
| 5 <script src="/resources/testharnessreport.js"></script> |
| 6 <script src="selectors.js"></script> |
| 7 <script src="ParentNode-querySelector-All.js"></script> |
| 8 <style>iframe { visibility: hidden; position: absolute; }</style> |
| 9 |
| 10 <div id="log">This test requires JavaScript.</div> |
| 11 |
| 12 <script> |
| 13 async_test(function() { |
| 14 var frame = document.createElement("iframe"); |
| 15 frame.onload = this.step_func_done(init); |
| 16 frame.src = "ParentNode-querySelector-All-content.html#target"; |
| 17 document.body.appendChild(frame); |
| 18 }); |
| 19 |
| 20 function init(e) { |
| 21 /* |
| 22 * This test suite tests Selectors API methods in 4 different contexts: |
| 23 * 1. Document node |
| 24 * 2. In-document Element node |
| 25 * 3. Detached Element node (an element with no parent, not in the document) |
| 26 * 4. Document Fragment node |
| 27 * |
| 28 * For each context, the following tests are run: |
| 29 * |
| 30 * The interface check tests ensure that each type of node exposes the Selecto
rs API methods |
| 31 * |
| 32 * The special selector tests verify the result of passing special values for
the selector parameter, |
| 33 * to ensure that the correct WebIDL processing is performed, such as stringif
ication of null and |
| 34 * undefined and missing parameter. The universal selector is also tested here
, rather than with the |
| 35 * rest of ordinary selectors for practical reasons. |
| 36 * |
| 37 * The static list verification tests ensure that the node lists returned by t
he method remain unchanged |
| 38 * due to subsequent document modication, and that a new list is generated eac
h time the method is |
| 39 * invoked based on the current state of the document. |
| 40 * |
| 41 * The invalid selector tests ensure that SyntaxError is thrown for invalid fo
rms of selectors |
| 42 * |
| 43 * The valid selector tests check the result from querying many different type
s of selectors, with a |
| 44 * list of expected elements. This checks that querySelector() always returns
the first result from |
| 45 * querySelectorAll(), and that all matching elements are correctly returned i
n tree-order. The tests |
| 46 * can be limited by specifying the test types to run, using the testType vari
able. The constants for this |
| 47 * can be found in selectors.js. |
| 48 * |
| 49 * All the selectors tested for both the valid and invalid selector tests are
found in selectors.js. |
| 50 * See comments in that file for documentation of the format used. |
| 51 * |
| 52 * The ParentNode-querySelector-All.js file contains all the common test funct
ions for running each of the aforementioned tests |
| 53 */ |
| 54 |
| 55 var testType = TEST_QSA; |
| 56 var docType = "html"; // Only run tests suitable for HTML |
| 57 |
| 58 // Prepare the nodes for testing |
| 59 var doc = e.target.contentDocument; // Document Node tests |
| 60 |
| 61 var element = doc.getElementById("root"); // In-document Element Node tests |
| 62 |
| 63 //Setup the namespace tests |
| 64 setupSpecialElements(doc, element); |
| 65 |
| 66 var outOfScope = element.cloneNode(true); // Append this to the body before
running the in-document |
| 67 // Element tests, but after runni
ng the Document tests. This |
| 68 // tests that no elements that ar
e not descendants of element |
| 69 // are selected. |
| 70 |
| 71 traverse(outOfScope, function(elem) { // Annotate each element as being
a clone; used for verifying |
| 72 elem.setAttribute("data-clone", ""); // that none of these elements ever
match. |
| 73 }); |
| 74 |
| 75 |
| 76 var detached = element.cloneNode(true); // Detached Element Node tests |
| 77 |
| 78 var fragment = doc.createDocumentFragment(); // Fragment Node tests |
| 79 fragment.appendChild(element.cloneNode(true)); |
| 80 |
| 81 // Setup Tests |
| 82 interfaceCheck("Document", doc); |
| 83 interfaceCheck("Detached Element", detached); |
| 84 interfaceCheck("Fragment", fragment); |
| 85 interfaceCheck("In-document Element", element); |
| 86 |
| 87 runSpecialSelectorTests("Document", doc); |
| 88 runSpecialSelectorTests("Detached Element", detached); |
| 89 runSpecialSelectorTests("Fragment", fragment); |
| 90 runSpecialSelectorTests("In-document Element", element); |
| 91 |
| 92 verifyStaticList("Document", doc, doc); |
| 93 verifyStaticList("Detached Element", doc, detached); |
| 94 verifyStaticList("Fragment", doc, fragment); |
| 95 verifyStaticList("In-document Element", doc, element); |
| 96 |
| 97 runInvalidSelectorTest("Document", doc, invalidSelectors); |
| 98 runInvalidSelectorTest("Detached Element", detached, invalidSelectors); |
| 99 runInvalidSelectorTest("Fragment", fragment, invalidSelectors); |
| 100 runInvalidSelectorTest("In-document Element", element, invalidSelectors); |
| 101 |
| 102 runValidSelectorTest("Document", doc, validSelectors, testType, docType); |
| 103 runValidSelectorTest("Detached Element", detached, validSelectors, testType, d
ocType); |
| 104 runValidSelectorTest("Fragment", fragment, validSelectors, testType, docType); |
| 105 |
| 106 doc.body.appendChild(outOfScope); // Append before in-document Element tests. |
| 107 // None of these elements should match |
| 108 runValidSelectorTest("In-document Element", element, validSelectors, testType,
docType); |
| 109 } |
| 110 </script> |
| OLD | NEW |