OLD | NEW |
(Empty) | |
| 1 /// Test for the Selectors API ported from |
| 2 /// <https://github.com/w3c/web-platform-tests/tree/master/selectors-api> |
| 3 /// |
| 4 /// Note, unlike the original we don't operate in-browser on a DOM loaded into |
| 5 /// an iframe, but instead operate over a parsed DOM. |
| 6 library html.test.selectors.level1_baseline_test; |
| 7 |
| 8 import 'dart:io'; |
| 9 import 'package:html/dom.dart'; |
| 10 import 'package:html/parser.dart'; |
| 11 import 'package:unittest/unittest.dart'; |
| 12 import 'level1_lib.dart' hide test; |
| 13 import 'selectors.dart'; |
| 14 |
| 15 Document getTestContentDocument() { |
| 16 var testPath = Platform.script.resolve('level1-content.html').toFilePath(); |
| 17 return parse(new File(testPath).readAsStringSync()); |
| 18 } |
| 19 |
| 20 var testType = TEST_QSA_BASELINE; // Only run baseline tests. |
| 21 var docType = "html"; // Only run tests suitable for HTML |
| 22 |
| 23 main() { |
| 24 /* |
| 25 * This test suite tests Selectors API methods in 4 different contexts: |
| 26 * 1. Document node |
| 27 * 2. In-document Element node |
| 28 * 3. Detached Element node (an element with no parent, not in the document) |
| 29 * 4. Document Fragment node |
| 30 * |
| 31 * For each context, the following tests are run: |
| 32 * |
| 33 * The interface check tests ensure that each type of node exposes the Selecto
rs API methods |
| 34 * |
| 35 * The special selector tests verify the result of passing special values for
the selector parameter, |
| 36 * to ensure that the correct WebIDL processing is performed, such as stringif
ication of null and |
| 37 * undefined and missing parameter. The universal selector is also tested here
, rather than with the |
| 38 * rest of ordinary selectors for practical reasons. |
| 39 * |
| 40 * The static list verification tests ensure that the node lists returned by t
he method remain unchanged |
| 41 * due to subsequent document modication, and that a new list is generated eac
h time the method is |
| 42 * invoked based on the current state of the document. |
| 43 * |
| 44 * The invalid selector tests ensure that SyntaxError is thrown for invalid fo
rms of selectors |
| 45 * |
| 46 * The valid selector tests check the result from querying many different type
s of selectors, with a |
| 47 * list of expected elements. This checks that querySelector() always returns
the first result from |
| 48 * querySelectorAll(), and that all matching elements are correctly returned i
n tree-order. The tests |
| 49 * can be limited by specifying the test types to run, using the testType vari
able. The constants for this |
| 50 * can be found in selectors.js. |
| 51 * |
| 52 * All the selectors tested for both the valid and invalid selector tests are
found in selectors.js. |
| 53 * See comments in that file for documentation of the format used. |
| 54 * |
| 55 * The level1-lib.js file contains all the common test functions for running e
ach of the aforementioned tests |
| 56 */ |
| 57 |
| 58 // Prepare the nodes for testing |
| 59 //doc = frame.contentDocument; // Document Node tests |
| 60 doc = getTestContentDocument(); |
| 61 |
| 62 var element = doc.getElementById("root"); // In-document Element Node tests |
| 63 |
| 64 //Setup the namespace tests |
| 65 setupSpecialElements(element); |
| 66 |
| 67 var outOfScope = element |
| 68 .clone(true); // Append this to the body before running the in-document |
| 69 // Element tests, but after running the Document tests. This |
| 70 // tests that no elements that are not descendants of element |
| 71 // are selected. |
| 72 |
| 73 traverse(outOfScope, (elem) { |
| 74 // Annotate each element as being a clone; used for verifying |
| 75 elem.attributes["data-clone"] = |
| 76 ""; // that none of these elements ever match. |
| 77 }); |
| 78 |
| 79 var detached = element.clone(true); // Detached Element Node tests |
| 80 |
| 81 var fragment = doc.createDocumentFragment(); // Fragment Node tests |
| 82 fragment.append(element.clone(true)); |
| 83 |
| 84 // Setup Tests |
| 85 interfaceCheck("Document", doc); |
| 86 interfaceCheck("Detached Element", detached); |
| 87 interfaceCheck("Fragment", fragment); |
| 88 interfaceCheck("In-document Element", element); |
| 89 |
| 90 runSpecialSelectorTests("Document", doc); |
| 91 runSpecialSelectorTests("Detached Element", detached); |
| 92 runSpecialSelectorTests("Fragment", fragment); |
| 93 runSpecialSelectorTests("In-document Element", element); |
| 94 |
| 95 verifyStaticList("Document", doc); |
| 96 verifyStaticList("Detached Element", detached); |
| 97 verifyStaticList("Fragment", fragment); |
| 98 verifyStaticList("In-document Element", element); |
| 99 |
| 100 // TODO(jmesserly): fix negative tests |
| 101 //runInvalidSelectorTest("Document", doc, invalidSelectors); |
| 102 //runInvalidSelectorTest("Detached Element", detached, invalidSelectors); |
| 103 //runInvalidSelectorTest("Fragment", fragment, invalidSelectors); |
| 104 //runInvalidSelectorTest("In-document Element", element, invalidSelectors); |
| 105 |
| 106 runValidSelectorTest("Document", doc, validSelectors, testType, docType); |
| 107 runValidSelectorTest( |
| 108 "Detached Element", detached, validSelectors, testType, docType); |
| 109 runValidSelectorTest("Fragment", fragment, validSelectors, testType, docType); |
| 110 |
| 111 group('out of scope', () { |
| 112 setUp(() { |
| 113 doc.body.append(outOfScope); // Append before in-document Element tests. |
| 114 // None of these elements should match |
| 115 }); |
| 116 tearDown(() { |
| 117 outOfScope.remove(); |
| 118 }); |
| 119 runValidSelectorTest( |
| 120 "In-document Element", element, validSelectors, testType, docType); |
| 121 }); |
| 122 } |
OLD | NEW |