tor-browser

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

browser_dbg-sourcemapped-breakpoint-console.js (2321B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 "use strict";
      6 
      7 // This test can be really slow on debug platforms and should be split.
      8 requestLongerTimeout(3);
      9 
     10 add_task(async function () {
     11  await pushPref("devtools.debugger.map-scopes-enabled", true);
     12  const dbg = await initDebugger("doc-sourcemapped.html");
     13 
     14  await evalInConsoleAtPoint(
     15    dbg,
     16    "webpack3-babel6",
     17    "eval-maps",
     18    { line: 14, column: 5 },
     19    ["one === 1", "two === 4", "three === 5"]
     20  );
     21 
     22  await evalInConsoleAtPoint(
     23    dbg,
     24    "webpack3-babel6",
     25    "esmodules-cjs",
     26    { line: 18, column: 3 },
     27    [
     28      `aDefault === "a-default"`,
     29      `anAliased === "an-original"`,
     30      `aNamed === "a-named"`,
     31      `aDefault2 === "a-default2"`,
     32      `anAliased2 === "an-original2"`,
     33      `aNamed2 === "a-named2"`,
     34      `aDefault3 === "a-default3"`,
     35      `anAliased3 === "an-original3"`,
     36      `aNamed3 === "a-named3"`,
     37    ]
     38  );
     39 
     40  await evalInConsoleAtPoint(
     41    dbg,
     42    "webpack3-babel6",
     43    "shadowed-vars",
     44    { line: 18, column: 7 },
     45    [`aVar === "var3"`, `aLet === "let3"`, `aConst === "const3"`]
     46  );
     47 
     48  await evalInConsoleAtPoint(
     49    dbg,
     50    "webpack3-babel6",
     51    "babel-classes",
     52    { line: 8, column: 17 },
     53    [`this.hasOwnProperty("bound")`]
     54  );
     55 });
     56 
     57 async function evalInConsoleAtPoint(
     58  dbg,
     59  target,
     60  fixture,
     61  { line, column },
     62  statements
     63 ) {
     64  const url = `${target}://./${fixture}/input.js`;
     65  const fnName = `${target}-${fixture}`.replace(/-([a-z])/g, (s, c) =>
     66    c.toUpperCase()
     67  );
     68 
     69  await invokeWithBreakpoint(dbg, fnName, url, { line, column }, async () => {
     70    await assertConsoleEval(dbg, statements);
     71  });
     72 
     73  ok(true, `Ran tests for ${fixture} at line ${line} column ${column}`);
     74 }
     75 
     76 async function assertConsoleEval(dbg, statements) {
     77  const { hud } = await dbg.toolbox.selectTool("webconsole");
     78 
     79  for (const statement of statements.values()) {
     80    await dbg.client.evaluate(`window.TEST_RESULT = false;`);
     81    await evaluateExpressionInConsole(hud, `TEST_RESULT = ${statement};`);
     82 
     83    const result = await dbg.client.evaluate(`window.TEST_RESULT`);
     84    is(result.result, true, `'${statement}' evaluates to true`);
     85  }
     86 }