Skip to content

Commit

Permalink
Test various contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Oct 23, 2022
1 parent f7748df commit 19e9d13
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// META: global=window,dedicatedworker,sharedworker
// META: script=ticker.js

promise_test(async t => {
const getCount = ticker(1000);

const importP = import("<invalid>");
await promise_rejects_js(t, TypeError, importP, 'import() should reject');

assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue if it fails during specifier resolution");

promise_test(async t => {
// Use Date.now() to ensure that the module is not in the module map
const specifier = "./empty-module.js?" + Date.now();

await import(specifier);

const getCount = ticker(1000);
await import(specifier);
assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue when loading an already loaded module");

promise_test(async t => {
// Use Date.now() to ensure that the module is not in the module map
const specifier = "./empty-module.js?" + Date.now();

const getCount = ticker(1e7);
await import(specifier);
assert_equals(getCount(), 1e7);
}, "import() should drain the microtask queue when fetching a new module");

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// META: global=dedicatedworker,sharedworker
// META: script=ticker.js

promise_test(async t => {
// Use Date.now() to ensure that the module is not in the module map
const specifier = "./empty-module.css?" + Date.now();

const getCount = ticker(1000);

const importP = import(specifier, { assert: { type: "css" } });
await promise_rejects_js(t, TypeError, importP, 'import() should reject');

assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue if it fails because of the 'type: css' assertion in a worker");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
This file is empty, because all it matters is if the
dynamic import that loads it fails or succedes.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
This file is empty, because all it matters is if the
dynamic import that loads it fails or succedes.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// META: global=serviceworker
// META: script=ticker.js

promise_test(async t => {
// Use Date.now() to ensure that the module is not in the module map
const specifier = "./empty-module.js?" + Date.now();

const getCount = ticker(1000);

const importP = import(specifier);
await promise_rejects_js(t, TypeError, importP, 'import() should reject');

assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue if it fails because it's used in a ServiceWorker");
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function ticker(max) {
globalThis.ticker = function ticker(max) {
let i = 0;
let stop = false;
Promise.resolve().then(function loop() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// META: global=window,dedicatedworker,sharedworker
// META: script=ticker.js

promise_test(async t => {
// Use Date.now() to ensure that the module is not in the module map
const specifier = "./empty-module.js?" + Date.now();

const getCount = ticker(1000);

const importP = import(specifier, { assert: { type: "<invalid>" } });
await promise_rejects_js(t, TypeError, importP, 'import() should reject');

assert_less_than(getCount(), 1000);
}, "import() should not drain the microtask queue if it fails while validating the 'type' assertion");

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<canvas id ="output" width="100" height="100" style="background: blue;"></canvas>
<script>
"use strict";
const canvas = document.getElementById('output');
const ctx = canvas.getContext('2d');

ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html class="reftest-wait">
<link rel="help" href="https://html.spec.whatwg.org/#hostimportmoduledynamically(referencingscriptormodule,-specifier,-promisecapability)">
<link rel="match" href="worklet-ref.html">
<style>
#output {
width: 100px;
height: 100px;
background-image: paint(rects);
background-color: blue;
}
</style>
<script src="/common/reftest-wait.js"></script>
<script src="/common/worklet-reftest.js"></script>
<body>
<div id="output"></div>

<script id="code" type="text/worklet">
registerPaint('rects', class {
async paint(ctx, geom) {
ctx.fillStyle = 'red';

const getCount = ticker(1000);

try {
// Use Date.now() to ensure that the module is not in the module map
await import("./empty-module.js?" + Date.now());
} catch (e) {
if (getCount() < 1000) {
ctx.fillStyle = 'green';
}
}
ctx.fillRect(0, 0, geom.width, geom.height);
}
});
</script>

<script>
"use strict";
CSS.paintWorklet.addModule("./ticker.js").then(() =>
importWorkletAndTerminateTestAfterAsyncPaint(CSS.paintWorklet, document.getElementById('code').textContent)
);
</script>

0 comments on commit 19e9d13

Please sign in to comment.