|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 'use strict'; |
|
5 |
|
6 const { isTabOpen, activateTab, openTab, |
|
7 closeTab, getTabURL, getWindowHoldingTab } = require('sdk/tabs/utils'); |
|
8 const windows = require('sdk/deprecated/window-utils'); |
|
9 const { LoaderWithHookedConsole } = require('sdk/test/loader'); |
|
10 const { setTimeout } = require('sdk/timers'); |
|
11 const app = require("sdk/system/xul-app"); |
|
12 const tabs = require('sdk/tabs'); |
|
13 const isAustralis = "gCustomizeMode" in windows.activeBrowserWindow; |
|
14 const { set: setPref, get: getPref } = require("sdk/preferences/service"); |
|
15 const { PrefsTarget } = require("sdk/preferences/event-target"); |
|
16 const { defer } = require('sdk/core/promise'); |
|
17 |
|
18 const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings"; |
|
19 |
|
20 let uri = require('sdk/self').data.url('index.html'); |
|
21 |
|
22 function closeTabPromise(tab) { |
|
23 let { promise, resolve } = defer(); |
|
24 let url = getTabURL(tab); |
|
25 |
|
26 tabs.on('close', function onCloseTab(t) { |
|
27 if (t.url == url) { |
|
28 tabs.removeListener('close', onCloseTab); |
|
29 setTimeout(_ => resolve(tab)) |
|
30 } |
|
31 }); |
|
32 closeTab(tab); |
|
33 |
|
34 return promise; |
|
35 } |
|
36 |
|
37 function isChromeVisible(window) { |
|
38 let x = window.document.documentElement.getAttribute('disablechrome') |
|
39 return x !== 'true'; |
|
40 } |
|
41 |
|
42 // Once Bug 903018 is resolved, just move the application testing to |
|
43 // module.metadata.engines |
|
44 if (app.is('Firefox')) { |
|
45 |
|
46 exports['test add-on page deprecation message'] = function(assert, done) { |
|
47 let { loader, messages } = LoaderWithHookedConsole(module); |
|
48 |
|
49 loader.require('sdk/preferences/event-target').PrefsTarget({ |
|
50 branchName: "devtools.errorconsole." |
|
51 }).on("deprecation_warnings", function() { |
|
52 if (!getPref(DEPRECATE_PREF, false)) { |
|
53 return undefined; |
|
54 } |
|
55 |
|
56 loader.require('sdk/addon-page'); |
|
57 |
|
58 assert.equal(messages.length, 1, "only one error is dispatched"); |
|
59 assert.equal(messages[0].type, "error", "the console message is an error"); |
|
60 |
|
61 let msg = messages[0].msg; |
|
62 assert.ok(msg.indexOf("DEPRECATED") === 0, |
|
63 "The message is deprecation message"); |
|
64 |
|
65 loader.unload(); |
|
66 done(); |
|
67 return undefined; |
|
68 }); |
|
69 setPref(DEPRECATE_PREF, false); |
|
70 setPref(DEPRECATE_PREF, true); |
|
71 }; |
|
72 |
|
73 exports['test that add-on page has no chrome'] = function(assert, done) { |
|
74 let { loader } = LoaderWithHookedConsole(module); |
|
75 loader.require('sdk/addon-page'); |
|
76 |
|
77 let window = windows.activeBrowserWindow; |
|
78 let tab = openTab(window, uri); |
|
79 |
|
80 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page'); |
|
81 |
|
82 // need to do this in another turn to make sure event listener |
|
83 // that sets property has time to do that. |
|
84 setTimeout(function() { |
|
85 activateTab(tab); |
|
86 |
|
87 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis, |
|
88 'chrome is not visible for addon page'); |
|
89 |
|
90 closeTabPromise(tab).then(function() { |
|
91 assert.ok(isChromeVisible(window), 'chrome is visible again'); |
|
92 loader.unload(); |
|
93 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload'); |
|
94 done(); |
|
95 }).then(null, assert.fail); |
|
96 }); |
|
97 }; |
|
98 |
|
99 exports['test that add-on page with hash has no chrome'] = function(assert, done) { |
|
100 let { loader } = LoaderWithHookedConsole(module); |
|
101 loader.require('sdk/addon-page'); |
|
102 |
|
103 let window = windows.activeBrowserWindow; |
|
104 let tab = openTab(window, uri + "#foo"); |
|
105 |
|
106 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page'); |
|
107 |
|
108 // need to do this in another turn to make sure event listener |
|
109 // that sets property has time to do that. |
|
110 setTimeout(function() { |
|
111 activateTab(tab); |
|
112 |
|
113 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis, |
|
114 'chrome is not visible for addon page'); |
|
115 |
|
116 closeTabPromise(tab).then(function() { |
|
117 assert.ok(isChromeVisible(window), 'chrome is visible again'); |
|
118 loader.unload(); |
|
119 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload'); |
|
120 done(); |
|
121 }).then(null, assert.fail); |
|
122 }); |
|
123 }; |
|
124 |
|
125 exports['test that add-on page with querystring has no chrome'] = function(assert, done) { |
|
126 let { loader } = LoaderWithHookedConsole(module); |
|
127 loader.require('sdk/addon-page'); |
|
128 |
|
129 let window = windows.activeBrowserWindow; |
|
130 let tab = openTab(window, uri + '?foo=bar'); |
|
131 |
|
132 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page'); |
|
133 |
|
134 // need to do this in another turn to make sure event listener |
|
135 // that sets property has time to do that. |
|
136 setTimeout(function() { |
|
137 activateTab(tab); |
|
138 |
|
139 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis, |
|
140 'chrome is not visible for addon page'); |
|
141 |
|
142 closeTabPromise(tab).then(function() { |
|
143 assert.ok(isChromeVisible(window), 'chrome is visible again'); |
|
144 loader.unload(); |
|
145 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload'); |
|
146 done(); |
|
147 }).then(null, assert.fail); |
|
148 }); |
|
149 }; |
|
150 |
|
151 exports['test that add-on page with hash and querystring has no chrome'] = function(assert, done) { |
|
152 let { loader } = LoaderWithHookedConsole(module); |
|
153 loader.require('sdk/addon-page'); |
|
154 |
|
155 let window = windows.activeBrowserWindow; |
|
156 let tab = openTab(window, uri + '#foo?foo=bar'); |
|
157 |
|
158 assert.ok(isChromeVisible(window), 'chrome is visible for non addon page'); |
|
159 |
|
160 // need to do this in another turn to make sure event listener |
|
161 // that sets property has time to do that. |
|
162 setTimeout(function() { |
|
163 activateTab(tab); |
|
164 |
|
165 assert.equal(isChromeVisible(window), app.is('Fennec') || isAustralis, |
|
166 'chrome is not visible for addon page'); |
|
167 |
|
168 closeTabPromise(tab).then(function() { |
|
169 assert.ok(isChromeVisible(window), 'chrome is visible again'); |
|
170 loader.unload(); |
|
171 assert.ok(!isTabOpen(tab), 'add-on page tab is closed on unload'); |
|
172 done(); |
|
173 }).then(null, assert.fail); |
|
174 }); |
|
175 }; |
|
176 |
|
177 exports['test that malformed uri is not an addon-page'] = function(assert, done) { |
|
178 let { loader } = LoaderWithHookedConsole(module); |
|
179 loader.require('sdk/addon-page'); |
|
180 |
|
181 let window = windows.activeBrowserWindow; |
|
182 let tab = openTab(window, uri + 'anguage'); |
|
183 |
|
184 // need to do this in another turn to make sure event listener |
|
185 // that sets property has time to do that. |
|
186 setTimeout(function() { |
|
187 activateTab(tab); |
|
188 |
|
189 assert.ok(isChromeVisible(window), 'chrome is visible for malformed uri'); |
|
190 |
|
191 closeTabPromise(tab).then(function() { |
|
192 loader.unload(); |
|
193 done(); |
|
194 }).then(null, assert.fail); |
|
195 }); |
|
196 }; |
|
197 |
|
198 } else { |
|
199 exports['test unsupported'] = (assert) => assert.pass('This application is unsupported.'); |
|
200 } |
|
201 |
|
202 require('sdk/test/runner').runTestsFromModule(module); |