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