From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../sessionstore/test/browser_frametree.js | 134 +++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_frametree.js (limited to 'browser/components/sessionstore/test/browser_frametree.js') diff --git a/browser/components/sessionstore/test/browser_frametree.js b/browser/components/sessionstore/test/browser_frametree.js new file mode 100644 index 0000000000..2171838a0c --- /dev/null +++ b/browser/components/sessionstore/test/browser_frametree.js @@ -0,0 +1,134 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const URL = HTTPROOT + "browser_frametree_sample.html"; +const URL_FRAMESET = HTTPROOT + "browser_frametree_sample_frameset.html"; +const URL_IFRAMES = HTTPROOT + "browser_frametree_sample_iframes.html"; + +/** + * Check that we correctly enumerate non-dynamic child frames. + */ +add_task(async function test_frametree() { + // Add an empty tab for a start. + let tab = BrowserTestUtils.addTab(gBrowser, URL); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // The page is a single frame with no children. + is(await countNonDynamicFrames(browser), 0, "no child frames"); + + // Navigate to a frameset. + BrowserTestUtils.loadURIString(browser, URL_FRAMESET); + await promiseBrowserLoaded(browser); + + // The frameset has two frames. + is(await countNonDynamicFrames(browser), 2, "two non-dynamic child frames"); + + // Go back in history. + let pageShowPromise = BrowserTestUtils.waitForContentEvent( + browser, + "pageshow", + true + ); + browser.goBack(); + await pageShowPromise; + + // We're at page one again. + is(await countNonDynamicFrames(browser), 0, "no child frames"); + + // Append a dynamic frame. + await SpecialPowers.spawn(browser, [URL], async ([url]) => { + let frame = content.document.createElement("iframe"); + frame.setAttribute("src", url); + content.document.body.appendChild(frame); + await ContentTaskUtils.waitForEvent(frame, "load"); + }); + + // The dynamic frame should be ignored. + is( + await countNonDynamicFrames(browser), + 0, + "we still have a single root frame" + ); + + // Cleanup. + BrowserTestUtils.removeTab(tab); +}); + +/** + * Check that we correctly enumerate non-dynamic child frames. + */ +add_task(async function test_frametree_dynamic() { + // Add an empty tab for a start. + let tab = BrowserTestUtils.addTab(gBrowser, URL_IFRAMES); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // The page has two iframes. + is(await countNonDynamicFrames(browser), 2, "two non-dynamic child frames"); + is(await enumerateIndexes(browser), "0,1", "correct indexes 0 and 1"); + + // Insert a dynamic frame. + await SpecialPowers.spawn(browser, [URL], async ([url]) => { + let frame = content.document.createElement("iframe"); + frame.setAttribute("src", url); + content.document.body.insertBefore( + frame, + content.document.getElementsByTagName("iframe")[1] + ); + await ContentTaskUtils.waitForEvent(frame, "load"); + }); + + // The page still has two iframes. + is(await countNonDynamicFrames(browser), 2, "two non-dynamic child frames"); + is(await enumerateIndexes(browser), "0,1", "correct indexes 0 and 1"); + + // Append a dynamic frame. + await SpecialPowers.spawn(browser, [URL], async ([url]) => { + let frame = content.document.createElement("iframe"); + frame.setAttribute("src", url); + content.document.body.appendChild(frame); + await ContentTaskUtils.waitForEvent(frame, "load"); + }); + + // The page still has two iframes. + is(await countNonDynamicFrames(browser), 2, "two non-dynamic child frames"); + is(await enumerateIndexes(browser), "0,1", "correct indexes 0 and 1"); + + // Remopve a non-dynamic iframe. + await SpecialPowers.spawn(browser, [URL], async ([url]) => { + // Remove the first iframe, which should be a non-dynamic iframe. + content.document.body.removeChild( + content.document.getElementsByTagName("iframe")[0] + ); + }); + + is(await countNonDynamicFrames(browser), 1, "one non-dynamic child frame"); + is(await enumerateIndexes(browser), "1", "correct index 1"); + + // Cleanup. + BrowserTestUtils.removeTab(tab); +}); + +async function countNonDynamicFrames(browser) { + return SpecialPowers.spawn(browser, [], async () => { + let count = 0; + content.SessionStoreUtils.forEachNonDynamicChildFrame( + content, + () => count++ + ); + return count; + }); +} + +async function enumerateIndexes(browser) { + return SpecialPowers.spawn(browser, [], async () => { + let indexes = []; + content.SessionStoreUtils.forEachNonDynamicChildFrame(content, (frame, i) => + indexes.push(i) + ); + return indexes.join(","); + }); +} -- cgit v1.2.3