@@ -184,6 +184,7 @@ add_setup(async function () {
184
184
const { _fetchLatestAddonVersion } = CFRPageActions ;
185
185
// Prevent fetching the real addon url and making a network request
186
186
CFRPageActions . _fetchLatestAddonVersion = ( ) => "http://example.com" ;
187
+ Services . fog . testResetFOG ( ) ;
187
188
188
189
registerCleanupFunction ( ( ) => {
189
190
CFRPageActions . _fetchLatestAddonVersion = _fetchLatestAddonVersion ;
@@ -193,20 +194,10 @@ add_setup(async function () {
193
194
} ) ;
194
195
195
196
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 ] ] ,
202
199
} ) ;
203
200
204
- Services . prefs . setBoolPref (
205
- "browser.newtabpage.activity-stream.telemetry" ,
206
- true
207
- ) ;
208
-
209
- Services . fog . testResetFOG ( ) ;
210
201
let pingSubmitted = false ;
211
202
GleanPings . messagingSystem . testBeforeNextSubmit ( ( ) => {
212
203
pingSubmitted = true ;
@@ -266,6 +257,7 @@ add_task(async function test_cfr_notification_show() {
266
257
) ;
267
258
268
259
Assert . ok ( pingSubmitted , "Recorded an event" ) ;
260
+ Services . fog . testResetFOG ( ) ;
269
261
} ) ;
270
262
271
263
add_task ( async function test_cfr_notification_show ( ) {
@@ -332,6 +324,7 @@ add_task(async function test_cfr_notification_show() {
332
324
0 ,
333
325
"Should have removed the notification"
334
326
) ;
327
+ Services . fog . testResetFOG ( ) ;
335
328
} ) ;
336
329
337
330
add_task ( async function test_cfr_notification_minimize ( ) {
@@ -379,6 +372,7 @@ add_task(async function test_cfr_notification_minimize() {
379
372
. getElementById ( "contextual-feature-recommendation-notification" )
380
373
. button . click ( ) ;
381
374
await hidePanel ;
375
+ Services . fog . testResetFOG ( ) ;
382
376
} ) ;
383
377
384
378
add_task ( async function test_cfr_notification_minimize_2 ( ) {
@@ -441,6 +435,7 @@ add_task(async function test_cfr_notification_minimize_2() {
441
435
442
436
clearNotifications ( ) ;
443
437
CFRPageActions . clearRecommendations ( ) ;
438
+ Services . fog . testResetFOG ( ) ;
444
439
} ) ;
445
440
446
441
add_task ( async function test_cfr_addon_install ( ) {
@@ -500,6 +495,7 @@ add_task(async function test_cfr_addon_install() {
500
495
) ;
501
496
502
497
clearNotifications ( ) ;
498
+ Services . fog . testResetFOG ( ) ;
503
499
} ) ;
504
500
505
501
add_task (
@@ -551,6 +547,7 @@ add_task(
551
547
await hidePanel ;
552
548
await SpecialPowers . popPrefEnv ( ) ;
553
549
clearNotifications ( ) ;
550
+ Services . fog . testResetFOG ( ) ;
554
551
}
555
552
) ;
556
553
@@ -642,6 +639,7 @@ add_task(async function test_cfr_addon_and_features_show() {
642
639
0 ,
643
640
"Should have removed the notification"
644
641
) ;
642
+ Services . fog . testResetFOG ( ) ;
645
643
} ) ;
646
644
647
645
add_task ( async function test_onLocationChange_cb ( ) {
@@ -678,9 +676,8 @@ add_task(async function test_onLocationChange_cb() {
678
676
679
677
Assert . equal ( count , 2 , "We moved to a new document" ) ;
680
678
681
- registerCleanupFunction ( ( ) => {
682
- ASRouterTriggerListeners . get ( "openURL" ) . uninit ( ) ;
683
- } ) ;
679
+ ASRouterTriggerListeners . get ( "openURL" ) . uninit ( ) ;
680
+ Services . fog . testResetFOG ( ) ;
684
681
} ) ;
685
682
686
683
add_task ( async function test_matchPattern ( ) {
@@ -730,9 +727,8 @@ add_task(async function test_matchPattern() {
730
727
"www.example.com is a different host that also matches the pattern."
731
728
) ;
732
729
733
- registerCleanupFunction ( ( ) => {
734
- ASRouterTriggerListeners . get ( "frequentVisits" ) . uninit ( ) ;
735
- } ) ;
730
+ ASRouterTriggerListeners . get ( "frequentVisits" ) . uninit ( ) ;
731
+ Services . fog . testResetFOG ( ) ;
736
732
} ) ;
737
733
738
734
add_task ( async function test_providerNames ( ) {
@@ -741,11 +737,11 @@ add_task(async function test_providerNames() {
741
737
const cfrProviderPrefs = Services . prefs . getChildList ( providersBranch ) ;
742
738
for ( const prefName of cfrProviderPrefs ) {
743
739
const prefValue = JSON . parse ( Services . prefs . getStringPref ( prefName ) ) ;
744
- if ( prefValue && prefValue . id ) {
740
+ if ( prefValue ? .id ) {
745
741
Assert . equal (
746
742
prefValue . id ,
747
743
prefName . slice ( providersBranch . length ) ,
748
- "Provider id and pref name do not match"
744
+ "Provider id and pref name should match"
749
745
) ;
750
746
}
751
747
}
@@ -804,26 +800,26 @@ add_task(async function test_cfr_notification_keyboard() {
804
800
. getElementById ( "contextual-feature-recommendation-notification" )
805
801
. button . click ( ) ;
806
802
await hidePanel ;
803
+ Services . fog . testResetFOG ( ) ;
807
804
} ) ;
808
805
809
806
add_task ( function test_updateCycleForProviders ( ) {
810
807
Services . prefs
811
808
. getChildList ( "browser.newtabpage.activity-stream.asrouter.providers." )
812
809
. forEach ( provider => {
813
810
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
+ ) ;
816
817
}
817
818
} ) ;
818
819
} ) ;
819
820
820
821
add_task ( async function test_heartbeat_tactic_2 ( ) {
821
822
clearNotifications ( ) ;
822
- registerCleanupFunction ( ( ) => {
823
- // Remove the tab opened by clicking the heartbeat message
824
- gBrowser . removeCurrentTab ( ) ;
825
- clearNotifications ( ) ;
826
- } ) ;
827
823
828
824
const msg = ( await CFRMessageProvider . getMessages ( ) ) . find (
829
825
m => m . id === "HEARTBEAT_TACTIC_2"
@@ -858,18 +854,15 @@ add_task(async function test_heartbeat_tactic_2() {
858
854
document . getElementById ( "contextual-feature-recommendation" ) . click ( ) ;
859
855
860
856
await newTabPromise ;
857
+ gBrowser . removeCurrentTab ( ) ;
858
+ clearNotifications ( ) ;
859
+ Services . fog . testResetFOG ( ) ;
861
860
} ) ;
862
861
863
862
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 ] ] ,
868
865
} ) ;
869
- Services . prefs . setBoolPref (
870
- "browser.newtabpage.activity-stream.telemetry" ,
871
- true
872
- ) ;
873
866
874
867
let pingSubmitted = false ;
875
868
GleanPings . messagingSystem . testBeforeNextSubmit ( ( ) => {
@@ -929,4 +922,5 @@ add_task(async function test_cfr_doorhanger_in_private_window() {
929
922
930
923
Assert . ok ( pingSubmitted , "Submitted a CFR messaging system ping" ) ;
931
924
await BrowserTestUtils . closeWindow ( win ) ;
925
+ Services . fog . testResetFOG ( ) ;
932
926
} ) ;
0 commit comments