tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_webconsole_eval_error.js (2864B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests that throwing uncaught errors while doing console evaluations shows the expected
      5 // error message, with or without stack, in the console.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "http://example.com/browser/devtools/client/webconsole/" +
     11  "test/browser/test-eval-error.html";
     12 
     13 add_task(async function () {
     14  const hud = await openNewTabAndConsole(TEST_URI);
     15 
     16  execute(hud, "throwErrorObject()");
     17  await checkMessageStack(hud, "ThrowErrorObject", [6, 1]);
     18 
     19  execute(hud, "throwValue(40 + 2)");
     20  await checkMessageStack(hud, "42", [14, 10, 1]);
     21 
     22  await checkThrowingEvaluationWithStack(hud, `"bloop"`, "Uncaught bloop");
     23  await checkThrowingEvaluationWithStack(hud, `""`, "Uncaught <empty string>");
     24  await checkThrowingEvaluationWithStack(hud, `0`, "Uncaught 0");
     25  await checkThrowingEvaluationWithStack(hud, `null`, "Uncaught null");
     26  await checkThrowingEvaluationWithStack(
     27    hud,
     28    `undefined`,
     29    "Uncaught undefined"
     30  );
     31  await checkThrowingEvaluationWithStack(hud, `false`, "Uncaught false");
     32 
     33  await checkThrowingEvaluationWithStack(
     34    hud,
     35    `new Error("watermelon")`,
     36    "Uncaught Error: watermelon"
     37  );
     38 
     39  await checkThrowingEvaluationWithStack(
     40    hud,
     41    `(err = new Error("lettuce"), err.name = "VegetableError", err)`,
     42    "Uncaught VegetableError: lettuce"
     43  );
     44 
     45  await checkThrowingEvaluationWithStack(
     46    hud,
     47    `{ fav: "eggplant" }`,
     48    `Uncaught Object { fav: "eggplant" }`
     49  );
     50  info("Check that object in errors can be expanded");
     51  const rejectedObjectMessage = findErrorMessage(hud, "eggplant");
     52  const oi = rejectedObjectMessage.querySelector(".tree");
     53  ok(true, "The object was rendered in an ObjectInspector");
     54 
     55  info("Expanding the object");
     56  await expandObjectInspectorNode(oi.querySelector(".tree-node"));
     57 
     58  // The object inspector now looks like:
     59  // {...}
     60  // |  fav: "eggplant"
     61  // |  <prototype>: Object { ... }
     62 
     63  const oiNodes = oi.querySelectorAll(".node");
     64  is(oiNodes.length, 3, "There is the expected number of nodes in the tree");
     65 
     66  ok(oiNodes[0].textContent.includes(`Object { fav: "eggplant" }`));
     67  ok(oiNodes[1].textContent.includes(`fav: "eggplant"`));
     68  ok(oiNodes[2].textContent.includes(`<prototype>: Object { \u2026 }`));
     69 
     70  execute(hud, `1 + @`);
     71  const messageNode = await waitFor(() =>
     72    findErrorMessage(hud, "illegal character U+0040")
     73  );
     74  is(
     75    messageNode.querySelector(".frames"),
     76    null,
     77    "There's no stacktrace for a SyntaxError evaluation"
     78  );
     79 });
     80 
     81 function checkThrowingEvaluationWithStack(hud, expression, expectedMessage) {
     82  execute(
     83    hud,
     84    `
     85    a = () => {throw ${expression}};
     86    b =  () => a();
     87    c =  () => b();
     88    d =  () => c();
     89    d();
     90  `
     91  );
     92  return checkMessageStack(hud, expectedMessage, [2, 3, 4, 5, 6]);
     93 }