Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Warnings

<!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: 'https://example:bogus'},
{success: false, origin: 'https://\ud800.com'},
{success: false, origin: 'http://example.com'},
{success: false, origin: 'ftp://example.com'},
{success: false, origin: 'chrome-extension://foobar'},
{success: false, origin: 'about:blank'},
{success: false, origin: 'about:srcdoc'},
{success: true, origin: 'https://example.com'},
{success: true, origin: 'http://localhost:3000'},
];
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>