Automatic update from web-platform-tests WebMCP: Expose document.modelContext Per https://github.com/webmachinelearning/webmcp/issues/173 and https://github.com/w3ctag/design-reviews/issues/1231#issuecomment-4502765330, we're moving `modelContext` to `document` from `navigator`. This CL does that, but keeps `navigator` exposure around for a bit and dispatches a console warning when it is used. This CL also updates all web platform tests to use `document.modelContext`. There might be other lingering tests elsewhere, but we can update those when we fully remove the API. R=mfoltz Bug: 489045948 Change-Id: I2005719574b78367199c0a87f94f3577b8039f15 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7867800 Reviewed-by: Mark Foltz <mfoltz@chromium.org> Commit-Queue: Dominic Farolino <dom@chromium.org> Cr-Commit-Position: refs/heads/main@{#1636216} -- wpt-commits: 8fe4fa01ce521ea03e09d978e905af1d25b8d410 wpt-pr: 60158
48 lines
1.5 KiB
HTML
48 lines
1.5 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>executeTool() in detached frame</title>
|
|
<link rel="author" href="mailto:dom@chromium.org">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
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.document.modelContext;
|
|
|
|
// Register a dummy tool so we have a valid tool object before detaching the frame.
|
|
const toolchange_promise = new Promise(resolve => {
|
|
iframe_modelContext.addEventListener('toolchange', resolve, { once: true });
|
|
});
|
|
|
|
iframe_modelContext.registerTool({
|
|
name: 'dummy_tool',
|
|
description: 'Dummy tool',
|
|
execute: async () => {}
|
|
});
|
|
|
|
await toolchange_promise;
|
|
|
|
const tools = await iframe_modelContext.getTools();
|
|
const tool = tools.find(t => t.name === 'dummy_tool');
|
|
assert_true(!!tool, 'Tool should be registered');
|
|
|
|
// Detach the iframe context.
|
|
iframe.remove();
|
|
|
|
// Calling executeTool() should reject with InvalidStateError.
|
|
await promise_rejects_dom(t, 'InvalidStateError', iDOMException, iframe_modelContext.executeTool(tool, '{}'));
|
|
}, 'executeTool() throws `InvalidStateError` in detached frame');
|
|
</script>
|
|
</body>
|
|
</html>
|