summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_frametree.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /browser/components/sessionstore/test/browser_frametree.js
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/sessionstore/test/browser_frametree.js')
-rw-r--r--browser/components/sessionstore/test/browser_frametree.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/browser/components/sessionstore/test/browser_frametree.js b/browser/components/sessionstore/test/browser_frametree.js
new file mode 100644
index 0000000000..7a9f10838b
--- /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.loadURI(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(",");
+ });
+}