summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_frecency_alternative_nimbus.js
blob: d50d5314ad9700f5370c040b00f818383dd12ec0 (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
75
76
77
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

add_task(async function () {
  const tests = [
    {
      enableVariable: "originsAlternativeEnable",
      enablePref: "places.frecency.origins.alternative.featureGate",
      variables: {
        originsDaysCutOff: "places.frecency.origins.alternative.daysCutOff",
      },
    },
    {
      enableVariable: "pagesAlternativeEnable",
      enablePref: "places.frecency.pages.alternative.featureGate",
      variables: {
        pagesNumSampledVisits:
          "places.frecency.pages.alternative.numSampledVisits",
        pagesHalfLifeDays: "places.frecency.pages.alternative.halfLifeDays",
        pagesHighWeight: "places.frecency.pages.alternative.highWeight",
        pagesMediumWeight: "places.frecency.pages.alternative.mediumWeight",
        pagesLowWeight: "places.frecency.pages.alternative.lowWeight",
      },
    },
  ];
  for (let test of tests) {
    await doTest(test.enableVariable, test.enablePref, test.variables);
  }
});

async function doTest(enableVariable, enablePref, otherVariables) {
  info(`Testing ${enableVariable}`);
  let reset = await UrlbarTestUtils.initNimbusFeature(
    {
      // Empty for sanity check.
    },
    "urlbar",
    "config"
  );
  Assert.ok(!Services.prefs.prefHasUserValue(enablePref));
  Assert.ok(!Services.prefs.getBoolPref(enablePref, false));
  for (let pref of Object.values(otherVariables)) {
    Assert.ok(!Services.prefs.prefHasUserValue(pref));
  }
  await reset();

  reset = await UrlbarTestUtils.initNimbusFeature(
    {
      [enableVariable]: true,
    },
    "urlbar",
    "config"
  );
  Assert.ok(Services.prefs.prefHasUserValue(enablePref));
  Assert.equal(Services.prefs.getBoolPref(enablePref), true);
  for (let pref of Object.values(otherVariables)) {
    Assert.ok(!Services.prefs.prefHasUserValue(pref));
  }
  await reset();

  const FAKE_VALUE = 777;
  let config = {
    [enableVariable]: true,
  };
  for (let variable of Object.keys(otherVariables)) {
    config[variable] = FAKE_VALUE;
  }
  reset = await UrlbarTestUtils.initNimbusFeature(config, "urlbar", "config");
  Assert.ok(Services.prefs.prefHasUserValue(enablePref));
  Assert.equal(Services.prefs.getBoolPref(enablePref), true);
  for (let pref of Object.values(otherVariables)) {
    Assert.ok(Services.prefs.prefHasUserValue(pref));
    Assert.equal(Services.prefs.getIntPref(pref, 90), FAKE_VALUE);
  }

  await reset();
}