tor-browser

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

browser_console_error_source_click.js (1844B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Check that JS errors and CSS warnings open view source when their source link
      5 // is clicked in the Browser Console.
      6 
      7 "use strict";
      8 
      9 const TEST_URI =
     10  "data:text/html;charset=utf8,<!DOCTYPE html><p>hello world" +
     11  "<button onclick='foobar.explode()'>click!</button>";
     12 
     13 add_task(async function () {
     14  // Disable the preloaded process as it creates processes intermittently
     15  // which forces the emission of RDP requests we aren't correctly waiting for.
     16  await pushPref("dom.ipc.processPrelaunch.enabled", false);
     17 
     18  await pushPref("devtools.browsertoolbox.scope", "everything");
     19  await addTab(TEST_URI);
     20 
     21  const hud = await BrowserConsoleManager.toggleBrowserConsole();
     22  ok(hud, "browser console opened");
     23 
     24  // On e10s, the exception is triggered in child process
     25  // and is ignored by test harness
     26  if (!Services.appinfo.browserTabsRemoteAutostart) {
     27    expectUncaughtException();
     28  }
     29 
     30  info("generate exception and wait for the message");
     31  SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
     32    const button = content.document.querySelector("button");
     33    button.click();
     34  });
     35 
     36  const messageText = "ReferenceError: foobar is not defined";
     37 
     38  const msg = await waitFor(
     39    () => findErrorMessage(hud, messageText),
     40    `Message "${messageText}" wasn't found`
     41  );
     42  ok(msg, `Message found: "${messageText}"`);
     43 
     44  const locationNode = msg.querySelector(
     45    ".message-location .frame-link-source"
     46  );
     47  ok(locationNode, "Message location link element found");
     48 
     49  const onTabOpen = BrowserTestUtils.waitForNewTab(
     50    gBrowser,
     51    url => url.startsWith("view-source:"),
     52    true
     53  );
     54  locationNode.click();
     55  await onTabOpen;
     56  ok(true, "The view source tab was opened in response to clicking the link");
     57 });