tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ParentNode-querySelector-All.html (5528B)


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