@@ -9,7 +9,6 @@ const { sinon } = ChromeUtils.importESModule(
9
9
10
10
ChromeUtils . defineESModuleGetters ( this , {
11
11
ScreenshotsUtils : "resource:///modules/ScreenshotsUtils.sys.mjs" ,
12
- AddonManager : "resource://gre/modules/AddonManager.sys.mjs" ,
13
12
} ) ;
14
13
ChromeUtils . defineLazyGetter ( this , "ExtensionManagement" , ( ) => {
15
14
const { Management } = ChromeUtils . importESModule (
@@ -18,11 +17,7 @@ ChromeUtils.defineLazyGetter(this, "ExtensionManagement", () => {
18
17
return Management ;
19
18
} ) ;
20
19
21
- const COMPONENT_PREF = "screenshots.browser.component.enabled" ;
22
- const SCREENSHOTS_PREF = "extensions.screenshots.disabled" ;
23
- const SCREENSHOT_EXTENSION = "screenshots@mozilla.org" ;
24
-
25
- add_task ( async function test_toggling_screenshots_pref ( ) {
20
+ add_task ( async function test ( ) {
26
21
let observerSpy = sinon . spy ( ) ;
27
22
let notifierSpy = sinon . spy ( ) ;
28
23
@@ -36,24 +31,13 @@ add_task(async function test_toggling_screenshots_pref() {
36
31
ScreenshotsUtils . notify . wrappedMethod . apply ( this , arguments ) ;
37
32
} ) ;
38
33
39
- // wait for startup idle tasks to complete
40
- await new Promise ( resolve => ChromeUtils . idleDispatch ( resolve ) ) ;
41
- ok ( Services . prefs . getBoolPref ( COMPONENT_PREF ) , "Component enabled" ) ;
42
- ok ( ! Services . prefs . getBoolPref ( SCREENSHOTS_PREF ) , "Screenshots enabled" ) ;
43
-
44
- let addon = await AddonManager . getAddonByID ( SCREENSHOT_EXTENSION ) ;
45
- await BrowserTestUtils . waitForCondition (
46
- ( ) => ! addon . isActive ,
47
- "The extension is not active when the component is prefd on"
48
- ) ;
49
-
50
34
await BrowserTestUtils . withNewTab (
51
35
{
52
36
gBrowser,
53
37
url : SHORT_TEST_PAGE ,
54
38
} ,
55
39
async browser => {
56
- function extensionEventPromise ( eventName , id ) {
40
+ function awaitExtensionEvent ( eventName , id ) {
57
41
return new Promise ( resolve => {
58
42
let listener = ( _eventName , ...args ) => {
59
43
let extension = args [ 0 ] ;
@@ -65,21 +49,9 @@ add_task(async function test_toggling_screenshots_pref() {
65
49
ExtensionManagement . on ( eventName , listener ) ;
66
50
} ) ;
67
51
}
52
+ const SCREENSHOT_EXTENSION = "screenshots@mozilla.org" ;
68
53
69
54
let helper = new ScreenshotsHelper ( browser ) ;
70
- ok (
71
- addon . userDisabled ,
72
- "The extension is disabled when the component is prefd on"
73
- ) ;
74
- ok (
75
- ! addon . isActive ,
76
- "The extension is not initially active when the component is prefd on"
77
- ) ;
78
- await BrowserTestUtils . waitForCondition (
79
- ( ) => ScreenshotsUtils . initialized ,
80
- "The component is initialized"
81
- ) ;
82
- ok ( ScreenshotsUtils . initialized , "The component is initialized" ) ;
83
55
84
56
ok ( observerSpy . notCalled , "Observer not called" ) ;
85
57
helper . triggerUIFromToolbar ( ) ;
@@ -108,20 +80,12 @@ add_task(async function test_toggling_screenshots_pref() {
108
80
109
81
Assert . equal ( observerSpy . callCount , 3 , "Observer function called thrice" ) ;
110
82
111
- let extensionReadyPromise = extensionEventPromise (
112
- "ready" ,
113
- SCREENSHOT_EXTENSION
114
- ) ;
115
- Services . prefs . setBoolPref ( COMPONENT_PREF , false ) ;
83
+ const COMPONENT_PREF = "screenshots.browser.component.enabled" ;
84
+ await SpecialPowers . pushPrefEnv ( {
85
+ set : [ [ COMPONENT_PREF , false ] ] ,
86
+ } ) ;
116
87
ok ( ! Services . prefs . getBoolPref ( COMPONENT_PREF ) , "Extension enabled" ) ;
117
-
118
- info ( "Waiting for the extension ready event" ) ;
119
- await extensionReadyPromise ;
120
- await BrowserTestUtils . waitForCondition (
121
- ( ) => ! addon . userDisabled ,
122
- "The extension gets un-disabled when the component is prefd off"
123
- ) ;
124
- ok ( addon . isActive , "Extension is active" ) ;
88
+ await awaitExtensionEvent ( "ready" , SCREENSHOT_EXTENSION ) ;
125
89
126
90
helper . triggerUIFromToolbar ( ) ;
127
91
Assert . equal (
@@ -130,7 +94,6 @@ add_task(async function test_toggling_screenshots_pref() {
130
94
"Observer function still called thrice"
131
95
) ;
132
96
133
- info ( "Waiting for the extensions overlay" ) ;
134
97
await SpecialPowers . spawn (
135
98
browser ,
136
99
[ "#firefox-screenshots-preselection-iframe" ] ,
@@ -152,7 +115,6 @@ add_task(async function test_toggling_screenshots_pref() {
152
115
}
153
116
) ;
154
117
155
- info ( "Waiting for the extensions overlay" ) ;
156
118
helper . triggerUIFromToolbar ( ) ;
157
119
await SpecialPowers . spawn (
158
120
browser ,
@@ -240,7 +202,9 @@ add_task(async function test_toggling_screenshots_pref() {
240
202
"screenshots-component-initialized"
241
203
) ;
242
204
243
- Services . prefs . setBoolPref ( COMPONENT_PREF , true ) ;
205
+ await SpecialPowers . pushPrefEnv ( {
206
+ set : [ [ COMPONENT_PREF , true ] ] ,
207
+ } ) ;
244
208
ok ( Services . prefs . getBoolPref ( COMPONENT_PREF ) , "Component enabled" ) ;
245
209
// Needed for component to initialize
246
210
await componentReady ;
@@ -251,6 +215,12 @@ add_task(async function test_toggling_screenshots_pref() {
251
215
4 ,
252
216
"Observer function called four times"
253
217
) ;
218
+
219
+ const SCREENSHOTS_PREF = "extensions.screenshots.disabled" ;
220
+ await SpecialPowers . pushPrefEnv ( {
221
+ set : [ [ SCREENSHOTS_PREF , true ] ] ,
222
+ } ) ;
223
+ ok ( Services . prefs . getBoolPref ( SCREENSHOTS_PREF ) , "Screenshots disabled" ) ;
254
224
}
255
225
) ;
256
226
@@ -260,9 +230,7 @@ add_task(async function test_toggling_screenshots_pref() {
260
230
url : SHORT_TEST_PAGE ,
261
231
} ,
262
232
async browser => {
263
- Services . prefs . setBoolPref ( SCREENSHOTS_PREF , true ) ;
264
- Services . prefs . setBoolPref ( COMPONENT_PREF , true ) ;
265
-
233
+ const SCREENSHOTS_PREF = "extensions.screenshots.disabled" ;
266
234
ok ( Services . prefs . getBoolPref ( SCREENSHOTS_PREF ) , "Screenshots disabled" ) ;
267
235
268
236
ok (
@@ -287,22 +255,21 @@ add_task(async function test_toggling_screenshots_pref() {
287
255
menu . hidePopup ( ) ;
288
256
await popuphidden ;
289
257
290
- let componentReady = TestUtils . topicObserved (
291
- "screenshots-component-initialized"
292
- ) ;
293
-
294
- Services . prefs . setBoolPref ( SCREENSHOTS_PREF , false ) ;
295
-
258
+ await SpecialPowers . pushPrefEnv ( {
259
+ set : [ [ SCREENSHOTS_PREF , false ] ] ,
260
+ } ) ;
296
261
ok ( ! Services . prefs . getBoolPref ( SCREENSHOTS_PREF ) , "Screenshots enabled" ) ;
262
+ }
263
+ ) ;
297
264
298
- await componentReady ;
299
-
300
- ok ( ScreenshotsUtils . initialized , "The component is initialized" ) ;
301
-
302
- ok (
303
- ! document . getElementById ( "screenshot-button" ) . disabled ,
304
- "Toolbar button is enabled"
305
- ) ;
265
+ await BrowserTestUtils . withNewTab (
266
+ {
267
+ gBrowser ,
268
+ url : SHORT_TEST_PAGE ,
269
+ } ,
270
+ async browser => {
271
+ const SCREENSHOTS_PREF = "extensions.screenshots.disabled" ;
272
+ ok ( ! Services . prefs . getBoolPref ( SCREENSHOTS_PREF ) , "Screenshots enabled" ) ;
306
273
307
274
let helper = new ScreenshotsHelper ( browser ) ;
308
275
@@ -317,4 +284,6 @@ add_task(async function test_toggling_screenshots_pref() {
317
284
318
285
observerStub . restore ( ) ;
319
286
notifierStub . restore ( ) ;
287
+
288
+ await SpecialPowers . popPrefEnv ( ) ;
320
289
} ) ;
0 commit comments