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/detached-frame-registerTool.https.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>registerTool() in detached frame</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(async t => {
const iframe = document.createElement('iframe');
const load_promise = new Promise(resolve => iframe.onload = resolve);
document.body.append(iframe);
await load_promise;
const iframe_navigator = iframe.contentWindow.navigator;
// Cache the iframe's `modelContext` object, even though we never use it. This
// is just so that internally, it gets allocated.
const iframe_modelContext = iframe.contentWindow.navigator.modelContext;
assert_equals(iframe_navigator.modelContext, iframe_modelContext)
iframe.remove();
assert_equals(iframe_navigator.modelContext, null);
}, 'Regardless of whether Navigator\'s modelContext object has been allocated' +
'its getter always returns null after the document has been detached');
promise_test(async t => {
const iframe = document.createElement('iframe');
iframe.src = '/common/blank.html';
const load_promise = new Promise(resolve => iframe.onload = resolve);
document.body.append(iframe);
await load_promise;
const iDOMException = iframe.contentWindow.DOMException;
const iframe_modelContext = iframe.contentWindow.navigator.modelContext;
iframe.remove();
assert_throws_dom('InvalidStateError', iDOMException, () => {
iframe_modelContext.registerTool({
name: 'detached_tool',
description: 'Tool registered in detached frame',
execute: async () => 'hello'
});
}, 'Throws InvalidStateError for detached frame');
}, 'registerTool() throws `InvalidStateError` in detached frame');
</script>
</body>
</html>