summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/test/addons/private-browsing-supported
diff options
context:
space:
mode:
Diffstat (limited to 'addon-sdk/source/test/addons/private-browsing-supported')
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/main.js28
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/package.json8
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js67
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-page-mod.js119
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-panel.js99
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-private-browsing.js111
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-selection.js447
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-sidebar.js212
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-tabs.js34
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js75
-rw-r--r--addon-sdk/source/test/addons/private-browsing-supported/test-windows.js240
11 files changed, 0 insertions, 1440 deletions
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/main.js b/addon-sdk/source/test/addons/private-browsing-supported/main.js
deleted file mode 100644
index 290427dc2..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/main.js
+++ /dev/null
@@ -1,28 +0,0 @@
-/* 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 { merge } = require('sdk/util/object');
-const app = require('sdk/system/xul-app');
-
-merge(module.exports,
- require('./test-tabs'),
- require('./test-page-mod'),
- require('./test-private-browsing'),
- require('./test-sidebar')
-);
-
-// Doesn't make sense to test window-utils and windows on fennec,
-// as there is only one window which is never private. Also ignore
-// unsupported modules (panel, selection)
-if (!app.is('Fennec')) {
- merge(module.exports,
- require('./test-selection'),
- require('./test-panel'),
- require('./test-window-tabs'),
- require('./test-windows')
- );
-}
-
-require('sdk/test/runner').runTestsFromModule(module);
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/package.json b/addon-sdk/source/test/addons/private-browsing-supported/package.json
deleted file mode 100644
index 87b96017d..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/package.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "id": "private-browsing-mode-test@jetpack",
- "permissions": {
- "private-browsing": true
- },
- "main": "./main.js",
- "version": "0.0.1"
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js b/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js
deleted file mode 100644
index e0f6234f6..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/sidebar/utils.js
+++ /dev/null
@@ -1,67 +0,0 @@
-/* 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 { Cu } = require('chrome');
-const { getMostRecentBrowserWindow } = require('sdk/window/utils');
-const { fromIterator } = require('sdk/util/array');
-
-const BUILTIN_SIDEBAR_MENUITEMS = exports.BUILTIN_SIDEBAR_MENUITEMS = [
- 'menu_socialSidebar',
- 'menu_historySidebar',
- 'menu_bookmarksSidebar',
-];
-
-function isSidebarShowing(window) {
- window = window || getMostRecentBrowserWindow();
- let sidebar = window.document.getElementById('sidebar-box');
- return !sidebar.hidden;
-}
-exports.isSidebarShowing = isSidebarShowing;
-
-function getSidebarMenuitems(window) {
- window = window || getMostRecentBrowserWindow();
- return fromIterator(window.document.querySelectorAll('#viewSidebarMenu menuitem'));
-}
-exports.getSidebarMenuitems = getSidebarMenuitems;
-
-function getExtraSidebarMenuitems() {
- let menuitems = getSidebarMenuitems();
- return menuitems.filter(function(mi) {
- return BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) < 0;
- });
-}
-exports.getExtraSidebarMenuitems = getExtraSidebarMenuitems;
-
-function makeID(id) {
- return 'jetpack-sidebar-' + id;
-}
-exports.makeID = makeID;
-
-function simulateCommand(ele) {
- let window = ele.ownerDocument.defaultView;
- let { document } = window;
- var evt = document.createEvent('XULCommandEvent');
- evt.initCommandEvent('command', true, true, window,
- 0, false, false, false, false, null);
- ele.dispatchEvent(evt);
-}
-exports.simulateCommand = simulateCommand;
-
-function simulateClick(ele) {
- let window = ele.ownerDocument.defaultView;
- let { document } = window;
- let evt = document.createEvent('MouseEvents');
- evt.initMouseEvent('click', true, true, window,
- 0, 0, 0, 0, 0, false, false, false, false, 0, null);
- ele.dispatchEvent(evt);
-}
-exports.simulateClick = simulateClick;
-
-// OSX and Windows exhibit different behaviors when 'checked' is false,
-// so compare against the consistent 'true'. See bug 894809.
-function isChecked(node) {
- return node.getAttribute('checked') === 'true';
-};
-exports.isChecked = isChecked;
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-page-mod.js b/addon-sdk/source/test/addons/private-browsing-supported/test-page-mod.js
deleted file mode 100644
index ca5122013..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-page-mod.js
+++ /dev/null
@@ -1,119 +0,0 @@
-/* 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 { getMostRecentBrowserWindow } = require('sdk/window/utils');
-const { PageMod } = require("sdk/page-mod");
-const { getActiveTab, setTabURL, openTab, closeTab } = require('sdk/tabs/utils');
-const xulApp = require('sdk/system/xul-app');
-const windowHelpers = require('sdk/window/helpers');
-const { defer } = require("sdk/core/promise");
-const { isPrivate } = require('sdk/private-browsing');
-const { isTabPBSupported, isWindowPBSupported } = require('sdk/private-browsing/utils');
-const { cleanUI } = require('sdk/test/utils');
-
-function openWebpage(url, enablePrivate) {
- return new Promise((resolve, reject) => {
- if (xulApp.is("Fennec")) {
- let chromeWindow = getMostRecentBrowserWindow();
- let rawTab = openTab(chromeWindow, url, {
- isPrivate: enablePrivate
- });
-
- resolve(() => new Promise(resolve => {
- closeTab(rawTab);
- resolve();
- }));
- }
- else {
- windowHelpers.open("", {
- features: {
- toolbar: true,
- private: enablePrivate
- }
- }).
- then((chromeWindow) => {
- if (isPrivate(chromeWindow) !== !!enablePrivate) {
- reject(new Error("Window should have Private set to " + !!enablePrivate));
- }
-
- let tab = getActiveTab(chromeWindow);
- setTabURL(tab, url);
-
- resolve(() => windowHelpers.close(chromeWindow));
- }).
- catch(reject);
- }
- });
-}
-
-exports["test page-mod on private tab"] = function*(assert) {
- // Only set private mode when explicitely supported.
- // (fennec 19 has some intermediate PB support where isTabPBSupported
- // will be false, but isPrivate(worker.tab) will be true if we open a private
- // tab)
- let setPrivate = isTabPBSupported || isWindowPBSupported;
-
- let id = Date.now().toString(36);
- let frameUri = "data:text/html;charset=utf-8," + id;
- let uri = "data:text/html;charset=utf-8," +
- encodeURIComponent(id + "<iframe src='" + frameUri + "'><iframe>");
-
- let count = 0;
-
- let close = yield openWebpage(uri, setPrivate);
- yield new Promise(resolve => {
- PageMod({
- include: [uri, frameUri],
-
- onAttach: function(worker) {
- assert.ok(worker.tab.url == uri || worker.tab.url == frameUri,
- "Got a worker attached to the private window tab");
-
- if (setPrivate) {
- assert.ok(isPrivate(worker), "The worker is really private");
- assert.ok(isPrivate(worker.tab), "The document is really private");
- }
- else {
- assert.ok(!isPrivate(worker),
- "private browsing isn't supported, " +
- "so that the worker isn't private");
- assert.ok(!isPrivate(worker.tab),
- "private browsing isn't supported, " +
- "so that the document isn't private");
- }
-
- if (++count == 2) {
- this.destroy();
- resolve();
- }
- }
- });
- });
- yield close();
- yield cleanUI();
-};
-
-exports["test page-mod on non-private tab"] = function*(assert) {
- let id = Date.now().toString(36);
- let url = "data:text/html;charset=utf-8," + encodeURIComponent(id);
-
- let close = yield openWebpage(url, false);
- let mod;
- let worker = yield new Promise(resolve => {
- mod = PageMod({
- include: url,
- onAttach: resolve
- });
- });
-
- assert.equal(worker.tab.url, url,
- "Got a worker attached to the private window tab");
- assert.ok(!isPrivate(worker), "The worker is really non-private");
- assert.ok(!isPrivate(worker.tab), "The document is really non-private");
-
- mod.destroy();
- yield close();
- yield cleanUI();
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-panel.js b/addon-sdk/source/test/addons/private-browsing-supported/test-panel.js
deleted file mode 100644
index 1ba3e9554..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-panel.js
+++ /dev/null
@@ -1,99 +0,0 @@
-/* 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 { open, focus, close } = require('sdk/window/helpers');
-const { isPrivate } = require('sdk/private-browsing');
-const { defer } = require('sdk/core/promise');
-const { browserWindows: windows } = require('sdk/windows');
-const { getInnerId, getMostRecentBrowserWindow } = require('sdk/window/utils');
-const { getActiveView } = require('sdk/view/core');
-
-const BROWSER = 'chrome://browser/content/browser.xul';
-
-exports.testRequirePanel = function(assert) {
- require('sdk/panel');
- assert.ok('the panel module should not throw an error');
-};
-
-exports.testShowPanelInPrivateWindow = function(assert, done) {
- let panel = require('sdk/panel').Panel({
- contentURL: "data:text/html;charset=utf-8,I'm a leaf on the wind"
- });
-
- assert.ok(windows.length > 0, 'there is at least one open window');
- for (let window of windows) {
- assert.equal(isPrivate(window), false, 'open window is private');
- }
-
- let panelView = getActiveView(panel);
- let expectedWindowId = getInnerId(panelView.backgroundFrame.contentWindow);
-
- function checkPanelFrame() {
- let iframe = panelView.firstChild;
-
- assert.equal(panelView.viewFrame, iframe, 'panel has the correct viewFrame value');
-
- let windowId = getInnerId(iframe.contentWindow);
-
- assert.equal(windowId, expectedWindowId, 'panel has the correct window visible');
-
- assert.equal(iframe.contentDocument.body.textContent,
- "I'm a leaf on the wind",
- 'the panel has the expected content');
- }
-
- function testPanel(window) {
- let { promise, resolve } = defer();
-
- assert.ok(!panel.isShowing, 'the panel is not showing [1]');
-
- panel.once('show', function() {
- assert.ok(panel.isShowing, 'the panel is showing');
-
- checkPanelFrame();
-
- panel.once('hide', function() {
- assert.ok(!panel.isShowing, 'the panel is not showing [2]');
-
- resolve(window);
- });
-
- panel.hide();
- });
-
- panel.show();
-
- return promise;
- };
-
- let initialWindow = getMostRecentBrowserWindow();
-
- testPanel(initialWindow).
- then(makeEmptyPrivateBrowserWindow).
- then(focus).
- then(function(window) {
- assert.equal(isPrivate(window), true, 'opened window is private');
- assert.pass('private window was focused');
- return window;
- }).
- then(testPanel).
- then(close).
- then(() => focus(initialWindow)).
- then(testPanel).
- then(done).
- then(null, assert.fail);
-};
-
-
-function makeEmptyPrivateBrowserWindow(options) {
- options = options || {};
- return open(BROWSER, {
- features: {
- chrome: true,
- toolbar: true,
- private: true
- }
- });
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-private-browsing.js b/addon-sdk/source/test/addons/private-browsing-supported/test-private-browsing.js
deleted file mode 100644
index a7b1e26ca..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-private-browsing.js
+++ /dev/null
@@ -1,111 +0,0 @@
-/* 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 { Ci } = require('chrome');
-const { isPrivateBrowsingSupported } = require('sdk/self');
-const tabs = require('sdk/tabs');
-const { browserWindows: windows } = require('sdk/windows');
-const { isPrivate } = require('sdk/private-browsing');
-const { is } = require('sdk/system/xul-app');
-const { isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
-const { cleanUI } = require('sdk/test/utils');
-
-const TAB_URL = 'about:addons';
-
-exports.testIsPrivateBrowsingTrue = function(assert) {
- assert.ok(isPrivateBrowsingSupported,
- 'isPrivateBrowsingSupported property is true');
-};
-
-// test that it is possible to open a private tab
-exports.testTabOpenPrivate = function(assert, done) {
- tabs.open({
- url: TAB_URL,
- isPrivate: true,
- onReady: function(tab) {
- assert.equal(tab.url, TAB_URL, 'opened correct tab');
- assert.equal(isPrivate(tab), (isWindowPBSupported || isTabPBSupported), "tab is private");
- cleanUI().then(done).catch(console.exception);
- }
- });
-}
-
-
-// test that it is possible to open a non private tab
-exports.testTabOpenPrivateDefault = function(assert, done) {
- tabs.open({
- url: TAB_URL,
- onReady: function(tab) {
- assert.equal(tab.url, TAB_URL, 'opened correct tab');
- assert.equal(isPrivate(tab), false, "tab is not private");
- cleanUI().then(done).catch(console.exception);
- }
- });
-}
-
-// test that it is possible to open a non private tab in explicit case
-exports.testTabOpenPrivateOffExplicit = function(assert, done) {
- tabs.open({
- url: TAB_URL,
- isPrivate: false,
- onReady: function(tab) {
- assert.equal(tab.url, TAB_URL, 'opened correct tab');
- assert.equal(isPrivate(tab), false, "tab is not private");
- cleanUI().then(done).catch(console.exception);
- }
- });
-}
-
-// test windows.open with isPrivate: true
-// test isPrivate on a window
-if (!is('Fennec')) {
- // test that it is possible to open a private window
- exports.testWindowOpenPrivate = function(assert, done) {
- windows.open({
- url: TAB_URL,
- isPrivate: true,
- onOpen: function(window) {
- let tab = window.tabs[0];
- tab.once('ready', function() {
- assert.equal(tab.url, TAB_URL, 'opened correct tab');
- assert.equal(isPrivate(tab), isWindowPBSupported, 'tab is private');
- cleanUI().then(done).catch(console.exception);
- });
- }
- });
- };
-
- exports.testIsPrivateOnWindowOn = function(assert, done) {
- windows.open({
- isPrivate: true,
- onOpen: function(window) {
- assert.equal(isPrivate(window), isWindowPBSupported, 'isPrivate for a window is true when it should be');
- assert.equal(isPrivate(window.tabs[0]), isWindowPBSupported, 'isPrivate for a tab is false when it should be');
- cleanUI().then(done).catch(console.exception);
- }
- });
- };
-
- exports.testIsPrivateOnWindowOffImplicit = function(assert, done) {
- windows.open({
- onOpen: function(window) {
- assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
- assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
- cleanUI().then(done).catch(console.exception);
- }
- })
- }
-
- exports.testIsPrivateOnWindowOffExplicit = function(assert, done) {
- windows.open({
- isPrivate: false,
- onOpen: function(window) {
- assert.equal(isPrivate(window), false, 'isPrivate for a window is false when it should be');
- assert.equal(isPrivate(window.tabs[0]), false, 'isPrivate for a tab is false when it should be');
- cleanUI().then(done).catch(console.exception);
- }
- })
- }
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-selection.js b/addon-sdk/source/test/addons/private-browsing-supported/test-selection.js
deleted file mode 100644
index 3fa1c1b5d..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-selection.js
+++ /dev/null
@@ -1,447 +0,0 @@
-/* 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 HTML = "<html>\
- <body>\
- <div>foo</div>\
- <div>and</div>\
- <textarea>noodles</textarea>\
- </body>\
-</html>";
-
-const URL = "data:text/html;charset=utf-8," + encodeURIComponent(HTML);
-
-const FRAME_HTML = "<iframe src='" + URL + "'><iframe>";
-const FRAME_URL = "data:text/html;charset=utf-8," + encodeURIComponent(FRAME_HTML);
-
-const { defer } = require("sdk/core/promise");
-const { browserWindows } = require("sdk/windows");
-const tabs = require("sdk/tabs");
-const { setTabURL, getActiveTab, getTabContentWindow, closeTab, getTabs,
- getTabTitle } = require("sdk/tabs/utils");
-const { getMostRecentBrowserWindow, isFocused } = require("sdk/window/utils");
-const { open: openNewWindow, close: closeWindow, focus } = require("sdk/window/helpers");
-const { Loader } = require("sdk/test/loader");
-const { merge } = require("sdk/util/object");
-const { isPrivate } = require("sdk/private-browsing");
-
-// General purpose utility functions
-
-/**
- * Opens the url given and return a promise, that will be resolved with the
- * content window when the document is ready.
- *
- * I believe this approach could be useful in most of our unit test, that
- * requires to open a tab and need to access to its content.
- */
-function open(url, options) {
- let { promise, resolve } = defer();
-
- if (options && typeof(options) === "object") {
- openNewWindow("", {
- features: merge({ toolbar: true }, options)
- }).then(function(chromeWindow) {
- if (isPrivate(chromeWindow) !== !!options.private)
- throw new Error("Window should have Private set to " + !!options.private);
-
- let tab = getActiveTab(chromeWindow);
-
- tab.linkedBrowser.addEventListener("load", function ready(event) {
- let { document } = getTabContentWindow(tab);
-
- if (document.readyState === "complete" && document.URL === url) {
- this.removeEventListener(event.type, ready);
-
- if (options.title)
- document.title = options.title;
-
- resolve(document.defaultView);
- }
- }, true);
-
- setTabURL(tab, url);
- });
-
- return promise;
- };
-
- tabs.open({
- url: url,
- onReady: function(tab) {
- // Unfortunately there is no way to get a XUL Tab from SDK Tab on Firefox,
- // only on Fennec. We should implement `tabNS` also on Firefox in order
- // to have that.
-
- // Here we assuming that the most recent browser window is the one we're
- // doing the test, and the active tab is the one we just opened.
- let window = getTabContentWindow(getActiveTab(getMostRecentBrowserWindow()));
-
- resolve(window);
- }
- });
-
- return promise;
-};
-
-/**
- * Reload the window given and return a promise, that will be resolved with the
- * content window after a small delay.
- */
-function reload(window) {
- let { promise, resolve } = defer();
-
- // Here we assuming that the most recent browser window is the one we're
- // doing the test, and the active tab is the one we just opened.
- let tab = tabs.activeTab;
-
- tab.once("ready", function () {
- resolve(window);
- });
-
- window.location.reload(true);
-
- return promise;
-}
-
-// Selection's unit test utility function
-
-/**
- * Select the first div in the page, adding the range to the selection.
- */
-function selectFirstDiv(window) {
- let div = window.document.querySelector("div");
- let selection = window.getSelection();
- let range = window.document.createRange();
-
- if (selection.rangeCount > 0)
- selection.removeAllRanges();
-
- range.selectNode(div);
- selection.addRange(range);
-
- return window;
-}
-
-/**
- * Select all divs in the page, adding the ranges to the selection.
- */
-function selectAllDivs(window) {
- let divs = window.document.getElementsByTagName("div");
- let selection = window.getSelection();
-
- if (selection.rangeCount > 0)
- selection.removeAllRanges();
-
- for (let i = 0; i < divs.length; i++) {
- let range = window.document.createRange();
-
- range.selectNode(divs[i]);
- selection.addRange(range);
- }
-
- return window;
-}
-
-/**
- * Select the textarea content
- */
-function selectTextarea(window) {
- let selection = window.getSelection();
- let textarea = window.document.querySelector("textarea");
-
- if (selection.rangeCount > 0)
- selection.removeAllRanges();
-
- textarea.setSelectionRange(0, textarea.value.length);
- textarea.focus();
-
- return window;
-}
-
-/**
- * Select the content of the first div
- */
-function selectContentFirstDiv(window) {
- let div = window.document.querySelector("div");
- let selection = window.getSelection();
- let range = window.document.createRange();
-
- if (selection.rangeCount > 0)
- selection.removeAllRanges();
-
- range.selectNodeContents(div);
- selection.addRange(range);
-
- return window;
-}
-
-/**
- * Dispatch the selection event for the selection listener added by
- * `nsISelectionPrivate.addSelectionListener`
- */
-function dispatchSelectionEvent(window) {
- // We modify the selection in order to dispatch the selection's event, by
- // contract the selection by one character. So if the text selected is "foo"
- // will be "fo".
- window.getSelection().modify("extend", "backward", "character");
-
- return window;
-}
-
-/**
- * Dispatch the selection event for the selection listener added by
- * `window.onselect` / `window.addEventListener`
- */
-function dispatchOnSelectEvent(window) {
- let { document } = window;
- let textarea = document.querySelector("textarea");
- let event = document.createEvent("UIEvents");
-
- event.initUIEvent("select", true, true, window, 1);
-
- textarea.dispatchEvent(event);
-
- return window;
-}
-
-// Test cases
-
-exports["test PWPB Selection Listener"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "PWPB Selection Listener"}).
- then(function(window) {
- selection.once("select", function() {
- assert.equal(browserWindows.length, 2, "there should be only two windows open.");
- assert.equal(getTabs().length, 2, "there should be only two tabs open: '" +
- getTabs().map(tab => getTabTitle(tab)).join("', '") +
- "'."
- );
-
- // window should be focused, but force the focus anyhow.. see bug 841823
- focus(window).then(function() {
- // check state of window
- assert.ok(isFocused(window), "the window is focused");
- assert.ok(isPrivate(window), "the window should be a private window");
-
- assert.equal(selection.text, "fo");
-
- closeWindow(window).
- then(loader.unload).
- then(done).
- then(null, assert.fail);
- });
- });
- return window;
- }).
- then(selectContentFirstDiv).
- then(dispatchSelectionEvent).
- then(null, assert.fail);
-};
-
-exports["test PWPB Textarea OnSelect Listener"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "PWPB OnSelect Listener"}).
- then(function(window) {
- selection.once("select", function() {
- assert.equal(browserWindows.length, 2, "there should be only two windows open.");
- assert.equal(getTabs().length, 2, "there should be only two tabs open: '" +
- getTabs().map(tab => getTabTitle(tab)).join("', '") +
- "'."
- );
-
- // window should be focused, but force the focus anyhow.. see bug 841823
- focus(window).then(function() {
- assert.equal(selection.text, "noodles");
-
- closeWindow(window).
- then(loader.unload).
- then(done).
- then(null, assert.fail);
- });
- });
- return window;
- }).
- then(selectTextarea).
- then(dispatchOnSelectEvent).
- then(null, assert.fail);
-};
-
-exports["test PWPB Single DOM Selection"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "PWPB Single DOM Selection"}).
- then(selectFirstDiv).
- then(focus).then(function(window) {
- assert.equal(selection.isContiguous, true,
- "selection.isContiguous with single DOM Selection works.");
-
- assert.equal(selection.text, "foo",
- "selection.text with single DOM Selection works.");
-
- assert.equal(selection.html, "<div>foo</div>",
- "selection.html with single DOM Selection works.");
-
- let selectionCount = 0;
- for (let sel of selection) {
- selectionCount++;
-
- assert.equal(sel.text, "foo",
- "iterable selection.text with single DOM Selection works.");
-
- assert.equal(sel.html, "<div>foo</div>",
- "iterable selection.html with single DOM Selection works.");
- }
-
- assert.equal(selectionCount, 1,
- "One iterable selection");
-
- return closeWindow(window);
- }).then(loader.unload).then(done).then(null, assert.fail);
-}
-
-exports["test PWPB Textarea Selection"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "PWPB Textarea Listener"}).
- then(selectTextarea).
- then(focus).
- then(function(window) {
-
- assert.equal(selection.isContiguous, true,
- "selection.isContiguous with Textarea Selection works.");
-
- assert.equal(selection.text, "noodles",
- "selection.text with Textarea Selection works.");
-
- assert.strictEqual(selection.html, null,
- "selection.html with Textarea Selection works.");
-
- let selectionCount = 0;
- for (let sel of selection) {
- selectionCount++;
-
- assert.equal(sel.text, "noodles",
- "iterable selection.text with Textarea Selection works.");
-
- assert.strictEqual(sel.html, null,
- "iterable selection.html with Textarea Selection works.");
- }
-
- assert.equal(selectionCount, 1,
- "One iterable selection");
-
- return closeWindow(window);
- }).then(loader.unload).then(done).then(null, assert.fail);
-};
-
-exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "PWPB Set HTML in Multiple DOM Selection"}).
- then(selectAllDivs).
- then(focus).
- then(function(window) {
- let html = "<span>b<b>a</b>r</span>";
-
- let expectedText = ["bar", "and"];
- let expectedHTML = [html, "<div>and</div>"];
-
- selection.html = html;
-
- assert.equal(selection.text, expectedText[0],
- "set selection.text with DOM Selection works.");
-
- assert.equal(selection.html, expectedHTML[0],
- "selection.html with DOM Selection works.");
-
- let selectionCount = 0;
- for (let sel of selection) {
-
- assert.equal(sel.text, expectedText[selectionCount],
- "iterable selection.text with multiple DOM Selection works.");
-
- assert.equal(sel.html, expectedHTML[selectionCount],
- "iterable selection.html with multiple DOM Selection works.");
-
- selectionCount++;
- }
-
- assert.equal(selectionCount, 2,
- "Two iterable selections");
-
- return closeWindow(window);
- }).then(loader.unload).then(done).then(null, assert.fail);
-};
-
-exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
- let loader = Loader(module);
- let selection = loader.require("sdk/selection");
-
- open(URL, {private: true, title: "test PWPB Set Text in Textarea Selection"}).
- then(selectTextarea).
- then(focus).
- then(function(window) {
-
- let text = "bar";
-
- selection.text = text;
-
- assert.equal(selection.text, text,
- "set selection.text with Textarea Selection works.");
-
- assert.strictEqual(selection.html, null,
- "selection.html with Textarea Selection works.");
-
- let selectionCount = 0;
- for (let sel of selection) {
- selectionCount++;
-
- assert.equal(sel.text, text,
- "iterable selection.text with Textarea Selection works.");
-
- assert.strictEqual(sel.html, null,
- "iterable selection.html with Textarea Selection works.");
- }
-
- assert.equal(selectionCount, 1,
- "One iterable selection");
-
- return closeWindow(window);
- }).then(loader.unload).then(done).then(null, assert.fail);
-};
-
-// If the platform doesn't support the PBPW, we're replacing PBPW tests
-if (!require("sdk/private-browsing/utils").isWindowPBSupported) {
- module.exports = {
- "test PBPW Unsupported": function Unsupported (assert) {
- assert.pass("Private Window Per Browsing is not supported on this platform.");
- }
- }
-}
-
-// If the module doesn't support the app we're being run in, require() will
-// throw. In that case, remove all tests above from exports, and add one dummy
-// test that passes.
-try {
- require("sdk/selection");
-}
-catch (err) {
- if (!/^Unsupported Application/.test(err.message))
- throw err;
-
- module.exports = {
- "test Unsupported Application": function Unsupported (assert) {
- assert.pass(err.message);
- }
- }
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-sidebar.js b/addon-sdk/source/test/addons/private-browsing-supported/test-sidebar.js
deleted file mode 100644
index 410e64ff5..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-sidebar.js
+++ /dev/null
@@ -1,212 +0,0 @@
-/* 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 { Loader } = require('sdk/test/loader');
-const { show, hide } = require('sdk/ui/sidebar/actions');
-const { isShowing } = require('sdk/ui/sidebar/utils');
-const { getMostRecentBrowserWindow, isWindowPrivate } = require('sdk/window/utils');
-const { open, close, focus, promise: windowPromise } = require('sdk/window/helpers');
-const { setTimeout } = require('sdk/timers');
-const { isPrivate } = require('sdk/private-browsing');
-const { data } = require('sdk/self');
-const { URL } = require('sdk/url');
-
-const { BUILTIN_SIDEBAR_MENUITEMS, isSidebarShowing,
- getSidebarMenuitems, getExtraSidebarMenuitems, makeID, simulateCommand,
- simulateClick, isChecked } = require('./sidebar/utils');
-
-exports.testSideBarIsInNewPrivateWindows = function(assert, done) {
- const { Sidebar } = require('sdk/ui/sidebar');
- let testName = 'testSideBarIsInNewPrivateWindows';
- let sidebar = Sidebar({
- id: testName,
- title: testName,
- url: 'data:text/html;charset=utf-8,'+testName
- });
-
- let startWindow = getMostRecentBrowserWindow();
- let ele = startWindow.document.getElementById(makeID(testName));
- assert.ok(ele, 'sidebar element was added');
-
- open(null, { features: { private: true } }).then(function(window) {
- let ele = window.document.getElementById(makeID(testName));
- assert.ok(isPrivate(window), 'the new window is private');
- assert.ok(!!ele, 'sidebar element was added');
-
- sidebar.destroy();
- assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
- assert.ok(!startWindow.document.getElementById(makeID(testName)), 'sidebar id DNE');
-
- return close(window);
- }).then(done).then(null, assert.fail);
-}
-
-// Disabled in order to land other fixes, see bug 910647 for further details.
-/*
-exports.testSidebarIsOpenInNewPrivateWindow = function(assert, done) {
- const { Sidebar } = require('sdk/ui/sidebar');
- let testName = 'testSidebarIsOpenInNewPrivateWindow';
- let window = getMostRecentBrowserWindow();
-
- let sidebar = Sidebar({
- id: testName,
- title: testName,
- url: 'data:text/html;charset=utf-8,'+testName
- });
-
- assert.equal(isPrivate(window), false, 'the window is not private');
-
- sidebar.on('show', function() {
- assert.equal(isSidebarShowing(window), true, 'the sidebar is showing');
- assert.equal(isShowing(sidebar), true, 'the sidebar is showing');
-
- windowPromise(window.OpenBrowserWindow({private: true}), 'DOMContentLoaded').then(function(window2) {
- assert.equal(isPrivate(window2), true, 'the new window is private');
-
- let sidebarEle = window2.document.getElementById('sidebar');
-
- // wait for the sidebar to load something
- function onSBLoad() {
- sidebarEle.contentDocument.getElementById('web-panels-browser').addEventListener('load', function() {
- assert.equal(isSidebarShowing(window), true, 'the sidebar is showing in old window still');
- assert.equal(isSidebarShowing(window2), true, 'the sidebar is showing in the new private window');
- assert.equal(isShowing(sidebar), true, 'the sidebar is showing');
-
- sidebar.destroy();
- close(window2).then(done);
- }, true);
- }
-
- sidebarEle.addEventListener('load', onSBLoad, true);
-
- assert.pass('waiting for the sidebar to open...');
- }, assert.fail).then(null, assert.fail);
- });
-
- sidebar.show();
-}
-*/
-// TEST: edge case where web panel is destroyed while loading
-exports.testDestroyEdgeCaseBugWithPrivateWindow = function(assert, done) {
- const { Sidebar } = require('sdk/ui/sidebar');
- let testName = 'testDestroyEdgeCaseBug';
- let window = getMostRecentBrowserWindow();
- let sidebar = Sidebar({
- id: testName,
- title: testName,
- url: 'data:text/html;charset=utf-8,'+testName
- });
-
- // NOTE: purposely not listening to show event b/c the event happens
- // between now and then.
- sidebar.show();
-
- assert.equal(isPrivate(window), false, 'the new window is not private');
- assert.equal(isSidebarShowing(window), true, 'the sidebar is showing');
-
- //assert.equal(isShowing(sidebar), true, 'the sidebar is showing');
-
- open(null, { features: { private: true } }).then(focus).then(function(window2) {
- assert.equal(isPrivate(window2), true, 'the new window is private');
- assert.equal(isSidebarShowing(window2), false, 'the sidebar is not showing');
- assert.equal(isShowing(sidebar), false, 'the sidebar is not showing');
-
- sidebar.destroy();
- assert.pass('destroying the sidebar');
-
- close(window2).then(function() {
- let loader = Loader(module);
-
- assert.equal(isPrivate(window), false, 'the current window is not private');
-
- let sidebar = loader.require('sdk/ui/sidebar').Sidebar({
- id: testName,
- title: testName,
- url: 'data:text/html;charset=utf-8,'+ testName,
- onShow: function() {
- assert.pass('onShow works for Sidebar');
- loader.unload();
-
- for (let mi of getSidebarMenuitems()) {
- assert.ok(BUILTIN_SIDEBAR_MENUITEMS.indexOf(mi.getAttribute('id')) >= 0, 'the menuitem is for a built-in sidebar')
- assert.ok(!isChecked(mi), 'no sidebar menuitem is checked');
- }
- assert.ok(!window.document.getElementById(makeID(testName)), 'sidebar id DNE');
- assert.equal(isSidebarShowing(window), false, 'the sidebar is not showing');
-
- done();
- }
- })
-
- sidebar.show();
- assert.pass('showing the sidebar');
- }).then(null, assert.fail);
- }).then(null, assert.fail);
-}
-
-exports.testShowInPrivateWindow = function(assert, done) {
- const { Sidebar } = require('sdk/ui/sidebar');
- let testName = 'testShowInPrivateWindow';
- let window1 = getMostRecentBrowserWindow();
- let url = 'data:text/html;charset=utf-8,'+testName;
-
- let sidebar1 = Sidebar({
- id: testName,
- title: testName,
- url: url
- });
- let menuitemID = makeID(sidebar1.id);
-
- assert.equal(sidebar1.url, url, 'url getter works');
- assert.equal(isShowing(sidebar1), false, 'the sidebar is not showing');
- assert.ok(!isChecked(window1.document.getElementById(menuitemID)),
- 'the menuitem is not checked');
- assert.equal(isSidebarShowing(window1), false, 'the new window sidebar is not showing');
-
- windowPromise(window1.OpenBrowserWindow({ private: true }), 'load').then(function(window) {
- let { document } = window;
- assert.equal(isWindowPrivate(window), true, 'new window is private');
- assert.equal(isPrivate(window), true, 'new window is private');
-
- sidebar1.show().then(
- function good() {
- assert.equal(isShowing(sidebar1), true, 'the sidebar is showing');
- assert.ok(!!document.getElementById(menuitemID),
- 'the menuitem exists on the private window');
- assert.equal(isSidebarShowing(window), true, 'the new window sidebar is showing');
-
- sidebar1.destroy();
- assert.equal(isSidebarShowing(window), false, 'the new window sidebar is showing');
- assert.ok(!window1.document.getElementById(menuitemID),
- 'the menuitem on the new window dne');
-
- // test old window state
- assert.equal(isSidebarShowing(window1), false, 'the old window sidebar is not showing');
- assert.equal(window1.document.getElementById(menuitemID),
- null,
- 'the menuitem on the old window dne');
-
- close(window).then(done).then(null, assert.fail);
- },
- function bad() {
- assert.fail('a successful show should not happen here..');
- });
- }).then(null, assert.fail);
-}
-
-// If the module doesn't support the app we're being run in, require() will
-// throw. In that case, remove all tests above from exports, and add one dummy
-// test that passes.
-try {
- require('sdk/ui/sidebar');
-}
-catch (err) {
- if (!/^Unsupported Application/.test(err.message))
- throw err;
-
- module.exports = {
- 'test Unsupported Application': assert => assert.pass(err.message)
- }
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-tabs.js b/addon-sdk/source/test/addons/private-browsing-supported/test-tabs.js
deleted file mode 100644
index c9cb34f0e..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-tabs.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/* 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 tabs = require('sdk/tabs');
-const { isPrivate } = require('sdk/private-browsing');
-const pbUtils = require('sdk/private-browsing/utils');
-
-exports.testPrivateTabsAreListed = function (assert, done) {
- let originalTabCount = tabs.length;
-
- tabs.open({
- url: 'about:blank',
- isPrivate: true,
- onOpen: function(tab) {
- // PWPB case
- if (pbUtils.isWindowPBSupported || pbUtils.isTabPBSupported) {
- assert.ok(isPrivate(tab), "tab is private");
- assert.equal(tabs.length, originalTabCount + 1,
- 'New private window\'s tab are visible in tabs list');
- }
- else {
- // Global case, openDialog didn't opened a private window/tab
- assert.ok(!isPrivate(tab), "tab isn't private");
- assert.equal(tabs.length, originalTabCount + 1,
- 'New non-private window\'s tab is visible in tabs list');
- }
-
- tab.close(done);
- }
- });
-};
-
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js b/addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js
deleted file mode 100644
index 647a73741..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-window-tabs.js
+++ /dev/null
@@ -1,75 +0,0 @@
-/* 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 tabs = require('sdk/tabs');
-const { isPrivate } = require('sdk/private-browsing');
-const { promise: windowPromise, close, focus } = require('sdk/window/helpers');
-const { getMostRecentBrowserWindow } = require('sdk/window/utils');
-
-exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
- let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
-
- windowPromise(window, 'load').then(focus).then(function (window) {
- assert.ok(isPrivate(window), 'new window is private');
-
- tabs.open({
- url: 'about:blank',
- onOpen: function(tab) {
- assert.ok(isPrivate(tab), 'new tab is private');
- close(window).then(done).then(null, assert.fail);
- }
- })
- }).then(null, assert.fail);
-}
-
-exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert, done) {
- let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
-
- windowPromise(window, 'load').then(focus).then(function (window) {
- assert.equal(isPrivate(window), false, 'new window is not private');
-
- tabs.open({
- url: 'about:blank',
- onOpen: function(tab) {
- assert.equal(isPrivate(tab), false, 'new tab is not private');
- close(window).then(done).then(null, assert.fail);
- }
- })
- }).then(null, assert.fail);
-}
-
-exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(assert, done) {
- let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: true });
-
- windowPromise(window, 'load').then(focus).then(function (window) {
- assert.ok(isPrivate(window), 'new window is private');
-
- tabs.open({
- url: 'about:blank',
- isPrivate: true,
- onOpen: function(tab) {
- assert.ok(isPrivate(tab), 'new tab is private');
- close(window).then(done).then(null, assert.fail);
- }
- })
- }).then(null, assert.fail);
-}
-
-exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function(assert, done) {
- let window = getMostRecentBrowserWindow().OpenBrowserWindow({ private: false });
-
- windowPromise(window, 'load').then(focus).then(function (window) {
- assert.equal(isPrivate(window), false, 'new window is not private');
-
- tabs.open({
- url: 'about:blank',
- isPrivate: false,
- onOpen: function(tab) {
- assert.equal(isPrivate(tab), false, 'new tab is not private');
- close(window).then(done).then(null, assert.fail);
- }
- })
- }).then(null, assert.fail);
-}
diff --git a/addon-sdk/source/test/addons/private-browsing-supported/test-windows.js b/addon-sdk/source/test/addons/private-browsing-supported/test-windows.js
deleted file mode 100644
index ce4e69cae..000000000
--- a/addon-sdk/source/test/addons/private-browsing-supported/test-windows.js
+++ /dev/null
@@ -1,240 +0,0 @@
-/* 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 { Cc, Ci } = require('chrome');
-const { isPrivate } = require('sdk/private-browsing');
-const { isWindowPBSupported } = require('sdk/private-browsing/utils');
-const { onFocus, getMostRecentWindow, getWindowTitle, getInnerId,
- getFrames, windows, open: openWindow, isWindowPrivate } = require('sdk/window/utils');
-const { open, close, focus, promise } = require('sdk/window/helpers');
-const { browserWindows } = require("sdk/windows");
-const winUtils = require("sdk/deprecated/window-utils");
-const { fromIterator: toArray } = require('sdk/util/array');
-const tabs = require('sdk/tabs');
-const { cleanUI } = require('sdk/test/utils');
-
-const WM = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
-
-const BROWSER = 'chrome://browser/content/browser.xul';
-
-function makeEmptyBrowserWindow(options) {
- options = options || {};
- return open(BROWSER, {
- features: {
- chrome: true,
- private: !!options.private
- }
- }).then(focus);
-}
-
-exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) {
- var myNonPrivateWindowId, myPrivateWindowId;
- var privateWindowClosed = false;
- var privateWindowOpened = false;
- var trackedWindowIds = [];
-
- let wt = winUtils.WindowTracker({
- onTrack: function(window) {
- let id = getInnerId(window);
- trackedWindowIds.push(id);
- },
- onUntrack: function(window) {
- let id = getInnerId(window);
- if (id === myPrivateWindowId) {
- privateWindowClosed = true;
- }
-
- if (id === myNonPrivateWindowId) {
- assert.equal(privateWindowClosed, true, 'private window was untracked');
- wt.unload();
- done();
- }
- }
- });
-
- // make a new private window
- makeEmptyBrowserWindow({ private: true }).then(function(window) {
- myPrivateWindowId = getInnerId(window);
-
- assert.ok(trackedWindowIds.indexOf(myPrivateWindowId) >= 0, 'private window was tracked');
- assert.equal(isPrivate(window), isWindowPBSupported, 'private window isPrivate');
- assert.equal(isWindowPrivate(window), isWindowPBSupported);
- assert.ok(getFrames(window).length > 1, 'there are frames for private window');
- assert.equal(getWindowTitle(window), window.document.title,
- 'getWindowTitle works');
-
- return close(window).then(function() {
- assert.pass('private window was closed');
-
- return makeEmptyBrowserWindow().then(function(window) {
- myNonPrivateWindowId = getInnerId(window);
- assert.notEqual(myPrivateWindowId, myNonPrivateWindowId, 'non private window was opened');
- return close(window);
- });
- });
- }).then(null, assert.fail);
-};
-
-// Test setting activeWIndow and onFocus for private windows
-exports.testSettingActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) {
- let browserWindow = WM.getMostRecentWindow("navigator:browser");
- let testSteps;
-
- assert.equal(winUtils.activeBrowserWindow, browserWindow,
- "Browser window is the active browser window.");
- assert.ok(!isPrivate(browserWindow), "Browser window is not private.");
-
- // make a new private window
- makeEmptyBrowserWindow({
- private: true
- }).then(function(window) {
- let continueAfterFocus = window => onFocus(window).then(nextTest);
-
- // PWPB case
- if (isWindowPBSupported) {
- assert.ok(isPrivate(window), "window is private");
- assert.notStrictEqual(winUtils.activeBrowserWindow, browserWindow);
- }
- // Global case
- else {
- assert.ok(!isPrivate(window), "window is not private");
- }
-
- assert.strictEqual(winUtils.activeBrowserWindow, window,
- "Correct active browser window pb supported");
- assert.notStrictEqual(browserWindow, window,
- "The window is not the old browser window");
-
- testSteps = [
- function() {
- // test setting a non private window
- continueAfterFocus(winUtils.activeWindow = browserWindow);
- },
- function() {
- assert.strictEqual(winUtils.activeWindow, browserWindow,
- "Correct active window [1]");
- assert.strictEqual(winUtils.activeBrowserWindow, browserWindow,
- "Correct active browser window [1]");
-
- // test focus(window)
- focus(window).then(nextTest);
- },
- function(w) {
- assert.strictEqual(w, window, 'require("sdk/window/helpers").focus on window works');
- assert.strictEqual(winUtils.activeBrowserWindow, window,
- "Correct active browser window [2]");
- assert.strictEqual(winUtils.activeWindow, window,
- "Correct active window [2]");
-
- // test setting a private window
- continueAfterFocus(winUtils.activeWindow = window);
- },
- function() {
- assert.strictEqual(winUtils.activeBrowserWindow, window,
- "Correct active browser window [3]");
- assert.strictEqual(winUtils.activeWindow, window,
- "Correct active window [3]");
-
- // just to get back to original state
- continueAfterFocus(winUtils.activeWindow = browserWindow);
- },
- function() {
- assert.strictEqual(winUtils.activeBrowserWindow, browserWindow,
- "Correct active browser window when pb mode is supported [4]");
- assert.strictEqual(winUtils.activeWindow, browserWindow,
- "Correct active window when pb mode is supported [4]");
-
- close(window).then(done).then(null, assert.fail);
- }
- ];
-
- function nextTest() {
- let args = arguments;
- if (testSteps.length) {
- require('sdk/timers').setTimeout(function() {
- (testSteps.shift()).apply(null, args);
- }, 0);
- }
- }
- nextTest();
- });
-};
-
-exports.testActiveWindowDoesNotIgnorePrivateWindow = function*(assert) {
- // make a new private window
- let window = yield makeEmptyBrowserWindow({
- private: true
- });
-
- // PWPB case
- if (isWindowPBSupported) {
- assert.equal(isPrivate(winUtils.activeWindow), true,
- "active window is private");
- assert.equal(isPrivate(winUtils.activeBrowserWindow), true,
- "active browser window is private");
- assert.ok(isWindowPrivate(window), "window is private");
- assert.ok(isPrivate(window), "window is private");
-
- // pb mode is supported
- assert.ok(
- isWindowPrivate(winUtils.activeWindow),
- "active window is private when pb mode is supported");
- assert.ok(
- isWindowPrivate(winUtils.activeBrowserWindow),
- "active browser window is private when pb mode is supported");
- assert.ok(isPrivate(winUtils.activeWindow),
- "active window is private when pb mode is supported");
- assert.ok(isPrivate(winUtils.activeBrowserWindow),
- "active browser window is private when pb mode is supported");
- }
-
- yield cleanUI();
-}
-
-exports.testWindowIteratorIgnoresPrivateWindows = function*(assert) {
- // make a new private window
- let window = yield makeEmptyBrowserWindow({
- private: true
- });
-
- assert.equal(isWindowPrivate(window), isWindowPBSupported);
- assert.ok(toArray(winUtils.windowIterator()).indexOf(window) > -1,
- "window is in windowIterator()");
-
- yield cleanUI();
-};
-
-// test that it is not possible to find a private window in
-// windows module's iterator
-exports.testWindowIteratorPrivateDefault = function(assert, done) {
- // there should only be one window open here, if not give us the
- // the urls
- if (browserWindows.length > 1) {
- for (let tab of tabs) {
- assert.fail("TAB URL: " + tab.url);
- }
- }
- else {
- assert.equal(browserWindows.length, 1, 'only one window open');
- }
-
- open('chrome://browser/content/browser.xul', {
- features: {
- private: true,
- chrome: true
- }
- }).then(focus).then(function(window) {
- // test that there is a private window opened
- assert.equal(isPrivate(window), isWindowPBSupported, 'there is a private window open');
- assert.equal(isPrivate(winUtils.activeWindow), isWindowPBSupported);
- assert.equal(isPrivate(getMostRecentWindow()), isWindowPBSupported);
- assert.equal(isPrivate(browserWindows.activeWindow), isWindowPBSupported);
-
- assert.equal(browserWindows.length, 2, '2 windows open');
- assert.equal(windows(null, { includePrivate: true }).length, 2);
-
- return close(window);
- }).then(done).then(null, assert.fail);
-};