summaryrefslogtreecommitdiffstats
path: root/toolkit/components/nimbus/test/browser/browser_experiment_single_feature_enrollment.js
blob: 17e821019fe928369c1c029ad16c568a67243ecf (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const { ExperimentFakes } = ChromeUtils.import(
  "resource://testing-common/NimbusTestUtils.jsm"
);
const { ExperimentAPI, NimbusFeatures } = ChromeUtils.import(
  "resource://nimbus/ExperimentAPI.jsm"
);

const SINGLE_FEATURE_RECIPE = {
  appId: "firefox-desktop",
  appName: "firefox_desktop",
  arguments: {},
  branches: [
    {
      feature: {
        featureId: "urlbar",
        isEarlyStartup: true,
        value: {
          enabled: true,
          quickSuggestEnabled: false,
          quickSuggestNonSponsoredIndex: -1,
          quickSuggestShouldShowOnboardingDialog: true,
          quickSuggestShowOnboardingDialogAfterNRestarts: 2,
          quickSuggestSponsoredIndex: -1,
        },
      },
      ratio: 1,
      slug: "control",
    },
    {
      feature: {
        featureId: "urlbar",
        isEarlyStartup: true,
        value: {
          enabled: true,
          quickSuggestEnabled: true,
          quickSuggestNonSponsoredIndex: -1,
          quickSuggestShouldShowOnboardingDialog: false,
          quickSuggestShowOnboardingDialogAfterNRestarts: 2,
          quickSuggestSponsoredIndex: -1,
        },
      },
      ratio: 1,
      slug: "treatment",
    },
  ],
  bucketConfig: {
    count: 10000,
    namespace: "urlbar-9",
    randomizationUnit: "normandy_id",
    start: 0,
    total: 10000,
  },
  channel: "release",
  endDate: null,
  featureIds: ["urlbar"],
  id: "firefox-suggest-history-vs-offline",
  isEnrollmentPaused: false,
  outcomes: [],
  probeSets: [],
  proposedDuration: 28,
  proposedEnrollment: 7,
  referenceBranch: "control",
  schemaVersion: "1.5.0",
  slug: "firefox-suggest-history-vs-offline",
  startDate: "2021-07-21",
  targeting: "true",
  userFacingDescription: "Smarter suggestions in the AwesomeBar",
  userFacingName: "Firefox Suggest - History vs Offline",
};

const SYNC_DATA_PREF_BRANCH = "nimbus.syncdatastore.";

add_task(async function test_TODO() {
  let {
    enrollmentPromise,
    doExperimentCleanup,
  } = ExperimentFakes.enrollmentHelper(SINGLE_FEATURE_RECIPE);
  let sandbox = sinon.createSandbox();
  let stub = sandbox.stub(ExperimentAPI, "recordExposureEvent");

  await enrollmentPromise;

  Assert.ok(
    ExperimentAPI.getExperiment({ featureId: "urlbar" }),
    "Should enroll in single feature experiment"
  );

  Assert.ok(
    Services.prefs.getStringPref(`${SYNC_DATA_PREF_BRANCH}urlbar`),
    "Should store early startup feature for sync access"
  );
  Assert.equal(
    Services.prefs.getIntPref(
      `${SYNC_DATA_PREF_BRANCH}urlbar.quickSuggestSponsoredIndex`
    ),
    -1,
    "Should store early startup variable for sync access"
  );

  Assert.equal(
    NimbusFeatures.urlbar.getVariable(
      "quickSuggestShowOnboardingDialogAfterNRestarts"
    ),
    2,
    "Should return value"
  );

  NimbusFeatures.urlbar.recordExposureEvent();

  Assert.ok(stub.calledOnce, "Should be called once by urlbar");
  Assert.equal(
    stub.firstCall.args[0].experimentSlug,
    "firefox-suggest-history-vs-offline",
    "Should have expected slug"
  );
  Assert.equal(
    stub.firstCall.args[0].featureId,
    "urlbar",
    "Should have expected featureId"
  );

  await doExperimentCleanup();
  sandbox.restore();
  NimbusFeatures.urlbar._didSendExposureEvent = false;
});