tor-browser

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

nonces.html (2725B)


      1 <!DOCTYPE html>
      2 <script src="/resources/testharness.js"></script>
      3 <script src="/resources/testharnessreport.js"></script>
      4 <div id=log></div>
      5 <script>
      6  const namespace_url= {
      7    "HTML": "http://www.w3.org/1999/xhtml",
      8    "SVG": "http://www.w3.org/2000/svg",
      9  }
     10  const test_cases = [
     11    ["meh"    , "HTML"],
     12    ["div"    , "HTML"],
     13    ["script" , "HTML"],
     14    ["meh"    , "SVG"],
     15    ["svg"    , "SVG"],
     16    ["script" , "SVG"],
     17    ["style"  , "HTML"],
     18    ["link"   , "HTML"]
     19  ];
     20 
     21  test_cases.forEach(([localName, namespace]) => {
     22    test(t => {
     23      const element = document.createElementNS(namespace_url[namespace], localName);
     24      t.add_cleanup(() => element.remove());
     25      assert_equals(element.nonce, "", "Initial IDL attribute value");
     26      assert_equals(element.getAttribute("nonce"), null, "Initial content attribute");
     27 
     28      element.setAttribute("nonce", "x");
     29      assert_equals(element.nonce, "x", "IDL attribute is modified after content attribute set");
     30      assert_equals(element.getAttribute("nonce"), "x", "Content attribute is modified after content attribute set");
     31 
     32      document.body.appendChild(element);
     33      assert_equals(element.nonce, "x", "IDL attribute is unchanged after element insertion");
     34      assert_equals(element.getAttribute("nonce"), "", "Content attribute is changed after element insertion");
     35    }, `Basic nonce tests for ${localName} in ${namespace} namespace`);
     36 
     37    test(t => {
     38      const element = document.createElementNS(namespace_url[namespace], localName);
     39      t.add_cleanup(() => element.remove());
     40      element.setAttribute("nonce", "x");
     41      assert_equals(element.nonce, "x", "IDL attribute is modified after content attribute set");
     42 
     43      element.removeAttribute("nonce");
     44      assert_equals(element.nonce, "", "IDL attribute is empty after content attribute removal");
     45    }, `Ensure that removal of content attribute does not affect IDL attribute for ${localName} in ${namespace} namespace`);
     46 
     47    test(t => {
     48      const element = document.createElementNS(namespace_url[namespace], localName);
     49      t.add_cleanup(() => element.remove());
     50      assert_equals(element.nonce, "");
     51      assert_equals(element.getAttribute("nonce"), null);
     52 
     53      element.setAttribute("nonce", "");
     54      assert_equals(element.nonce, "");
     55      assert_equals(element.getAttribute("nonce"), "");
     56 
     57      document.body.appendChild(element);
     58      assert_equals(element.nonce, "");
     59      assert_equals(element.getAttribute("nonce"), "");
     60 
     61      element.removeAttribute("nonce");
     62      assert_equals(element.nonce, "");
     63      assert_equals(element.getAttribute("nonce"), null);
     64    }, `Test empty nonces for ${localName} in ${namespace} namespace`);
     65  });
     66 </script>