tor-browser

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

browser_telemetry_button_responsive.js (2898B)


      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_URI =
      7  "data:text/html;charset=utf-8," +
      8  "<p>browser_telemetry_button_responsive.js</p>";
      9 
     10 // Because we need to gather stats for the period of time that a tool has been
     11 // opened we make use of setTimeout() to create tool active times.
     12 const TOOL_DELAY = 200;
     13 
     14 const asyncStorage = require("resource://devtools/shared/async-storage.js");
     15 
     16 // Toggling the RDM UI involves several docShell swap operations, which are somewhat slow
     17 // on debug builds. Usually we are just barely over the limit, so a blanket factor of 2
     18 // should be enough.
     19 requestLongerTimeout(2);
     20 
     21 Services.prefs.clearUserPref("devtools.responsive.html.displayedDeviceList");
     22 
     23 registerCleanupFunction(() => {
     24  asyncStorage.removeItem("devtools.devices.local");
     25 });
     26 
     27 loader.lazyRequireGetter(
     28  this,
     29  "ResponsiveUIManager",
     30  "resource://devtools/client/responsive/manager.js"
     31 );
     32 
     33 add_task(async function () {
     34  await addTab(TEST_URI);
     35  startTelemetry();
     36 
     37  const tab = gBrowser.selectedTab;
     38  const toolbox = await gDevTools.showToolboxForTab(tab, {
     39    toolId: "inspector",
     40  });
     41  info("inspector opened");
     42 
     43  info("testing the responsivedesign button");
     44  await testButton(tab, toolbox);
     45 
     46  await toolbox.destroy();
     47  gBrowser.removeCurrentTab();
     48 });
     49 
     50 async function testButton(tab, toolbox) {
     51  info("Testing command-button-responsive");
     52 
     53  const button = toolbox.doc.querySelector("#command-button-responsive");
     54  ok(button, "Captain, we have the button");
     55 
     56  await delayedClicks(tab, button, 4);
     57 
     58  checkResults();
     59 }
     60 
     61 function waitForToggle() {
     62  return new Promise(resolve => {
     63    const handler = () => {
     64      ResponsiveUIManager.off("on", handler);
     65      ResponsiveUIManager.off("off", handler);
     66      resolve();
     67    };
     68    ResponsiveUIManager.on("on", handler);
     69    ResponsiveUIManager.on("off", handler);
     70  });
     71 }
     72 
     73 var delayedClicks = async function (tab, node, clicks) {
     74  for (let i = 0; i < clicks; i++) {
     75    info("Clicking button " + node.id);
     76    const toggled = waitForToggle();
     77    node.click();
     78    await toggled;
     79    // See TOOL_DELAY for why we need setTimeout here
     80    await DevToolsUtils.waitForTime(TOOL_DELAY);
     81 
     82    // When opening RDM
     83    if (i % 2 == 0) {
     84      // wait for RDM to be fully loaded to prevent Promise rejection when closing
     85      await waitFor(() => ResponsiveUIManager.isActiveForTab(tab));
     86      const rdmUI = ResponsiveUIManager.getResponsiveUIForTab(tab);
     87      await waitForRDMLoaded(rdmUI);
     88    }
     89  }
     90 };
     91 
     92 function checkResults() {
     93  // For help generating these tests use generateTelemetryTests("DEVTOOLS_RESPONSIVE_")
     94  // here.
     95  checkTelemetry(
     96    "DEVTOOLS_RESPONSIVE_OPENED_COUNT",
     97    "",
     98    { 0: 2, 1: 0 },
     99    "array"
    100  );
    101  checkTelemetry(
    102    "DEVTOOLS_RESPONSIVE_TIME_ACTIVE_SECONDS",
    103    "",
    104    null,
    105    "hasentries"
    106  );
    107 }