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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
const { OnboardingMessageProvider } = ChromeUtils.import(
"resource://activity-stream/lib/OnboardingMessageProvider.jsm"
);
const { sinon } = ChromeUtils.importESModule(
"resource://testing-common/Sinon.sys.mjs"
);
function getOnboardingScreenById(screens, screenId) {
return screens.find(screen => {
return screen?.id === screenId;
});
}
add_task(
async function test_OnboardingMessageProvider_getUpgradeMessage_no_pin() {
let sandbox = sinon.createSandbox();
sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin").resolves(true);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// If Firefox is not pinned, the screen should have "pin" content
equal(
message.content.screens[0].id,
"UPGRADE_PIN_FIREFOX",
"Screen has pin screen id"
);
equal(
message.content.screens[0].content.primary_button.action.type,
"PIN_FIREFOX_TO_TASKBAR",
"Primary button has pin action type"
);
sandbox.restore();
}
);
add_task(
async function test_OnboardingMessageProvider_getUpgradeMessage_pin_no_default() {
let sandbox = sinon.createSandbox();
sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin").resolves(false);
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(true);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// If Firefox is pinned, but not the default, the screen should have "make default" content
equal(
message.content.screens[0].id,
"UPGRADE_ONLY_DEFAULT",
"Screen has make default screen id"
);
equal(
message.content.screens[0].content.primary_button.action.type,
"SET_DEFAULT_BROWSER",
"Primary button has make default action"
);
sandbox.restore();
}
);
add_task(
async function test_OnboardingMessageProvider_getUpgradeMessage_pin_and_default() {
let sandbox = sinon.createSandbox();
sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin").resolves(false);
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(false);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// If Firefox is pinned and the default, the screen should have "get started" content
equal(
message.content.screens[0].id,
"UPGRADE_GET_STARTED",
"Screen has get started screen id"
);
ok(
!message.content.screens[0].content.primary_button.action.type,
"Primary button has no action type"
);
sandbox.restore();
}
);
add_task(async function test_OnboardingMessageProvider_getNoImport_default() {
let sandbox = sinon.createSandbox();
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(false);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// No import screen is shown when user has Firefox both pinned and default
Assert.notEqual(
message.content.screens[1]?.id,
"UPGRADE_IMPORT_SETTINGS",
"Screen has no import screen id"
);
sandbox.restore();
});
add_task(async function test_OnboardingMessageProvider_getImport_nodefault() {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.shell.checkDefaultBrowser");
});
let sandbox = sinon.createSandbox();
sandbox.stub(OnboardingMessageProvider, "_doesAppNeedDefault").resolves(true);
sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin").resolves(false);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// Import screen is shown when user doesn't have Firefox pinned and default
Assert.equal(
message.content.screens[1]?.id,
"UPGRADE_IMPORT_SETTINGS",
"Screen has import screen id"
);
sandbox.restore();
});
add_task(
async function test_OnboardingMessageProvider_getPinPrivateWindow_noPrivatePin() {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.shell.checkDefaultBrowser");
});
let sandbox = sinon.createSandbox();
// User needs default to ensure Pin Private window shows as third screen after import
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(true);
let pinStub = sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin");
pinStub.resolves(false);
pinStub.withArgs(true).resolves(true);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// Pin Private screen is shown when user doesn't have Firefox private pinned but has Firefox pinned
Assert.ok(
getOnboardingScreenById(
message.content.screens,
"UPGRADE_PIN_PRIVATE_WINDOW"
)
);
sandbox.restore();
}
);
add_task(
async function test_OnboardingMessageProvider_getNoPinPrivateWindow_noPin() {
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", true);
registerCleanupFunction(() => {
Services.prefs.clearUserPref("browser.shell.checkDefaultBrowser");
});
let sandbox = sinon.createSandbox();
// User needs default to ensure Pin Private window shows as third screen after import
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(true);
let pinStub = sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin");
pinStub.resolves(true);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// Pin Private screen is not shown when user doesn't have Firefox pinned
Assert.ok(
!getOnboardingScreenById(
message.content.screens,
"UPGRADE_PIN_PRIVATE_WINDOW"
)
);
sandbox.restore();
}
);
add_task(async function test_schemaValidation() {
const { experimentValidator, messageValidators } = await makeValidators();
const messages = await OnboardingMessageProvider.getMessages();
for (const message of messages) {
const validator = messageValidators[message.template];
Assert.ok(
typeof validator !== "undefined",
typeof validator !== "undefined"
? `Schema validator found for ${message.template}.`
: `No schema validator found for template ${message.template}. Please update this test to add one.`
);
assertValidates(
validator,
message,
`Message ${message.id} validates as template ${message.template}`
);
assertValidates(
experimentValidator,
message,
`Message ${message.id} validates as MessagingExperiment`
);
}
});
add_task(
async function test_OnboardingMessageProvider_getPinPrivateWindow_pinPBMPrefDisabled() {
Services.prefs.setBoolPref(
"browser.startup.upgradeDialog.pinPBM.disabled",
true
);
registerCleanupFunction(() => {
Services.prefs.clearUserPref(
"browser.startup.upgradeDialog.pinPBM.disabled"
);
});
let sandbox = sinon.createSandbox();
// User needs default to ensure Pin Private window shows as third screen after import
sandbox
.stub(OnboardingMessageProvider, "_doesAppNeedDefault")
.resolves(true);
let pinStub = sandbox.stub(OnboardingMessageProvider, "_doesAppNeedPin");
pinStub.resolves(true);
const message = await OnboardingMessageProvider.getUpgradeMessage();
// Pin Private screen is not shown when pref is turned on
Assert.ok(
!getOnboardingScreenById(
message.content.screens,
"UPGRADE_PIN_PRIVATE_WINDOW"
)
);
sandbox.restore();
}
);
|