tor-browser

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

browser_webconsole_string.js (2196B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_URI =
      7  "http://example.com/browser/devtools/client/webconsole/test/browser/test-console.html";
      8 
      9 add_task(async function () {
     10  const hud = await openNewTabAndConsole(TEST_URI);
     11 
     12  info("Test that console.log with a string argument does not include quotes");
     13  let receivedMessages = waitForMessageByType(hud, "stringLog", ".console-api");
     14 
     15  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     16    content.wrappedJSObject.stringLog();
     17  });
     18  await receivedMessages;
     19  ok(true, "console.log result does not have quotes");
     20 
     21  info(
     22    "Test that console.log with empty string argument render <empty string>"
     23  );
     24  receivedMessages = waitForMessageByType(
     25    hud,
     26    "hello <empty string>",
     27    ".console-api"
     28  );
     29 
     30  await ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
     31    const name = "";
     32    content.wrappedJSObject.console.log("hello", name);
     33  });
     34  await receivedMessages;
     35  ok(true, "console.log empty string argument renders as expected");
     36 
     37  info(
     38    "Test that log with object containing an empty string property renders as expected"
     39  );
     40  receivedMessages = waitForMessageByType(
     41    hud,
     42    `Object { a: "" }`,
     43    ".console-api"
     44  );
     45 
     46  await ContentTask.spawn(gBrowser.selectedBrowser, {}, function () {
     47    content.wrappedJSObject.console.log({ a: "" });
     48  });
     49  await receivedMessages;
     50  ok(true, "object with empty string property renders as expected");
     51 
     52  info("evaluating a string constant");
     53  let msg = await executeAndWaitForResultMessage(
     54    hud,
     55    '"string\\nconstant"',
     56    "constant"
     57  );
     58  let body = msg.node.querySelector(".message-body");
     59  // On the other hand, a string constant result should be quoted, but
     60  // newlines should be let through.
     61  ok(
     62    body.textContent.includes('"string\nconstant"'),
     63    `found expected text - "${body.textContent}"`
     64  );
     65 
     66  info("evaluating an empty string constant");
     67  msg = await executeAndWaitForResultMessage(hud, '""', '""');
     68  body = msg.node.querySelector(".message-body");
     69  ok(body.textContent.includes('""'), `found expected text`);
     70 });