diff options
Diffstat (limited to 'tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module')
6 files changed, 55 insertions, 18 deletions
diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.html b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.html index 1618f40eb61..7ff672da6a9 100644 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.html +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.html @@ -3,34 +3,51 @@ <head> <script src="/resources/testharness.js"></script> <script src="/resources/testharnessreport.js"></script> + <script src="/common/utils.js"></script> </head> <body> <script> setup({allow_uncaught_exception: true}); - async_test(function (test) { - const worker = new Worker("./resources/worker.js", { + promise_test(function (test) { + const uuid = token(); + const worker = new Worker(`./resources/worker.sub.js?key=${uuid}`, { type: "module" }); - worker.onmessage = test.unreached_func("A CSS Module within a web worker should not load."); - worker.onerror = test.step_func_done(); - }, "A static import CSS Module within a web worker should not load."); + return new Promise((resolve, reject) => { + worker.addEventListener("error", resolve); + worker.addEventListener("message", reject); + }).then(async () => { + const fetchResponse = await fetch(`./resources/record-fetch.py?key=${uuid}&action=getCount`); + const fetchData = await fetchResponse.json(); + assert_equals(fetchData.count, 0, "Shouldn't have tried fetching CSS module in worker"); + }); + }, "A static import CSS Module within a web worker should not load and should not attempt to fetch the module."); - async_test(function (test) { - const worker = new Worker("./resources/worker-dynamic-import.js", { + promise_test(function (test) { + const uuid = token(); + const worker = new Worker(`./resources/worker-dynamic-import.sub.js?key=${uuid}`, { type: "module" }); - worker.onmessage = test.step_func_done(e => { - assert_equals(e.data, "NOT LOADED"); + + return new Promise(resolve => { + worker.addEventListener("message", resolve); + }).then(async (event) => { + assert_equals(event.data, "NOT LOADED"); + const fetchResponse = await fetch(`./resources/record-fetch.py?key=${uuid}&action=getCount`); + const fetchData = await fetchResponse.json(); + assert_equals(fetchData.count, 0, "Shouldn't have tried fetching CSS module in worker"); }); - }, "A dynamic import CSS Module within a web worker should not load."); + }, "A dynamic import CSS Module within a web worker should not load and should not attempt to fetch the module."); - async_test(function (test) { + promise_test(function (test) { const worker = new Worker("./resources/basic.css", { type: "module" }); - worker.onerror = test.step_func_done(); - }, "A CSS Module within a web worker should not load."); + return new Promise(resolve => { + worker.onerror = resolve; + }); + }, "An attempt to load a CSS module as a worker should fail."); </script> diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/record-fetch.py b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/record-fetch.py new file mode 100644 index 00000000000..4928cb4acb9 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/record-fetch.py @@ -0,0 +1,20 @@ +def main(request, response): + try: + stash_key = request.GET.first(b"key") + action = request.GET.first(b"action") + + run_count = request.server.stash.take(stash_key) + if not run_count: + run_count = 0 + + if action == b"incCount": + request.server.stash.put(stash_key, run_count + 1) + response.headers.set(b"Content-Type", b"text/css") + response.content = b'#test { background-color: #FF0000; }' + elif action == b"getCount": + response.headers.set(b"Content-Type", b"text/json") + response.content = b'{"count": %d }' % run_count + else: + response.set_error(400, u"Invalid action") + except: + response.set_error(400, u"Not enough parameters") diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.js deleted file mode 100644 index 6f6852ce550..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.js +++ /dev/null @@ -1,3 +0,0 @@ -import("./basic.css", { assert: { type: "css" } }) - .then(() => postMessage("LOADED")) - .catch(e => postMessage("NOT LOADED"));
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.sub.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.sub.js new file mode 100644 index 00000000000..791bd7d3f94 --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker-dynamic-import.sub.js @@ -0,0 +1,3 @@ +import("./record-fetch.py?key={{GET[key]}}&action=incCount", { assert: { type: "css" } }) + .then(() => postMessage("LOADED")) + .catch(e => postMessage("NOT LOADED"));
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.js deleted file mode 100644 index c97d9652d35..00000000000 --- a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.js +++ /dev/null @@ -1,2 +0,0 @@ -import "./basic.css" assert { type: "css" }; -postMessage("Unexpectedly loaded");
\ No newline at end of file diff --git a/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.sub.js b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.sub.js new file mode 100644 index 00000000000..ffee312d21e --- /dev/null +++ b/tests/wpt/web-platform-tests/html/semantics/scripting-1/the-script-element/css-module/resources/worker.sub.js @@ -0,0 +1,2 @@ +import "./record-fetch.py?key={{GET[key]}}&action=incCount" assert { type: "css" }; +postMessage("Unexpectedly loaded");
\ No newline at end of file |