tor-browser

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

browser_dbg-sources-project-search.js (4004B)


      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 // Testing project search for various types of sources scenarios
      6 
      7 "use strict";
      8 
      9 requestLongerTimeout(3);
     10 
     11 // Tests for searching in dynamic (without urls) sources
     12 add_task(async function testSearchDynamicScripts() {
     13  const dbg = await initDebugger("doc-minified.html");
     14 
     15  const executeComplete = dbg.commands.scriptCommand.execute(
     16    `const foo = 5; debugger; console.log(foo)`
     17  );
     18  await waitForPaused(dbg);
     19 
     20  await openProjectSearch(dbg);
     21  const fileResults = await doProjectSearch(dbg, "foo", 1);
     22  ok(
     23    /source\d+/g.test(fileResults[0].innerText),
     24    "The search result was found in the eval script."
     25  );
     26 
     27  await resume(dbg);
     28  await executeComplete;
     29 });
     30 
     31 // Tests that minified sources are ignored when the prettyfied versions
     32 // exist.
     33 add_task(async function testIgnoreMinifiedSourceForPrettySource() {
     34  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
     35 
     36  await openProjectSearch(dbg);
     37  let fileResults = await doProjectSearch(dbg, "stuff", 1);
     38 
     39  is(fileResults.length, 1, "Only the result was found");
     40  ok(
     41    fileResults[0].innerText.includes("pretty.js\n(1 match)"),
     42    "The search result was found in the minified (pretty.js) source"
     43  );
     44 
     45  await selectSource(dbg, "pretty.js");
     46  await waitForSelectedSource(dbg, "pretty.js");
     47 
     48  info("Pretty print the source");
     49  await togglePrettyPrint(dbg);
     50 
     51  fileResults = await doProjectSearch(dbg, "stuff", 2);
     52 
     53  is(
     54    fileResults.length,
     55    2,
     56    "Two results were found form both the pretty and minified sources"
     57  );
     58  ok(
     59    fileResults[0].innerText.includes("pretty.js:formatted\n(1 match)"),
     60    "The first search result was found in the prettyified (pretty.js:formatted) source"
     61  );
     62 
     63  ok(
     64    fileResults[1].innerText.includes("pretty.js\n(1 match)"),
     65    "The second search result was found in the minified (pretty.js) source"
     66  );
     67 });
     68 
     69 // Test the prioritization of files. Original files should be prioritized over
     70 // generated files and third-party files should be deprioritized and load after the others.
     71 add_task(async function testFilesPrioritization() {
     72  const dbg = await initDebugger("doc-react.html", "App.js");
     73 
     74  await openProjectSearch(dbg);
     75  const fileResults = await doProjectSearch(dbg, "componentDidMount", 3);
     76 
     77  is(getExpandedResultsCount(dbg), 13);
     78 
     79  ok(
     80    fileResults[0].innerText.includes(
     81      "browser/devtools/client/debugger/test/mochitest/examples/react/build/App.js"
     82    ),
     83    "The first item should be the original (prettified) file"
     84  );
     85 
     86  ok(
     87    findAllElements(dbg, "projectSearchExpandedResults")[0].innerText.endsWith(
     88      "componentDidMount() {"
     89    ),
     90    "The first result match in the original file is correct"
     91  );
     92 
     93  const firstNodeModulesResultFound = [...fileResults].findIndex(el =>
     94    el.innerText.includes("node_modules")
     95  );
     96  is(
     97    firstNodeModulesResultFound,
     98    2,
     99    "The node_modules (third-party) file is the last result in the list"
    100  );
    101 });
    102 
    103 add_task(async function testBlackBoxedSources() {
    104  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
    105  await selectSource(dbg, "pretty.js");
    106 
    107  info("Blackbox pretty.js");
    108  await toggleBlackbox(dbg);
    109 
    110  await openProjectSearch(dbg);
    111  let fileResults = await doProjectSearch(dbg, "stuff", 0);
    112 
    113  is(fileResults.length, 0, "No results were found as pretty.js is blackboxed");
    114 
    115  info("Unblackbox pretty.js");
    116  await toggleBlackbox(dbg);
    117 
    118  await openProjectSearch(dbg);
    119  fileResults = await doProjectSearch(dbg, "stuff", 1);
    120 
    121  is(
    122    fileResults.length,
    123    1,
    124    "One result was found as pretty.js is no longer blackboxed"
    125  );
    126 });
    127 
    128 async function toggleBlackbox(dbg) {
    129  await clickElement(dbg, "blackbox");
    130  await Promise.any([
    131    waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES"),
    132    waitForDispatch(dbg.store, "UNBLACKBOX_WHOLE_SOURCES"),
    133  ]);
    134 }