Chromium Code Reviews| 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 html5lib.test.selectors.level1_baseline_test; | |
| 7 | |
| 8 import 'dart:io'; | |
| 9 import 'package:html5lib/dom.dart'; | |
| 10 import 'package:html5lib/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.clone(true); // Append this to the body before runn ing the in-document | |
| 68 // Element tests, but after runni ng the Document tests. This | |
| 69 // tests that no elements that ar e not descendants of element | |
| 70 // are selected. | |
| 71 | |
| 72 traverse(outOfScope, (elem) { // Annotate each element as being a clone ; used for verifying | |
| 73 elem.attributes["data-clone"] = ""; // that none of these elements ever match. | |
| 74 }); | |
| 75 | |
| 76 var detached = element.clone(true); // Detached Element Node tests | |
| 77 | |
| 78 var fragment = doc.createDocumentFragment(); // Fragment Node tests | |
| 79 fragment.append(element.clone(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); | |
| 93 verifyStaticList("Detached Element", detached); | |
| 94 verifyStaticList("Fragment", fragment); | |
| 95 verifyStaticList("In-document Element", element); | |
| 96 | |
| 97 // TODO(jmesserly): fix negative tests | |
| 98 //runInvalidSelectorTest("Document", doc, invalidSelectors); | |
| 99 //runInvalidSelectorTest("Detached Element", detached, invalidSelectors); | |
| 100 //runInvalidSelectorTest("Fragment", fragment, invalidSelectors); | |
| 101 //runInvalidSelectorTest("In-document Element", element, invalidSelectors); | |
| 102 | |
| 103 runValidSelectorTest("Document", doc, validSelectors, testType, docType); | |
| 104 runValidSelectorTest("Detached Element", detached, validSelectors, testType, d ocType); | |
|
Siggi Cherem (dart-lang)
2014/05/02 17:46:10
80 col? Or does the same note you made in the next
Jennifer Messerly
2014/05/08 21:15:41
yeah, it's another ported test file :)
| |
| 105 runValidSelectorTest("Fragment", fragment, validSelectors, testType, docType); | |
| 106 | |
| 107 group('out of scope', () { | |
| 108 setUp(() { | |
| 109 doc.body.append(outOfScope); // Append before in-document Element tests. | |
| 110 // None of these elements should match | |
| 111 }); | |
| 112 tearDown(() { | |
| 113 outOfScope.remove(); | |
| 114 }); | |
| 115 runValidSelectorTest("In-document Element", element, validSelectors, testTyp e, docType); | |
| 116 }); | |
| 117 } | |
| OLD | NEW |