summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/dom
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--remote/cdp/test/browser/dom/browser.toml23
-rw-r--r--remote/cdp/test/browser/dom/browser_describeNode.js160
-rw-r--r--remote/cdp/test/browser/dom/browser_resolveNode.js79
-rw-r--r--remote/cdp/test/browser/dom/head.js9
4 files changed, 271 insertions, 0 deletions
diff --git a/remote/cdp/test/browser/dom/browser.toml b/remote/cdp/test/browser/dom/browser.toml
new file mode 100644
index 0000000000..0815ae681f
--- /dev/null
+++ b/remote/cdp/test/browser/dom/browser.toml
@@ -0,0 +1,23 @@
+[DEFAULT]
+tags = "cdp"
+subsuite = "remote"
+args = [
+ "--remote-debugging-port",
+ "--remote-allow-origins=null",
+]
+prefs = [ # Bug 1600054: Make CDP Fission compatible
+ "fission.bfcacheInParent=false",
+ "fission.webContentIsolationStrategy=0",
+]
+skip-if = [
+ "display == 'wayland'" # Bug 1861933: Timestamp unreliable due to worker setup
+]
+support-files = [
+ "!/remote/cdp/test/browser/chrome-remote-interface.js",
+ "!/remote/cdp/test/browser/head.js",
+ "head.js",
+]
+
+["browser_describeNode.js"]
+
+["browser_resolveNode.js"]
diff --git a/remote/cdp/test/browser/dom/browser_describeNode.js b/remote/cdp/test/browser/dom/browser_describeNode.js
new file mode 100644
index 0000000000..8db9a85685
--- /dev/null
+++ b/remote/cdp/test/browser/dom/browser_describeNode.js
@@ -0,0 +1,160 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const DOC = toDataURL("<div id='content'><p>foo</p><p>bar</p></div>");
+const DOC_FRAME = toDataURL(`<iframe src="${DOC}"></iframe>`);
+
+add_task(async function objectIdInvalidTypes({ client }) {
+ const { DOM } = client;
+
+ for (const objectId of [null, true, 1, [], {}]) {
+ await Assert.rejects(
+ DOM.describeNode({ objectId }),
+ /objectId: string value expected/,
+ `Fails with invalid type: ${objectId}`
+ );
+ }
+});
+
+add_task(async function objectIdUnknownValue({ client }) {
+ const { DOM } = client;
+
+ await Assert.rejects(
+ DOM.describeNode({ objectId: "foo" }),
+ /Could not find object with given id/,
+ `Fails with unknown objectId`
+ );
+});
+
+add_task(async function objectIdIsNotANode({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({
+ expression: "[42]",
+ });
+
+ await Assert.rejects(
+ DOM.describeNode({ objectId: result.objectId }),
+ /Object id doesn't reference a Node/,
+ `Fails if objectId doesn't reference a DOM node`
+ );
+});
+
+add_task(async function objectIdAllProperties({ client }) {
+ const { DOM, Page, Runtime } = client;
+
+ await Page.enable();
+ const { frameId } = await Page.navigate({ url: DOC });
+ await Page.loadEventFired();
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({
+ expression: `document.getElementById('content')`,
+ });
+ const { node } = await DOM.describeNode({
+ objectId: result.objectId,
+ });
+
+ ok(!!node.nodeId, "The node has a node id");
+ ok(!!node.backendNodeId, "The node has a backend node id");
+ is(node.nodeName, "DIV", "Found expected node name");
+ is(node.localName, "div", "Found expected local name");
+ is(node.nodeType, 1, "Found expected node type");
+ is(node.nodeValue, "", "Found expected node value");
+ is(node.childNodeCount, 2, "Expected number of child nodes found");
+ is(node.attributes.length, 2, "Found expected attribute's name and value");
+ is(node.attributes[0], "id", "Found expected attribute name");
+ is(node.attributes[1], "content", "Found expected attribute value");
+ is(node.frameId, frameId, "Found expected frame id");
+});
+
+add_task(async function objectIdNoAttributes({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({
+ expression: "document",
+ });
+ const { node } = await DOM.describeNode({
+ objectId: result.objectId,
+ });
+
+ is(node.attributes, undefined, "No attributes returned");
+});
+
+add_task(async function objectIdDiffersForDifferentNodes({ client }) {
+ const { DOM, Runtime } = client;
+
+ await loadURL(DOC);
+
+ await Runtime.enable();
+ const { result: doc } = await Runtime.evaluate({
+ expression: "document",
+ });
+ const { node: node1 } = await DOM.describeNode({
+ objectId: doc.objectId,
+ });
+
+ const { result: body } = await Runtime.evaluate({
+ expression: `document.getElementById('content')`,
+ });
+ const { node: node2 } = await DOM.describeNode({
+ objectId: body.objectId,
+ });
+
+ for (const prop in node1) {
+ if (["nodeValue", "frameId"].includes(prop)) {
+ is(node1[prop], node2[prop], `Values of ${prop} are equal`);
+ } else {
+ isnot(node1[prop], node2[prop], `Values of ${prop} are different`);
+ }
+ }
+});
+
+add_task(async function objectIdDoesNotChangeForTheSameNode({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({
+ expression: "document",
+ });
+ const { node: node1 } = await DOM.describeNode({
+ objectId: result.objectId,
+ });
+ const { node: node2 } = await DOM.describeNode({
+ objectId: result.objectId,
+ });
+
+ for (const prop in node1) {
+ is(node1[prop], node2[prop], `Values of ${prop} are equal`);
+ }
+});
+
+add_task(async function frameIdForFrameElement({ client }) {
+ const { DOM, Page, Runtime } = client;
+
+ await Page.enable();
+
+ const frameAttached = Page.frameAttached();
+ await loadURL(DOC_FRAME);
+ const { frameId, parentFrameId } = await frameAttached;
+
+ await Runtime.enable();
+
+ const { result: frameObj } = await Runtime.evaluate({
+ expression: "document.getElementsByTagName('iframe')[0]",
+ });
+ const { node: frame } = await DOM.describeNode({
+ objectId: frameObj.objectId,
+ });
+
+ is(frame.frameId, frameId, "Reported frameId is from the frame itself");
+ isnot(
+ frame.frameId,
+ parentFrameId,
+ "Reported frameId is not the parentFrameId"
+ );
+});
diff --git a/remote/cdp/test/browser/dom/browser_resolveNode.js b/remote/cdp/test/browser/dom/browser_resolveNode.js
new file mode 100644
index 0000000000..759c4ee76c
--- /dev/null
+++ b/remote/cdp/test/browser/dom/browser_resolveNode.js
@@ -0,0 +1,79 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+add_task(async function backendNodeIdInvalidTypes({ client }) {
+ const { DOM } = client;
+
+ for (const backendNodeId of [null, true, "foo", [], {}]) {
+ await Assert.rejects(
+ DOM.resolveNode({ backendNodeId }),
+ /backendNodeId: number value expected/,
+ `Fails for invalid type: ${backendNodeId}`
+ );
+ }
+});
+
+add_task(async function backendNodeIdInvalidValue({ client }) {
+ const { DOM } = client;
+
+ await Assert.rejects(
+ DOM.resolveNode({ backendNodeId: -1 }),
+ /No node with given id found/,
+ "Fails for unknown backendNodeId"
+ );
+});
+
+add_task(async function backendNodeIdResultProperties({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({ expression: "document" });
+ const { node } = await DOM.describeNode({ objectId: result.objectId });
+
+ const { object } = await DOM.resolveNode({
+ backendNodeId: node.backendNodeId,
+ });
+
+ ok(!!object, "Javascript node object returned");
+ is(object.type, result.type, "Expected type returned");
+ is(object.subtype, result.subtype, "Expected subtype returned");
+ isnot(object.objectId, result.objectId, "Object has been duplicated");
+});
+
+add_task(async function executionContextIdInvalidTypes({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({ expression: "document" });
+ const { node } = await DOM.describeNode({ objectId: result.objectId });
+
+ for (const executionContextId of [null, true, "foo", [], {}]) {
+ await Assert.rejects(
+ DOM.resolveNode({
+ backendNodeId: node.backendNodeId,
+ executionContextId,
+ }),
+ /executionContextId: integer value expected/,
+ `Fails for invalid type: ${executionContextId}`
+ );
+ }
+});
+
+add_task(async function executionContextIdInvalidValue({ client }) {
+ const { DOM, Runtime } = client;
+
+ await Runtime.enable();
+ const { result } = await Runtime.evaluate({ expression: "document" });
+ const { node } = await DOM.describeNode({ objectId: result.objectId });
+
+ await Assert.rejects(
+ DOM.resolveNode({
+ backendNodeId: node.backendNodeId,
+ executionContextId: -1,
+ }),
+ /Node with given id does not belong to the document/,
+ "Fails for unknown executionContextId"
+ );
+});
diff --git a/remote/cdp/test/browser/dom/head.js b/remote/cdp/test/browser/dom/head.js
new file mode 100644
index 0000000000..1a1c90fbf6
--- /dev/null
+++ b/remote/cdp/test/browser/dom/head.js
@@ -0,0 +1,9 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+Services.scriptloader.loadSubScript(
+ "chrome://mochitests/content/browser/remote/cdp/test/browser/head.js",
+ this
+);