|
25 | 25 |
|
26 | 26 | await promise_rejects_dom( |
27 | 27 | t, |
28 | | - 'DataError', |
| 28 | + 'NotSupportedError', |
29 | 29 | document.modelContext.executeTool(tool, '{}'), |
30 | | - 'executeTool() must reject with DataError in opaque origin documents' |
| 30 | + 'executeTool() must reject with NotSupportedError in opaque origin documents' |
31 | 31 | ); |
32 | 32 | }, 'An opaque origin document can register but not execute its own tools'); |
33 | 33 |
|
| 34 | +// The below three tests are almost the same, with the following distinctions: |
| 35 | +// 1. The first test asserts that executing a tool whose origin as returned |
| 36 | +// from `getTools()` is "null", synchronously rejects the execution |
| 37 | +// Promise. "null" fails to parse as a URL, because we don't parse it |
| 38 | +// relative to the document's URL as a base URL. |
| 39 | +// 2. The second and third tests below, captured by |
| 40 | +// `invalid_execution_origins`, don't reference legitimately-registered |
| 41 | +// tools. Instead, they test when the passed-in tool origin is: |
| 42 | +// |
| 43 | +// a.) An invalid URL that's not a single "null" string value. Rather, it's |
| 44 | +// an `https://` URL that fails to parse due to an invalid port. |
| 45 | +// b.) A string that successfully parses as a URL, but whose origin is opaque. |
34 | 46 | promise_test(async t => { |
35 | 47 | const tools = await document.modelContext.getTools(); |
36 | 48 | const tool = tools.find(t => t.name === 'opaque_tool'); |
| 49 | + assert_equals(tool.origin, "null", "getTools() gives"); |
37 | 50 |
|
38 | 51 | let events = []; |
39 | 52 | const p = document.modelContext.executeTool(tool, '{}'); |
|
48 | 61 |
|
49 | 62 | await promise_rejects_dom( |
50 | 63 | t, |
51 | | - 'DataError', |
| 64 | + 'NotSupportedError', |
52 | 65 | document.modelContext.executeTool(tool, '{"param1":"value"}'), |
53 | | - 'executeTool() must reject with DataError in opaque origin documents' |
| 66 | + 'executeTool() must reject with NotSupportedError in opaque origin documents' |
54 | 67 | ); |
55 | 68 |
|
56 | 69 | assert_array_equals(events, ['rejection', 'microtask'], |
57 | 70 | 'returned promise is rejected before custom microtask is queued'); |
58 | | -}, 'executeTool() rejects synchronously for opaque origins'); |
| 71 | +}, 'executeTool() rejects synchronously for origin "null" that fails to parse as a URL'); |
| 72 | + |
| 73 | +const invalid_execution_origins = ["https://test.example:invalidport", "data:text/html,foo"]; |
| 74 | +for (const invalid_origin of invalid_execution_origins) { |
| 75 | + promise_test(async t => { |
| 76 | + const fake_tool = { |
| 77 | + name: 'data_opaque_tool', |
| 78 | + description: 'Data URL opaque tool description', |
| 79 | + window: window, |
| 80 | + origin: invalid_origin |
| 81 | + }; |
| 82 | + |
| 83 | + let events = []; |
| 84 | + const p = document.modelContext.executeTool(fake_tool, '{}'); |
| 85 | + p.catch(() => events.push('rejection')); |
| 86 | + |
| 87 | + // Queue another microtask immediately after. |
| 88 | + queueMicrotask(() => events.push('microtask')); |
| 89 | + |
| 90 | + await promise_rejects_dom( |
| 91 | + t, |
| 92 | + 'NotSupportedError', |
| 93 | + document.modelContext.executeTool(fake_tool, '{"param1":"value"}')); |
| 94 | + |
| 95 | + assert_array_equals(events, ['rejection', 'microtask'], |
| 96 | + 'returned promise is rejected before custom microtask is queued'); |
| 97 | + }, `executeTool() rejects synchronously for invalid origin: ${invalid_origin}`); |
| 98 | +} |
59 | 99 | </script> |
60 | 100 | </body> |
61 | 101 | </html> |
0 commit comments