summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/engagementTelemetry/browser/browser_glean_telemetry_record_preferences.js
blob: 88adc2fc11e86cf9a1e07116865703ec069c4c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test for preference telemetry.

add_setup(async function () {
  await Services.fog.testFlushAllChildren();
  Services.fog.testResetFOG();

  // Create a new window in order to initialize TelemetryEvent of
  // UrlbarController.
  const win = await BrowserTestUtils.openNewBrowserWindow();
  registerCleanupFunction(async function () {
    await BrowserTestUtils.closeWindow(win);
  });
});

add_task(async function prefMaxRichResults() {
  Assert.equal(
    Glean.urlbar.prefMaxResults.testGetValue(),
    UrlbarPrefs.get("maxRichResults"),
    "Record prefMaxResults when UrlbarController is initialized"
  );

  await SpecialPowers.pushPrefEnv({
    set: [["browser.urlbar.maxRichResults", 0]],
  });
  Assert.equal(
    Glean.urlbar.prefMaxResults.testGetValue(),
    UrlbarPrefs.get("maxRichResults"),
    "Record prefMaxResults when the maxRichResults pref is updated"
  );
});

add_task(async function boolPref() {
  const testData = [
    {
      green: "prefSuggestDataCollection",
      pref: "quicksuggest.dataCollection.enabled",
    },
    {
      green: "prefSuggestNonsponsored",
      pref: "suggest.quicksuggest.nonsponsored",
    },
    {
      green: "prefSuggestSponsored",
      pref: "suggest.quicksuggest.sponsored",
    },
    {
      green: "prefSuggestTopsites",
      pref: "suggest.topsites",
    },
  ];

  for (const { green, pref } of testData) {
    Assert.equal(
      Glean.urlbar[green].testGetValue(),
      UrlbarPrefs.get(pref),
      `Record ${green} when UrlbarController is initialized`
    );

    await SpecialPowers.pushPrefEnv({
      set: [[`browser.urlbar.${pref}`, !UrlbarPrefs.get(pref)]],
    });

    Assert.equal(
      Glean.urlbar[green].testGetValue(),
      UrlbarPrefs.get(pref),
      `Record ${green} when the ${pref} pref is updated`
    );
  }
});