tor-browser

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

ttwf-cssom-doc-ext-load-count.html (2760B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4    <title>CSSOM - Extensions to the Document Interface: StyleSheetList length reflects dynamically loaded and unloaded sheets</title>
      5    <link rel="author" title="Jesse Bounds" href="mailto:jesse@codeforamerica.org">
      6    <link rel="help" href="http://www.w3.org/TR/cssom-1/#extensions-to-the-document-interface">
      7    <link rel="help" href="http://www.w3.org/TR/cssom-1/#the-stylesheetlist-interface">
      8    <link rel="help" href="http://www.w3.org/TR/cssom-1/#css-style-sheet-collections">
      9    <link rel="stylesheet" href="stylesheet.css" type="text/css">
     10    <meta name="flags" content="dom">
     11    <meta name="assert" content="The styleSheets length attribute must reflect the number of sheets at page load and after dynamically">
     12    <script src="/resources/testharness.js"></script>
     13    <script src="/resources/testharnessreport.js"></script>
     14 </head>
     15 <body>
     16    <div id="log"></div>
     17    <script>
     18 
     19      // Get the Document's styleSheets attribute
     20      var styleSheets = document.styleSheets;
     21 
     22      // Verify that the styleSheets list length is 1 due to "stylesheet.css" loaded in head section
     23      test(function() {
     24        assert_equals(styleSheets.length, 1, "styleSheets.length is incorrect:");
     25      }, "stylesheet.css should be loaded and styleSheets.length === 1");
     26 
     27      // Verify that the styleSheets list length is 0 after removing the loaded sheet from the DOM
     28      test(function() {
     29 
     30        // get the one and only sheet loaded
     31        var sheet = styleSheets.item(0);
     32 
     33        // remove the sheet from the DOM
     34        sheet.ownerNode.parentNode.removeChild(sheet.ownerNode)
     35 
     36        // assert that there are 0 styleSheets in the styleSheets property
     37        assert_equals(styleSheets.length, 0, "styleSheets.length is incorrect:");
     38 
     39      }, "stylesheet.css should be unloaded and styleSheets.length === 0");
     40 
     41      // Verify that the styleSheets list length is back to 1 after loading a new sheet
     42      async_test(function(t) {
     43 
     44        // create a css file reference
     45        var fileReference = document.createElement("link");
     46        fileReference.setAttribute("rel", "stylesheet");
     47        fileReference.setAttribute("type", "text/css");
     48        fileReference.setAttribute("href", "stylesheet-1.css");
     49        fileReference.onerror = t.step_func_done(function() {
     50          // assert that there is 1 styleSheet in the styleSheets property
     51          assert_equals(styleSheets.length, 1, "styleSheets.length is incorrect:");
     52        });
     53 
     54        // load the css file reference into the head section
     55        var head = document.getElementsByTagName("HEAD")[0];
     56        head.appendChild(fileReference);
     57      }, "stylesheet-1.css should be loaded and styleSheets.length === 1");
     58 
     59    </script>
     60 </body>
     61 </html>