summaryrefslogtreecommitdiffstats
path: root/remote/cdp/test/browser/dom/browser_resolveNode.js
blob: 553c42f5b447829f05f3719e942ff2e1c89ff8d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* 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;

  // Bug 1625417 - CDP expects the id as number
  for (const backendNodeId of [null, true, 1, /* "foo", */ [], {}]) {
    let errorThrown = "";
    try {
      await DOM.resolveNode({ backendNodeId });
    } catch (e) {
      errorThrown = e.message;
    }
    ok(
      errorThrown.match(/backendNodeId: string value expected/),
      `Fails for invalid type: ${backendNodeId}`
    );
  }
});

add_task(async function backendNodeIdInvalidValue({ client }) {
  const { DOM } = client;

  let errorThrown = "";
  try {
    await DOM.resolveNode({ backendNodeId: "-1" });
  } catch (e) {
    errorThrown = e.message;
  }
  ok(
    errorThrown.match(/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", [], {}]) {
    let errorThrown = "";
    try {
      await DOM.resolveNode({
        backendNodeId: node.backendNodeId,
        executionContextId,
      });
    } catch (e) {
      errorThrown = e.message;
    }
    ok(
      errorThrown.match(/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 });

  let errorThrown = "";
  try {
    await DOM.resolveNode({
      backendNodeId: node.backendNodeId,
      executionContextId: -1,
    });
  } catch (e) {
    errorThrown = e.message;
  }
  ok(
    errorThrown.match(/Node with given id does not belong to the document/),
    "Fails for unknown executionContextId"
  );
});