Skip to content

Commit d5888b2

Browse files
committed
Bug 1775847 - Fix Glean timeout in browser_asrouter_cfr.js. r=omc-reviewers,pdahiya
Differential Revision: https://phabricator.services.mozilla.com/D202078
1 parent b8931ee commit d5888b2

File tree

1 file changed

+29
-35
lines changed

1 file changed

+29
-35
lines changed

browser/components/asrouter/tests/browser/browser_asrouter_cfr.js

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ add_setup(async function () {
184184
const { _fetchLatestAddonVersion } = CFRPageActions;
185185
// Prevent fetching the real addon url and making a network request
186186
CFRPageActions._fetchLatestAddonVersion = () => "http://example.com";
187+
Services.fog.testResetFOG();
187188

188189
registerCleanupFunction(() => {
189190
CFRPageActions._fetchLatestAddonVersion = _fetchLatestAddonVersion;
@@ -193,20 +194,10 @@ add_setup(async function () {
193194
});
194195

195196
add_task(async function test_cfr_notification_show() {
196-
registerCleanupFunction(() => {
197-
Services.prefs.clearUserPref(
198-
"browser.newtabpage.activity-stream.telemetry"
199-
);
200-
// Reset fog to clear pings here for private window test later.
201-
Services.fog.testResetFOG();
197+
await SpecialPowers.pushPrefEnv({
198+
set: [["browser.newtabpage.activity-stream.telemetry", true]],
202199
});
203200

204-
Services.prefs.setBoolPref(
205-
"browser.newtabpage.activity-stream.telemetry",
206-
true
207-
);
208-
209-
Services.fog.testResetFOG();
210201
let pingSubmitted = false;
211202
GleanPings.messagingSystem.testBeforeNextSubmit(() => {
212203
pingSubmitted = true;
@@ -266,6 +257,7 @@ add_task(async function test_cfr_notification_show() {
266257
);
267258

268259
Assert.ok(pingSubmitted, "Recorded an event");
260+
Services.fog.testResetFOG();
269261
});
270262

271263
add_task(async function test_cfr_notification_show() {
@@ -332,6 +324,7 @@ add_task(async function test_cfr_notification_show() {
332324
0,
333325
"Should have removed the notification"
334326
);
327+
Services.fog.testResetFOG();
335328
});
336329

337330
add_task(async function test_cfr_notification_minimize() {
@@ -379,6 +372,7 @@ add_task(async function test_cfr_notification_minimize() {
379372
.getElementById("contextual-feature-recommendation-notification")
380373
.button.click();
381374
await hidePanel;
375+
Services.fog.testResetFOG();
382376
});
383377

384378
add_task(async function test_cfr_notification_minimize_2() {
@@ -441,6 +435,7 @@ add_task(async function test_cfr_notification_minimize_2() {
441435

442436
clearNotifications();
443437
CFRPageActions.clearRecommendations();
438+
Services.fog.testResetFOG();
444439
});
445440

446441
add_task(async function test_cfr_addon_install() {
@@ -500,6 +495,7 @@ add_task(async function test_cfr_addon_install() {
500495
);
501496

502497
clearNotifications();
498+
Services.fog.testResetFOG();
503499
});
504500

505501
add_task(
@@ -551,6 +547,7 @@ add_task(
551547
await hidePanel;
552548
await SpecialPowers.popPrefEnv();
553549
clearNotifications();
550+
Services.fog.testResetFOG();
554551
}
555552
);
556553

@@ -642,6 +639,7 @@ add_task(async function test_cfr_addon_and_features_show() {
642639
0,
643640
"Should have removed the notification"
644641
);
642+
Services.fog.testResetFOG();
645643
});
646644

647645
add_task(async function test_onLocationChange_cb() {
@@ -678,9 +676,8 @@ add_task(async function test_onLocationChange_cb() {
678676

679677
Assert.equal(count, 2, "We moved to a new document");
680678

681-
registerCleanupFunction(() => {
682-
ASRouterTriggerListeners.get("openURL").uninit();
683-
});
679+
ASRouterTriggerListeners.get("openURL").uninit();
680+
Services.fog.testResetFOG();
684681
});
685682

686683
add_task(async function test_matchPattern() {
@@ -730,9 +727,8 @@ add_task(async function test_matchPattern() {
730727
"www.example.com is a different host that also matches the pattern."
731728
);
732729

733-
registerCleanupFunction(() => {
734-
ASRouterTriggerListeners.get("frequentVisits").uninit();
735-
});
730+
ASRouterTriggerListeners.get("frequentVisits").uninit();
731+
Services.fog.testResetFOG();
736732
});
737733

738734
add_task(async function test_providerNames() {
@@ -741,11 +737,11 @@ add_task(async function test_providerNames() {
741737
const cfrProviderPrefs = Services.prefs.getChildList(providersBranch);
742738
for (const prefName of cfrProviderPrefs) {
743739
const prefValue = JSON.parse(Services.prefs.getStringPref(prefName));
744-
if (prefValue && prefValue.id) {
740+
if (prefValue?.id) {
745741
Assert.equal(
746742
prefValue.id,
747743
prefName.slice(providersBranch.length),
748-
"Provider id and pref name do not match"
744+
"Provider id and pref name should match"
749745
);
750746
}
751747
}
@@ -804,26 +800,26 @@ add_task(async function test_cfr_notification_keyboard() {
804800
.getElementById("contextual-feature-recommendation-notification")
805801
.button.click();
806802
await hidePanel;
803+
Services.fog.testResetFOG();
807804
});
808805

809806
add_task(function test_updateCycleForProviders() {
810807
Services.prefs
811808
.getChildList("browser.newtabpage.activity-stream.asrouter.providers.")
812809
.forEach(provider => {
813810
const prefValue = JSON.parse(Services.prefs.getStringPref(provider, ""));
814-
if (prefValue && prefValue.type === "remote-settings") {
815-
Assert.ok(prefValue.updateCycleInMs);
811+
if (prefValue?.type === "remote-settings") {
812+
is(
813+
typeof prefValue.updateCycleInMs,
814+
"number",
815+
"updateCycleInMs is set"
816+
);
816817
}
817818
});
818819
});
819820

820821
add_task(async function test_heartbeat_tactic_2() {
821822
clearNotifications();
822-
registerCleanupFunction(() => {
823-
// Remove the tab opened by clicking the heartbeat message
824-
gBrowser.removeCurrentTab();
825-
clearNotifications();
826-
});
827823

828824
const msg = (await CFRMessageProvider.getMessages()).find(
829825
m => m.id === "HEARTBEAT_TACTIC_2"
@@ -858,18 +854,15 @@ add_task(async function test_heartbeat_tactic_2() {
858854
document.getElementById("contextual-feature-recommendation").click();
859855

860856
await newTabPromise;
857+
gBrowser.removeCurrentTab();
858+
clearNotifications();
859+
Services.fog.testResetFOG();
861860
});
862861

863862
add_task(async function test_cfr_doorhanger_in_private_window() {
864-
registerCleanupFunction(() => {
865-
Services.prefs.clearUserPref(
866-
"browser.newtabpage.activity-stream.telemetry"
867-
);
863+
await SpecialPowers.pushPrefEnv({
864+
set: [["browser.newtabpage.activity-stream.telemetry", true]],
868865
});
869-
Services.prefs.setBoolPref(
870-
"browser.newtabpage.activity-stream.telemetry",
871-
true
872-
);
873866

874867
let pingSubmitted = false;
875868
GleanPings.messagingSystem.testBeforeNextSubmit(() => {
@@ -929,4 +922,5 @@ add_task(async function test_cfr_doorhanger_in_private_window() {
929922

930923
Assert.ok(pingSubmitted, "Submitted a CFR messaging system ping");
931924
await BrowserTestUtils.closeWindow(win);
925+
Services.fog.testResetFOG();
932926
});

0 commit comments

Comments
 (0)