|
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 windowUtils = require('sdk/deprecated/window-utils'); |
|
7 const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils'); |
|
8 const { getFrames, getWindowTitle, onFocus, isWindowPrivate, windows, isBrowser } = require('sdk/window/utils'); |
|
9 const { open, close, focus } = require('sdk/window/helpers'); |
|
10 const { isPrivate } = require('sdk/private-browsing'); |
|
11 const { pb } = require('./private-browsing/helper'); |
|
12 const { fromIterator: toArray } = require('sdk/util/array'); |
|
13 |
|
14 function makeEmptyBrowserWindow(options) { |
|
15 options = options || {}; |
|
16 return open('chrome://browser/content/browser.xul', { |
|
17 features: { |
|
18 chrome: true, |
|
19 private: !!options.private, |
|
20 toolbar: true |
|
21 } |
|
22 }); |
|
23 } |
|
24 |
|
25 exports.testShowPanelAndWidgetOnPrivateWindow = function(assert, done) { |
|
26 var myPrivateWindow; |
|
27 var finished = false; |
|
28 var privateWindow; |
|
29 var privateWindowClosed = false; |
|
30 var { Panel } = require('sdk/panel'); |
|
31 var { Widget } = require('sdk/widget'); |
|
32 |
|
33 pb.once('start', function() { |
|
34 assert.pass('private browsing mode started'); |
|
35 |
|
36 // make a new private window |
|
37 makeEmptyBrowserWindow().then(function(window) { |
|
38 myPrivateWindow = window; |
|
39 |
|
40 let wt = windowUtils.WindowTracker({ |
|
41 onTrack: function(window) { |
|
42 if (!isBrowser(window) || window !== myPrivateWindow) return; |
|
43 |
|
44 assert.ok(isWindowPrivate(window), 'window is private onTrack!'); |
|
45 let panel = Panel({ |
|
46 onShow: function() { |
|
47 assert.ok(this.isShowing, 'the panel is showing on the private window'); |
|
48 |
|
49 let count = 0; |
|
50 let widget = Widget({ |
|
51 id: "testShowPanelAndWidgetOnPrivateWindow-id", |
|
52 label: "My Hello Widget", |
|
53 content: "Hello!", |
|
54 onAttach: function(mod) { |
|
55 count++; |
|
56 if (count == 2) { |
|
57 panel.destroy(); |
|
58 widget.destroy(); |
|
59 close(window); |
|
60 } |
|
61 } |
|
62 }); |
|
63 } |
|
64 }).show(null, window.gBrowser); |
|
65 }, |
|
66 onUntrack: function(window) { |
|
67 if (window === myPrivateWindow) { |
|
68 wt.unload(); |
|
69 |
|
70 pb.once('stop', function() { |
|
71 assert.pass('private browsing mode end'); |
|
72 done(); |
|
73 }); |
|
74 |
|
75 pb.deactivate(); |
|
76 } |
|
77 } |
|
78 }); |
|
79 |
|
80 assert.equal(isWindowPrivate(window), true, 'the opened window is private'); |
|
81 assert.equal(isPrivate(window), true, 'the opened window is private'); |
|
82 assert.ok(getFrames(window).length > 1, 'there are frames for private window'); |
|
83 assert.equal(getWindowTitle(window), window.document.title, |
|
84 'getWindowTitle works'); |
|
85 }); |
|
86 }); |
|
87 pb.activate(); |
|
88 }; |
|
89 |
|
90 exports.testWindowTrackerDoesNotIgnorePrivateWindows = function(assert, done) { |
|
91 var myPrivateWindow; |
|
92 var count = 0; |
|
93 |
|
94 let wt = windowUtils.WindowTracker({ |
|
95 onTrack: function(window) { |
|
96 if (!isBrowser(window) || !isWindowPrivate(window)) return; |
|
97 assert.ok(isWindowPrivate(window), 'window is private onTrack!'); |
|
98 if (++count == 1) |
|
99 close(window); |
|
100 }, |
|
101 onUntrack: function(window) { |
|
102 if (count == 1 && isWindowPrivate(window)) { |
|
103 wt.unload(); |
|
104 |
|
105 pb.once('stop', function() { |
|
106 assert.pass('private browsing mode end'); |
|
107 done(); |
|
108 }); |
|
109 pb.deactivate(); |
|
110 } |
|
111 } |
|
112 }); |
|
113 |
|
114 pb.once('start', function() { |
|
115 assert.pass('private browsing mode started'); |
|
116 makeEmptyBrowserWindow(); |
|
117 }); |
|
118 pb.activate(); |
|
119 } |
|
120 |
|
121 exports.testWindowIteratorDoesNotIgnorePrivateWindows = function(assert, done) { |
|
122 pb.once('start', function() { |
|
123 // make a new private window |
|
124 makeEmptyBrowserWindow().then(function(window) { |
|
125 assert.ok(isWindowPrivate(window), "window is private"); |
|
126 assert.equal(isPrivate(window), true, 'the opened window is private'); |
|
127 assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1, |
|
128 "window is in windowIterator()"); |
|
129 assert.ok(windows(null, { includePrivate: true }).indexOf(window) > -1, |
|
130 "window is in windows()"); |
|
131 |
|
132 close(window).then(function() { |
|
133 pb.once('stop', function() { |
|
134 done(); |
|
135 }); |
|
136 pb.deactivate(); |
|
137 }); |
|
138 }); |
|
139 }); |
|
140 pb.activate(); |
|
141 }; |
|
142 |
|
143 if (!isGlobalPBSupported) { |
|
144 module.exports = { |
|
145 "test Unsupported Test": function UnsupportedTest (assert) { |
|
146 assert.pass( |
|
147 "Skipping global private browsing tests"); |
|
148 } |
|
149 } |
|
150 } |
|
151 |
|
152 require("test").run(exports); |