summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/page/browser_getFrameTree.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 /remote/cdp/test/browser/page/browser_getFrameTree.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/cdp/test/browser/page/browser_getFrameTree.js')
-rw-r--r--remote/cdp/test/browser/page/browser_getFrameTree.js149
1 files changed, 149 insertions, 0 deletions
diff --git a/remote/cdp/test/browser/page/browser_getFrameTree.js b/remote/cdp/test/browser/page/browser_getFrameTree.js
new file mode 100644
index 0000000000..e96dc26d45
--- /dev/null
+++ b/remote/cdp/test/browser/page/browser_getFrameTree.js
@@ -0,0 +1,149 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function pageWithoutFrames({ client }) {
+ const { Page } = client;
+
+ info("Navigate to a page without a frame");
+ await loadURL(PAGE_URL);
+
+ const { frameTree } = await Page.getFrameTree();
+ ok(!!frameTree.frame, "Expected frame details found");
+
+ const expectedFrames = await getFlattenedFrameList();
+
+ // Check top-level frame
+ const expectedFrame = expectedFrames.get(frameTree.frame.id);
+ is(frameTree.frame.id, expectedFrame.id, "Expected frame id found");
+ is(frameTree.frame.parentId, undefined, "Parent frame doesn't exist");
+ is(frameTree.name, undefined, "Top frame doens't contain name property");
+ is(frameTree.frame.url, expectedFrame.url, "Expected url found");
+ is(frameTree.childFrames, undefined, "No sub frames found");
+});
+
+add_task(async function PageWithFrames({ client }) {
+ const { Page } = client;
+
+ info("Navigate to a page with frames");
+ await loadURL(FRAMESET_MULTI_URL);
+
+ const { frameTree } = await Page.getFrameTree();
+ ok(!!frameTree.frame, "Expected frame details found");
+
+ const expectedFrames = await getFlattenedFrameList();
+
+ let frame = frameTree.frame;
+ let expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check top frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, undefined, "Parent frame doesn't exist");
+ is(frame.name, undefined, "Top frame doesn't contain name property");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+
+ is(frameTree.childFrames.length, 2, "Expected two sub frames");
+ for (const childFrameTree of frameTree.childFrames) {
+ let frame = childFrameTree.frame;
+ let expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check sub frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, expectedFrame.parentId, "Expected parent id found");
+ is(frame.name, expectedFrame.name, "Frame has expected name set");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+ is(childFrameTree.childFrames, undefined, "No sub frames found");
+ }
+});
+
+add_task(async function pageWithNestedFrames({ client }) {
+ const { Page } = client;
+
+ info("Navigate to a page with nested frames");
+ await loadURL(FRAMESET_NESTED_URL);
+
+ const { frameTree } = await Page.getFrameTree();
+ ok(!!frameTree.frame, "Expected frame details found");
+
+ const expectedFrames = await getFlattenedFrameList();
+
+ let frame = frameTree.frame;
+ let expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check top frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, undefined, "Parent frame doesn't exist");
+ is(frame.name, undefined, "Top frame doesn't contain name property");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+ is(frameTree.childFrames.length, 1, "Expected a single sub frame");
+
+ const childFrameTree = frameTree.childFrames[0];
+ frame = childFrameTree.frame;
+ expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check sub frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, expectedFrame.parentId, "Expected parent id found");
+ is(frame.name, expectedFrame.name, "Frame has expected name set");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+ is(childFrameTree.childFrames.length, 2, "Expected two sub frames");
+
+ let nestedChildFrameTree = childFrameTree.childFrames[0];
+ frame = nestedChildFrameTree.frame;
+ expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check first nested frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, expectedFrame.parentId, "Expected parent id found");
+ is(frame.name, expectedFrame.name, "Frame has expected name set");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+ is(nestedChildFrameTree.childFrames, undefined, "No sub frames found");
+
+ nestedChildFrameTree = childFrameTree.childFrames[1];
+ frame = nestedChildFrameTree.frame;
+ expectedFrame = expectedFrames.get(frame.id);
+
+ info(`Check second nested frame with id: ${frame.id}`);
+ is(frame.id, expectedFrame.id, "Expected frame id found");
+ is(frame.parentId, expectedFrame.parentId, "Expected parent id found");
+ is(frame.name, expectedFrame.name, "Frame has expected name set");
+ is(frame.url, expectedFrame.url, "Expected URL found");
+ is(nestedChildFrameTree.childFrames, undefined, "No sub frames found");
+});
+
+/**
+ * Retrieve all frames for the current tab as flattened list.
+ */
+function getFlattenedFrameList() {
+ return SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
+ const frames = new Map();
+
+ function getFrameDetails(context) {
+ const frameElement = context.embedderElement;
+
+ const frame = {
+ id: context.id.toString(),
+ parentId: context.parent ? context.parent.id.toString() : null,
+ loaderId: null,
+ name: frameElement?.id || frameElement?.name,
+ url: context.docShell.domWindow.location.href,
+ securityOrigin: null,
+ mimeType: null,
+ };
+
+ if (context.parent) {
+ frame.parentId = context.parent.id.toString();
+ }
+
+ frames.set(context.id.toString(), frame);
+
+ for (const childContext of context.children) {
+ getFrameDetails(childContext);
+ }
+ }
+
+ getFrameDetails(content.docShell.browsingContext);
+ return frames;
+ });
+}