Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 11 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /webmcp/imperative/exposedTo-invalid-origins.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>Invalid origins in exposedTo array</title>
<link rel="author" href="mailto:dom@chromium.org">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
const test_cases = [
{success: false, origin: '/'},
{success: false, origin: '*'},
{success: false, origin: 'about:blank'},
{success: false, origin: 'about:srcdoc'},
];
for (const test of test_cases) {
promise_test(async t => {
const register = () => {
return document.modelContext.registerTool({
name: 'test_tool_' + Math.random(),
description: 'Test tool',
execute: async () => 'hello'
}, { exposedTo: [test.origin] });
};
if (!test.success) {
return promise_rejects_dom(t, 'SecurityError', register(), `Should throw SecurityError for origin: ${test.origin}`);
} else {
try {
await register();
} catch (e) {
throw new Error(`Should not have thrown for ${test.origin}`);
}
}}, `registerTool() throws SecurityError for invalid or ` +
`non-potentially-trustworthy origins like ${test.origin} in exposedTo`);
}
promise_test(async t => {
const signal = AbortSignal.abort('aborted');
return promise_rejects_exactly(t, 'aborted', document.modelContext.registerTool({
name: "name",
description: "description",
execute: () => {}
}, { signal, exposedTo: ['about:blank#invalidOrigin']}) )
}, "registerTool() with abort signal reason because signal is processed before `exposedTo`");
</script>
</body>
</html>