tor-browser

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

browser_jsonview_serviceworker.js (2658B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_JSON_URL = URL_ROOT_SSL + "valid_json.json";
      7 const EMPTY_PAGE = URL_ROOT_SSL + "empty.html";
      8 const SW = URL_ROOT_SSL + "passthrough-sw.js";
      9 
     10 add_task(async function () {
     11  info("Test valid JSON with service worker started");
     12 
     13  await SpecialPowers.pushPrefEnv({
     14    set: [
     15      ["dom.serviceWorkers.exemptFromPerDomainMax", true],
     16      ["dom.serviceWorkers.enabled", true],
     17      ["dom.serviceWorkers.testing.enabled", true],
     18    ],
     19  });
     20 
     21  const swTab = BrowserTestUtils.addTab(gBrowser, EMPTY_PAGE);
     22  const browser = gBrowser.getBrowserForTab(swTab);
     23  await BrowserTestUtils.browserLoaded(browser);
     24  await SpecialPowers.spawn(
     25    browser,
     26    [{ script: SW, scope: TEST_JSON_URL }],
     27    async opts => {
     28      const reg = await content.navigator.serviceWorker.register(opts.script, {
     29        scope: opts.scope,
     30      });
     31      return new content.window.Promise(resolve => {
     32        const worker = reg.installing;
     33        if (worker.state === "activated") {
     34          resolve();
     35          return;
     36        }
     37        worker.addEventListener("statechange", () => {
     38          if (worker.state === "activated") {
     39            resolve();
     40          }
     41        });
     42      });
     43    }
     44  );
     45 
     46  const tab = await addJsonViewTab(TEST_JSON_URL);
     47 
     48  is(
     49    tab.linkedBrowser.contentPrincipal.origin,
     50    "resource://devtools",
     51    "Should have a resource devtools principal"
     52  );
     53 
     54  is(await countRows(), 3, "There must be three rows");
     55 
     56  const objectCellCount = await getElementCount(
     57    ".jsonPanelBox .treeTable .objectCell"
     58  );
     59  is(objectCellCount, 1, "There must be one object cell");
     60 
     61  const objectCellText = await getElementText(
     62    ".jsonPanelBox .treeTable .objectCell"
     63  );
     64  is(objectCellText, "", "The summary is hidden when object is expanded");
     65 
     66  // Clicking the value does not collapse it (so that it can be selected and copied).
     67  await clickJsonNode(".jsonPanelBox .treeTable .treeValueCell");
     68  is(await countRows(), 3, "There must still be three rows");
     69 
     70  // Clicking the label collapses the auto-expanded node.
     71  await clickJsonNode(".jsonPanelBox .treeTable .treeLabel");
     72  is(await countRows(), 1, "There must be one row");
     73 
     74  await SpecialPowers.spawn(
     75    browser,
     76    [{ script: SW, scope: TEST_JSON_URL }],
     77    async opts => {
     78      const reg = await content.navigator.serviceWorker.getRegistration(
     79        opts.scope
     80      );
     81      await reg.unregister();
     82    }
     83  );
     84 
     85  BrowserTestUtils.removeTab(swTab);
     86 });
     87 
     88 function countRows() {
     89  return getElementCount(".jsonPanelBox .treeTable .treeRow");
     90 }