tor-browser

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

browser_inspector_command_search.js (2598B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Testing basic inspector search
      7 
      8 add_task(async () => {
      9  const html = `<div>
     10                  <div>
     11                    <p>This is the paragraph node down in the tree</p>
     12                  </div>
     13                  <div class="child"></div>
     14                  <div class="child"></div>
     15                  <iframe src="data:text/html,${encodeURIComponent(
     16                    "<html><body><div class='frame-child'>foo</div></body></html>"
     17                  )}">
     18                  </iframe>
     19                </div>`;
     20 
     21  const tab = await addTab("data:text/html," + encodeURIComponent(html));
     22 
     23  const commands = await CommandsFactory.forTab(tab);
     24  await commands.targetCommand.startListening();
     25 
     26  info("Search using text");
     27  await searchAndAssert(
     28    commands,
     29    { query: "paragraph", reverse: false },
     30    { resultsLength: 1, resultsIndex: 0 }
     31  );
     32 
     33  info("Search using class selector");
     34  info(" > Get first result ");
     35  await searchAndAssert(
     36    commands,
     37    { query: ".child", reverse: false },
     38    { resultsLength: 2, resultsIndex: 0 }
     39  );
     40 
     41  info(" > Get next result ");
     42  await searchAndAssert(
     43    commands,
     44    { query: ".child", reverse: false },
     45    { resultsLength: 2, resultsIndex: 1 }
     46  );
     47 
     48  info("Search using el selector with reverse option");
     49  info(" > Get first result ");
     50  await searchAndAssert(
     51    commands,
     52    { query: "div", reverse: true },
     53    { resultsLength: 6, resultsIndex: 5 }
     54  );
     55 
     56  info(" > Get next result ");
     57  await searchAndAssert(
     58    commands,
     59    { query: "div", reverse: true },
     60    { resultsLength: 6, resultsIndex: 4 }
     61  );
     62 
     63  info("Search for foo in remote frame");
     64  await searchAndAssert(
     65    commands,
     66    { query: ".frame-child", reverse: false },
     67    { resultsLength: 1, resultsIndex: 0 }
     68  );
     69 
     70  await commands.destroy();
     71 });
     72 /**
     73 * Does an inspector search to find the next node and assert the results
     74 *
     75 * @param {object} commands
     76 * @param {object} options
     77 *            options.query - search query
     78 *            options.reverse - search in reverse
     79 * @param {object} expected
     80 *         Holds the expected values
     81 */
     82 async function searchAndAssert(commands, { query, reverse }, expected) {
     83  const response = await commands.inspectorCommand.findNextNode(query, {
     84    reverse,
     85  });
     86 
     87  is(
     88    response.resultsLength,
     89    expected.resultsLength,
     90    "Got the expected no of results"
     91  );
     92 
     93  is(
     94    response.resultsIndex,
     95    expected.resultsIndex,
     96    "Got the expected currently selected node index"
     97  );
     98 }