Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 2 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>
test(t => {
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) {
const register = () => {
document.modelContext.registerTool({
name: 'test_tool_' + Math.random(),
description: 'Test tool',
execute: async () => 'hello'
}, { exposedTo: [test.origin] });
};
if (!test.success) {
assert_throws_dom('SecurityError', register, `Should throw SecurityError for origin: ${origin}`);
} else {
try {
register();
} catch (e) {
throw new Error(`Should not have thrown for ${test.origin}`);
}
}
}
}, 'registerTool() throws SecurityError for invalid or ' +
'non-potentially-trustworthy origins in exposedTo');
test(t => {
// Does not throw, because the given abort signal is processed before `exposedTo` is.
navigator.modelContext.registerTool({
name: "name",
description: "description",
execute: () => {}
}, {signal: AbortSignal.abort('already-aborted'), exposedTo: ['about:blank#invalidOrigin']})
}, "registerTool() does not throw for invalid exposedTo, if aborted signal is passed in");
</script>
</body>
</html>