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
131
132
133
134
135
136
137
138
139
140
141
|
"use strict";
const { IndexedDB } = ChromeUtils.importESModule(
"resource://gre/modules/IndexedDB.sys.mjs"
);
const { AddonRollouts } = ChromeUtils.importESModule(
"resource://normandy/lib/AddonRollouts.sys.mjs"
);
decorate_task(AddonRollouts.withTestMock(), async function testGetMissing() {
ok(
!(await AddonRollouts.get("does-not-exist")),
"get should return null when the requested rollout does not exist"
);
});
decorate_task(
AddonRollouts.withTestMock(),
async function testAddUpdateAndGet() {
const rollout = {
slug: "test-rollout",
state: AddonRollouts.STATE_ACTIVE,
extension: {},
};
await AddonRollouts.add(rollout);
let storedRollout = await AddonRollouts.get(rollout.slug);
Assert.deepEqual(
rollout,
storedRollout,
"get should retrieve a rollout from storage."
);
rollout.state = AddonRollouts.STATE_ROLLED_BACK;
await AddonRollouts.update(rollout);
storedRollout = await AddonRollouts.get(rollout.slug);
Assert.deepEqual(
rollout,
storedRollout,
"get should retrieve a rollout from storage."
);
}
);
decorate_task(
AddonRollouts.withTestMock(),
async function testCantUpdateNonexistent() {
const rollout = {
slug: "test-rollout",
state: AddonRollouts.STATE_ACTIVE,
extensions: {},
};
await Assert.rejects(
AddonRollouts.update(rollout),
/doesn't already exist/,
"Update should fail if the rollout doesn't exist"
);
ok(
!(await AddonRollouts.has("test-rollout")),
"rollout should not have been added"
);
}
);
decorate_task(AddonRollouts.withTestMock(), async function testGetAll() {
const rollout1 = { slug: "test-rollout-1", extension: {} };
const rollout2 = { slug: "test-rollout-2", extension: {} };
await AddonRollouts.add(rollout1);
await AddonRollouts.add(rollout2);
const storedRollouts = await AddonRollouts.getAll();
Assert.deepEqual(
storedRollouts.sort((a, b) => a.id - b.id),
[rollout1, rollout2],
"getAll should return every stored rollout."
);
});
decorate_task(AddonRollouts.withTestMock(), async function testGetAllActive() {
const rollout1 = {
slug: "test-rollout-1",
state: AddonRollouts.STATE_ACTIVE,
};
const rollout3 = {
slug: "test-rollout-2",
state: AddonRollouts.STATE_ROLLED_BACK,
};
await AddonRollouts.add(rollout1);
await AddonRollouts.add(rollout3);
const activeRollouts = await AddonRollouts.getAllActive();
Assert.deepEqual(
activeRollouts,
[rollout1],
"getAllActive should return only active rollouts"
);
});
decorate_task(AddonRollouts.withTestMock(), async function testHas() {
const rollout = { slug: "test-rollout", extensions: {} };
await AddonRollouts.add(rollout);
ok(
await AddonRollouts.has(rollout.slug),
"has should return true for an existing rollout"
);
ok(
!(await AddonRollouts.has("does not exist")),
"has should return false for a missing rollout"
);
});
// init should mark active rollouts in telemetry
decorate_task(
AddonRollouts.withTestMock(),
withStub(TelemetryEnvironment, "setExperimentActive"),
async function testInitTelemetry({ setExperimentActiveStub }) {
await AddonRollouts.add({
slug: "test-rollout-active-1",
state: AddonRollouts.STATE_ACTIVE,
});
await AddonRollouts.add({
slug: "test-rollout-active-2",
state: AddonRollouts.STATE_ACTIVE,
});
await AddonRollouts.add({
slug: "test-rollout-rolled-back",
state: AddonRollouts.STATE_ROLLED_BACK,
});
await AddonRollouts.init();
Assert.deepEqual(
setExperimentActiveStub.args,
[
["test-rollout-active-1", "active", { type: "normandy-addonrollout" }],
["test-rollout-active-2", "active", { type: "normandy-addonrollout" }],
],
"init should set activate a telemetry experiment for active addons"
);
}
);
|