michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: const windowUtils = require('sdk/deprecated/window-utils'); michael@0: const { isWindowPBSupported, isGlobalPBSupported } = require('sdk/private-browsing/utils'); michael@0: const { getFrames, getWindowTitle, onFocus, isWindowPrivate, windows, isBrowser } = require('sdk/window/utils'); michael@0: const { open, close, focus } = require('sdk/window/helpers'); michael@0: const { isPrivate } = require('sdk/private-browsing'); michael@0: const { pb } = require('./private-browsing/helper'); michael@0: const { fromIterator: toArray } = require('sdk/util/array'); michael@0: michael@0: function makeEmptyBrowserWindow(options) { michael@0: options = options || {}; michael@0: return open('chrome://browser/content/browser.xul', { michael@0: features: { michael@0: chrome: true, michael@0: private: !!options.private, michael@0: toolbar: true michael@0: } michael@0: }); michael@0: } michael@0: michael@0: exports.testShowPanelAndWidgetOnPrivateWindow = function(assert, done) { michael@0: var myPrivateWindow; michael@0: var finished = false; michael@0: var privateWindow; michael@0: var privateWindowClosed = false; michael@0: var { Panel } = require('sdk/panel'); michael@0: var { Widget } = require('sdk/widget'); michael@0: michael@0: pb.once('start', function() { michael@0: assert.pass('private browsing mode started'); michael@0: michael@0: // make a new private window michael@0: makeEmptyBrowserWindow().then(function(window) { michael@0: myPrivateWindow = window; michael@0: michael@0: let wt = windowUtils.WindowTracker({ michael@0: onTrack: function(window) { michael@0: if (!isBrowser(window) || window !== myPrivateWindow) return; michael@0: michael@0: assert.ok(isWindowPrivate(window), 'window is private onTrack!'); michael@0: let panel = Panel({ michael@0: onShow: function() { michael@0: assert.ok(this.isShowing, 'the panel is showing on the private window'); michael@0: michael@0: let count = 0; michael@0: let widget = Widget({ michael@0: id: "testShowPanelAndWidgetOnPrivateWindow-id", michael@0: label: "My Hello Widget", michael@0: content: "Hello!", michael@0: onAttach: function(mod) { michael@0: count++; michael@0: if (count == 2) { michael@0: panel.destroy(); michael@0: widget.destroy(); michael@0: close(window); michael@0: } michael@0: } michael@0: }); michael@0: } michael@0: }).show(null, window.gBrowser); michael@0: }, michael@0: onUntrack: function(window) { michael@0: if (window === myPrivateWindow) { michael@0: wt.unload(); michael@0: michael@0: pb.once('stop', function() { michael@0: assert.pass('private browsing mode end'); michael@0: done(); michael@0: }); michael@0: michael@0: pb.deactivate(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: assert.equal(isWindowPrivate(window), true, 'the opened window is private'); michael@0: assert.equal(isPrivate(window), true, 'the opened window is private'); michael@0: assert.ok(getFrames(window).length > 1, 'there are frames for private window'); michael@0: assert.equal(getWindowTitle(window), window.document.title, michael@0: 'getWindowTitle works'); michael@0: }); michael@0: }); michael@0: pb.activate(); michael@0: }; michael@0: michael@0: exports.testWindowTrackerDoesNotIgnorePrivateWindows = function(assert, done) { michael@0: var myPrivateWindow; michael@0: var count = 0; michael@0: michael@0: let wt = windowUtils.WindowTracker({ michael@0: onTrack: function(window) { michael@0: if (!isBrowser(window) || !isWindowPrivate(window)) return; michael@0: assert.ok(isWindowPrivate(window), 'window is private onTrack!'); michael@0: if (++count == 1) michael@0: close(window); michael@0: }, michael@0: onUntrack: function(window) { michael@0: if (count == 1 && isWindowPrivate(window)) { michael@0: wt.unload(); michael@0: michael@0: pb.once('stop', function() { michael@0: assert.pass('private browsing mode end'); michael@0: done(); michael@0: }); michael@0: pb.deactivate(); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: pb.once('start', function() { michael@0: assert.pass('private browsing mode started'); michael@0: makeEmptyBrowserWindow(); michael@0: }); michael@0: pb.activate(); michael@0: } michael@0: michael@0: exports.testWindowIteratorDoesNotIgnorePrivateWindows = function(assert, done) { michael@0: pb.once('start', function() { michael@0: // make a new private window michael@0: makeEmptyBrowserWindow().then(function(window) { michael@0: assert.ok(isWindowPrivate(window), "window is private"); michael@0: assert.equal(isPrivate(window), true, 'the opened window is private'); michael@0: assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1, michael@0: "window is in windowIterator()"); michael@0: assert.ok(windows(null, { includePrivate: true }).indexOf(window) > -1, michael@0: "window is in windows()"); michael@0: michael@0: close(window).then(function() { michael@0: pb.once('stop', function() { michael@0: done(); michael@0: }); michael@0: pb.deactivate(); michael@0: }); michael@0: }); michael@0: }); michael@0: pb.activate(); michael@0: }; michael@0: michael@0: if (!isGlobalPBSupported) { michael@0: module.exports = { michael@0: "test Unsupported Test": function UnsupportedTest (assert) { michael@0: assert.pass( michael@0: "Skipping global private browsing tests"); michael@0: } michael@0: } michael@0: } michael@0: michael@0: require("test").run(exports);