Element-matches-init.js (2987B)
1 function init(e, method) { 2 /* 3 * This test suite tests Selectors API methods in 4 different contexts: 4 * 1. Document node 5 * 2. In-document Element node 6 * 3. Detached Element node (an element with no parent, not in the document) 7 * 4. Document Fragment node 8 * 9 * For each context, the following tests are run: 10 * 11 * The interface check tests ensure that each type of node exposes the Selectors API methods. 12 * 13 * The matches() tests are run 14 * All the selectors tested for both the valid and invalid selector tests are found in selectors.js. 15 * See comments in that file for documentation of the format used. 16 * 17 * The level2-lib.js file contains all the common test functions for running each of the aforementioned tests 18 */ 19 20 var docType = "html"; // Only run tests suitable for HTML 21 22 // Prepare the nodes for testing 23 var doc = e.target.contentDocument; // Document Node tests 24 25 var element = doc.getElementById("root"); // In-document Element Node tests 26 27 //Setup the namespace tests 28 setupSpecialElements(doc, element); 29 30 var outOfScope = element.cloneNode(true); // Append this to the body before running the in-document 31 // Element tests, but after running the Document tests. This 32 // tests that no elements that are not descendants of element 33 // are selected. 34 35 traverse(outOfScope, function(elem) { // Annotate each element as being a clone; used for verifying 36 elem.setAttribute("data-clone", ""); // that none of these elements ever match. 37 }); 38 39 40 var detached = element.cloneNode(true); // Detached Element Node tests 41 42 var fragment = doc.createDocumentFragment(); // Fragment Node tests 43 fragment.appendChild(element.cloneNode(true)); 44 45 // Setup Tests 46 interfaceCheckMatches(method, "Document", doc); 47 interfaceCheckMatches(method, "Detached Element", detached); 48 interfaceCheckMatches(method, "Fragment", fragment); 49 interfaceCheckMatches(method, "In-document Element", element); 50 51 runSpecialMatchesTests(method, "DIV Element", element); 52 runSpecialMatchesTests(method, "NULL Element", document.createElement("null")); 53 runSpecialMatchesTests(method, "UNDEFINED Element", document.createElement("undefined")); 54 55 runInvalidSelectorTestMatches(method, "Document", doc, invalidSelectors); 56 runInvalidSelectorTestMatches(method, "Detached Element", detached, invalidSelectors); 57 runInvalidSelectorTestMatches(method, "Fragment", fragment, invalidSelectors); 58 runInvalidSelectorTestMatches(method, "In-document Element", element, invalidSelectors); 59 60 runMatchesTest(method, "In-document", doc, validSelectors, "html"); 61 runMatchesTest(method, "Detached", detached, validSelectors, "html"); 62 runMatchesTest(method, "Fragment", fragment, validSelectors, "html"); 63 64 runMatchesTest(method, "In-document", doc, scopedSelectors, "html"); 65 }