tor-browser

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

emptyish-script-elements.html (3756B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8">
      3 <title>Treatment of various empty-ish script elements</title>
      4 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
      5 <link rel="help" href="https://html.spec.whatwg.org/multipage/#prepare-a-script">
      6 <link rel="help" href="https://html.spec.whatwg.org/multipage/#already-started">
      7 <link rel="help" href="https://github.com/whatwg/html/issues/3419">
      8 
      9 <script src="/resources/testharness.js"></script>
     10 <script src="/resources/testharnessreport.js"></script>
     11 
     12 <script id="no-children"></script>
     13 <script id="whitespace-child"> </script>
     14 
     15 <script id="gets-a-no-text-child"></script>
     16 <script id="gets-an-empty-text-child"></script>
     17 <script id="gets-a-text-child"></script>
     18 <script id="gets-a-comment-child"></script>
     19 <script id="gets-a-text-descendant"></script>
     20 
     21 <script>
     22 "use strict";
     23 
     24 test(() => {
     25  const el = document.querySelector("#no-children");
     26  el.appendChild(document.createTextNode("window.noChildrenExecuted = true;"));
     27  assert_true(window.noChildrenExecuted);
     28 }, "A script with no children bails early, before setting already-started, so can be executed when adding text");
     29 
     30 test(() => {
     31  const el = document.querySelector("#whitespace-child");
     32  el.appendChild(document.createTextNode("window.whitespaceChildExecuted = true;"));
     33  assert_equals(window.whitespaceChildExecuted, undefined);
     34 }, "A script with a whitespace child executes, setting already-started, so adding text is a no-op");
     35 
     36 test(() => {
     37  const el = document.querySelector("#gets-a-no-text-child");
     38  el.appendChild(document.createElement("span"));
     39  el.appendChild(document.createTextNode("window.getsANoTextChildExecuted = true;"));
     40  assert_true(window.getsANoTextChildExecuted);
     41 }, "A script with an empty element inserted bails early, before setting already-started, so can be executed when adding text");
     42 
     43 test(() => {
     44  const el = document.querySelector("#gets-an-empty-text-child");
     45  el.appendChild(document.createTextNode(""));
     46  el.appendChild(document.createTextNode("window.getsAnEmptyTextChildExecuted = true;"));
     47  assert_true(window.getsAnEmptyTextChildExecuted);
     48 }, "A script with an empty text node inserted bails early, before setting already-started, so can be executed when adding text");
     49 
     50 test(() => {
     51  const el = document.querySelector("#gets-a-text-child");
     52  el.appendChild(document.createTextNode("window.getsATextChildExecuted1 = true;"));
     53  el.appendChild(document.createTextNode("window.getsATextChildExecuted2 = true;"));
     54  assert_true(window.getsATextChildExecuted1);
     55  assert_equals(window.getsATextChildExecuted2, undefined);
     56 }, "A script with a text child inserted executes, setting already-started, so adding text is a no-op");
     57 
     58 test(() => {
     59  const el = document.querySelector("#gets-a-comment-child");
     60  el.appendChild(document.createComment("window.getsACommentChild1 = true;"));
     61  el.appendChild(document.createTextNode("window.getsACommentChild2 = true;"));
     62  assert_equals(window.getsACommentChild1, undefined);
     63  assert_true(window.getsACommentChild2);
     64 }, "A script with a comment child inserted bails early, before setting already-started, so can be executed when adding text");
     65 
     66 test(() => {
     67  const el = document.querySelector("#gets-a-text-descendant");
     68  const child = document.createElement("span");
     69  child.appendChild(document.createTextNode("window.getsATextDescendantExecuted1 = true;"));
     70  el.appendChild(child);
     71  el.appendChild(document.createTextNode("window.getsATextDescendantExecuted2 = true;"));
     72  assert_equals(window.getsATextDescendantExecuted1, undefined);
     73  assert_true(window.getsATextDescendantExecuted2);
     74 }, "A script with an element containing text inserted bails early, before setting already-started, so can be executed when adding text");
     75 </script>