2
2
/* vim: set sts=2 sw=2 et tw=80: */
3
3
"use strict" ;
4
4
5
+ ChromeUtils . defineModuleGetter (
6
+ this ,
7
+ "PromptTestUtils" ,
8
+ "resource://testing-common/PromptTestUtils.jsm"
9
+ ) ;
10
+
11
+ async function waitForExtensionModalPrompt ( extension ) {
12
+ const dialog = await PromptTestUtils . waitForPrompt ( gBrowser . selectedBrowser , {
13
+ modalType : Ci . nsIPrompt . MODAL_TYPE_CONTENT ,
14
+ } ) ;
15
+ ok ( dialog , "Got an active modal prompt dialog as expected" ) ;
16
+ Assert . equal (
17
+ dialog ?. args . promptPrincipal . addonId ,
18
+ extension . id ,
19
+ "Got a prompt associated to the expected extension id"
20
+ ) ;
21
+
22
+ const promptTitle = dialog ?. ui . infoTitle . textContent ;
23
+ ok (
24
+ / T h e p a g e a t T e s t E x t N a m e s a y s : / . test ( promptTitle ) ,
25
+ `Got the expect title on the modal prompt dialog: "${ promptTitle } "`
26
+ ) ;
27
+
28
+ return {
29
+ async closeModalPrompt ( ) {
30
+ info ( "Close the tab modal prompt" ) ;
31
+ await PromptTestUtils . handlePrompt ( dialog ) ;
32
+ } ,
33
+ assertClosedModalPrompt ( ) {
34
+ ok (
35
+ ! dialog . args . promptActive ,
36
+ "modal prompt dialog has been closed as expected"
37
+ ) ;
38
+ } ,
39
+ } ;
40
+ }
41
+
5
42
add_task ( async function test_tab_options_modals ( ) {
6
43
function backgroundScript ( ) {
7
44
browser . runtime . openOptionsPage ( ) ;
@@ -26,6 +63,7 @@ add_task(async function test_tab_options_modals() {
26
63
options_ui : {
27
64
page : "options.html" ,
28
65
} ,
66
+ name : "TestExtName" ,
29
67
} ,
30
68
files : {
31
69
"options.html" : `<!DOCTYPE html>
@@ -42,57 +80,15 @@ add_task(async function test_tab_options_modals() {
42
80
43
81
await BrowserTestUtils . openNewForegroundTab ( gBrowser , "about:addons" ) ;
44
82
83
+ const testPromptPromise = waitForExtensionModalPrompt ( extension ) ;
45
84
await extension . startup ( ) ;
46
85
47
- const onceModalOpened = new Promise ( resolve => {
48
- const aboutAddonsBrowser = gBrowser . selectedBrowser ;
49
-
50
- aboutAddonsBrowser . addEventListener (
51
- "DOMWillOpenModalDialog" ,
52
- function onModalDialog ( event ) {
53
- // Wait for the next event tick to make sure the remaining part of the
54
- // testcase runs after the dialog gets opened.
55
- SimpleTest . executeSoon ( resolve ) ;
56
- } ,
57
- { once : true , capture : true }
58
- ) ;
59
- } ) ;
60
-
61
86
info ( "Wait the options_ui modal to be opened" ) ;
62
- await onceModalOpened ;
63
-
64
- const optionsBrowser = getInlineOptionsBrowser ( gBrowser . selectedBrowser ) ;
65
-
66
- // The stack that contains the tabmodalprompt elements is the parent of
67
- // the extensions options_ui browser element.
68
- let stack = optionsBrowser . parentNode ;
69
-
70
- let dialogs = stack . querySelectorAll ( "tabmodalprompt" ) ;
71
- Assert . equal (
72
- dialogs . length ,
73
- 1 ,
74
- "Expect a tab modal opened for the about addons tab"
75
- ) ;
76
-
77
- // Verify that the expected stylesheets have been applied on the
78
- // tabmodalprompt element (See Bug 1550529).
79
- const tabmodalStyle = dialogs [ 0 ] . ownerGlobal . getComputedStyle ( dialogs [ 0 ] ) ;
80
- is (
81
- tabmodalStyle [ "background-color" ] ,
82
- "rgba(26, 26, 26, 0.5)" ,
83
- "Got the expected styles applied to the tabmodalprompt"
84
- ) ;
85
-
86
- info ( "Close the tab modal prompt" ) ;
87
- dialogs [ 0 ] . querySelector ( ".tabmodalprompt-button0" ) . click ( ) ;
87
+ const testModalPrompt = await testPromptPromise ;
88
88
89
+ testModalPrompt . closeModalPrompt ( ) ;
89
90
await extension . awaitFinish ( "options-ui-modals" ) ;
90
-
91
- Assert . equal (
92
- stack . querySelectorAll ( "tabmodalprompt" ) . length ,
93
- 0 ,
94
- "Expect the tab modal to be closed"
95
- ) ;
91
+ testModalPrompt . assertClosedModalPrompt ( ) ;
96
92
97
93
BrowserTestUtils . removeTab ( gBrowser . selectedTab ) ;
98
94
0 commit comments