tor-browser

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

insertion-removing-steps-script.window.js (2032B)


      1 promise_test(async t => {
      2  const fragmentWithTwoScripts = new DocumentFragment();
      3  const script0 = document.createElement('script');
      4  const script1 = fragmentWithTwoScripts.appendChild(document.createElement('script'));
      5  const script2 = fragmentWithTwoScripts.appendChild(document.createElement('script'));
      6 
      7  window.kBaselineNumberOfScripts = document.scripts.length;
      8  assert_equals(document.scripts.length, kBaselineNumberOfScripts,
      9      "The WPT infra starts out with exactly 3 scripts");
     10 
     11  window.script0Executed = false;
     12  script0.innerText = `
     13    script0Executed = true;
     14    assert_equals(document.scripts.length, kBaselineNumberOfScripts + 1,
     15        'script0 can observe itself and no other scripts');
     16  `;
     17 
     18  window.script1Executed = false;
     19  script1.innerText = `
     20    script1Executed = true;
     21    assert_equals(document.scripts.length, kBaselineNumberOfScripts + 2,
     22        "script1 executes synchronously, and thus observes only itself and " +
     23        "previous scripts");
     24  `;
     25 
     26  window.script2Executed = false;
     27  script2.innerText = `
     28    script2Executed = true;
     29    assert_equals(document.scripts.length, kBaselineNumberOfScripts + 3,
     30        "script2 executes synchronously, and thus observes itself and all " +
     31        "previous scripts");
     32  `;
     33 
     34  assert_false(script0Executed, "Script0 does not execute before append()");
     35  document.body.append(script0);
     36  assert_true(script0Executed,
     37      "Script0 executes synchronously during append()");
     38 
     39  assert_false(script1Executed, "Script1 does not execute before append()");
     40  assert_false(script2Executed, "Script2 does not execute before append()");
     41  document.body.append(fragmentWithTwoScripts);
     42  assert_true(script1Executed,
     43      "Script1 executes synchronously during fragment append()");
     44  assert_true(script2Executed,
     45      "Script2 executes synchronously during fragment append()");
     46 }, "Script node insertion is not atomic with regard to execution. Each " +
     47   "script is synchronously executed during the HTML element insertion " +
     48   "steps hook");