tor-browser

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

browser_net_security-icon-click.js (2089B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Test that clicking on the security indicator opens the security details tab.
      8 */
      9 
     10 add_task(async function () {
     11  const { tab, monitor } = await initNetMonitor(CUSTOM_GET_URL, {
     12    requestCount: 1,
     13  });
     14  const { document, store, windowRequire } = monitor.panelWin;
     15  const Actions = windowRequire("devtools/client/netmonitor/src/actions/index");
     16 
     17  store.dispatch(Actions.batchEnable(false));
     18 
     19  info("Requesting a resource over HTTPS.");
     20  await performRequestAndWait(
     21    "https://example.com" + CORS_SJS_PATH + "?request_2"
     22  );
     23  await performRequestAndWait(
     24    "https://example.com" + CORS_SJS_PATH + "?request_1"
     25  );
     26 
     27  is(store.getState().requests.requests.length, 2, "Two events event logged.");
     28 
     29  await clickAndTestSecurityIcon();
     30 
     31  info("Selecting headers panel again.");
     32  clickOnSidebarTab(document, "headers");
     33 
     34  info("Sorting the items by filename.");
     35  EventUtils.sendMouseEvent(
     36    { type: "click" },
     37    document.querySelector("#requests-list-file-button")
     38  );
     39 
     40  info(
     41    "Testing that security icon can be clicked after the items were sorted."
     42  );
     43 
     44  await clickAndTestSecurityIcon();
     45 
     46  return teardown(monitor);
     47 
     48  async function performRequestAndWait(url) {
     49    const wait = waitForNetworkEvents(monitor, 1);
     50    await SpecialPowers.spawn(
     51      tab.linkedBrowser,
     52      [{ url }],
     53      async function (args) {
     54        content.wrappedJSObject.performRequests(1, args.url);
     55      }
     56    );
     57    return wait;
     58  }
     59 
     60  async function clickAndTestSecurityIcon() {
     61    const icon = document.querySelector(".requests-security-state-icon");
     62    info(
     63      "Clicking security icon of the first request and waiting for panel update."
     64    );
     65    EventUtils.synthesizeMouseAtCenter(icon, {}, monitor.panelWin);
     66    await waitUntil(() =>
     67      document.querySelector("#security-panel .security-info-value")
     68    );
     69 
     70    ok(
     71      document.querySelector("#security-tab[aria-selected=true]"),
     72      "Security tab is selected."
     73    );
     74  }
     75 });