|
1 'use strict'; |
|
2 |
|
3 const { open, focus, close } = require('sdk/window/helpers'); |
|
4 const { isPrivate } = require('sdk/private-browsing'); |
|
5 const { defer } = require('sdk/core/promise'); |
|
6 const { browserWindows: windows } = require('sdk/windows'); |
|
7 |
|
8 const BROWSER = 'chrome://browser/content/browser.xul'; |
|
9 |
|
10 exports.testRequirePanel = function(assert) { |
|
11 require('sdk/panel'); |
|
12 assert.ok('the panel module should not throw an error'); |
|
13 }; |
|
14 |
|
15 exports.testShowPanelInPrivateWindow = function(assert, done) { |
|
16 let panel = require('sdk/panel').Panel({ |
|
17 contentURL: "data:text/html;charset=utf-8," |
|
18 }); |
|
19 |
|
20 assert.ok(windows.length > 0, 'there is at least one open window'); |
|
21 for (let window of windows) { |
|
22 assert.equal(isPrivate(window), false, 'open window is private'); |
|
23 } |
|
24 |
|
25 testShowPanel(assert, panel). |
|
26 then(makeEmptyPrivateBrowserWindow). |
|
27 then(focus). |
|
28 then(function(window) { |
|
29 assert.equal(isPrivate(window), true, 'opened window is private'); |
|
30 assert.pass('private window was focused'); |
|
31 return window; |
|
32 }). |
|
33 then(function(window) { |
|
34 let { promise, resolve } = defer(); |
|
35 |
|
36 assert.ok(!panel.isShowing, 'the panel is not showing [1]'); |
|
37 |
|
38 panel.once('show', function() { |
|
39 assert.ok(panel.isShowing, 'the panel is showing'); |
|
40 |
|
41 panel.once('hide', function() { |
|
42 assert.ok(!panel.isShowing, 'the panel is not showing [2]'); |
|
43 |
|
44 resolve(window); |
|
45 }); |
|
46 |
|
47 panel.hide(); |
|
48 }); |
|
49 |
|
50 panel.show(); |
|
51 |
|
52 return promise; |
|
53 }). |
|
54 then(close). |
|
55 then(done). |
|
56 then(null, assert.fail); |
|
57 }; |
|
58 |
|
59 |
|
60 function makeEmptyPrivateBrowserWindow(options) { |
|
61 options = options || {}; |
|
62 return open(BROWSER, { |
|
63 features: { |
|
64 chrome: true, |
|
65 toolbar: true, |
|
66 private: true |
|
67 } |
|
68 }); |
|
69 } |
|
70 |
|
71 function testShowPanel(assert, panel) { |
|
72 let { promise, resolve } = defer(); |
|
73 let shown = false; |
|
74 |
|
75 assert.ok(!panel.isShowing, 'the panel is not showing [1]'); |
|
76 |
|
77 panel.once('hide', function() { |
|
78 assert.ok(!panel.isShowing, 'the panel is not showing [2]'); |
|
79 assert.ok(shown, 'the panel was shown') |
|
80 |
|
81 resolve(null); |
|
82 }); |
|
83 |
|
84 panel.once('show', function() { |
|
85 shown = true; |
|
86 |
|
87 assert.ok(panel.isShowing, 'the panel is showing'); |
|
88 |
|
89 panel.hide(); |
|
90 }); |
|
91 |
|
92 panel.show(); |
|
93 |
|
94 return promise; |
|
95 } |
|
96 |
|
97 //Test disabled because of bug 911071 |
|
98 module.exports = {} |