1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
// Runs a series of tests related to importing scripts on a worklet.
//
// Usage:
// runImportTests("paint");
function runImportTests(worklet_type) {
const worklet = get_worklet(worklet_type);
promise_test(() => {
const kScriptURL = 'resources/empty-worklet-script.js';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined,
'Promise should resolve with no arguments.');
});
}, 'Importing a script resolves the given promise.');
promise_test(() => {
const kScriptURL = 'resources/empty-worklet-script.js';
return Promise.all([
worklet.addModule(kScriptURL + '?1'),
worklet.addModule(kScriptURL + '?2'),
worklet.addModule(kScriptURL + '?3')
]).then(undefined_args => {
assert_array_equals(undefined_args,
[undefined, undefined, undefined],
'Promise should resolve with no arguments.');
});
}, 'Importing scripts resolves all the given promises.');
promise_test(() => {
const kScriptURL = 'resources/import-nested-worklet-script.js';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined,
'Promise should resolve with no arguments.');
});
}, 'Importing nested scripts resolves the given promise');
promise_test(() => {
const kScriptURL = 'resources/import-cyclic-worklet-script.js';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined,
'Promise should resolve with no arguments.');
});
}, 'Importing cyclic scripts resolves the given promise');
promise_test(() => {
const kScriptURL = 'resources/throwing-worklet-script.js';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined,
'Promise should resolve with no arguments.');
});
}, 'Importing a script which throws should still resolve the given ' +
'promise.');
promise_test(t => {
const kScriptURL = 'non-existent-worklet-script.js';
return promise_rejects_dom(t, 'AbortError',
worklet.addModule(kScriptURL));
}, 'Importing a non-existent script rejects the given promise with an ' +
'AbortError.');
promise_test(t => {
const kInvalidScriptURL = 'http://invalid:123$'
return promise_rejects_dom(t, 'SyntaxError',
worklet.addModule(kInvalidScriptURL));
}, 'Importing an invalid URL should reject the given promise with a ' +
'SyntaxError.');
promise_test(() => {
const kBlob = new Blob([""], {type: 'text/javascript'});
const kBlobURL = URL.createObjectURL(kBlob);
return worklet.addModule(kBlobURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a blob URL should resolve the given promise.');
promise_test(t => {
const kFileURL = 'file:///empty-worklet-script.js';
return promise_rejects_dom(t, 'AbortError',
worklet.addModule(kFileURL));
}, 'Importing a file:// URL should reject the given promise.');
promise_test(() => {
const kDataURL = 'data:text/javascript, // Do nothing.';
return worklet.addModule(kDataURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a data URL should resolve the given promise.');
promise_test(t => {
const kScriptURL = 'about:blank';
return promise_rejects_dom(t, 'AbortError',
worklet.addModule(kScriptURL));
}, 'Importing about:blank should reject the given promise.');
promise_test(() => {
// Specify the Access-Control-Allow-Origin header to enable cross origin
// access.
const kScriptURL = get_host_info().HTTPS_REMOTE_ORIGIN +
'/worklets/resources/empty-worklet-script.js' +
'?pipe=header(Access-Control-Allow-Origin, *)';
return worklet.addModule(kScriptURL).then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a cross origin resource with the ' +
'Access-Control-Allow-Origin header should resolve the given promise');
promise_test(t => {
// Don't specify the Access-Control-Allow-Origin header. addModule()
// should be rejected because of disallowed cross origin access.
const kScriptURL = get_host_info().HTTPS_REMOTE_ORIGIN +
'/worklets/resources/empty-worklet-script.js';
return promise_rejects_dom(t, 'AbortError',
worklet.addModule(kScriptURL));
}, 'Importing a cross origin resource without the ' +
'Access-Control-Allow-Origin header should reject the given promise');
promise_test(() => {
const kScriptURL = get_host_info().HTTPS_REMOTE_ORIGIN +
'/worklets/resources/empty-worklet-script.js' +
'?pipe=header(Access-Control-Allow-Origin, ' +
location.origin + ')';
return worklet.addModule('/common/redirect.py?location=' +
encodeURIComponent(kScriptURL))
.then(undefined_arg => {
assert_equals(undefined_arg, undefined);
});
}, 'Importing a cross-origin-redirected resource with the ' +
'Access-Control-Allow-Origin header should resolve the given promise');
promise_test(t => {
const kScriptURL = get_host_info().HTTPS_REMOTE_ORIGIN +
'/worklets/resources/empty-worklet-script.js';
return promise_rejects_dom(t, 'AbortError',
worklet.addModule(
'/common/redirect.py?location=' +
encodeURIComponent(kScriptURL)));
}, 'Importing a cross-origin-redirected resource without the ' +
'Access-Control-Allow-Origin header should reject the given promise');
promise_test(t => {
const kScriptURL = 'resources/syntax-error-worklet-script.js';
return promise_rejects_js(t, SyntaxError,
worklet.addModule(kScriptURL));
}, 'Importing a script that has a syntax error should reject the given ' +
'promise.');
promise_test(t => {
const kScriptURL = 'resources/import-syntax-error-worklet-script.js';
return promise_rejects_js(t, SyntaxError,
worklet.addModule(kScriptURL));
}, 'Importing a nested script that has a syntax error should reject the ' +
'given promise.');
promise_test(t => {
const kBlob = new Blob(["import 'invalid-specifier.js';"],
{type: 'text/javascript'});
const kBlobURL = URL.createObjectURL(kBlob);
return promise_rejects_js(t, TypeError,
worklet.addModule(kBlobURL));
}, 'Importing a script that imports an invalid identifier should reject ' +
'the given promise.');
}
|