tor-browser

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

css-module-worker-test.html (2268B)


      1 <!doctype html>
      2 
      3 <head>
      4    <script src="/resources/testharness.js"></script>
      5    <script src="/resources/testharnessreport.js"></script>
      6    <script src="/common/utils.js"></script>
      7 </head>
      8 
      9 <body>
     10    <script>
     11        setup({allow_uncaught_exception: true});
     12        promise_test(function (test) {
     13            const uuid = token();
     14            const worker = new Worker(`./resources/worker.sub.js?key=${uuid}`, {
     15                type: "module"
     16            });
     17            return new Promise((resolve, reject) => {
     18                worker.addEventListener("error", resolve);
     19                worker.addEventListener("message", reject);
     20            }).then(async () => {
     21                const fetchResponse = await fetch(`./resources/record-fetch.py?key=${uuid}&action=getCount`);
     22                const fetchData = await fetchResponse.json();
     23                assert_equals(fetchData.count, 0, "Shouldn't have tried fetching CSS module in worker");
     24            });
     25        }, "A static import CSS Module within a web worker should not load and should not attempt to fetch the module.");
     26 
     27        promise_test(function (test) {
     28            const uuid = token();
     29            const worker = new Worker(`./resources/worker-dynamic-import.sub.js?key=${uuid}`, {
     30                type: "module"
     31            });
     32 
     33            return new Promise(resolve => {
     34                worker.addEventListener("message", resolve);
     35            }).then(async (event) => {
     36                assert_equals(event.data, "NOT LOADED");
     37                const fetchResponse = await fetch(`./resources/record-fetch.py?key=${uuid}&action=getCount`);
     38                const fetchData = await fetchResponse.json();
     39                assert_equals(fetchData.count, 0, "Shouldn't have tried fetching CSS module in worker");
     40            });
     41        }, "A dynamic import CSS Module within a web worker should not load and should not attempt to fetch the module.");
     42 
     43        promise_test(function (test) {
     44            const worker = new Worker("./resources/basic.css", {
     45                type: "module"
     46            });
     47            return new Promise(resolve => {
     48                worker.onerror = resolve;
     49            });
     50        }, "An attempt to load a CSS module as a worker should fail.");
     51 
     52    </script>
     53 
     54 </body>