tor-browser

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

later-script-removed-by-earlier-script.html (1651B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>A later-inserted script removed by an earlier-inserted script does not run</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <body>
      7 <script>
      8 
      9 test(t => {
     10  const fragment = document.createDocumentFragment();
     11  // Global so they can be more easily accessed by the inner script blocks.
     12  window.script1 = fragment.appendChild(document.createElement("script"));
     13  window.script2 = fragment.appendChild(document.createElement("script"));
     14 
     15  window.script2Run = false;
     16  t.add_cleanup(() => { window.script2Run = false; });
     17  script1.textContent = `
     18    assert_true(script2.isConnected, 'script2 is connected when script2 runs');
     19    script2.remove();
     20  `;
     21  script2.textContent = "window.script2Run = true;";
     22 
     23  document.body.append(fragment);
     24  assert_false(window.script2Run, "script2 did not run");
     25 }, "A later-inserted script removed by an earlier-inserted script in the " +
     26   "same document fragment should not run");
     27 
     28 test(t => {
     29  window.script1 = document.createElement("script");
     30  window.script2 = document.createElement("script");
     31 
     32  window.script2Run = false;
     33  t.add_cleanup(() => { window.script2Run = false; });
     34  script1.textContent = `
     35    assert_true(script2.isConnected, 'script2 is connected when script2 runs');
     36    script2.remove();
     37  `;
     38  script2.textContent = "window.script2Run = true;";
     39 
     40  document.body.append(script1, script2);
     41  assert_false(window.script2Run, "script2 did not run");
     42 }, "A later-inserted script removed by an earlier-inserted script in the " +
     43   "same append() call should not run");
     44 </script>
     45 </body>