tor-browser

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

browser_usage_telemetry.js (7172B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   https://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 add_task(async function testSettingGroupTelemetry() {
      7  await BrowserTestUtils.withNewTab(
      8    {
      9      gBrowser,
     10      url: "about:preferences",
     11    },
     12    async () => {
     13      let win = gBrowser.selectedBrowser.contentWindow;
     14      let doc = win.document;
     15 
     16      win.Preferences.addSetting({
     17        id: "test-checkbox",
     18        get: () => false,
     19        set: () => {},
     20      });
     21      win.Preferences.addSetting({
     22        id: "test-radio",
     23        get: () => "one",
     24        set: () => {},
     25      });
     26      win.Preferences.addSetting({
     27        id: "test-select",
     28        get: () => "one",
     29        set: () => {},
     30      });
     31      win.Preferences.addSetting({
     32        id: "test-button",
     33      });
     34      win.Preferences.addSetting({
     35        id: "test-picker",
     36        get: () => "light",
     37        set: () => {},
     38      });
     39 
     40      let group = doc.createElement("setting-group");
     41      group.groupId = "testing";
     42      group.config = {
     43        id: "testingGroup",
     44        items: [
     45          {
     46            id: "test-checkbox",
     47            l10nId: "httpsonly-radio-disabled3",
     48          },
     49          {
     50            id: "test-radio",
     51            l10nId: "httpsonly-radio-disabled3",
     52            control: "moz-radio-group",
     53            options: [
     54              {
     55                id: "test-radio-one",
     56                l10nId: "httpsonly-radio-disabled3",
     57                value: "one",
     58              },
     59              {
     60                id: "test-radio-two",
     61                l10nId: "httpsonly-radio-disabled3",
     62                value: "two",
     63                items: [
     64                  {
     65                    id: "test-button",
     66                    l10nId: "httpsonly-radio-enabled-pbm",
     67                    control: "moz-button",
     68                  },
     69                ],
     70              },
     71            ],
     72          },
     73          {
     74            id: "test-select",
     75            l10nId: "httpsonly-radio-disabled3",
     76            control: "moz-select",
     77            options: [
     78              {
     79                id: "test-select-one",
     80                l10nId: "httpsonly-radio-enabled-pbm",
     81                value: "one",
     82              },
     83              {
     84                id: "test-select-two",
     85                l10nId: "httpsonly-radio-enabled-pbm",
     86                value: "two",
     87              },
     88            ],
     89          },
     90          {
     91            id: "test-picker",
     92            control: "moz-visual-picker",
     93            options: [
     94              {
     95                value: "light",
     96                l10nId: "preferences-web-appearance-choice-light2",
     97                controlAttrs: {
     98                  id: "test-picker-light",
     99                  class: "appearance-chooser-item",
    100                  imagesrc:
    101                    "chrome://browser/content/preferences/web-appearance-light.svg",
    102                },
    103              },
    104              {
    105                value: "dark",
    106                l10nId: "preferences-web-appearance-choice-dark2",
    107                controlAttrs: {
    108                  id: "test-picker-dark",
    109                  class: "appearance-chooser-item",
    110                  imagesrc:
    111                    "chrome://browser/content/preferences/web-appearance-dark.svg",
    112                },
    113              },
    114            ],
    115          },
    116        ],
    117      };
    118      group.getSetting = win.Preferences.getSetting.bind(win.Preferences);
    119      group.dataset.category = "paneGeneral";
    120      doc.body.append(group);
    121 
    122      // Ensure all elements have updated.
    123      await new Promise(r => win.requestAnimationFrame(r));
    124 
    125      let checkbox = doc.getElementById("test-checkbox");
    126      EventUtils.synthesizeMouseAtCenter(checkbox.inputEl, {}, win);
    127      EventUtils.synthesizeMouseAtCenter(checkbox.labelEl, {}, win);
    128      // Check that clicking the description is not counted as a click.
    129      AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
    130      EventUtils.synthesizeMouseAtCenter(checkbox.descriptionEl, {}, win);
    131      AccessibilityUtils.resetEnv();
    132 
    133      let button = doc.getElementById("test-button");
    134      is(button.buttonEl.disabled, true, "button is disabled");
    135      let radio = doc.getElementById("test-radio-two");
    136      EventUtils.synthesizeMouseAtCenter(radio.inputEl, {}, win);
    137      // Check that clicking the description is not counted as a click.
    138      AccessibilityUtils.setEnv({ mustHaveAccessibleRule: false });
    139      EventUtils.synthesizeMouseAtCenter(radio.descriptionEl, {}, win);
    140      AccessibilityUtils.resetEnv();
    141 
    142      // Ensure the button disabled state updated.
    143      await new Promise(r => win.requestAnimationFrame(r));
    144 
    145      is(button.buttonEl.disabled, false, "button is enabled");
    146      EventUtils.synthesizeMouseAtCenter(button, {}, win);
    147 
    148      let select = doc.getElementById("test-select");
    149      let popupShown = BrowserTestUtils.waitForSelectPopupShown(window);
    150      EventUtils.synthesizeMouseAtCenter(select.inputEl, {}, win);
    151      let popup = await popupShown;
    152      let popupHidden = BrowserTestUtils.waitForEvent(popup, "popuphidden");
    153      EventUtils.synthesizeKey("KEY_ArrowDown", {}, win);
    154      EventUtils.synthesizeKey("KEY_Enter", {}, win);
    155      await popupHidden;
    156 
    157      // Focus the visual picker via the keyboard.
    158      EventUtils.synthesizeKey("KEY_Tab", {}, win);
    159 
    160      let picker = doc.getElementById("test-picker");
    161      let secondItem = doc.getElementById("test-picker-dark");
    162      AccessibilityUtils.setEnv({
    163        mustHaveAccessibleRule: false,
    164      });
    165      EventUtils.synthesizeMouseAtCenter(secondItem.itemEl, {}, win);
    166 
    167      // Ensure the selected state of the picker updated.
    168      await picker.updateComplete;
    169 
    170      // Navigate to the second picker item and select it via keyboard.
    171      EventUtils.synthesizeKey("KEY_ArrowRight", {}, win);
    172      AccessibilityUtils.resetEnv();
    173 
    174      // Check that telemetry appeared:
    175      const { TelemetryTestUtils } = ChromeUtils.importESModule(
    176        "resource://testing-common/TelemetryTestUtils.sys.mjs"
    177      );
    178      let snapshot = TelemetryTestUtils.getProcessScalars("parent", true, true);
    179      TelemetryTestUtils.assertKeyedScalar(
    180        snapshot,
    181        "browser.ui.interaction.preferences_paneGeneral",
    182        "test-checkbox",
    183        2 // input and label clicked
    184      );
    185      TelemetryTestUtils.assertKeyedScalar(
    186        snapshot,
    187        "browser.ui.interaction.preferences_paneGeneral",
    188        "test-radio-two",
    189        1 // only input clicked
    190      );
    191      TelemetryTestUtils.assertKeyedScalar(
    192        snapshot,
    193        "browser.ui.interaction.preferences_paneGeneral",
    194        "test-button",
    195        1
    196      );
    197      TelemetryTestUtils.assertKeyedScalar(
    198        snapshot,
    199        "browser.ui.interaction.preferences_paneGeneral",
    200        "test-select",
    201        1
    202      );
    203      TelemetryTestUtils.assertKeyedScalar(
    204        snapshot,
    205        "browser.ui.interaction.preferences_paneGeneral",
    206        "test-picker-light",
    207        1
    208      );
    209      TelemetryTestUtils.assertKeyedScalar(
    210        snapshot,
    211        "browser.ui.interaction.preferences_paneGeneral",
    212        "test-picker-dark",
    213        1
    214      );
    215    }
    216  );
    217 });