Update web-platform-tests to revision cf261625e2d230ab219eec966f4abe26e3401b64

This commit is contained in:
WPT Sync Bot 2018-05-29 21:17:45 -04:00
parent 11a89bcc47
commit 8f98acd0e7
297 changed files with 3396 additions and 1555 deletions

View file

@ -0,0 +1,42 @@
<!DOCTYPE html>
<title>DedicatedWorker: import failure</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async () => {
const scriptURL = 'resources/import-scripts-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
const msg_event = await new Promise(resolve => worker.onmessage = resolve);
assert_equals(msg_event.data, 'TypeError');
}, 'importScripts() on module worker should throw an exception.');
promise_test(async () => {
const scriptURL = 'resources/static-import-worker.js';
const worker = new Worker(scriptURL, { type: 'classic' });
await new Promise(resolve => worker.onerror = resolve);
}, 'Static import on classic worker should throw an exception.');
promise_test(() => {
const scriptURL = 'resources/non-existent-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
return new Promise(resolve => worker.onerror = resolve);
}, 'Worker construction for non-existent script should dispatch an ' +
'ErrorEvent.');
promise_test(() => {
const scriptURL = 'resources/static-import-non-existent-script-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
return new Promise(resolve => worker.onerror = resolve);
}, 'Static import for non-existent script should dispatch an ErrorEvent.');
promise_test(async () => {
const script_url = './non-existent-worker.js';
const worker = new Worker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.postMessage(script_url);
const msg_event = await new Promise(resolve => worker.onmessage = resolve);
assert_equals(msg_event.data, 'TypeError');
}, 'Dynamic import for non-existent script should throw an exception.');
</script>

View file

@ -4,73 +4,44 @@
<script src="/resources/testharnessreport.js"></script>
<script>
// Start a dedicated worker for |scriptURL| and wait until MessageEvents from
// imported modules up to |expectedNumberOfImportedModules|.
function RunImportTest(scriptURL, expectedNumberOfImportedModules) {
return new Promise(resolve => {
let numberOfImportedModules = 0;
// Starts a dedicated worker for |scriptURL| and waits until the list of
// imported modules is sent from the worker. Passes if the list is equal to
// |expectedImportedModules|.
function import_test(scriptURL, expectedImportedModules, description) {
promise_test(async () => {
const worker = new Worker(scriptURL, { type: 'module' });
worker.onmessage = e => {
if (e.data === 'LOADED')
++numberOfImportedModules;
if (numberOfImportedModules === expectedNumberOfImportedModules)
resolve();
};
});
const msg_event = await new Promise(resolve => worker.onmessage = resolve);
assert_array_equals(msg_event.data, expectedImportedModules);
}, description);
}
promise_test(() => {
return RunImportTest('resources/static-import-worker.js', 2);
}, 'Test static import on DedicatedWorkerGlobalScope.');
import_test('resources/static-import-worker.js',
['export-on-load-script.js'],
'Static import.');
promise_test(() => {
return RunImportTest('resources/nested-static-import-worker.js', 3);
}, 'Test nested static import on DedicatedWorkerGlobalScope.');
import_test('resources/nested-static-import-worker.js',
['export-on-static-import-script.js', 'export-on-load-script.js'],
'Nested static import.');
promise_test(() => {
return RunImportTest(
'resources/static-import-and-then-dynamic-import-worker.js', 3);
}, 'Test static import and then dynamic import on DedicatedWorkerGlobalScope.');
promise_test(() => {
return RunImportTest('resources/dynamic-import-worker.js', 2);
}, 'Test dynamic import on DedicatedWorkerGlobalScope.');
import_test('resources/static-import-and-then-dynamic-import-worker.js',
['export-on-dynamic-import-script.js', 'export-on-load-script.js'],
'Static import and then dynamic import.');
promise_test(() => {
return RunImportTest('resources/nested-dynamic-import-worker.js', 3);
}, 'Test nested dynamic import on DedicatedWorkerGlobalScope.');
import_test('resources/dynamic-import-worker.js',
['export-on-load-script.js'],
'Dynamic import.');
promise_test(() => {
return RunImportTest(
'resources/dynamic-import-and-then-static-import-worker.js', 3);
}, 'Test dynamic import and then static import on DedicatedWorkerGlobalScope.');
import_test('resources/nested-dynamic-import-worker.js',
['export-on-dynamic-import-script.js', 'export-on-load-script.js'],
'Nested dynamic import.');
promise_test(() => {
const scriptURL = 'resources/import-scripts-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
return (new Promise(resolve => worker.onmessage = resolve))
.then(e => assert_equals(e.data, 'TypeError'));
}, 'importScripts() on module worker should throw an exception.');
import_test('resources/dynamic-import-and-then-static-import-worker.js',
['export-on-static-import-script.js', 'export-on-load-script.js'],
'Dynamic import and then static import.');
promise_test(() => {
const scriptURL = 'resources/non-existent-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
return new Promise(resolve => worker.onerror = resolve);
}, 'Worker construction for non-existent script should throw an exception.');
promise_test(() => {
const scriptURL = 'resources/static-import-non-existent-script-worker.js';
const worker = new Worker(scriptURL, { type: 'module' });
return new Promise(resolve => worker.onerror = resolve);
}, 'Static import for non-existent script should throw an exception.');
promise_test(() => {
const script_url = './non-existent-worker.js';
const worker = new Worker('resources/dynamic-import-given-url-worker.js',
{ type: 'module' });
worker.postMessage(script_url);
return new Promise(resolve => worker.onmessage = resolve)
.then(msg_event => assert_equals(msg_event.data, 'ERROR'));
}, 'Dynamic import for non-existent script should throw an exception.');
import_test('resources/eval-dynamic-import-worker.js',
['export-on-load-script.js'],
'eval(import()).');
</script>

View file

@ -1,2 +1,2 @@
import('./static-import-worker.js')
.then(module => postMessage('LOADED'));
import('./export-on-static-import-script.js')
.then(module => postMessage(module.importedModules));

View file

@ -1,4 +1,5 @@
// Dynamically import the script URL sent by postMessage().
self.addEventListener('message', e => {
import(e.data).catch(error_event => postMessage('ERROR'));
// This worker dynamically imports the script URL sent by postMessage(), and
// sends back an error name if the dynamic import fails.
self.addEventListener('message', msg_event => {
import(msg_event.data).catch(e => postMessage(e.name));
});

View file

@ -1,2 +1,2 @@
import('./post-message-on-load-worker.js')
.then(module => postMessage('LOADED'));
import('./export-on-load-script.js')
.then(module => postMessage(module.importedModules));

View file

@ -0,0 +1,3 @@
const code = "import('./export-on-load-script.js')" +
" .then(module => postMessage(module.importedModules));"
eval(code);

View file

@ -0,0 +1,7 @@
// Export the list of imported modules. It's available after the |ready| promise
// is resolved.
export let importedModules = ['export-on-dynamic-import-script.js'];
export let ready = import('./export-on-load-script.js')
.then(module => {
Array.prototype.push.apply(importedModules, module.importedModules);
});

View file

@ -0,0 +1 @@
export const importedModules = ['export-on-load-script.js'];

View file

@ -0,0 +1,3 @@
import * as module from './export-on-load-script.js';
const filename = 'export-on-static-import-script.js';
export const importedModules = [filename].concat(module.importedModules);

View file

@ -2,5 +2,14 @@ try {
importScripts('empty-worker.js');
postMessage('LOADED');
} catch (e) {
// Post a message instead of propagating an ErrorEvent to the page because
// propagated event loses an error name.
//
// Step 1. "Let notHandled be the result of firing an event named error at the
// Worker object associated with the worker, using ErrorEvent, with the
// cancelable attribute initialized to true, the message, filename, lineno,
// and colno attributes initialized appropriately, and the error attribute
// initialized to null."
// https://html.spec.whatwg.org/multipage/workers.html#runtime-script-errors-2
postMessage(e.name);
}

View file

@ -1,2 +1,5 @@
import('./dynamic-import-worker.js')
.then(module => postMessage('LOADED'));
import('./export-on-dynamic-import-script.js')
.then(async module => {
await module.ready;
postMessage(module.importedModules);
});

View file

@ -1,2 +1,2 @@
import './static-import-worker.js';
postMessage('LOADED')
import * as module from './export-on-static-import-script.js';
postMessage(module.importedModules);

View file

@ -1,2 +1,2 @@
import './dynamic-import-worker.js';
postMessage('LOADED');
import * as module from './export-on-dynamic-import-script.js';
module.ready.then(() => postMessage(module.importedModules));

View file

@ -1,2 +1,2 @@
import './post-message-on-load-worker.js';
postMessage('LOADED');
import * as module from './export-on-load-script.js';
postMessage(module.importedModules);