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
53 lines
1.7 KiB
HTML
53 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>WebMCP executeTool with Target Navigation</title>
|
|
<link rel="author" href="mailto:dom@chromium.org">
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<script src="/common/get-host-info.sub.js"></script>
|
|
<script src="resources/helpers.js"></script>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
const host_info = get_host_info();
|
|
|
|
promise_test(async t => {
|
|
const iframe = document.createElement('iframe');
|
|
iframe.src = 'resources/iframe-register-tool.html';
|
|
iframe.allow = 'tools *';
|
|
|
|
const load_promise = new Promise(resolve => iframe.onload = resolve);
|
|
document.body.appendChild(iframe);
|
|
t.add_cleanup(() => iframe.remove());
|
|
await load_promise;
|
|
|
|
// Tell iframe to register a tool.
|
|
iframe.contentWindow.postMessage({
|
|
action: 'register',
|
|
hangsForever: true,
|
|
tool: {
|
|
name: 'iframe_tool',
|
|
description: 'Iframe tool'
|
|
}
|
|
}, '*');
|
|
|
|
// Wait for toolchange.
|
|
await new Promise(resolve => {
|
|
document.modelContext.addEventListener('toolchange', resolve, {once: true});
|
|
});
|
|
|
|
// Invoke tool and immediately navigate iframe away.
|
|
const tools = await document.modelContext.getTools();
|
|
const tool = tools.find(t => t.name === 'iframe_tool');
|
|
const promise = document.modelContext.executeTool(tool, '{}');
|
|
iframe.src = 'about:blank';
|
|
|
|
// The promise should be rejected because the target document died.
|
|
// We expect AbortError or similar. Let's assume AbortError for now.
|
|
await promise_rejects_dom(t, 'UnknownError', promise, 'Promise should be rejected when target document dies');
|
|
}, 'executeTool() rejects when target document navigates away');
|
|
</script>
|
|
</body>
|
|
</html>
|