tor-browser

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

nomodule-set-on-async-classic-script.html (1977B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <title>External classic scripts with nomodule content attribute must not run</title>
      5 <link rel="author" title="Yusuke Suzuki" href="mailto:utatane.tea@gmail.com">
      6 <link rel="author" title="Ryosuke Niwa" href="mailto:rniwa@webkit.org">
      7 <script src="/resources/testharness.js"></script>
      8 <script src="/resources/testharnessreport.js"></script>
      9 <!-- Load this script synchronously to ensure test cases below can load it in 200ms -->
     10 <script src="resources/set-script-executed.js"></script>
     11 </head>
     12 <body>
     13 <script>
     14 let supportsNoModule = "noModule" in document.getElementsByTagName("script")[0];
     15 
     16 waitForLoadEvent = new Promise((resolve) => {
     17    window.onload = resolve;
     18 });
     19 
     20 promise_test(() => {
     21    window.executed = false;
     22    let loaded = false;
     23    let errored = false;
     24 
     25    let script = document.createElement('script');
     26 
     27    script.src = './resources/set-script-executed.js';
     28    script.onload = () => loaded = true;
     29    script.onerror = () => errored = true;
     30    script.noModule = false;
     31    document.body.appendChild(script);
     32 
     33    return waitForLoadEvent.then(() => {
     34        assert_true(supportsNoModule);
     35        assert_true(executed);
     36        assert_true(loaded);
     37        assert_false(errored);
     38    });
     39 }, 'An asynchronously loaded classic script with noModule set to false must run');
     40 
     41 promise_test(() => {
     42    window.executed = false;
     43    let loaded = false;
     44    let errored = false;
     45 
     46    let script = document.createElement('script');
     47    script.src = './resources/set-script-executed.js';
     48    script.onload = () => loaded = true;
     49    script.onerror = () => errored = true;
     50    script.noModule = true;
     51    document.body.appendChild(script);
     52 
     53    return waitForLoadEvent.then(() => {
     54        assert_true(supportsNoModule);
     55        assert_false(executed);
     56        assert_false(loaded);
     57        assert_false(errored);
     58    });
     59 }, 'An asynchronously loaded classic script with noModule set to true must not run');
     60 
     61 </script>
     62 </body>
     63 </html>