Bug 1004395 - Uplift Add-on SDK to Firefox r=me

This commit is contained in:
Erik Vold 2014-05-09 10:10:05 -07:00
parent d45ba78b4b
commit e145a1e55c
41 changed files with 342 additions and 378 deletions

View File

@ -50,7 +50,8 @@ function PlainTextConsole(print, innerID) {
prefix: self.name + ": ",
maxLogLevel: logLevel,
dump: print,
innerID: innerID
innerID: innerID,
consoleID: "addon/" + self.id
};
let console = new ConsoleAPI(consoleOptions);

View File

@ -292,7 +292,7 @@ const ContentWorker = Object.freeze({
"function, which works the same. Replace calls to `on()` " +
"with calls to `self.on()`" +
"For more info on `self.on`, see " +
"<https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/web-content.html>.");
"<https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/using_postMessage>.");
return self.on.apply(null, arguments);
};
@ -309,7 +309,7 @@ const ContentWorker = Object.freeze({
"definitions with calls to `self.on('message', " +
"function (data){})`. " +
"For more info on `self.on`, see " +
"<https://addons.mozilla.org/en-US/developers/docs/sdk/latest/dev-guide/addon-development/web-content.html>.");
"<https://developer.mozilla.org/en-US/Add-ons/SDK/Guides/Content_Scripts/using_postMessage>.");
onMessage = v;
if (typeof onMessage == "function")
self.on("message", onMessage);

View File

@ -20,6 +20,7 @@ const events = require('../system/events');
const { getInnerId } = require("../window/utils");
const { WorkerSandbox } = require('./sandbox');
const { getTabForWindow } = require('../tabs/helpers');
const { isPrivate } = require('../private-browsing/utils');
// A weak map of workers to hold private attributes that
// should not be exposed
@ -37,7 +38,7 @@ const ERR_FROZEN = "The page is currently hidden and can no longer be used " +
/**
* Message-passing facility for communication between code running
* in the content and add-on process.
* @see https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/content/worker.html
* @see https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/content_worker
*/
const Worker = Class({
implements: [EventTarget],
@ -186,6 +187,8 @@ detach.define(Worker, function (worker, reason) {
model.inited = false;
});
isPrivate.define(Worker, ({ tab }) => isPrivate(tab));
/**
* Tells content worker to unload itself and
* removes all the references from itself.

View File

@ -11,7 +11,7 @@ const { Trait } = require('../deprecated/traits');
const { iteratorSymbol } = require('../util/iteration');
/**
* @see https://jetpack.mozillalabs.com/sdk/latest/docs/#module/api-utils/list
* @see https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/util_list
*/
const Iterable = Trait.compose({
/**

View File

@ -393,7 +393,7 @@ const WorkerSandbox = EventEmitter.compose({
/**
* Message-passing facility for communication between code running
* in the content and add-on process.
* @see https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/content/worker.html
* @see https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/content_worker
*/
const Worker = EventEmitter.compose({
on: Trait.required,

View File

@ -11,6 +11,8 @@ module.metadata = {
const memory = require('./memory');
var timer = require("../timers");
var cfxArgs = require("@test/options");
const { getTabs, getURI } = require("../tabs/utils");
const { windows, isBrowser } = require("../window/utils");
exports.findAndRunTests = function findAndRunTests(options) {
var TestFinder = require("./unit-test-finder").TestFinder;
@ -278,14 +280,39 @@ TestRunner.prototype = {
this.failed++;
this.test.failed++;
}
let wins = windows(null, { includePrivate: true });
let tabs = [];
for (let win of wins.filter(isBrowser)) {
for (let tab of getTabs(win)) {
tabs.push(tab);
}
}
if (wins.length != 1)
this.fail("Should not be any unexpected windows open");
if (tabs.length != 1)
this.fail("Should not be any unexpected tabs open");
if (tabs.length != 1 || wins.length != 1) {
console.log("Windows open:");
for (let win of wins) {
if (isBrowser(win)) {
tabs = getTabs(win);
console.log(win.location + " - " + tabs.map(getURI).join(", "));
}
else {
console.log(win.location);
}
}
}
this.testRunSummary.push({
name: this.test.name,
passed: this.test.passed,
failed: this.test.failed,
errors: [error for (error in this.test.errors)].join(", ")
});
if (this.onDone !== null) {
var onDone = this.onDone;
var self = this;

View File

@ -25,7 +25,7 @@ const { windowIterator } = require('./deprecated/window-utils');
const { isBrowser, getFrames } = require('./window/utils');
const { getTabs, getTabContentWindow, getTabForContentWindow,
getURI: getTabURI } = require('./tabs/utils');
const { ignoreWindow } = require('sdk/private-browsing/utils');
const { ignoreWindow } = require('./private-browsing/utils');
const { Style } = require("./stylesheet/style");
const { attach, detach } = require("./content/mod");
const { has, hasAny } = require("./util/array");
@ -167,22 +167,8 @@ function onContentWindow({ subject: document }) {
}
}
// Returns all tabs on all currently opened windows
function getAllTabs() {
let tabs = [];
// Iterate over all chrome windows
for (let window in windowIterator()) {
if (!isBrowser(window))
continue;
tabs = tabs.concat(getTabs(window));
}
return tabs;
}
function applyOnExistingDocuments (mod) {
let tabs = getAllTabs();
tabs.forEach(function (tab) {
getTabs().forEach(tab => {
// Fake a newly created document
let window = getTabContentWindow(tab);
if (has(mod.attachTo, "top") && mod.include.matchesAny(getTabURI(tab)))

View File

@ -165,7 +165,7 @@ function register(factory) {
throw new Error("xpcom.register() expect a Factory instance.\n" +
"Please refactor your code to new xpcom module if you" +
" are repacking an addon from SDK <= 1.5:\n" +
"https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/api-utils/xpcom.html");
"https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/platform_xpcom");
}
registerFactory(factory.id, factory.description, factory.contract, factory);

View File

@ -7,13 +7,10 @@ module.metadata = {
"stability": "stable"
};
const { Ci } = require('chrome');
const { setMode, getMode, on: onStateChange, isPermanentPrivateBrowsing } = require('./private-browsing/utils');
const { isWindowPrivate } = require('./window/utils');
const { setMode, getMode, on: onStateChange, isPrivate } = require('./private-browsing/utils');
const { emit, on, once, off } = require('./event/core');
const { when: unload } = require('./system/unload');
const { deprecateUsage, deprecateFunction, deprecateEvent } = require('./util/deprecate');
const { getOwnerWindow } = require('./private-browsing/window/utils');
const { deprecateFunction, deprecateEvent } = require('./util/deprecate');
onStateChange('start', function onStart() {
emit(exports, 'start');
@ -39,48 +36,7 @@ exports.removeListener = deprecateEvents(function removeListener(type, listener)
off(exports, type, listener);
});
exports.isPrivate = function(thing) {
// if thing is defined, and we can find a window for it
// then check if the window is private
if (!!thing) {
// if the thing is a window, and the window is private
// then return true
if (isWindowPrivate(thing)) {
return true;
}
// does the thing have an associated tab?
// page-mod instances do..
if (thing.tab) {
let tabWindow = getOwnerWindow(thing.tab);
if (tabWindow) {
let isThingPrivate = isWindowPrivate(tabWindow);
if (isThingPrivate)
return isThingPrivate;
}
}
// can we find an associated window?
let window = getOwnerWindow(thing);
if (window)
return isWindowPrivate(window);
try {
let { isChannelPrivate } = thing.QueryInterface(Ci.nsIPrivateBrowsingChannel);
if (isChannelPrivate)
return true;
} catch(e) {}
}
// check if the post pwpb, global pb service is enabled.
if (isPermanentPrivateBrowsing())
return true;
// if we get here, and global private browsing
// is available, and it is true, then return
// true otherwise false is returned here
return getMode();
};
exports.isPrivate = isPrivate;
function deprecateEvents(func) deprecateEvent(
func,

View File

@ -16,6 +16,7 @@ const { deprecateFunction } = require('../util/deprecate');
const { isOneOf, is, satisfiesVersion, version } = require('../system/xul-app');
const { isWindowPrivate } = require('../window/utils');
const { isPrivateBrowsingSupported } = require('../self');
const { dispatcher } = require("../util/dispatcher");
let deferredEmit = defer(emit);
let pbService;
@ -53,10 +54,11 @@ let isWindowPBSupported = exports.isWindowPBSupported =
let isTabPBSupported = exports.isTabPBSupported =
!pbService && !!PrivateBrowsingUtils && is('Fennec') && satisfiesVersion(version, '>=20.0*');
exports.isPermanentPrivateBrowsing = function() {
function isPermanentPrivateBrowsing() {
return !!(PrivateBrowsingUtils && PrivateBrowsingUtils.permanentPrivateBrowsing);
}
exports.isPermanentPrivateBrowsing = isPermanentPrivateBrowsing;
function ignoreWindow(window) {
return !isPrivateBrowsingSupported && isWindowPrivate(window) && !isGlobalPBSupported;
}
@ -90,14 +92,25 @@ exports.setMode = deprecateFunction(
);
let getMode = function getMode(chromeWin) {
if (isWindowPrivate(chromeWin))
if (chromeWin !== undefined && isWindowPrivate(chromeWin))
return true;
// default
return pbService ? pbService.privateBrowsingEnabled : false;
return isGlobalPrivateBrowsing();
};
exports.getMode = getMode;
function isGlobalPrivateBrowsing() {
return pbService ? pbService.privateBrowsingEnabled : false;
}
const isPrivate = dispatcher("isPrivate");
isPrivate.when(isPermanentPrivateBrowsing, _ => true);
isPrivate.when(x => x instanceof Ci.nsIDOMWindow, isWindowPrivate);
isPrivate.when(x => Ci.nsIPrivateBrowsingChannel && x instanceof Ci.nsIPrivateBrowsingChannel, x => x.isChannelPrivate);
isPrivate.define(isGlobalPrivateBrowsing);
exports.isPrivate = isPrivate;
exports.on = on.bind(null, exports);
// Make sure listeners are cleaned up.

View File

@ -1,33 +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';
module.metadata = {
'stability': 'unstable'
};
const privateNS = require('../../core/namespace').ns();
function getOwnerWindow(thing) {
try {
// check for and return associated window
let fn = (privateNS(thing.prototype) || privateNS(thing) || {}).getOwnerWindow;
if (fn)
return fn.apply(fn, [thing].concat(arguments));
}
// stuff like numbers and strings throw errors with namespaces
catch(e) {}
// default
return undefined;
}
getOwnerWindow.define = function(Type, fn) {
privateNS(Type.prototype).getOwnerWindow = fn;
}
getOwnerWindow.implement = function(instance, fn) {
privateNS(instance).getOwnerWindow = fn;
}
exports.getOwnerWindow = getOwnerWindow;

View File

@ -11,7 +11,8 @@ const { activateTab, getTabTitle, setTabTitle, closeTab, getTabURL, getTabConten
getTabForBrowser,
setTabURL, getOwnerWindow, getTabContentType, getTabId } = require('./utils');
const { emit } = require('../event/core');
const { getOwnerWindow: getPBOwnerWindow } = require('../private-browsing/window/utils');
const { isPrivate } = require('../private-browsing/utils');
const { isWindowPrivate } = require('../window/utils');
const { when: unload } = require('../system/unload');
const { viewFor } = require('../view/core');
const { EVENTS } = require('./events');
@ -240,6 +241,6 @@ function onTabClose(event) {
cleanupTab(this);
};
getPBOwnerWindow.define(Tab, function(tab) {
return getTabContentWindow(tabNS(tab).tab);
isPrivate.implement(Tab, tab => {
return isWindowPrivate(getTabContentWindow(tabNS(tab).tab));
});

View File

@ -12,11 +12,13 @@ const { getThumbnailURIForWindow } = require("../content/thumbnail");
const { getFaviconURIForLocation } = require("../io/data");
const { activateTab, getOwnerWindow, getBrowserForTab, getTabTitle, setTabTitle,
getTabURL, setTabURL, getTabContentType, getTabId } = require('./utils');
const { getOwnerWindow: getPBOwnerWindow } = require('../private-browsing/window/utils');
const { isPrivate } = require('../private-browsing/utils');
const { isWindowPrivate } = require('../window/utils');
const viewNS = require('../core/namespace').ns();
const { deprecateUsage } = require('../util/deprecate');
const { getURL } = require('../url/utils');
const { viewFor } = require('../view/core');
const { observer } = require('./observer');
// Array of the inner instances of all the wrapped tabs.
const TABS = [];
@ -64,8 +66,8 @@ const TabTrait = Trait.compose(EventEmitter, {
this.pin();
viewNS(this._public).tab = this._tab;
getPBOwnerWindow.implement(this._public, getChromeTab);
viewFor.implement(this._public, getTabView);
isPrivate.implement(this._public, tab => isWindowPrivate(getChromeTab(tab)));
// Add tabs to getURL method
getURL.implement(this._public, (function (obj) this._public.url).bind(this));
@ -256,8 +258,12 @@ const TabTrait = Trait.compose(EventEmitter, {
callback();
return;
}
if (callback)
this.once(EVENTS.close.name, callback);
if (callback) {
if (this.window.tabs.activeTab && (this.window.tabs.activeTab.id == this.id))
observer.once('select', callback);
else
this.once(EVENTS.close.name, callback);
}
this._window.gBrowser.removeTab(this._tab);
},
/**

View File

@ -81,9 +81,9 @@ exports.getTabContainer = getTabContainer;
*/
function getTabs(window) {
if (arguments.length === 0) {
return getWindows().filter(isBrowser).reduce(function(tabs, window) {
return tabs.concat(getTabs(window))
}, []);
return getWindows().
filter(isBrowser).
reduce((tabs, window) => tabs.concat(getTabs(window)), []);
}
// fennec
@ -91,7 +91,7 @@ function getTabs(window) {
return window.BrowserApp.tabs;
// firefox - default
return Array.slice(getTabContainer(window).children);
return Array.filter(getTabContainer(window).children, function(t) !t.closing);
}
exports.getTabs = getTabs;

View File

@ -9,11 +9,10 @@ const { on, off, once } = require('../event/core');
const { method } = require('../lang/functional');
const { getWindowTitle } = require('./utils');
const unload = require('../system/unload');
const { isWindowPrivate } = require('../window/utils');
const { EventTarget } = require('../event/target');
const { getOwnerWindow: getPBOwnerWindow } = require('../private-browsing/window/utils');
const { isPrivate } = require('../private-browsing/utils');
const { isWindowPrivate } = require('../window/utils');
const { viewFor } = require('../view/core');
const { deprecateUsage } = require('../util/deprecate');
const ERR_FENNEC_MSG = 'This method is not yet supported by Fennec, consider using require("sdk/tabs") instead';
@ -38,18 +37,11 @@ const BrowserWindow = Class({
get activeTab() require('../tabs').activeTab,
on: method(on),
removeListener: method(off),
once: method(once),
get isPrivateBrowsing() {
deprecateUsage('`browserWindow.isPrivateBrowsing` is deprecated, please ' +
'consider using ' +
'`require("sdk/private-browsing").isPrivate(browserWindow)` ' +
'instead.');
return isWindowPrivate(windowNS(this).window);
}
once: method(once)
});
exports.BrowserWindow = BrowserWindow;
const getWindowView = window => windowNS(window).window;
getPBOwnerWindow.define(BrowserWindow, getWindowView);
isPrivate.define(BrowserWindow, window => isWindowPrivate(windowNS(this).window));
viewFor.define(BrowserWindow, getWindowView);

View File

@ -10,18 +10,18 @@ const { Cc, Ci, Cr } = require('chrome'),
{ WindowTabs, WindowTabTracker } = require('./tabs-firefox'),
{ WindowDom } = require('./dom'),
{ WindowLoader } = require('./loader'),
{ isBrowser, getWindowDocShell, windows: windowIterator } = require('../window/utils'),
{ isBrowser, getWindowDocShell,
windows: windowIterator, isWindowPrivate } = require('../window/utils'),
{ Options } = require('../tabs/common'),
apiUtils = require('../deprecated/api-utils'),
unload = require('../system/unload'),
windowUtils = require('../deprecated/window-utils'),
{ WindowTrackerTrait } = windowUtils,
{ ns } = require('../core/namespace'),
{ observer: windowObserver } = require('./observer'),
{ getOwnerWindow } = require('../private-browsing/window/utils');
{ observer: windowObserver } = require('./observer');
const { windowNS } = require('../window/namespace');
const { isPrivateBrowsingSupported } = require('../self');
const { ignoreWindow } = require('sdk/private-browsing/utils');
const { ignoreWindow, isPrivate } = require('sdk/private-browsing/utils');
const { viewFor } = require('../view/core');
/**
@ -76,7 +76,8 @@ const BrowserWindowTrait = Trait.compose(
this._load();
windowNS(this._public).window = this._window;
getOwnerWindow.implement(this._public, getChromeWindow);
isPrivate.implement(this._public, window => isWindowPrivate(getChromeWindow(window)));
viewFor.implement(this._public, getChromeWindow);
return this;

View File

@ -40,7 +40,7 @@ const { notifyObservers } = Cc['@mozilla.org/observer-service;1'].
getService(Ci.nsIObserverService);
const { NetUtil } = Cu.import("resource://gre/modules/NetUtil.jsm", {});
const { Reflect } = Cu.import("resource://gre/modules/reflect.jsm", {});
const { console } = Cu.import("resource://gre/modules/devtools/Console.jsm");
const { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm");
const { join: pathJoin, normalize, dirname } = Cu.import("resource://gre/modules/osfile/ospath_unix.jsm");
// Define some shortcuts.
@ -56,7 +56,7 @@ const NODE_MODULES = ["assert", "buffer_ieee754", "buffer", "child_process", "cl
const COMPONENT_ERROR = '`Components` is not available in this context.\n' +
'Functionality provided by Components may be available in an SDK\n' +
'module: https://jetpack.mozillalabs.com/sdk/latest/docs/ \n\n' +
'module: https://developer.mozilla.org/en-US/Add-ons/SDK \n\n' +
'However, if you still need to import Components, you may use the\n' +
'`chrome` module\'s properties for shortcuts to Component properties:\n\n' +
'Shortcuts: \n' +
@ -688,6 +688,10 @@ exports.unload = unload;
// If `resolve` does not returns `uri` string exception will be thrown by
// an associated `require` call.
const Loader = iced(function Loader(options) {
let console = new ConsoleAPI({
consoleID: options.id ? "addon/" + options.id : ""
});
let {
modules, globals, resolve, paths, rootURI, manifest, requireMap, isNative
} = override({

View File

@ -264,10 +264,11 @@ parser_groups = (
cmds=['test', 'run', 'xpi', 'testex',
'testpkgs', 'testall'])),
(("", "--e10s",), dict(dest="enable_e10s",
help="enable out-of-process Jetpacks",
help="enable remote windows",
action="store_true",
default=False,
cmds=['test', 'run', 'testex', 'testpkgs'])),
cmds=['test', 'run', 'testex', 'testpkgs',
'testaddons', 'testcfx', 'testall'])),
(("", "--logfile",), dict(dest="logfile",
help="log console output to file",
metavar=None,
@ -902,6 +903,8 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
if options.addons is not None:
options.addons = options.addons.split(",")
enable_e10s = options.enable_e10s or target_cfg.get('e10s', False)
try:
retval = run_app(harness_root_dir=app_extension_dir,
manifest_rdf=manifest_rdf,
@ -924,7 +927,8 @@ def run(arguments=sys.argv[1:], target_cfg=None, pkg_cfg=None,
is_running_tests=(command == "test"),
overload_modules=options.overload_modules,
bundle_sdk=options.bundle_sdk,
pkgdir=options.pkgdir)
pkgdir=options.pkgdir,
enable_e10s=enable_e10s)
except ValueError, e:
print ""
print "A given cfx option has an inappropriate value:"

View File

@ -418,7 +418,8 @@ def run_app(harness_root_dir, manifest_rdf, harness_options,
is_running_tests=False,
overload_modules=False,
bundle_sdk=True,
pkgdir=""):
pkgdir="",
enable_e10s=False):
if binary:
binary = os.path.expanduser(binary)
@ -430,6 +431,9 @@ def run_app(harness_root_dir, manifest_rdf, harness_options,
cmdargs = []
preferences = dict(DEFAULT_COMMON_PREFS)
if enable_e10s:
preferences['browser.tabs.remote.autostart'] = True
# For now, only allow running on Mobile with --force-mobile argument
if app_type in ["fennec", "fennec-on-device"] and not enable_mobile:
print """

View File

@ -60,7 +60,7 @@ def welcome():
print ("Your SDK may not work properly.")
return
print ("Welcome to the Add-on SDK. For the docs, visit https://addons.mozilla.org/en-US/developers/docs/sdk/latest/")
print ("Welcome to the Add-on SDK. For the docs, visit https://developer.mozilla.org/en-US/Add-ons/SDK")
if __name__ == '__main__':
welcome()

View File

@ -0,0 +1,10 @@
<!-- 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/. -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body></body>
</html>

View File

@ -0,0 +1,8 @@
/* 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';
self.port.on('echo', _ => {
self.port.emit('echo', '');
});

View File

@ -7,6 +7,8 @@ const { Cu, Cc, Ci } = require('chrome');
const Request = require('sdk/request').Request;
const { WindowTracker } = require('sdk/deprecated/window-utils');
const { close, open } = require('sdk/window/helpers');
const { data } = require('sdk/self');
const { Panel } = require('sdk/panel');
const XUL_URL = 'chrome://test/content/new-window.xul'
@ -65,4 +67,26 @@ exports.testChromeLocale = function(assert) {
'locales en-US folder was copied correctly');
}
exports.testChromeInPanel = function(assert, done) {
let panel = Panel({
contentURL: 'chrome://test/content/panel.html',
contentScriptWhen: 'start',
contentScriptFile: data.url('panel.js')
});
panel.once('show', _ => {
assert.pass('panel shown');
panel.port.once('echo', _ => {
assert.pass('got echo');
panel.once('hide', _ => {
panel.destroy();
assert.pass('panel is destroyed');
done();
});
panel.hide();
});
panel.port.emit('echo');
});
panel.show();
}
require('sdk/test/runner').runTestsFromModule(module);

View File

@ -0,0 +1,29 @@
/* 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 { get: getPref } = require('sdk/preferences/service');
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { openTab, closeTab, getBrowserForTab } = require('sdk/tabs/utils');
exports.testRemotePrefIsSet = function(assert) {
assert.ok(getPref('browser.tabs.remote.autostart'),
"Electrolysis remote tabs pref should be set");
}
exports.testTabIsRemote = function(assert, done) {
const url = 'data:text/html,test-tab-is-remote';
let tab = openTab(getMostRecentBrowserWindow(), url);
assert.ok(tab.getAttribute('remote'), "The new tab should be remote");
// can't simply close a remote tab before it is loaded, bug 1006043
let mm = getBrowserForTab(tab).messageManager;
mm.addMessageListener(7, function() {
closeTab(tab);
done();
})
mm.loadFrameScript('data:,sendAsyncMessage(7)', false);
}
require('sdk/test/runner').runTestsFromModule(module);

View File

@ -0,0 +1,10 @@
{
"name": "e10s-flag",
"title": "e10s-flag",
"id": "jid1-DYaXFHAPlHwbgw",
"description": "a basic e10s test add-on",
"author": "Tomislav Jovanovic",
"license": "MPL 2.0",
"version": "0.1",
"e10s": true
}

View File

@ -6,6 +6,7 @@
const { Cu } = require('chrome');
const { PageMod } = require('sdk/page-mod');
const tabs = require('sdk/tabs');
const { closeTab } = require('sdk/tabs/utils');
const promise = require('sdk/core/promise')
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { data } = require('sdk/self');
@ -47,6 +48,7 @@ exports.testDebugger = function(assert, done) {
then(_ => { assert.pass('testDebuggerStatement called') }).
then(closeConnection).
then(_ => { assert.pass('closeConnection called') }).
then(_ => { tab.close() }).
then(done).
then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);

View File

@ -6,6 +6,7 @@
const { Cu } = require('chrome');
const { PageMod } = require('sdk/page-mod');
const tabs = require('sdk/tabs');
const { closeTab } = require('sdk/tabs/utils');
const promise = require('sdk/core/promise')
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { data } = require('sdk/self');
@ -54,6 +55,7 @@ exports.testDebugger = function(assert, done) {
then(_ => { assert.pass('testDebuggerStatement called') }).
then(closeConnection).
then(_ => { assert.pass('closeConnection called') }).
then(_ => { tab.close() }).
then(done).
then(null, aError => {
ok(false, "Got an error: " + aError.message + "\n" + aError.stack);

View File

@ -8,7 +8,6 @@ const { isPrivateBrowsingSupported } = require('sdk/self');
const tabs = require('sdk/tabs');
const { browserWindows: windows } = require('sdk/windows');
const { isPrivate } = require('sdk/private-browsing');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { is } = require('sdk/system/xul-app');
const { isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
@ -19,47 +18,6 @@ exports.testIsPrivateBrowsingTrue = function(assert) {
'isPrivateBrowsingSupported property is true');
};
// test tab.open with isPrivate: true
// test isPrivate on a tab
// test getOwnerWindow on windows and tabs
exports.testGetOwnerWindow = function(assert, done) {
let window = windows.activeWindow;
let chromeWindow = getOwnerWindow(window);
assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');
tabs.open({
url: 'about:blank',
isPrivate: true,
onOpen: function(tab) {
// test that getOwnerWindow works as expected
if (is('Fennec')) {
assert.notStrictEqual(chromeWindow, getOwnerWindow(tab));
assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
}
else {
if (isWindowPBSupported) {
assert.notStrictEqual(chromeWindow,
getOwnerWindow(tab),
'associated window is not the same for window and window\'s tab');
}
else {
assert.strictEqual(chromeWindow,
getOwnerWindow(tab),
'associated window is the same for window and window\'s tab');
}
}
let pbSupported = isTabPBSupported || isWindowPBSupported;
// test that the tab is private if it should be
assert.equal(isPrivate(tab), pbSupported);
assert.equal(isPrivate(getOwnerWindow(tab)), pbSupported);
tab.close(function() done());
}
});
};
// test that it is possible to open a private tab
exports.testTabOpenPrivate = function(assert, done) {
tabs.open({
@ -68,10 +26,7 @@ exports.testTabOpenPrivate = function(assert, done) {
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), (isWindowPBSupported || isTabPBSupported));
tab.close(function() {
done();
});
tab.close(done);
}
});
}
@ -84,10 +39,7 @@ exports.testTabOpenPrivateDefault = function(assert, done) {
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), false);
tab.close(function() {
done();
});
tab.close(done);
}
});
}
@ -100,10 +52,7 @@ exports.testTabOpenPrivateOffExplicit = function(assert, done) {
onReady: function(tab) {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), false);
tab.close(function() {
done();
});
tab.close(done);
}
});
}
@ -121,10 +70,7 @@ if (!is('Fennec')) {
tab.once('ready', function() {
assert.equal(tab.url, TAB_URL, 'opened correct tab');
assert.equal(isPrivate(tab), isWindowPBSupported, 'tab is private');
window.close(function() {
done();
});
window.close(done);
});
}
});

View File

@ -86,25 +86,6 @@ function open(url, options) {
return promise;
};
/**
* Close the Active Tab
*/
function close(window) {
let { promise, resolve } = defer();
if (window && typeof(window.close) === "function") {
closeWindow(window).then(function() resolve());
}
else {
// 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.
closeTab(getActiveTab(getMostRecentBrowserWindow()));
resolve();
}
return promise;
}
/**
* Reload the window given and return a promise, that will be resolved with the
* content window after a small delay.
@ -249,7 +230,7 @@ exports["test PWPB Selection Listener"] = function(assert, done) {
assert.equal(selection.text, "fo");
close(window).
closeWindow(window).
then(loader.unload).
then(done).
then(null, assert.fail);
@ -279,7 +260,7 @@ exports["test PWPB Textarea OnSelect Listener"] = function(assert, done) {
focus(window).then(function() {
assert.equal(selection.text, "noodles");
close(window).
closeWindow(window).
then(loader.unload).
then(done).
then(null, assert.fail);
@ -298,7 +279,7 @@ exports["test PWPB Single DOM Selection"] = function(assert, done) {
open(URL, {private: true, title: "PWPB Single DOM Selection"}).
then(selectFirstDiv).
then(focus).then(function() {
then(focus).then(function(window) {
assert.equal(selection.isContiguous, true,
"selection.isContiguous with single DOM Selection works.");
@ -321,7 +302,9 @@ exports["test PWPB Single DOM Selection"] = function(assert, done) {
assert.equal(selectionCount, 1,
"One iterable selection");
}).then(close).then(loader.unload).then(done).then(null, assert.fail);
return closeWindow(window);
}).then(loader.unload).then(done).then(null, assert.fail);
}
exports["test PWPB Textarea Selection"] = function(assert, done) {
@ -331,7 +314,7 @@ exports["test PWPB Textarea Selection"] = function(assert, done) {
open(URL, {private: true, title: "PWPB Textarea Listener"}).
then(selectTextarea).
then(focus).
then(function() {
then(function(window) {
assert.equal(selection.isContiguous, true,
"selection.isContiguous with Textarea Selection works.");
@ -355,7 +338,9 @@ exports["test PWPB Textarea Selection"] = function(assert, done) {
assert.equal(selectionCount, 1,
"One iterable selection");
}).then(close).then(loader.unload).then(done).then(null, assert.fail);
return closeWindow(window);
}).then(loader.unload).then(done).then(null, assert.fail);
};
exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done) {
@ -365,7 +350,7 @@ exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done)
open(URL, {private: true, title: "PWPB Set HTML in Multiple DOM Selection"}).
then(selectAllDivs).
then(focus).
then(function() {
then(function(window) {
let html = "<span>b<b>a</b>r</span>";
let expectedText = ["bar", "and"];
@ -393,7 +378,9 @@ exports["test PWPB Set HTML in Multiple DOM Selection"] = function(assert, done)
assert.equal(selectionCount, 2,
"Two iterable selections");
}).then(close).then(loader.unload).then(done).then(null, assert.fail);
return closeWindow(window);
}).then(loader.unload).then(done).then(null, assert.fail);
};
exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
@ -403,7 +390,7 @@ exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
open(URL, {private: true, title: "test PWPB Set Text in Textarea Selection"}).
then(selectTextarea).
then(focus).
then(function() {
then(function(window) {
let text = "bar";
@ -429,7 +416,8 @@ exports["test PWPB Set Text in Textarea Selection"] = function(assert, done) {
assert.equal(selectionCount, 1,
"One iterable selection");
}).then(close).then(loader.unload).then(done).then(null, assert.fail);
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

View File

@ -1,9 +1,11 @@
/* 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');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
exports.testPrivateTabsAreListed = function (assert, done) {
let originalTabCount = tabs.length;
@ -12,7 +14,6 @@ exports.testPrivateTabsAreListed = function (assert, done) {
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");

View File

@ -1,8 +1,10 @@
/* 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 { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { promise: windowPromise, close, focus } = require('sdk/window/helpers');
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
@ -16,9 +18,6 @@ exports.testOpenTabWithPrivateActiveWindowNoIsPrivateOption = function(assert, d
url: 'about:blank',
onOpen: function(tab) {
assert.ok(isPrivate(tab), 'new tab is private');
assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
close(window).then(done).then(null, assert.fail);
}
})
@ -35,9 +34,6 @@ exports.testOpenTabWithNonPrivateActiveWindowNoIsPrivateOption = function(assert
url: 'about:blank',
onOpen: function(tab) {
assert.equal(isPrivate(tab), false, 'new tab is not private');
assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
close(window).then(done).then(null, assert.fail);
}
})
@ -55,9 +51,6 @@ exports.testOpenTabWithPrivateActiveWindowWithIsPrivateOptionTrue = function(ass
isPrivate: true,
onOpen: function(tab) {
assert.ok(isPrivate(tab), 'new tab is private');
assert.ok(isPrivate(getOwnerWindow(tab)), 'new tab window is private');
assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the private window are the same');
close(window).then(done).then(null, assert.fail);
}
})
@ -75,9 +68,6 @@ exports.testOpenTabWithNonPrivateActiveWindowWithIsPrivateOptionFalse = function
isPrivate: false,
onOpen: function(tab) {
assert.equal(isPrivate(tab), false, 'new tab is not private');
assert.equal(isPrivate(getOwnerWindow(tab)), false, 'new tab window is not private');
assert.strictEqual(getOwnerWindow(tab), window, 'the tab window and the new window are the same');
close(window).then(done).then(null, assert.fail);
}
})

View File

@ -3,15 +3,10 @@
const { Ci } = require('chrome');
const { openTab, closeTab } = require('sdk/tabs/utils');
const { browserWindows } = require('sdk/windows');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { isPrivate } = require('sdk/private-browsing');
exports.testIsPrivateOnTab = function(assert) {
let window = browserWindows.activeWindow;
let chromeWindow = getOwnerWindow(window);
assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');
assert.ok(!isPrivate(chromeWindow), 'the top level window is not private');
let rawTab = openTab(chromeWindow, 'data:text/html,<h1>Hi!</h1>', {

View File

@ -6,7 +6,8 @@
const { Cc, Ci } = require('chrome');
const { Loader } = require('sdk/test/loader');
const { setTimeout } = require('sdk/timers');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { viewFor } = require('sdk/view/core');
const { getOwnerWindow } = require('sdk/tabs/utils');
const { windows, onFocus, getMostRecentBrowserWindow } = require('sdk/window/utils');
const { open, focus, close } = require('sdk/window/helpers');
const tabs = require('sdk/tabs');
@ -165,12 +166,12 @@ exports.testTabPropertiesInNewWindow = function(assert, done) {
});
let tabs = loader.require('sdk/tabs');
let { getOwnerWindow } = loader.require('sdk/private-browsing/window/utils');
let { viewFor } = loader.require('sdk/view/core');
let count = 0;
function onReadyOrLoad (tab) {
if (count++) {
close(getOwnerWindow(tab)).then(done).then(null, assert.fail);
close(getOwnerWindow(viewFor(tab))).then(done).then(null, assert.fail);
}
}
@ -368,6 +369,33 @@ exports.testTabMove = function(assert, done) {
}).then(null, assert.fail);
};
exports.testIgnoreClosing = function(assert, done) {
let originalWindow = browserWindows.activeWindow;
openBrowserWindow(function(window, browser) {
let url = "data:text/html;charset=utf-8,foobar";
assert.equal(tabs.length, 2, "should be two windows open each with one tab");
tabs.on('ready', function onReady(tab) {
tabs.removeListener('ready', onReady);
let win = tab.window;
assert.equal(win.tabs.length, 2, "should be two tabs in the new window");
assert.equal(tabs.length, 3, "should be three tabs in total");
tab.close(function() {
assert.equal(win.tabs.length, 1, "should be one tab in the new window");
assert.equal(tabs.length, 2, "should be two tabs in total");
originalWindow.once("activate", done);
close(window);
});
});
tabs.open(url);
});
};
// TEST: open tab with default options
exports.testOpen = function(assert, done) {
let url = "data:text/html;charset=utf-8,default";
@ -413,6 +441,8 @@ exports.testPinUnpin = function(assert, done) {
// TEST: open tab in background
exports.testInBackground = function(assert, done) {
assert.equal(tabs.length, 1, "Should be one tab");
let window = getMostRecentBrowserWindow();
let activeUrl = tabs.activeTab.url;
let url = "data:text/html;charset=utf-8,background";
@ -441,7 +471,7 @@ exports.testOpenInNewWindow = function(assert, done) {
url: url,
inNewWindow: true,
onReady: function(tab) {
let newWindow = getOwnerWindow(tab);
let newWindow = getOwnerWindow(viewFor(tab));
assert.equal(windows().length, startWindowCount + 1, "a new window was opened");
onFocus(newWindow).then(function() {
@ -466,7 +496,7 @@ exports.testOpenInNewWindowOnOpen = function(assert, done) {
url: url,
inNewWindow: true,
onOpen: function(tab) {
let newWindow = getOwnerWindow(tab);
let newWindow = getOwnerWindow(viewFor(tab));
onFocus(newWindow).then(function() {
assert.equal(windows().length, startWindowCount + 1, "a new window was opened");
@ -942,9 +972,11 @@ exports['test unique tab ids'] = function(assert, done) {
var one = openWindow(), two = openWindow();
all([one, two]).then(function(results) {
assert.notEqual(results[0].id, results[1].id, "tab Ids should not be equal.");
results[0].win.close();
results[1].win.close();
done();
results[0].win.close(function() {
results[1].win.close(function () {
done();
});
});
});
}

View File

@ -66,7 +66,7 @@ exports.testExecOptionsEnvironment = function (assert, done) {
'receives environment option');
done();
});
});
}).then(null, assert.fail);
};
exports.testExecOptionsTimeout = function (assert, done) {
@ -104,7 +104,7 @@ exports.testExecOptionsTimeout = function (assert, done) {
child.off('close', closeHandler);
done();
}
});
}).then(null, assert.fail);
};
exports.testExecFileCallbackSuccess = function (assert, done) {
@ -116,7 +116,7 @@ exports.testExecFileCallbackSuccess = function (assert, done) {
assert.equal(stdout.trim(), '--myargs -j -s'.trim(), 'passes in correct arguments');
done();
});
});
}).then(null, assert.fail);
};
exports.testExecFileCallbackError = function (assert, done) {
@ -143,7 +143,7 @@ exports.testExecFileOptionsEnvironment = function (assert, done) {
'receives environment option');
done();
});
});
}).then(null, assert.fail);
};
exports.testExecFileOptionsTimeout = function (assert, done) {
@ -181,7 +181,7 @@ exports.testExecFileOptionsTimeout = function (assert, done) {
child.off('close', closeHandler);
done();
}
});
}).then(null, assert.fail);
};
/**
@ -204,7 +204,7 @@ exports.testExecFileOptionsMaxBufferLargeStdOut = function (assert, done) {
});
stdoutChild.on('exit', exitHandler);
stdoutChild.on('close', closeHandler);
});
}).then(null, assert.fail);
function exitHandler (code, signal) {
assert.equal(code, null, 'Exit code is null in exit handler');
@ -239,7 +239,7 @@ exports.testExecFileOptionsMaxBufferLargeStdOErr = function (assert, done) {
});
stderrChild.on('exit', exitHandler);
stderrChild.on('close', closeHandler);
});
}).then(null, assert.fail);
function exitHandler (code, signal) {
assert.equal(code, null, 'Exit code is null in exit handler');
@ -280,7 +280,7 @@ exports.testExecFileOptionsMaxBufferSmallStdOut = function (assert, done) {
});
stdoutChild.on('exit', exitHandler);
stdoutChild.on('close', closeHandler);
});
}).then(null, assert.fail);
function exitHandler (code, signal) {
// Sometimes the buffer limit is hit before the process closes successfully
@ -331,7 +331,7 @@ exports.testExecFileOptionsMaxBufferSmallStdErr = function (assert, done) {
});
stderrChild.on('exit', exitHandler);
stderrChild.on('close', closeHandler);
});
}).then(null, assert.fail);
function exitHandler (code, signal) {
// Sometimes the buffer limit is hit before the process closes successfully
@ -377,7 +377,7 @@ exports.testChildExecFileKillSignal = function (assert, done) {
assert.equal(err.signal, 'beepbeep', 'correctly used custom killSignal');
done();
});
});
}).then(null, assert.fail);
};
exports.testChildProperties = function (assert, done) {
@ -390,8 +390,7 @@ exports.testChildProperties = function (assert, done) {
assert.ok(true, 'Windows environment does not have `pid`');
else
assert.ok(child.pid > 0, 'Child has a pid');
done();
});
}).then(done, assert.fail);
};
exports.testChildStdinStreamLarge = function (assert, done) {
@ -509,7 +508,7 @@ exports.testSpawnOptions = function (assert, done) {
envChild.on('close', envClose);
cwdChild.on('close', cwdClose);
});
}).then(null, assert.fail);
function envClose () {
assert.equal(envStdout.trim(), 'my-value-test', 'spawn correctly passed in ENV');

View File

@ -90,8 +90,7 @@ function comparePixelImages(imageA, imageB, callback) {
compared = pixels;
this.emit("draw-image", imageB);
} else {
callback(compared === pixels);
tab.close()
tab.close(callback.bind(null, compared === pixels))
}
});

View File

@ -986,7 +986,7 @@ exports['test panel CSS'] = function(assert, done) {
getActiveView(panel).querySelector('iframe').contentWindow;
let panel = Panel({
contentURL: 'data:text/html;charset=utf-8,' +
contentURL: 'data:text/html;charset=utf-8,' +
'<div style="background: silver">css test</div>',
contentStyle: 'div { height: 100px; }',
contentStyleFile: CSS_URL,
@ -999,7 +999,7 @@ exports['test panel CSS'] = function(assert, done) {
loader.unload();
done();
}).then(null, assert.fail);
}).then(null, assert.fail);
}
});
@ -1016,7 +1016,7 @@ exports['test panel CSS list'] = function(assert, done) {
getActiveView(panel).querySelector('iframe').contentWindow;
let panel = Panel({
contentURL: 'data:text/html;charset=utf-8,' +
contentURL: 'data:text/html;charset=utf-8,' +
'<div style="width:320px; max-width: 480px!important">css test</div>',
contentStyleFile: [
// Highlight evaluation order in this list
@ -1049,8 +1049,7 @@ exports['test panel CSS list'] = function(assert, done) {
'add-on author/page author stylesheet !important precedence works');
loader.unload();
done();
}).then(null, assert.fail);
}).then(done, assert.fail);
}
});
@ -1065,12 +1064,12 @@ if (isWindowPBSupported) {
toolbar: true,
chrome: true,
private: true
} }).then(function(window) {
} }).then(window => {
assert.ok(isPrivate(window), 'window is private');
assert.equal(getWindow(window.gBrowser), null, 'private window elements returns null');
assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'non-private window elements returns window');
close(window).then(done);
})
return window;
}).then(close).then(done).then(null, assert.fail);
}
}
else if (isGlobalPBSupported) {
@ -1084,7 +1083,7 @@ else if (isGlobalPBSupported) {
open(null, { features: {
toolbar: true,
chrome: true
} }).then(function(window) {
} }).then(window => {
assert.ok(isPrivate(window), 'window is private');
assert.equal(getWindow(window.gBrowser), window, 'private window elements returns window');
assert.equal(getWindow(activeWindow.gBrowser), activeWindow, 'active window elements returns window');

View File

@ -12,7 +12,6 @@ const { isWindowPrivate } = winUtils;
const { isPrivateBrowsingSupported } = require('sdk/self');
const { is } = require('sdk/system/xul-app');
const { isPrivate } = require('sdk/private-browsing');
const { getOwnerWindow } = require('sdk/private-browsing/window/utils');
const { LoaderWithHookedConsole } = require("sdk/test/loader");
const { getMode, isGlobalPBSupported,
isWindowPBSupported, isTabPBSupported } = require('sdk/private-browsing/utils');
@ -84,34 +83,6 @@ exports.testIsPrivateBrowsingFalseDefault = function(assert) {
'isPrivateBrowsingSupported property is false by default');
};
exports.testGetOwnerWindow = function(assert, done) {
let window = windows.activeWindow;
let chromeWindow = getOwnerWindow(window);
assert.ok(chromeWindow instanceof Ci.nsIDOMWindow, 'associated window is found');
tabs.open({
url: 'about:blank',
isPrivate: true,
onOpen: function(tab) {
// test that getOwnerWindow works as expected
if (is('Fennec')) {
assert.notStrictEqual(chromeWindow, getOwnerWindow(tab));
assert.ok(getOwnerWindow(tab) instanceof Ci.nsIDOMWindow);
}
else {
assert.strictEqual(chromeWindow, getOwnerWindow(tab), 'associated window is the same for window and window\'s tab');
}
// test that the tab is not private
// private flag should be ignored by default
assert.ok(!isPrivate(tab));
assert.ok(!isPrivate(getOwnerWindow(tab)));
tab.close(done);
}
});
};
exports.testNSIPrivateBrowsingChannel = function(assert) {
let channel = Services.io.newChannel("about:blank", null, null);
channel.QueryInterface(Ci.nsIPrivateBrowsingChannel);

View File

@ -28,7 +28,7 @@ const tabs = require("sdk/tabs");
const { setTabURL } = require("sdk/tabs/utils");
const { getActiveTab, getTabContentWindow, closeTab } = require("sdk/tabs/utils")
const { getMostRecentBrowserWindow } = require("sdk/window/utils");
const { open: openNewWindow } = require("sdk/window/helpers");
const { open: openNewWindow, close: closeWindow } = require("sdk/window/helpers");
const { Loader } = require("sdk/test/loader");
const { setTimeout } = require("sdk/timers");
const { Cu } = require("chrome");
@ -698,13 +698,13 @@ exports["test Selection Listener"] = function(assert, done) {
selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});
open(URL).then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};
exports["test Textarea OnSelect Listener"] = function(assert, done) {
@ -713,13 +713,13 @@ exports["test Textarea OnSelect Listener"] = function(assert, done) {
selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});
open(URL).then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};
exports["test Selection listener removed on unload"] = function(assert, done) {
@ -769,14 +769,14 @@ exports["test Selection Listener on existing document"] = function(assert, done)
selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});
return window;
}).then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};
@ -788,14 +788,14 @@ exports["test Textarea OnSelect Listener on existing document"] = function(asser
selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});
return window;
}).then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};
exports["test Selection Listener on document reload"] = function(assert, done) {
@ -804,15 +804,15 @@ exports["test Selection Listener on document reload"] = function(assert, done) {
selection.once("select", function() {
assert.equal(selection.text, "fo");
close();
loader.unload();
done();
});
open(URL).
then(reload).
then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchSelectionEvent, assert.fail);
};
exports["test Textarea OnSelect Listener on document reload"] = function(assert, done) {
@ -821,15 +821,15 @@ exports["test Textarea OnSelect Listener on document reload"] = function(assert,
selection.once("select", function() {
assert.equal(selection.text, "noodles");
close();
loader.unload();
done();
});
open(URL).
then(reload).
then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(loader.unload, assert.fail);
then(dispatchOnSelectEvent, assert.fail);
};
exports["test Selection Listener on frame"] = function(assert, done) {
@ -884,7 +884,7 @@ exports["test PBPW Selection Listener"] = function(assert, done) {
open(URL, {private: true}).
then(selectContentFirstDiv).
then(dispatchSelectionEvent).
then(close).
then(closeWindow).
then(loader.unload).
then(done, assert.fail);
};
@ -902,7 +902,7 @@ exports["test PBPW Textarea OnSelect Listener"] = function(assert, done) {
open(URL, {private: true}).
then(selectTextarea).
then(dispatchOnSelectEvent).
then(close).
then(closeWindow).
then(loader.unload).
then(done, assert.fail);
};
@ -931,7 +931,7 @@ exports["test PBPW Single DOM Selection"] = function(assert, done) {
"No iterable selection in PBPW");
return window;
}).then(close).then(loader.unload).then(done, assert.fail);
}).then(closeWindow).then(loader.unload).then(done, assert.fail);
};
exports["test PBPW Textarea Selection"] = function(assert, done) {
@ -964,7 +964,7 @@ exports["test PBPW Textarea Selection"] = function(assert, done) {
"No iterable selection in PBPW");
return window;
}).then(close).then(loader.unload).then(done, assert.fail);
}).then(closeWindow).then(loader.unload).then(done, assert.fail);
};
// TODO: test Selection Listener on long-held connection (Bug 661884)

View File

@ -172,4 +172,4 @@ exports["test modelFor(xulTab)"] = (assert, done) => {
});
};
require("test").run(exports);
require("sdk/test").run(exports);

View File

@ -563,33 +563,34 @@ exports.testDestroyEdgeCaseBug = function(assert, done) {
sidebar.show();
assert.pass('showing the sidebar');
});
});
}
exports.testClickingACheckedMenuitem = function(assert, done) {
const { Sidebar } = require('sdk/ui/sidebar');
let testName = 'testClickingACheckedMenuitem';
let window = getMostRecentBrowserWindow();
const testName = 'testClickingACheckedMenuitem';
let sidebar = Sidebar({
id: testName,
title: testName,
url: 'data:text/html;charset=utf-8,'+testName,
});
assert.pass('sidebar was created');
sidebar.show().then(function() {
assert.pass('the show callback works');
open().then(focus).then(window => {
return sidebar.show().then(_ => {
assert.pass('the show callback works');
sidebar.once('hide', function() {
assert.pass('clicking the menuitem after the sidebar has shown hides it.');
sidebar.destroy();
done();
sidebar.once('hide', _ => {
assert.pass('clicking the menuitem after the sidebar has shown hides it.');
sidebar.destroy();
close(window).then(done, assert.fail);
});
let menuitem = window.document.getElementById(makeID(sidebar.id));
simulateCommand(menuitem);
});
let menuitem = window.document.getElementById(makeID(sidebar.id));
simulateCommand(menuitem);
});
}).catch(assert.fail);
};
exports.testTitleSetter = function(assert, done) {

View File

@ -90,37 +90,30 @@ exports['test close on unload'] = function(assert) {
};
exports.testWindowTracker = function(assert, done) {
var myWindow;
var finished = false;
var myWindow = makeEmptyWindow();
assert.pass('window was created');
var delegate = {
onTrack: function(window) {
if (window == myWindow) {
assert.pass("onTrack() called with our test window");
timer.setTimeout(function() myWindow.close());
}
},
onUntrack: function(window) {
if (window == myWindow) {
assert.pass("onUntrack() called with our test window");
timer.setTimeout(function() {
if (!finished) {
finished = true;
myWindow = null;
wt.unload();
done();
}
else {
assert.fail("finishTest() called multiple times.");
}
});
}
}
};
myWindow.addEventListener("load", function onload() {
myWindow.removeEventListener("load", onload, false);
assert.pass("test window has opened");
// test bug 638007 (new is optional), using new
var wt = new windowUtils.WindowTracker(delegate);
myWindow = makeEmptyWindow();
// test bug 638007 (new is optional), using new
var wt = new windowUtils.WindowTracker({
onTrack: window => {
if (window === myWindow) {
assert.pass("onTrack() called with our test window");
close(window);
}
},
onUntrack: window => {
if (window === myWindow) {
assert.pass("onUntrack() called with our test window");
wt.unload();
timer.setTimeout(done);
}
}
});
}, false);
};
exports['test window watcher untracker'] = function(assert, done) {