mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 02:14:43 +00:00
Bug 849009 followup, add missing files from Add-on SDK uplift in 0745394ef7b1, r=KWierso
This commit is contained in:
parent
adbfc7c6c3
commit
5490faf3e4
41
addon-sdk/source/lib/sdk/window/helpers.js
Normal file
41
addon-sdk/source/lib/sdk/window/helpers.js
Normal file
@ -0,0 +1,41 @@
|
||||
/* 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 { defer } = require('../core/promise');
|
||||
const { open: openWindow, onFocus } = require('./utils');
|
||||
|
||||
function open(uri, options) {
|
||||
return promise(openWindow.apply(null, arguments), 'load');
|
||||
}
|
||||
exports.open = open;
|
||||
|
||||
function close(window) {
|
||||
// unload event could happen so fast that it is not resolved
|
||||
// if we listen to unload after calling close()
|
||||
let p = promise(window, 'unload');
|
||||
window.close();
|
||||
return p;
|
||||
}
|
||||
exports.close = close;
|
||||
|
||||
function focus(window) {
|
||||
let p = onFocus(window);
|
||||
window.focus();
|
||||
return p;
|
||||
}
|
||||
exports.focus = focus;
|
||||
|
||||
function promise(target, evt, capture) {
|
||||
let deferred = defer();
|
||||
capture = !!capture;
|
||||
|
||||
target.addEventListener(evt, function eventHandler() {
|
||||
target.removeEventListener(evt, eventHandler, capture);
|
||||
deferred.resolve(target);
|
||||
}, capture);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
exports.promise = promise;
|
@ -0,0 +1,30 @@
|
||||
const tabs = require('sdk/tabs');
|
||||
const { is } = require('sdk/system/xul-app');
|
||||
const { isPrivate } = require('sdk/private-browsing');
|
||||
const pbUtils = require('sdk/private-browsing/utils');
|
||||
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
|
||||
|
||||
exports.testPrivateTabsAreListed = function (assert, done) {
|
||||
let originalTabCount = tabs.length;
|
||||
|
||||
tabs.open({
|
||||
url: 'about:blank',
|
||||
isPrivate: true,
|
||||
onOpen: function(tab) {
|
||||
let win = getOwnerWindow(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);
|
||||
}
|
||||
});
|
||||
}
|
@ -0,0 +1,245 @@
|
||||
/* 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,
|
||||
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 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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) {
|
||||
var myNonPrivateWindow, myPrivateWindow;
|
||||
var finished = false;
|
||||
var privateWindow;
|
||||
var privateWindowClosed = false;
|
||||
var privateWindowOpened = false;
|
||||
|
||||
let wt = winUtils.WindowTracker({
|
||||
onTrack: function(window) {
|
||||
if (window === myPrivateWindow) {
|
||||
assert.equal(isPrivate(window), isWindowPBSupported);
|
||||
privateWindowOpened = true;
|
||||
}
|
||||
},
|
||||
onUntrack: function(window) {
|
||||
if (window === myPrivateWindow && isWindowPBSupported) {
|
||||
privateWindowClosed = true;
|
||||
}
|
||||
|
||||
if (window === myNonPrivateWindow) {
|
||||
assert.equal(privateWindowClosed, isWindowPBSupported);
|
||||
assert.ok(privateWindowOpened);
|
||||
wt.unload();
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make a new private window
|
||||
myPrivateWindow = openWindow(BROWSER, {
|
||||
features: {
|
||||
private: true
|
||||
}
|
||||
});
|
||||
promise(myPrivateWindow, 'load').then(function(window) {
|
||||
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');
|
||||
|
||||
close(myPrivateWindow).then(function() {
|
||||
assert.pass('private window was closed');
|
||||
makeEmptyBrowserWindow().then(function(window) {
|
||||
myNonPrivateWindow = window;
|
||||
assert.notDeepEqual(myPrivateWindow, myNonPrivateWindow);
|
||||
assert.pass('opened new window');
|
||||
close(myNonPrivateWindow).then(function() {
|
||||
assert.pass('non private window was closed');
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 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(focus).then(function(window) {
|
||||
let continueAfterFocus = function(window) onFocus(window).then(nextTest);
|
||||
|
||||
// PWPB case
|
||||
if (isWindowPBSupported) {
|
||||
assert.ok(isPrivate(window), "window is private");
|
||||
assert.notDeepEqual(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.deepEqual(winUtils.activeBrowserWindow, window,
|
||||
"Correct active browser window [3]");
|
||||
assert.deepEqual(winUtils.activeWindow, window,
|
||||
"Correct active window [3]");
|
||||
|
||||
// just to get back to original state
|
||||
continueAfterFocus(winUtils.activeWindow = browserWindow);
|
||||
},
|
||||
function() {
|
||||
assert.deepEqual(winUtils.activeBrowserWindow, browserWindow,
|
||||
"Correct active browser window when pb mode is supported [4]");
|
||||
assert.deepEqual(winUtils.activeWindow, browserWindow,
|
||||
"Correct active window when pb mode is supported [4]");
|
||||
|
||||
close(window).then(done);
|
||||
}
|
||||
];
|
||||
|
||||
function nextTest() {
|
||||
let args = arguments;
|
||||
if (testSteps.length) {
|
||||
require('sdk/timers').setTimeout(function() {
|
||||
(testSteps.shift()).apply(null, args);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
nextTest();
|
||||
});
|
||||
};
|
||||
|
||||
exports.testActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) {
|
||||
// make a new private window
|
||||
makeEmptyBrowserWindow({
|
||||
private: true
|
||||
}).then(function(window) {
|
||||
// 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");
|
||||
}
|
||||
// Global case
|
||||
else {
|
||||
assert.equal(isPrivate(winUtils.activeWindow), false,
|
||||
"active window is not private");
|
||||
assert.equal(isPrivate(winUtils.activeBrowserWindow), false,
|
||||
"active browser window is not private");
|
||||
assert.equal(isWindowPrivate(window), false, "window is not private");
|
||||
assert.equal(isPrivate(window), false, "window is not private");
|
||||
}
|
||||
|
||||
close(window).then(done);
|
||||
});
|
||||
}
|
||||
|
||||
exports.testWindowIteratorIgnoresPrivateWindows = function(assert, done) {
|
||||
// make a new private window
|
||||
makeEmptyBrowserWindow({
|
||||
private: true
|
||||
}).then(function(window) {
|
||||
assert.equal(isWindowPrivate(window), isWindowPBSupported);
|
||||
assert.ok(toArray(winUtils.windowIterator()).indexOf(window) > -1,
|
||||
"window is in windowIterator()");
|
||||
|
||||
close(window).then(done);
|
||||
});
|
||||
};
|
||||
|
||||
// test that it is not possible to find a private window in
|
||||
// windows module's iterator
|
||||
exports.testWindowIteratorPrivateDefault = function(assert, done) {
|
||||
assert.equal(browserWindows.length, 1, 'only one window open');
|
||||
|
||||
open('chrome://browser/content/browser.xul', {
|
||||
features: {
|
||||
private: true,
|
||||
chrome: true
|
||||
}
|
||||
}).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);
|
||||
|
||||
close(window).then(done);
|
||||
});
|
||||
};
|
77
addon-sdk/source/test/addons/require/main.js
Normal file
77
addon-sdk/source/test/addons/require/main.js
Normal file
@ -0,0 +1,77 @@
|
||||
/* 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";
|
||||
|
||||
exports["test local vs sdk module"] = function (assert) {
|
||||
assert.notEqual(require("memory"),
|
||||
require("sdk/deprecated/memory"),
|
||||
"Local module takes the priority over sdk modules");
|
||||
assert.ok(require("memory").local,
|
||||
"this module is really the local one");
|
||||
}
|
||||
|
||||
exports["test 3rd party vs sdk module"] = function (assert) {
|
||||
// We are testing with a 3rd party package called `panel` with 3 modules
|
||||
// main, page-mod and third-party
|
||||
|
||||
// the only way to require 3rd party package modules are to use absolute paths
|
||||
// require("panel/main"), require("panel/page-mod"),
|
||||
// require("panel/third-party") and also require("panel") which will refer
|
||||
// to panel's main package module.
|
||||
|
||||
// So require(page-mod) shouldn't map the 3rd party
|
||||
assert.equal(require("page-mod"),
|
||||
require("sdk/page-mod"),
|
||||
"Third party modules don't overload sdk modules");
|
||||
assert.ok(require("page-mod").PageMod,
|
||||
"page-mod module is really the sdk one");
|
||||
|
||||
assert.equal(require("panel/page-mod").id, "page-mod",
|
||||
"panel/page-mod is the 3rd party");
|
||||
|
||||
// But require(panel) will map to 3rd party main module
|
||||
// *and* overload the sdk module
|
||||
// and also any local module with the same name
|
||||
assert.equal(require("panel").id, "panel-main",
|
||||
"Third party main module overload sdk modules");
|
||||
assert.equal(require("panel"),
|
||||
require("panel/main"),
|
||||
"require(panel) maps to require(panel/main)");
|
||||
// So that you have to use relative path to ensure getting the local module
|
||||
assert.equal(require("./panel").id,
|
||||
"local-panel",
|
||||
"require(./panel) maps to the local module");
|
||||
|
||||
// It should still be possible to require sdk module with absolute path
|
||||
assert.ok(require("sdk/panel").Panel,
|
||||
"We can bypass this overloading with absolute path to sdk modules");
|
||||
assert.equal(require("sdk/panel"),
|
||||
require("addon-kit/panel"),
|
||||
"Old and new layout both work");
|
||||
}
|
||||
|
||||
// /!\ Always use distinct module for each test.
|
||||
// Otherwise, the linker can correctly parse and allow the first usage of it
|
||||
// but still silently fail on the second.
|
||||
|
||||
exports.testRelativeRequire = function (assert) {
|
||||
assert.equal(require('./same-folder').id, 'same-folder');
|
||||
}
|
||||
|
||||
exports.testRelativeSubFolderRequire = function (assert) {
|
||||
assert.equal(require('./sub-folder/module').id, 'sub-folder');
|
||||
}
|
||||
|
||||
exports.testMultipleRequirePerLine = function (assert) {
|
||||
var a=require('./multiple/a'),b=require('./multiple/b');
|
||||
assert.equal(a.id, 'a');
|
||||
assert.equal(b.id, 'b');
|
||||
}
|
||||
|
||||
exports.testSDKRequire = function (assert) {
|
||||
assert.deepEqual(Object.keys(require('sdk/widget')), ['Widget']);
|
||||
assert.equal(require('widget'), require('sdk/widget'));
|
||||
}
|
||||
|
||||
require("sdk/test/runner").runTestsFromModule(module);
|
5
addon-sdk/source/test/addons/require/memory.js
Normal file
5
addon-sdk/source/test/addons/require/memory.js
Normal file
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.local = true;
|
5
addon-sdk/source/test/addons/require/multiple/a.js
Normal file
5
addon-sdk/source/test/addons/require/multiple/a.js
Normal file
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = 'a';
|
5
addon-sdk/source/test/addons/require/multiple/b.js
Normal file
5
addon-sdk/source/test/addons/require/multiple/b.js
Normal file
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = 'b';
|
4
addon-sdk/source/test/addons/require/package.json
Normal file
4
addon-sdk/source/test/addons/require/package.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"id": "test-require",
|
||||
"packages": "packages"
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = "panel-main";
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"id": "test-panel"
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = "page-mod";
|
5
addon-sdk/source/test/addons/require/panel.js
Normal file
5
addon-sdk/source/test/addons/require/panel.js
Normal file
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = "local-panel";
|
5
addon-sdk/source/test/addons/require/same-folder.js
Normal file
5
addon-sdk/source/test/addons/require/same-folder.js
Normal file
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = 'same-folder';
|
@ -0,0 +1,5 @@
|
||||
/* 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/. */
|
||||
|
||||
exports.id = 'sub-folder';
|
60
addon-sdk/source/test/test-test-loader.js
Normal file
60
addon-sdk/source/test/test-test-loader.js
Normal file
@ -0,0 +1,60 @@
|
||||
/* 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 { LoaderWithHookedConsole } = require("sdk/test/loader");
|
||||
|
||||
exports["test LoaderWithHookedConsole"] = function (assert) {
|
||||
let count = 0;
|
||||
function onMessage(type, message) {
|
||||
switch (count++) {
|
||||
case 0:
|
||||
assert.equal(type, "log", "got log type");
|
||||
assert.equal(message, "1st", "got log msg");
|
||||
break;
|
||||
case 1:
|
||||
assert.equal(type, "error", "got error type");
|
||||
assert.equal(message, "2nd", "got error msg");
|
||||
break;
|
||||
case 2:
|
||||
assert.equal(type, "warn", "got warn type");
|
||||
assert.equal(message, "3rd", "got warn msg");
|
||||
break;
|
||||
case 3:
|
||||
assert.equal(type, "info", "got info type");
|
||||
assert.equal(message, "4th", "got info msg");
|
||||
break;
|
||||
case 4:
|
||||
assert.equal(type, "debug", "got debug type");
|
||||
assert.equal(message, "5th", "got debug msg");
|
||||
break;
|
||||
case 5:
|
||||
assert.equal(type, "exception", "got exception type");
|
||||
assert.equal(message, "6th", "got exception msg");
|
||||
break;
|
||||
default:
|
||||
assert.fail("Got unexception message: " + i);
|
||||
}
|
||||
}
|
||||
|
||||
let { loader, messages } = LoaderWithHookedConsole(module, onMessage);
|
||||
let console = loader.globals.console;
|
||||
console.log("1st");
|
||||
console.error("2nd");
|
||||
console.warn("3rd");
|
||||
console.info("4th");
|
||||
console.debug("5th");
|
||||
console.exception("6th");
|
||||
assert.equal(messages.length, 6, "Got all console messages");
|
||||
assert.deepEqual(messages[0], {type: "log", msg: "1st"}, "Got log");
|
||||
assert.deepEqual(messages[1], {type: "error", msg: "2nd"}, "Got error");
|
||||
assert.deepEqual(messages[2], {type: "warn", msg: "3rd"}, "Got warn");
|
||||
assert.deepEqual(messages[3], {type: "info", msg: "4th"}, "Got info");
|
||||
assert.deepEqual(messages[4], {type: "debug", msg: "5th"}, "Got debug");
|
||||
assert.deepEqual(messages[5], {type: "exception", msg: "6th"}, "Got exception");
|
||||
assert.equal(count, 6, "Called for all messages");
|
||||
};
|
||||
|
||||
require("test").run(exports);
|
231
addon-sdk/source/test/test-window-utils-private-browsing.js
Normal file
231
addon-sdk/source/test/test-window-utils-private-browsing.js
Normal file
@ -0,0 +1,231 @@
|
||||
/* 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 { Cc, Ci } = require('chrome');
|
||||
const { isWindowPBSupported } = require('sdk/private-browsing/utils');
|
||||
const { getFrames, getWindowTitle, onFocus, isWindowPrivate } = require('sdk/window/utils');
|
||||
const { open, close, focus } = require('sdk/window/helpers');
|
||||
const WM = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);
|
||||
const { isPrivate } = require('sdk/private-browsing');
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
exports.testWindowTrackerIgnoresPrivateWindows = function(assert, done) {
|
||||
var myNonPrivateWindow, myPrivateWindow;
|
||||
var finished = false;
|
||||
var privateWindow;
|
||||
var privateWindowClosed = false;
|
||||
|
||||
let wt = windowUtils.WindowTracker({
|
||||
onTrack: function(window) {
|
||||
if (isWindowPrivate(window)) {
|
||||
assert.fail('private window was tracked!');
|
||||
}
|
||||
},
|
||||
onUntrack: function(window) {
|
||||
if (isWindowPrivate(window)) {
|
||||
assert.fail('private window was tracked!');
|
||||
}
|
||||
// PWPB case
|
||||
if (window === myPrivateWindow && isWindowPBSupported) {
|
||||
privateWindowClosed = true;
|
||||
}
|
||||
if (window === myNonPrivateWindow) {
|
||||
assert.ok(!privateWindowClosed);
|
||||
wt.unload();
|
||||
done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// make a new private window
|
||||
makeEmptyBrowserWindow({
|
||||
private: true
|
||||
}).then(function(window) {
|
||||
myPrivateWindow = window;
|
||||
|
||||
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');
|
||||
|
||||
close(window).then(function() {
|
||||
makeEmptyBrowserWindow().then(function(window) {
|
||||
myNonPrivateWindow = window;
|
||||
assert.pass('opened new window');
|
||||
window.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Test setting activeWIndow and onFocus for private windows
|
||||
exports.testSettingActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) {
|
||||
let browserWindow = WM.getMostRecentWindow("navigator:browser");
|
||||
let testSteps;
|
||||
|
||||
assert.equal(windowUtils.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(focus).then(function(window) {
|
||||
let continueAfterFocus = function(window) onFocus(window).then(nextTest);
|
||||
|
||||
// PWPB case
|
||||
if (isWindowPBSupported) {
|
||||
assert.ok(isPrivate(window), "window is private");
|
||||
assert.notDeepEqual(windowUtils.activeBrowserWindow, browserWindow);
|
||||
}
|
||||
// Global case
|
||||
else {
|
||||
assert.ok(!isPrivate(window), "window is not private");
|
||||
}
|
||||
|
||||
assert.strictEqual(windowUtils.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(windowUtils.activeWindow = browserWindow);
|
||||
},
|
||||
function() {
|
||||
assert.strictEqual(windowUtils.activeWindow, browserWindow,
|
||||
"Correct active window [1]");
|
||||
assert.strictEqual(windowUtils.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(windowUtils.activeBrowserWindow, window,
|
||||
"Correct active browser window [2]");
|
||||
assert.strictEqual(windowUtils.activeWindow, window,
|
||||
"Correct active window [2]");
|
||||
|
||||
// test setting a private window
|
||||
continueAfterFocus(windowUtils.activeWindow = window);
|
||||
},
|
||||
function() {
|
||||
assert.deepEqual(windowUtils.activeBrowserWindow, window,
|
||||
"Correct active browser window [3]");
|
||||
assert.deepEqual(windowUtils.activeWindow, window,
|
||||
"Correct active window [3]");
|
||||
|
||||
// just to get back to original state
|
||||
continueAfterFocus(windowUtils.activeWindow = browserWindow);
|
||||
},
|
||||
function() {
|
||||
assert.deepEqual(windowUtils.activeBrowserWindow, browserWindow,
|
||||
"Correct active browser window when pb mode is supported [4]");
|
||||
assert.deepEqual(windowUtils.activeWindow, browserWindow,
|
||||
"Correct active window when pb mode is supported [4]");
|
||||
|
||||
close(window).then(done);
|
||||
}
|
||||
];
|
||||
|
||||
function nextTest() {
|
||||
let args = arguments;
|
||||
if (testSteps.length) {
|
||||
require('sdk/timers').setTimeout(function() {
|
||||
(testSteps.shift()).apply(null, args);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
nextTest();
|
||||
});
|
||||
};
|
||||
|
||||
exports.testActiveWindowDoesNotIgnorePrivateWindow = function(assert, done) {
|
||||
// make a new private window
|
||||
makeEmptyBrowserWindow({
|
||||
private: true
|
||||
}).then(function(window) {
|
||||
// PWPB case
|
||||
if (isWindowPBSupported) {
|
||||
assert.equal(isPrivate(windowUtils.activeWindow), true,
|
||||
"active window is private");
|
||||
assert.equal(isPrivate(windowUtils.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(windowUtils.activeWindow),
|
||||
"active window is private when pb mode is supported");
|
||||
assert.ok(
|
||||
isWindowPrivate(windowUtils.activeBrowserWindow),
|
||||
"active browser window is private when pb mode is supported");
|
||||
assert.ok(isPrivate(windowUtils.activeWindow),
|
||||
"active window is private when pb mode is supported");
|
||||
assert.ok(isPrivate(windowUtils.activeBrowserWindow),
|
||||
"active browser window is private when pb mode is supported");
|
||||
}
|
||||
// Global case
|
||||
else {
|
||||
assert.equal(isPrivate(windowUtils.activeWindow), false,
|
||||
"active window is not private");
|
||||
assert.equal(isPrivate(windowUtils.activeBrowserWindow), false,
|
||||
"active browser window is not private");
|
||||
assert.equal(isWindowPrivate(window), false, "window is not private");
|
||||
assert.equal(isPrivate(window), false, "window is not private");
|
||||
}
|
||||
|
||||
close(window).then(done);
|
||||
});
|
||||
}
|
||||
|
||||
exports.testWindowIteratorIgnoresPrivateWindows = function(assert, done) {
|
||||
// make a new private window
|
||||
makeEmptyBrowserWindow({
|
||||
private: true
|
||||
}).then(function(window) {
|
||||
// PWPB case
|
||||
if (isWindowPBSupported) {
|
||||
assert.ok(isWindowPrivate(window), "window is private");
|
||||
assert.equal(toArray(windowUtils.windowIterator()).indexOf(window), -1,
|
||||
"window is not in windowIterator()");
|
||||
}
|
||||
// Global case
|
||||
else {
|
||||
assert.equal(isWindowPrivate(window), false, "window is not private");
|
||||
assert.ok(toArray(windowUtils.windowIterator()).indexOf(window) > -1,
|
||||
"window is in windowIterator()");
|
||||
}
|
||||
|
||||
close(window).then(done);
|
||||
});
|
||||
};
|
||||
|
||||
if (require("sdk/system/xul-app").is("Fennec")) {
|
||||
module.exports = {
|
||||
"test Unsupported Test": function UnsupportedTest (assert) {
|
||||
assert.pass(
|
||||
"Skipping this test until Fennec support is implemented." +
|
||||
"See bug 809412");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
require("test").run(exports);
|
Loading…
Reference in New Issue
Block a user