Commit 76c72072 authored by Tooru Fujisawa's avatar Tooru Fujisawa
Browse files

Bug 1820951 - Part 2: Add tests. r=nchevobbe,devtools-reviewers

Depends on D175093

Differential Revision: https://phabricator.services.mozilla.com/D177613
parent ce97c68a
Loading
Loading
Loading
Loading
+98 −54
Original line number Diff line number Diff line
@@ -22,9 +22,7 @@ add_task(async function() {
  await SpecialPowers.spawn(gBrowser.selectedBrowser, [LONGSTRING], function(
    longString
  ) {
    content.wrappedJSObject.console.log(
      "oi-test",
      Object.create(
    const obj = Object.create(
      null,
      Object.getOwnPropertyDescriptors({
        get myStringGetter() {
@@ -75,8 +73,20 @@ add_task(async function() {
          return longString;
        },
      })
      )
    );
    Object.defineProperty(obj, "MyPrint", { get: content.print });
    Object.defineProperty(obj, "MyElement", { get: content.Element });
    Object.defineProperty(obj, "MySetAttribute", {
      get: content.Element.prototype.setAttribute,
    });
    Object.defineProperty(obj, "MySetClassName", {
      get: Object.getOwnPropertyDescriptor(
        content.Element.prototype,
        "className"
      ).set,
    });

    content.wrappedJSObject.console.log("oi-test", obj);
  });

  const node = await waitFor(() => findConsoleAPIMessage(hud, "oi-test"));
@@ -99,6 +109,7 @@ add_task(async function() {
  await testProxyGetter(oi);
  await testThrowingGetter(oi);
  await testLongStringGetter(oi, LONGSTRING);
  await testUnsafeGetters(oi);
});

async function testStringGetter(oi) {
@@ -567,6 +578,39 @@ async function testLongStringGetter(oi, longString) {
  ok(true, "the longstring was expanded");
}

async function testUnsafeGetters(oi) {
  const props = [
    [
      "MyPrint",
      "MyPrint: TypeError: 'print' called on an object that does not implement interface Window.",
    ],
    ["MyElement", "MyElement: TypeError: Illegal constructor."],
    [
      "MySetAttribute",
      "MySetAttribute: TypeError: 'setAttribute' called on an object that does not implement interface Element.",
    ],
    [
      "MySetClassName",
      "MySetClassName: TypeError: 'set className' called on an object that does not implement interface Element.",
    ],
  ];

  for (const [name, text] of props) {
    const getNode = () => findObjectInspectorNode(oi, name);
    is(
      isObjectInspectorNodeExpandable(getNode()),
      false,
      `The ${name} node can't be expanded`
    );
    const invokeButton = getObjectInspectorInvokeGetterButton(getNode());
    ok(invokeButton, `There is an invoke button for ${name} as expected`);

    invokeButton.click();
    await waitFor(() => getNode().textContent.includes(text));
    ok(true, `${name} getter shows the error message ${text}`);
  }
}

function checkChildren(node, expectedChildren) {
  const children = getObjectInspectorChildrenNodes(node);
  is(