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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { ExperimentFakes } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
const TOGGLE_HAS_USED_PREF =
"media.videocontrols.picture-in-picture.video-toggle.has-used";
const TOGGLE_FIRST_SEEN_PREF =
"media.videocontrols.picture-in-picture.video-toggle.first-seen-secs";
/**
* This tests that the first-time toggle doesn't change to the icon toggle.
*/
add_task(async function test_experiment_control_displayDuration() {
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await SimpleTest.promiseFocus(browser);
await ensureVideosReady(browser);
await SpecialPowers.pushPrefEnv({
set: [
[TOGGLE_FIRST_SEEN_PREF, 0],
[TOGGLE_HAS_USED_PREF, false],
],
});
let videoID = "with-controls";
await hoverToggle(browser, videoID);
const hasUsed = Services.prefs.getBoolPref(TOGGLE_HAS_USED_PREF);
const firstSeen = Services.prefs.getIntPref(TOGGLE_FIRST_SEEN_PREF);
Assert.ok(!hasUsed, "has-used is false and toggle is not icon");
Assert.notEqual(firstSeen, 0, "First seen should not be 0");
}
);
});
/**
* This tests that the first-time toggle changes to the icon toggle
* if the displayDuration end date is reached or passed.
*/
add_task(async function test_experiment_displayDuration_end_date_was_reached() {
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pictureinpicture",
value: {
displayDuration: 1,
},
});
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await SimpleTest.promiseFocus(browser);
await ensureVideosReady(browser);
await SpecialPowers.pushPrefEnv({
set: [
[TOGGLE_FIRST_SEEN_PREF, 222],
[TOGGLE_HAS_USED_PREF, false],
],
});
let videoID = "with-controls";
await hoverToggle(browser, videoID);
const hasUsed = Services.prefs.getBoolPref(TOGGLE_HAS_USED_PREF);
const firstSeen = Services.prefs.getIntPref(TOGGLE_FIRST_SEEN_PREF);
Assert.ok(hasUsed, "has-used is true and toggle is icon");
Assert.equal(firstSeen, 222, "First seen should remain unchanged");
}
);
await doExperimentCleanup();
});
/**
* This tests that the first-time toggle does not change to the icon toggle
* if the displayDuration end date is not yet reached or passed.
*/
add_task(async function test_experiment_displayDuration_end_date_not_reached() {
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pictureinpicture",
value: {
displayDuration: 5,
},
});
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await SimpleTest.promiseFocus(browser);
await ensureVideosReady(browser);
const currentDateSec = Math.round(Date.now() / 1000);
await SpecialPowers.pushPrefEnv({
set: [
[TOGGLE_FIRST_SEEN_PREF, currentDateSec],
[TOGGLE_HAS_USED_PREF, false],
],
});
let videoID = "with-controls";
await hoverToggle(browser, videoID);
const hasUsed = Services.prefs.getBoolPref(TOGGLE_HAS_USED_PREF);
const firstSeen = Services.prefs.getIntPref(TOGGLE_FIRST_SEEN_PREF);
Assert.ok(!hasUsed, "has-used is false and toggle is not icon");
Assert.equal(
firstSeen,
currentDateSec,
"First seen should remain unchanged"
);
}
);
await doExperimentCleanup();
});
/**
* This tests that the toggle does not change to the icon toggle if duration is negative.
*/
add_task(async function test_experiment_displayDuration_negative_duration() {
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pictureinpicture",
value: {
displayDuration: -1,
},
});
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await SimpleTest.promiseFocus(browser);
await ensureVideosReady(browser);
await SpecialPowers.pushPrefEnv({
set: [
[TOGGLE_FIRST_SEEN_PREF, 0],
[TOGGLE_HAS_USED_PREF, false],
],
});
let videoID = "with-controls";
await hoverToggle(browser, videoID);
const hasUsed = Services.prefs.getBoolPref(TOGGLE_HAS_USED_PREF);
const firstSeen = Services.prefs.getIntPref(TOGGLE_FIRST_SEEN_PREF);
Assert.ok(!hasUsed, "has-used is false and toggle is not icon");
Assert.notEqual(firstSeen, 0, "First seen should not be 0");
}
);
await doExperimentCleanup();
});
/**
* This tests that first-seen is only recorded for the first-time toggle.
*/
add_task(async function test_experiment_displayDuration_already_icon() {
let doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig({
featureId: "pictureinpicture",
value: {
displayDuration: 1,
},
});
await BrowserTestUtils.withNewTab(
{
gBrowser,
url: TEST_PAGE,
},
async browser => {
await SimpleTest.promiseFocus(browser);
await ensureVideosReady(browser);
await SpecialPowers.pushPrefEnv({
set: [
[TOGGLE_FIRST_SEEN_PREF, 0],
[TOGGLE_HAS_USED_PREF, true],
],
});
let videoID = "with-controls";
await hoverToggle(browser, videoID);
const firstSeen = Services.prefs.getIntPref(TOGGLE_FIRST_SEEN_PREF);
Assert.equal(firstSeen, 0, "First seen should be 0");
}
);
await doExperimentCleanup();
});
|