tor-browser

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

browser_connection_telemetry.js (2593B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const PROXY_TYPE = "network.proxy.type";
      7 const proxyService = Ci.nsIProtocolProxyService;
      8 // The integer pref value for proxy type gets saved to telemetry
      9 // as a string for better readabillity according to the following map
     10 const PROXY_TYPES_MAP_REVERSE = new Map([
     11  [proxyService.PROXYCONFIG_DIRECT, "DIRECT"],
     12  [proxyService.PROXYCONFIG_MANUAL, "MANUAL"],
     13  [proxyService.PROXYCONFIG_PAC, "PAC"],
     14  [proxyService.PROXYCONFIG_WPAD, "WPAD"],
     15  [proxyService.PROXYCONFIG_SYSTEM, "SYSTEM"],
     16 ]);
     17 
     18 add_task(async function testProxyTelemetry() {
     19  // Open settings dialog
     20  await openPreferencesViaOpenPreferencesAPI("general", { leaveOpen: true });
     21  const connectionURL =
     22    "chrome://browser/content/preferences/dialogs/connection.xhtml";
     23  let dialog = await openAndLoadSubDialog(connectionURL);
     24  let dialogElement = dialog.document.getElementById("ConnectionsDialog");
     25 
     26  // Revert the proxy type to what it was before the test was run
     27  let oldNetworkProxyType = Services.prefs.getIntPref(PROXY_TYPE);
     28  registerCleanupFunction(function () {
     29    Services.prefs.setIntPref(PROXY_TYPE, oldNetworkProxyType);
     30  });
     31 
     32  let proxyType = dialog.Preferences.get(PROXY_TYPE);
     33 
     34  setPrefAndCheck(
     35    dialogElement,
     36    proxyType,
     37    proxyService.PROXYCONFIG_DIRECT,
     38    PROXY_TYPES_MAP_REVERSE.get(proxyService.PROXYCONFIG_DIRECT)
     39  );
     40  setPrefAndCheck(
     41    dialogElement,
     42    proxyType,
     43    proxyService.PROXYCONFIG_MANUAL,
     44    PROXY_TYPES_MAP_REVERSE.get(proxyService.PROXYCONFIG_MANUAL)
     45  );
     46  setPrefAndCheck(
     47    dialogElement,
     48    proxyType,
     49    proxyService.PROXYCONFIG_PAC,
     50    PROXY_TYPES_MAP_REVERSE.get(proxyService.PROXYCONFIG_PAC)
     51  );
     52  setPrefAndCheck(
     53    dialogElement,
     54    proxyType,
     55    proxyService.PROXYCONFIG_WPAD,
     56    PROXY_TYPES_MAP_REVERSE.get(proxyService.PROXYCONFIG_WPAD)
     57  );
     58  setPrefAndCheck(
     59    dialogElement,
     60    proxyType,
     61    proxyService.PROXYCONFIG_SYSTEM,
     62    PROXY_TYPES_MAP_REVERSE.get(proxyService.PROXYCONFIG_SYSTEM)
     63  );
     64  setPrefAndCheck(dialogElement, proxyType, 42, "OTHER");
     65 
     66  gBrowser.removeCurrentTab();
     67 });
     68 
     69 function setPrefAndCheck(
     70  dialogElement,
     71  proxyType,
     72  proxyTypePref,
     73  proxyTypePrefStr
     74 ) {
     75  Services.fog.testResetFOG();
     76 
     77  proxyType.value = proxyTypePref;
     78  dialogElement.acceptDialog();
     79  let events = Glean.networkProxySettings.proxyTypePreference.testGetValue();
     80  is(
     81    events[0].extra.value,
     82    proxyTypePrefStr,
     83    `Extra field for '${proxyTypePref}' should be '${proxyTypePrefStr}'.`
     84  );
     85 }