Files
sousa-gecko/testing/web-platform/tests/webmcp/imperative/executeTool-target-detachment.https.html
T
mark a. foltz 510408316f Bug 2046333 [wpt PR 60514] - [WebMCP] Fix WPTs for WebMCP after getTools() change., a=testonly
Automatic update from web-platform-tests
[WebMCP] Fix WPTs for WebMCP after getTools() change.

- Updates all cross-origin WebMCP Web Platform Tests (WPT) to utilize
  the new API with explicit `fromOrigins` parameters, ensuring they
  now pass cleanly.
- Removes the temporary failure expectations for these WPT tests from
  TestExpectations.

Bug: 485810761
Change-Id: Ia278140565a3c2f1aa6896685a3fcba3ef9500f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7913488
Reviewed-by: Dominic Farolino <dom@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1644383}

--

wpt-commits: 8894a59b3a729aebd3427ea8572a0f14b37792df
wpt-pr: 60514
2026-06-11 08:50:13 +00:00

115 lines
3.7 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>WebMCP executeTool with Target Frame Detachment</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>
</head>
<body>
<script>
const host_info = get_host_info();
promise_test(async t => {
const iframe = document.createElement('iframe');
iframe.src = host_info.HTTPS_REMOTE_ORIGIN + '/webmcp/imperative/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;
const toolchange_promise = new Promise(resolve => {
document.modelContext.addEventListener('toolchange', resolve, { once: true });
});
// Have the iframe register a tool (it will never execute though).
iframe.contentWindow.postMessage({
action: 'register',
tool: {
name: 'iframe_tool',
description: 'Iframe tool description'
},
options: {
exposedTo: [self.origin]
}
}, '*');
await toolchange_promise;
const tools = await document.modelContext.getTools(
{fromOrigins: [host_info.HTTPS_REMOTE_ORIGIN]});
const tool = tools.find(t => t.name === 'iframe_tool');
assert_true(!!tool, 'Tool should be retrieved successfully');
// Detach the frame before executing the tool.
iframe.remove();
// Calling executeTool() on the detached tool will internally fail to locate
// the frame, and thus reject the caller's Promise.
//
// TODO(https://crbug.com/509555636): It should probably reject with a `NotFoundError`.
await promise_rejects_dom(
t,
'InvalidStateError',
document.modelContext.executeTool(tool, '{}'),
'Promise should be rejected with InvalidStateError when target frame is detached before execution'
);
}, 'executeTool() rejects when target frame is detached before execution');
promise_test(async t => {
const iframe = document.createElement('iframe');
iframe.src = host_info.HTTPS_REMOTE_ORIGIN + '/webmcp/imperative/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;
const toolchange_promise = new Promise(resolve => {
document.modelContext.addEventListener('toolchange', resolve, { once: true });
});
// The iframe tool hangs forever, because it must be executing *while* we
// detach the iframe.
iframe.contentWindow.postMessage({
action: 'register',
hangsForever: true,
tool: {
name: 'iframe_tool_hanging',
description: 'Iframe tool description'
},
options: {
exposedTo: [self.origin]
}
}, '*');
await toolchange_promise;
const tools = await document.modelContext.getTools(
{fromOrigins: [host_info.HTTPS_REMOTE_ORIGIN]});
const tool = tools.find(t => t.name === 'iframe_tool_hanging');
assert_true(!!tool, 'Tool should be retrieved successfully');
// Execute the tool (hangs forever).
const execute_promise = document.modelContext.executeTool(tool, '{}');
iframe.remove();
// The execute promise rejects because the target document died
// mid-execution. See the bug referenced from the above test, about making
// the reason more specific.
await promise_rejects_dom(
t,
'UnknownError',
execute_promise,
'Promise should be rejected with UnknownError when target frame is detached mid-execution'
);
}, 'executeTool() rejects when target frame is detached mid-execution');
</script>
</body>
</html>