1
0
Fork 0
firefox/testing/web-platform/tests/ai/summarizer/summarizer-from-detached-iframe.tentative.https.window.js
Daniel Baumann 5e9a113729
Adding upstream version 140.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-25 09:37:52 +02:00

57 lines
2.4 KiB
JavaScript

// META: title=Summarizer Detached Iframe
// META: script=/resources/testdriver.js
// META: script=../resources/util.js
// META: timeout=long
'use strict';
promise_test(async (t) => {
const iframe = document.body.appendChild(document.createElement('iframe'));
await test_driver.bless('Summarizer create()', null, iframe.contentWindow);
iframe.contentWindow.Summarizer.create();
iframe.remove();
}, 'Detaching iframe during Summarizer.create() should not leak memory');
promise_test(async (t) => {
const iframe = document.body.appendChild(document.createElement('iframe'));
await test_driver.bless('Summarizer create()', null, iframe.contentWindow);
const iframeWindow = iframe.contentWindow;
const iframeDOMException = iframeWindow.DOMException;
const iframeSummarizer = iframeWindow.Summarizer;
iframe.remove();
await promise_rejects_dom(
t, 'InvalidStateError', iframeDOMException, iframeSummarizer.create());
}, 'Summarizer.create() fails on a detached iframe');
promise_test(async (t) => {
const iframe = document.body.appendChild(document.createElement('iframe'));
await test_driver.bless('Summarizer create()', null, iframe.contentWindow);
const iframeDOMException = iframe.contentWindow.DOMException;
const summarizer = await iframe.contentWindow.Summarizer.create();
iframe.remove();
await promise_rejects_dom(
t, 'InvalidStateError', iframeDOMException, summarizer.summarize(kTestPrompt));
}, 'Summarizer.summarize() fails on a detached iframe');
promise_test(async (t) => {
const iframe = document.body.appendChild(document.createElement('iframe'));
await test_driver.bless('Summarizer create()', null, iframe.contentWindow);
const iframeWindow = iframe.contentWindow;
const iframeDOMException = iframeWindow.DOMException;
const summarizer = await iframeWindow.Summarizer.create();
iframe.remove();
assert_throws_dom(
'InvalidStateError',
iframeDOMException, () => summarizer.summarizeStreaming(kTestPrompt));
}, 'Summarizer.summarizeStreaming() fails on a detached iframe');
promise_test(async (t) => {
const iframe = document.body.appendChild(document.createElement('iframe'));
await test_driver.bless('Summarizer create()', null, iframe.contentWindow);
const summarizer = await iframe.contentWindow.Summarizer.create();
summarizer.summarize(kTestPrompt);
iframe.remove();
}, 'Detaching iframe during Summarizer.summarize() should not leak memory');