Backed out changeset 116c5049e8f4 (bug 941933) for Jetpack SDK perma orange failure

This commit is contained in:
Carsten "Tomcat" Book 2013-11-22 08:20:22 +01:00
parent 33ae087ede
commit d515499caf
22 changed files with 147 additions and 627 deletions

View File

@ -89,7 +89,7 @@ to support private browsing, refer to the
var utils = require('sdk/window/utils');
var browserWindow = utils.getMostRecentBrowserWindow();
var window = browserWindow.content; // `window` object for the current webpage
utils.getToplevelWindow(window) == browserWindow // => true
utils.getToplevelWindw(window) == browserWindow // => true
@param window {nsIDOMWindow}
@returns {nsIDOMWindow}

View File

@ -137,14 +137,6 @@ const ContentWorker = Object.freeze({
registerMethod = chromeSetInterval;
else
throw new Error("Unknown timer kind: " + timer.kind);
if (typeof timer.fun == 'string') {
let code = timer.fun;
timer.fun = () => chromeAPI.sandbox.evaluate(exports, code);
} else if (typeof timer.fun != 'function') {
throw new Error('Unsupported callback type' + typeof timer.fun);
}
let id = registerMethod(onFire, timer.delay);
function onFire() {
try {
@ -153,47 +145,12 @@ const ContentWorker = Object.freeze({
timer.fun.apply(null, timer.args);
} catch(e) {
console.exception(e);
let wrapper = {
instanceOfError: instanceOf(e, Error),
value: e,
};
if (wrapper.instanceOfError) {
wrapper.value = {
message: e.message,
fileName: e.fileName,
lineNumber: e.lineNumber,
stack: e.stack,
name: e.name,
};
}
pipe.emit('error', wrapper);
}
}
_timers[id] = timer;
return id;
}
// copied from sdk/lang/type.js since modules are not available here
function instanceOf(value, Type) {
var isConstructorNameSame;
var isConstructorSourceSame;
// If `instanceof` returned `true` we know result right away.
var isInstanceOf = value instanceof Type;
// If `instanceof` returned `false` we do ducktype check since `Type` may be
// from a different sandbox. If a constructor of the `value` or a constructor
// of the value's prototype has same name and source we assume that it's an
// instance of the Type.
if (!isInstanceOf && value) {
isConstructorNameSame = value.constructor.name === Type.name;
isConstructorSourceSame = String(value.constructor) == String(Type);
isInstanceOf = (isConstructorNameSame && isConstructorSourceSame) ||
instanceOf(Object.getPrototypeOf(value), Type);
}
return isInstanceOf;
}
function unregisterTimer(id) {
if (!(id in _timers))
return;

View File

@ -13,7 +13,6 @@ const { validateOptions } = require('../deprecated/api-utils');
const { isValidURI, URL } = require('../url');
const file = require('../io/file');
const { contract } = require('../util/contract');
const { isString, instanceOf } = require('../lang/type');
const LOCAL_URI_SCHEMES = ['resource', 'data'];
@ -33,7 +32,7 @@ const valid = {
msg: 'The `contentURL` option must be a valid URL.'
},
contentScriptFile: {
is: ['undefined', 'null', 'string', 'array', 'object'],
is: ['undefined', 'null', 'string', 'array'],
map: ensureNull,
ok: function(value) {
if (value === null)
@ -41,13 +40,8 @@ const valid = {
value = [].concat(value);
// Make sure every item is a string or an
// URL instance, and also a local file URL.
// Make sure every item is a local file URL.
return value.every(function (item) {
if (!isString(item) && !(item instanceof URL))
return false;
try {
return ~LOCAL_URI_SCHEMES.indexOf(URL(item).scheme);
}

View File

@ -108,27 +108,6 @@ const Symbiont = Worker.resolve({
this._frame = frame;
if (getDocShell(frame)) {
this._reallyInitFrame(frame);
}
else {
if (this._waitForFrame) {
observers.remove('content-document-global-created', this._waitForFrame);
}
this._waitForFrame = this.__waitForFrame.bind(this, frame);
observers.add('content-document-global-created', this._waitForFrame);
}
},
__waitForFrame: function _waitForFrame(frame, win, topic) {
if (frame.contentWindow == win) {
observers.remove('content-document-global-created', this._waitForFrame);
delete this._waitForFrame;
this._reallyInitFrame(frame);
}
},
_reallyInitFrame: function _reallyInitFrame(frame) {
getDocShell(frame).allowJavascript = this.allow.script;
frame.setAttribute("src", this._contentURL);
@ -200,11 +179,6 @@ const Symbiont = Worker.resolve({
* This listener is registered in `Symbiont._initFrame`.
*/
_unregisterListener: function _unregisterListener() {
if (this._waitForFrame) {
observers.remove('content-document-global-created', this._waitForFrame);
delete this._waitForFrame;
}
if (!this._loadListener)
return;
if (this._loadEvent == "start") {

View File

@ -202,15 +202,8 @@ const WorkerSandbox = EventEmitter.compose({
clearInterval: 'r'
}
},
sandbox: {
evaluate: evaluate,
__exposedProps__: {
evaluate: 'r',
}
},
__exposedProps__: {
timers: 'r',
sandbox: 'r',
timers: 'r'
}
};
let onEvent = this._onContentEvent.bind(this);
@ -240,19 +233,6 @@ const WorkerSandbox = EventEmitter.compose({
self._addonWorker._onContentScriptEvent.apply(self._addonWorker, arguments);
});
// unwrap, recreate and propagate async Errors thrown from content-script
this.on("error", function onError({instanceOfError, value}) {
if (self._addonWorker) {
let error = value;
if (instanceOfError) {
error = new Error(value.message, value.fileName, value.lineNumber);
error.stack = value.stack;
error.name = value.name;
}
self._addonWorker._emit('error', error);
}
});
// Inject `addon` global into target document if document is trusted,
// `addon` in document is equivalent to `self` in content script.
if (worker._injectInDocument) {

View File

@ -36,7 +36,7 @@ const observers = function observers(target, type) {
* The listener function that processes the event.
*/
function on(target, type, listener) {
if (typeof(listener) !== 'function')
if (typeof(listener) !== 'function')
throw new Error(BAD_LISTENER);
let listeners = observers(target, type);
@ -56,9 +56,9 @@ exports.on = on;
* The listener function that processes the event.
*/
function once(target, type, listener) {
on(target, type, function observer(...args) {
on(target, type, function observer() {
off(target, type, observer);
listener.apply(target, args);
listener.apply(target, arguments);
});
}
exports.once = once;
@ -74,24 +74,40 @@ exports.once = once;
* Event target object.
* @param {String} type
* The type of event.
* @params {Object|Number|String|Boolean} args
* Arguments that will be passed to listeners.
* @params {Object|Number|String|Boolean} message
* First argument that will be passed to listeners.
* @params {Object|Number|String|Boolean} ...
* More arguments that will be passed to listeners.
*/
function emit (target, type, ...args) {
function emit(target, type, message /*, ...*/) {
for each (let item in emit.lazy.apply(emit.lazy, arguments)) {
// We just iterate, iterator take care of emitting events.
}
}
/**
* This is very experimental feature that you should not use unless absolutely
* need it. Also it may be removed at any point without any further notice.
*
* Creates lazy iterator of return values of listeners. You can think of it
* as lazy array of return values of listeners for the `emit` with the given
* arguments.
*/
emit.lazy = function lazy(target, type, message /*, ...*/) {
let args = Array.slice(arguments, 2);
let state = observers(target, type);
let listeners = state.slice();
let count = listeners.length;
let index = 0;
let count = listeners.length;
// If error event and there are no handlers then print error message
// into a console.
if (count === 0 && type === 'error') console.exception(args[0]);
if (count === 0 && type === 'error') console.exception(message);
while (index < count) {
try {
let listener = listeners[index];
// Dispatch only if listener is still registered.
if (~state.indexOf(listener))
listener.apply(target, args);
if (~state.indexOf(listener)) yield listener.apply(target, args);
}
catch (error) {
// If exception is not thrown by a error listener and error listener is
@ -99,10 +115,8 @@ function emit (target, type, ...args) {
if (type !== 'error') emit(target, 'error', error);
else console.exception(error);
}
index++;
index = index + 1;
}
// Also emit on `"*"` so that one could listen for all events.
if (type !== '*') emit(target, '*', type, ...args);
}
exports.emit = emit;
@ -131,7 +145,7 @@ function off(target, type, listener) {
}
else if (length === 1) {
let listeners = event(target);
Object.keys(listeners).forEach(type => delete listeners[type]);
Object.keys(listeners).forEach(function(type) delete listeners[type]);
}
}
exports.off = off;
@ -157,7 +171,7 @@ exports.count = count;
* Dictionary of listeners.
*/
function setListeners(target, listeners) {
Object.keys(listeners || {}).forEach(key => {
Object.keys(listeners || {}).forEach(function onEach(key) {
let match = EVENT_TYPE_PATTERN.exec(key);
let type = match && match[1].toLowerCase();
let listener = listeners[key];

View File

@ -11,10 +11,6 @@ module.metadata = {
const { Cc, Ci, Cr } = require("chrome");
const apiUtils = require("./deprecated/api-utils");
const errors = require("./deprecated/errors");
const { isString, isUndefined, instanceOf } = require('./lang/type');
const { URL } = require('./url');
const NOTIFICATION_DIRECTIONS = ["auto", "ltr", "rtl"];
try {
let alertServ = Cc["@mozilla.org/alerts-service;1"].
@ -40,7 +36,7 @@ exports.notify = function notifications_notify(options) {
};
function notifyWithOpts(notifyFn) {
notifyFn(valOpts.iconURL, valOpts.title, valOpts.text, !!clickObserver,
valOpts.data, clickObserver, valOpts.tag, valOpts.dir, valOpts.lang);
valOpts.data, clickObserver);
}
try {
notifyWithOpts(notify);
@ -70,32 +66,15 @@ function validateOptions(options) {
is: ["string", "undefined"]
},
iconURL: {
is: ["string", "undefined", "object"],
ok: function(value) {
return isUndefined(value) || isString(value) || (value instanceof URL);
},
msg: "`iconURL` must be a string or an URL instance."
is: ["string", "undefined"]
},
onClick: {
is: ["function", "undefined"]
},
text: {
is: ["string", "undefined", "number"]
is: ["string", "undefined"]
},
title: {
is: ["string", "undefined", "number"]
},
tag: {
is: ["string", "undefined", "number"]
},
dir: {
is: ["string", "undefined"],
ok: function(value) {
return isUndefined(value) || ~NOTIFICATION_DIRECTIONS.indexOf(value);
},
msg: '`dir` option must be one of: "auto", "ltr" or "rtl".'
},
lang: {
is: ["string", "undefined"]
}
});

View File

@ -130,10 +130,6 @@ const Request = Class({
request(this).contentType = validateSingleOption('contentType', value);
},
get response() { return request(this).response; },
delete: function() {
runRequest('DELETE', this);
return this;
},
get: function() {
runRequest('GET', this);
return this;

View File

@ -13,7 +13,6 @@ const { activateTab, getTabTitle, setTabTitle, closeTab, getTabURL, getTabConten
const { emit } = require('../event/core');
const { getOwnerWindow: getPBOwnerWindow } = require('../private-browsing/window/utils');
const { when: unload } = require('../system/unload');
const { viewFor } = require('../event/core');
const { EVENTS } = require('./events');
const ERR_FENNEC_MSG = 'This method is not yet supported by Fennec';
@ -34,7 +33,7 @@ const Tab = Class({
// TabReady
let onReady = tabInternals.onReady = onTabReady.bind(this);
tab.browser.addEventListener(EVENTS.ready.dom, onReady, false);
let onPageShow = tabInternals.onPageShow = onTabPageShow.bind(this);
tab.browser.addEventListener(EVENTS.pageshow.dom, onPageShow, false);
@ -177,10 +176,6 @@ const Tab = Class({
});
exports.Tab = Tab;
// Implement `viewFor` polymorphic function for the Tab
// instances.
viewFor.define(Tab, x => tabNS(x).tab);
function cleanupTab(tab) {
let tabInternals = tabNS(tab);
if (!tabInternals.tab)

View File

@ -13,10 +13,9 @@ 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 viewNS = require('../core/namespace').ns();
const { deprecateUsage } = require('../util/deprecate');
const { getURL } = require('../url/utils');
const { viewFor } = require('../view/core');
const viewNS = require('sdk/core/namespace').ns();
const { deprecateUsage } = require('sdk/util/deprecate');
const { getURL } = require('sdk/url/utils');
// Array of the inner instances of all the wrapped tabs.
const TABS = [];
@ -65,7 +64,6 @@ const TabTrait = Trait.compose(EventEmitter, {
viewNS(this._public).tab = this._tab;
getPBOwnerWindow.implement(this._public, getChromeTab);
viewFor.implement(this._public, getTabView);
// Add tabs to getURL method
getURL.implement(this._public, (function (obj) this._public.url).bind(this));
@ -99,7 +97,7 @@ const TabTrait = Trait.compose(EventEmitter, {
if (event.target == this._contentDocument)
this._emit(EVENTS.ready.name, this._public);
},
/**
* Internal listener that emits public event 'load' when the page of this
* tab is loaded, for triggering on non-HTML content, bug #671305
@ -274,10 +272,6 @@ function getChromeTab(tab) {
return getOwnerWindow(viewNS(tab).tab);
}
// Implement `viewFor` polymorphic function for the Tab
// instances.
const getTabView = tab => viewNS(tab).tab;
function Tab(options, existingOnly) {
let chromeTab = options.tab;
for each (let tab in TABS) {

View File

@ -16,9 +16,13 @@ var method = require("method/core");
// it returns `null`. You can implement this method for
// this type to define what the result should be for it.
let getNodeView = method("getNodeView");
getNodeView.define(x => x instanceof Ci.nsIDOMNode ? x : null);
getNodeView.define(function(value) {
if (value instanceof Ci.nsIDOMNode)
return value;
return null;
});
exports.getNodeView = getNodeView;
exports.viewFor = getNodeView;
let getActiveView = method("getActiveView");
exports.getActiveView = getActiveView;

View File

@ -26,8 +26,6 @@ const ERR_CONTENT = "No content or contentURL property found. Widgets must "
"position.",
ERR_DESTROYED = "The widget has been destroyed and can no longer be used.";
const INSERTION_PREF_ROOT = "extensions.sdk-widget-inserted.";
// Supported events, mapping from DOM event names to our event names
const EVENTS = {
"click": "click",
@ -35,11 +33,6 @@ const EVENTS = {
"mouseout": "mouseout",
};
// In the Australis menu panel, normally widgets should be treated like
// normal toolbarbuttons. If they're any wider than this margin, we'll
// treat them as wide widgets instead, which fill up the width of the panel:
const AUSTRALIS_PANEL_WIDE_WIDGET_CUTOFF = 70;
const { validateOptions } = require("./deprecated/api-utils");
const panels = require("./panel");
const { EventEmitter, EventEmitterTrait } = require("./deprecated/events");
@ -52,8 +45,8 @@ const { WindowTracker } = require("./deprecated/window-utils");
const { isBrowser } = require("./window/utils");
const { setTimeout } = require("./timers");
const unload = require("./system/unload");
const { uuid } = require("./util/uuid");
const { getNodeView } = require("./view/core");
const prefs = require('./preferences/service');
// Data types definition
const valid = {
@ -222,13 +215,6 @@ let model = {
};
function saveInserted(widgetId) {
prefs.set(INSERTION_PREF_ROOT + widgetId, true);
}
function haveInserted(widgetId) {
return prefs.has(INSERTION_PREF_ROOT + widgetId);
}
/**
* Main Widget class: entry point of the widget API
@ -569,9 +555,6 @@ let browserManager = {
let idx = this.items.indexOf(item);
if (idx > -1)
this.items.splice(idx, 1);
},
propagateCurrentset: function browserManager_propagateCurrentset(id, currentset) {
this.windows.forEach(function (w) w.doc.getElementById(id).setAttribute("currentset", currentset));
}
};
@ -622,14 +605,36 @@ BrowserWindow.prototype = {
if (this.window.CustomizableUI) {
let placement = this.window.CustomizableUI.getPlacementOfWidget(node.id);
if (!placement) {
if (haveInserted(node.id)) {
return;
}
placement = {area: 'nav-bar', position: undefined};
saveInserted(node.id);
}
this.window.CustomizableUI.addWidgetToArea(node.id, placement.area, placement.position);
this.window.CustomizableUI.ensureWidgetPlacedInWindow(node.id, this.window);
// Depending on when this gets called, we might be in the right place now. In that case,
// don't run the following code.
if (node.parentNode != palette) {
return;
}
// Otherwise, insert:
let container = this.doc.getElementById(placement.area);
if (container.customizationTarget) {
container = container.customizationTarget;
}
if (placement.position !== undefined) {
// Find a position:
let items = this.window.CustomizableUI.getWidgetIdsInArea(placement.area);
let itemIndex = placement.position;
for (let l = items.length; itemIndex < l; itemIndex++) {
let realItems = container.getElementsByAttribute("id", items[itemIndex]);
if (realItems[0]) {
container.insertBefore(node, realItems[0]);
break;
}
}
}
if (node.parentNode != container) {
container.appendChild(node);
}
return;
}
@ -645,14 +650,10 @@ BrowserWindow.prototype = {
}
// if widget isn't in any toolbar, add it to the addon-bar
let needToPropagateCurrentset = false;
// TODO: we may want some "first-launch" module to do this only on very
// first execution
if (!container) {
if (haveInserted(node.id)) {
return;
}
container = this.doc.getElementById("addon-bar");
saveInserted(node.id);
needToPropagateCurrentset = true;
// TODO: find a way to make the following code work when we use "cfx run":
// http://mxr.mozilla.org/mozilla-central/source/browser/base/content/browser.js#8586
// until then, force display of addon bar directly from sdk code
@ -683,11 +684,9 @@ BrowserWindow.prototype = {
// Otherwise, this code will collide with other instance of Widget module
// during Firefox startup. See bug 685929.
if (ids.indexOf(id) == -1) {
let set = container.currentSet;
container.setAttribute("currentset", set);
container.setAttribute("currentset", container.currentSet);
// Save DOM attribute in order to save position on new window opened
this.window.document.persist(container.id, "currentset");
browserManager.propagateCurrentset(container.id, set);
}
}
}
@ -737,6 +736,7 @@ WidgetChrome.prototype.update = function WC_update(updatedItem, property, value)
WidgetChrome.prototype._createNode = function WC__createNode() {
// XUL element container for widget
let node = this._doc.createElement("toolbaritem");
let guid = String(uuid());
// Temporary work around require("self") failing on unit-test execution ...
let jetpackID = "testID";
@ -753,14 +753,6 @@ WidgetChrome.prototype._createNode = function WC__createNode() {
// Bug 626326: Prevent customize toolbar context menu to appear
node.setAttribute("context", "");
// For use in styling by the browser
node.setAttribute("sdkstylewidget", "true");
// Mark wide widgets as such:
if (this.window.CustomizableUI &&
this._widget.width > AUSTRALIS_PANEL_WIDE_WIDGET_CUTOFF) {
node.classList.add("panel-wide-item");
}
// TODO move into a stylesheet, configurable by consumers.
// Either widget.style, exposing the style object, or a URL
// (eg, can load local stylesheet file).
@ -792,13 +784,6 @@ WidgetChrome.prototype.fill = function WC_fill() {
// until the node is attached to a document.
this.node.appendChild(iframe);
var label = this._doc.createElement("label");
label.setAttribute("value", this._widget.label);
label.className = "toolbarbutton-text";
label.setAttribute("crop", "right");
label.setAttribute("flex", "1");
this.node.appendChild(label);
// add event handlers
this.addEventHandlers();

View File

@ -76,6 +76,9 @@ function Worker(options) {
["pageshow", "pagehide", "detach", "message", "error"].forEach(function(key) {
trait.on(key, function() {
emit.apply(emit, [worker, key].concat(Array.slice(arguments)));
// Workaround lack of ability to listen on all events by emulating
// such ability. This will become obsolete once Bug 821065 is fixed.
emit.apply(emit, [worker, "*", key].concat(Array.slice(arguments)));
});
});
traits.set(worker, trait);

View File

@ -6,7 +6,6 @@
const { Loader } = require('sdk/content/loader');
const self = require("sdk/self");
const fixtures = require("./fixtures");
const { URL } = require('sdk/url');
exports['test:contentURL'] = function(assert) {
let loader = Loader(),
@ -205,28 +204,6 @@ exports['test:contentScriptFile'] = function(assert) {
);
}
let data = 'data:text/html,test';
try {
loader.contentScriptFile = [ { toString: () => data } ];
test.fail('must throw when non-URL object is set');
} catch(e) {
assert.equal(
'The `contentScriptFile` option must be a local URL or an array of URLs.',
e.message
);
}
loader.contentScriptFile = new URL(data);
assert.ok(
loader.contentScriptFile instanceof URL,
'must be able to set `contentScriptFile` to an instance of URL'
);
assert.equal(
data,
loader.contentScriptFile.toString(),
'setting `contentScriptFile` to an instance of URL should preserve the url'
);
loader.contentScriptFile = undefined;
assert.equal(
null,

View File

@ -17,10 +17,6 @@ const { LoaderWithHookedConsole } = require("sdk/test/loader");
const { Worker } = require("sdk/content/worker");
const { close } = require("sdk/window/helpers");
const { set: setPref } = require("sdk/preferences/service");
const { isArray } = require("sdk/lang/type");
const { URL } = require('sdk/url');
const fixtures = require("./fixtures");
const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings";
const DEFAULT_CONTENT_URL = "data:text/html;charset=utf-8,foo";
@ -400,116 +396,8 @@ exports["test:ensure console.xxx works in cs"] = WorkerTest(
}
);
exports["test:setTimeout works with string argument"] = WorkerTest(
"data:text/html;charset=utf-8,<script>var docVal=5;</script>",
function(assert, browser, done) {
let worker = Worker({
window: browser.contentWindow,
contentScript: "new " + function ContentScriptScope() {
// must use "window.scVal" instead of "var csVal"
// since we are inside ContentScriptScope function.
// i'm NOT putting code-in-string inside code-in-string </YO DAWG>
window.csVal = 13;
setTimeout("self.postMessage([" +
"csVal, " +
"window.docVal, " +
"'ContentWorker' in window, " +
"'UNWRAP_ACCESS_KEY' in window, " +
"'getProxyForObject' in window, " +
"])", 1);
},
contentScriptWhen: "ready",
onMessage: function([csVal, docVal, chrome1, chrome2, chrome3]) {
// test timer code is executed in the correct context
assert.equal(csVal, 13, "accessing content-script values");
assert.notEqual(docVal, 5, "can't access document values (directly)");
assert.ok(!chrome1 && !chrome2 && !chrome3, "nothing is leaked from chrome");
done();
}
});
}
);
exports["test:setInterval works with string argument"] = WorkerTest(
DEFAULT_CONTENT_URL,
function(assert, browser, done) {
let count = 0;
let worker = Worker({
window: browser.contentWindow,
contentScript: "setInterval('self.postMessage(1)', 50)",
contentScriptWhen: "ready",
onMessage: function(one) {
count++;
assert.equal(one, 1, "got " + count + " message(s) from setInterval");
if (count >= 3) done();
}
});
}
);
exports["test:setInterval async Errors passed to .onError"] = WorkerTest(
DEFAULT_CONTENT_URL,
function(assert, browser, done) {
let count = 0;
let worker = Worker({
window: browser.contentWindow,
contentScript: "setInterval(() => { throw Error('ubik') }, 50)",
contentScriptWhen: "ready",
onError: function(err) {
count++;
assert.equal(err.message, "ubik",
"error (corectly) propagated " + count + " time(s)");
if (count >= 3) done();
}
});
}
);
exports["test:setTimeout throws array, passed to .onError"] = WorkerTest(
DEFAULT_CONTENT_URL,
function(assert, browser, done) {
let worker = Worker({
window: browser.contentWindow,
contentScript: "setTimeout(function() { throw ['array', 42] }, 1)",
contentScriptWhen: "ready",
onError: function(arr) {
assert.ok(isArray(arr),
"the type of thrown/propagated object is array");
assert.ok(arr.length==2,
"the propagated thrown array is the right length");
assert.equal(arr[1], 42,
"element inside the thrown array correctly propagated");
done();
}
});
}
);
exports["test:setTimeout string arg with SyntaxError to .onError"] = WorkerTest(
DEFAULT_CONTENT_URL,
function(assert, browser, done) {
let worker = Worker({
window: browser.contentWindow,
contentScript: "setTimeout('syntax 123 error', 1)",
contentScriptWhen: "ready",
onError: function(err) {
assert.equal(err.name, "SyntaxError",
"received SyntaxError thrown from bad code in string argument to setTimeout");
assert.ok('fileName' in err,
"propagated SyntaxError contains a fileName property");
assert.ok('stack' in err,
"propagated SyntaxError contains a stack property");
assert.equal(err.message, "missing ; before statement",
"propagated SyntaxError has the correct (helpful) message");
assert.equal(err.lineNumber, 1,
"propagated SyntaxError was thrown on the right lineNumber");
done();
}
});
}
);
exports["test:setTimeout can't be cancelled by content"] = WorkerTest(
exports["test:setTimeout can\"t be cancelled by content"] = WorkerTest(
"data:text/html;charset=utf-8,<script>var documentValue=true;</script>",
function(assert, browser, done) {
@ -812,21 +700,4 @@ exports["test:global postMessage"] = WorkerTest(
}
);
exports['test:conentScriptFile as URL instance'] = WorkerTest(
DEFAULT_CONTENT_URL,
function(assert, browser, done) {
let url = new URL(fixtures.url("test-contentScriptFile.js"));
let worker = Worker({
window: browser.contentWindow,
contentScriptFile: url,
onMessage: function(msg) {
assert.equal(msg, "msg from contentScriptFile",
"received a wrong message from contentScriptFile");
done();
}
});
}
);
require("test").run(exports);

View File

@ -222,24 +222,23 @@ exports['test count'] = function(assert) {
assert.equal(count(target, 'foo'), 0, 'listeners unregistered');
};
exports['test listen to all events'] = function(assert) {
let actual = [];
let target = {};
exports['test emit.lazy'] = function(assert) {
let target = {}, boom = Error('boom!'), errors = [], actual = []
on(target, 'foo', message => actual.push(message));
on(target, '*', (type, ...message) => {
actual.push([type].concat(message));
});
emit(target, 'foo', 'hello');
assert.equal(actual[0], 'hello',
'non-wildcard listeners still work');
assert.deepEqual(actual[1], ['foo', 'hello'],
'wildcard listener called');
on(target, 'error', function error(e) errors.push(e))
emit(target, 'bar', 'goodbye');
assert.deepEqual(actual[2], ['bar', 'goodbye'],
'wildcard listener called for unbound event name');
on(target, 'a', function() 1);
on(target, 'a', function() {});
on(target, 'a', function() 2);
on(target, 'a', function() { throw boom });
on(target, 'a', function() 3);
for each (let value in emit.lazy(target, 'a'))
actual.push(value);
assert.deepEqual(actual, [ 1, undefined, 2, 3 ],
'all results were collected');
assert.deepEqual(errors, [ boom ], 'errors reporetd');
};
require('test').run(exports);

View File

@ -5,7 +5,7 @@
'use strict';
const { on, emit } = require("sdk/event/core");
const { filter, map, merge, expand, pipe } = require("sdk/event/utils");
const { filter, map, merge, expand } = require("sdk/event/utils");
const $ = require("./event/helpers");
function isEven(x) !(x % 2)
@ -163,96 +163,7 @@ exports["test expand"] = function(assert) {
assert.deepEqual(actual, ["a1", "b1", "a2", "c1", "c2", "b2", "a3"],
"all inputs data merged into one");
};
}
exports["test pipe"] = function (assert, done) {
let src = {};
let dest = {};
let aneventCount = 0, multiargsCount = 0;
let wildcardCount = {};
on(dest, 'an-event', arg => {
assert.equal(arg, 'my-arg', 'piped argument to event');
++aneventCount;
check();
});
on(dest, 'multiargs', (...data) => {
assert.equal(data[0], 'a', 'multiple arguments passed via pipe');
assert.equal(data[1], 'b', 'multiple arguments passed via pipe');
assert.equal(data[2], 'c', 'multiple arguments passed via pipe');
++multiargsCount;
check();
});
on(dest, '*', (name, ...data) => {
wildcardCount[name] = (wildcardCount[name] || 0) + 1;
if (name === 'multiargs') {
assert.equal(data[0], 'a', 'multiple arguments passed via pipe, wildcard');
assert.equal(data[1], 'b', 'multiple arguments passed via pipe, wildcard');
assert.equal(data[2], 'c', 'multiple arguments passed via pipe, wildcard');
}
if (name === 'an-event')
assert.equal(data[0], 'my-arg', 'argument passed via pipe, wildcard');
check();
});
pipe(src, dest);
for (let i = 0; i < 3; i++)
emit(src, 'an-event', 'my-arg');
emit(src, 'multiargs', 'a', 'b', 'c');
function check () {
if (aneventCount === 3 && multiargsCount === 1 &&
wildcardCount['an-event'] === 3 &&
wildcardCount['multiargs'] === 1)
done();
}
};
exports["test pipe multiple targets"] = function (assert) {
let src1 = {};
let src2 = {};
let middle = {};
let dest = {};
pipe(src1, middle);
pipe(src2, middle);
pipe(middle, dest);
let middleFired = 0;
let destFired = 0;
let src1Fired = 0;
let src2Fired = 0;
on(src1, '*', () => src1Fired++);
on(src2, '*', () => src2Fired++);
on(middle, '*', () => middleFired++);
on(dest, '*', () => destFired++);
emit(src1, 'ev');
assert.equal(src1Fired, 1, 'event triggers in source in pipe chain');
assert.equal(middleFired, 1, 'event passes through the middle of pipe chain');
assert.equal(destFired, 1, 'event propagates to end of pipe chain');
assert.equal(src2Fired, 0, 'event does not fire on alternative chain routes');
emit(src2, 'ev');
assert.equal(src2Fired, 1, 'event triggers in source in pipe chain');
assert.equal(middleFired, 2,
'event passes through the middle of pipe chain from different src');
assert.equal(destFired, 2,
'event propagates to end of pipe chain from different src');
assert.equal(src1Fired, 1, 'event does not fire on alternative chain routes');
emit(middle, 'ev');
assert.equal(middleFired, 3,
'event triggers in source of pipe chain');
assert.equal(destFired, 3,
'event propagates to end of pipe chain from middle src');
assert.equal(src1Fired, 1, 'event does not fire on alternative chain routes');
assert.equal(src2Fired, 1, 'event does not fire on alternative chain routes');
};
require('test').run(exports);

View File

@ -24,53 +24,6 @@ exports.testOnClick = function (assert) {
loader.unload();
};
exports['test:numbers and URLs in options'] = function(assert) {
let [loader] = makeLoader(module);
let notifs = loader.require('sdk/notifications');
let opts = {
title: 123,
text: 45678,
// must use in-loader `sdk/url` module for the validation type check to work
iconURL: loader.require('sdk/url').URL('data:image/png,blah')
};
try {
notifs.notify(opts);
assert.pass('using numbers and URLs in options works');
} catch (e) {
assert.fail('using numbers and URLs in options must not throw');
}
loader.unload();
}
exports['test:new tag, dir and lang options'] = function(assert) {
let [loader] = makeLoader(module);
let notifs = loader.require('sdk/notifications');
let opts = {
title: 'best',
tag: 'tagging',
lang: 'en'
};
try {
opts.dir = 'ttb';
notifs.notify(opts);
assert.fail('`dir` option must not accept TopToBottom direction.');
} catch (e) {
assert.equal(e.message,
'`dir` option must be one of: "auto", "ltr" or "rtl".');
}
try {
opts.dir = 'rtl';
notifs.notify(opts);
assert.pass('`dir` option accepts "rtl" direction.');
} catch (e) {
assert.fail('`dir` option must accept "rtl" direction.');
}
loader.unload();
}
// Returns [loader, mockAlertService].
function makeLoader(module) {
let loader = Loader(module);

View File

@ -245,14 +245,15 @@ exports.testMultipleOnMessageCallbacks = function(assert, done) {
let page = Page({
contentScript: "self.postMessage('')",
contentScriptWhen: "end",
onMessage: () => count += 1
onMessage: function() count += 1
});
page.on('message', () => count += 2);
page.on('message', () => count *= 3);
page.on('message', () =>
page.on('message', function() count += 2);
page.on('message', function() count *= 3);
page.on('message', function()
assert.equal(count, 9, "All callbacks were called, in order."));
page.on('message', done);
};
page.on('message', function() done());
}
exports.testLoadContentPage = function(assert, done) {
let page = Page({

View File

@ -210,27 +210,6 @@ exports.testInvalidJSON = function (assert, done) {
});
};
exports.testDelete = function (assert, done) {
let srv = startServerAsync(port, basePath);
srv.registerPathHandler("/test-delete",
function handle(request, response) {
response.setHeader("Content-Type", "text/plain", false);
});
Request({
url: "http://localhost:" + port + "/test-delete",
onComplete: function (response) {
// We cannot access the METHOD of the request to verify it's set
// correctly.
assert.equal(response.text, "");
assert.equal(response.statusText, "OK");
assert.equal(response.headers["Content-Type"], "text/plain");
srv.stop(done);
}
}).delete();
};
exports.testHead = function (assert, done) {
let srv = startServerAsync(port, basePath);

View File

@ -7,8 +7,6 @@ const tabs = require("sdk/tabs"); // From addon-kit
const windowUtils = require("sdk/deprecated/window-utils");
const { getTabForWindow } = require('sdk/tabs/helpers');
const app = require("sdk/system/xul-app");
const { viewFor } = require("sdk/view/core");
const { getTabId } = require("sdk/tabs/utils");
// The primary test tab
var primaryTab;
@ -138,17 +136,4 @@ exports["test behavior on close"] = function(assert, done) {
});
};
exports["test viewFor(tab)"] = (assert, done) => {
tabs.once("open", tab => {
const view = viewFor(tab);
assert.ok(view, "view is returned");
assert.equal(getTabId(view), tab.id, "tab has a same id");
tab.close();
done();
});
tabs.open({ url: "about:mozilla" });
}
require("test").run(exports);

View File

@ -18,7 +18,6 @@ const self = require("sdk/self");
const windowUtils = require("sdk/deprecated/window-utils");
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const { close } = require("sdk/window/helpers");
const unload = require("sdk/system/unload");
const fixtures = require("./fixtures");
let jetpackID = "testID";
@ -52,7 +51,7 @@ exports.testConstructor = function(assert, done) {
// Test basic construct/destroy
AddonsMgrListener.onInstalling();
let w = widgets.Widget({ id: "basic-construct-destroy", label: "foo", content: "bar" });
let w = widgets.Widget({ id: "fooID", label: "foo", content: "bar" });
AddonsMgrListener.onInstalled();
assert.equal(widgetCount(), widgetStartCount + 1, "panel has correct number of child elements after widget construction");
@ -70,7 +69,7 @@ exports.testConstructor = function(assert, done) {
let loader = Loader(module);
let widgetsFromLoader = loader.require("sdk/widget");
let widgetStartCount = widgetCount();
let w = widgetsFromLoader.Widget({ id: "destroy-on-unload", label: "foo", content: "bar" });
let w = widgetsFromLoader.Widget({ id: "fooID", label: "foo", content: "bar" });
assert.equal(widgetCount(), widgetStartCount + 1, "widget has been correctly added");
loader.unload();
assert.equal(widgetCount(), widgetStartCount, "widget has been destroyed on module unload");
@ -95,25 +94,25 @@ exports.testConstructor = function(assert, done) {
// Test no content or image
assert.throws(
function() widgets.Widget({id: "no-content-throws", label: "foo"}),
function() widgets.Widget({id: "fooID", label: "foo"}),
/^No content or contentURL property found\. Widgets must have one or the other\.$/,
"throws on no content");
// Test empty content, no image
assert.throws(
function() widgets.Widget({id:"empty-content-throws", label: "foo", content: ""}),
function() widgets.Widget({id:"fooID", label: "foo", content: ""}),
/^No content or contentURL property found\. Widgets must have one or the other\.$/,
"throws on empty content");
// Test empty image, no content
assert.throws(
function() widgets.Widget({id:"empty-image-throws", label: "foo", image: ""}),
function() widgets.Widget({id:"fooID", label: "foo", image: ""}),
/^No content or contentURL property found\. Widgets must have one or the other\.$/,
"throws on empty content");
// Test empty content, empty image
assert.throws(
function() widgets.Widget({id:"empty-image-and-content-throws", label: "foo", content: "", image: ""}),
function() widgets.Widget({id:"fooID", label: "foo", content: "", image: ""}),
/^No content or contentURL property found. Widgets must have one or the other\.$/,
"throws on empty content");
@ -139,14 +138,14 @@ exports.testConstructor = function(assert, done) {
// Test position restore on create/destroy/create
// Create 3 ordered widgets
let w1 = widgets.Widget({id: "position-first", label:"first", content: "bar"});
let w2 = widgets.Widget({id: "position-second", label:"second", content: "bar"});
let w3 = widgets.Widget({id: "position-third", label:"third", content: "bar"});
let w1 = widgets.Widget({id: "first", label:"first", content: "bar"});
let w2 = widgets.Widget({id: "second", label:"second", content: "bar"});
let w3 = widgets.Widget({id: "third", label:"third", content: "bar"});
// Remove the middle widget
assert.equal(widgetNode(1).getAttribute("label"), "second", "second widget is the second widget inserted");
w2.destroy();
assert.equal(widgetNode(1).getAttribute("label"), "third", "second widget is removed, so second widget is now the third one");
w2 = widgets.Widget({id: "position-second", label:"second", content: "bar"});
w2 = widgets.Widget({id: "second", label:"second", content: "bar"});
assert.equal(widgetNode(1).getAttribute("label"), "second", "second widget is created again, at the same location");
// Cleanup this testcase
AddonsMgrListener.onUninstalling();
@ -161,14 +160,14 @@ exports.testConstructor = function(assert, done) {
let anotherWidgetsInstance = loader.require("sdk/widget");
assert.ok(container().collapsed, "UI is hidden when no widgets");
AddonsMgrListener.onInstalling();
let w1 = widgets.Widget({id: "ui-unhide", label: "foo", content: "bar"});
let w1 = widgets.Widget({id: "foo", label: "foo", content: "bar"});
// Ideally we would let AddonsMgrListener display the addon bar
// But, for now, addon bar is immediatly displayed by sdk code
// https://bugzilla.mozilla.org/show_bug.cgi?id=627484
assert.ok(!container().collapsed, "UI is already visible when we just added the widget");
AddonsMgrListener.onInstalled();
assert.ok(!container().collapsed, "UI become visible when we notify AddonsMgrListener about end of addon installation");
let w2 = anotherWidgetsInstance.Widget({id: "ui-stay-open", label: "bar", content: "foo"});
let w2 = anotherWidgetsInstance.Widget({id: "bar", label: "bar", content: "foo"});
assert.ok(!container().collapsed, "UI still visible when we add a second widget");
AddonsMgrListener.onUninstalling();
w1.destroy();
@ -215,7 +214,7 @@ exports.testConstructor = function(assert, done) {
// text widget
tests.push(function testTextWidget() testSingleWidget({
id: "text-single",
id: "text",
label: "text widget",
content: "oh yeah",
contentScript: "self.postMessage(document.body.innerHTML);",
@ -279,7 +278,7 @@ exports.testConstructor = function(assert, done) {
// event: onclick + content
tests.push(function testOnclickEventContent() testSingleWidget({
id: "click-content",
id: "click",
label: "click test widget - content",
content: "<div id='me'>foo</div>",
contentScript: "var evt = new MouseEvent('click', {button: 0});" +
@ -294,7 +293,7 @@ exports.testConstructor = function(assert, done) {
// event: onmouseover + content
tests.push(function testOnmouseoverEventContent() testSingleWidget({
id: "mouseover-content",
id: "mouseover",
label: "mouseover test widget - content",
content: "<div id='me'>foo</div>",
contentScript: "var evt = new MouseEvent('mouseover'); " +
@ -309,7 +308,7 @@ exports.testConstructor = function(assert, done) {
// event: onmouseout + content
tests.push(function testOnmouseoutEventContent() testSingleWidget({
id: "mouseout-content",
id: "mouseout",
label: "mouseout test widget - content",
content: "<div id='me'>foo</div>",
contentScript: "var evt = new MouseEvent('mouseout');" +
@ -324,7 +323,7 @@ exports.testConstructor = function(assert, done) {
// event: onclick + image
tests.push(function testOnclickEventImage() testSingleWidget({
id: "click-image",
id: "click",
label: "click test widget - image",
contentURL: fixtures.url("moz_favicon.ico"),
contentScript: "var evt = new MouseEvent('click'); " +
@ -339,7 +338,7 @@ exports.testConstructor = function(assert, done) {
// event: onmouseover + image
tests.push(function testOnmouseoverEventImage() testSingleWidget({
id: "mouseover-image",
id: "mouseover",
label: "mouseover test widget - image",
contentURL: fixtures.url("moz_favicon.ico"),
contentScript: "var evt = new MouseEvent('mouseover');" +
@ -354,7 +353,7 @@ exports.testConstructor = function(assert, done) {
// event: onmouseout + image
tests.push(function testOnmouseoutEventImage() testSingleWidget({
id: "mouseout-image",
id: "mouseout",
label: "mouseout test widget - image",
contentURL: fixtures.url("moz_favicon.ico"),
contentScript: "var evt = new MouseEvent('mouseout'); " +
@ -381,7 +380,7 @@ exports.testConstructor = function(assert, done) {
// test updating widget content
let loads = 0;
tests.push(function testUpdatingWidgetContent() testSingleWidget({
id: "content-updating",
id: "content",
label: "content update test widget",
content: "<div id='me'>foo</div>",
contentScript: "self.postMessage(1)",
@ -404,7 +403,7 @@ exports.testConstructor = function(assert, done) {
let url2 = "data:text/html;charset=utf-8,<body>nistel</body>";
tests.push(function testUpdatingContentURL() testSingleWidget({
id: "content-url-updating",
id: "content",
label: "content update test widget",
contentURL: url1,
contentScript: "self.postMessage(document.location.href);",
@ -427,7 +426,7 @@ exports.testConstructor = function(assert, done) {
// test tooltip
tests.push(function testTooltip() testSingleWidget({
id: "text-with-tooltip",
id: "text",
label: "text widget",
content: "oh yeah",
tooltip: "foo",
@ -457,7 +456,7 @@ exports.testConstructor = function(assert, done) {
// test updating widget tooltip
let updated = false;
tests.push(function testUpdatingTooltip() testSingleWidget({
id: "tooltip-updating",
id: "tooltip",
label: "tooltip update test widget",
tooltip: "foo",
content: "<div id='me'>foo</div>",
@ -473,7 +472,7 @@ exports.testConstructor = function(assert, done) {
// test allow attribute
tests.push(function testDefaultAllow() testSingleWidget({
id: "allow-default",
id: "allow",
label: "allow.script attribute",
content: "<script>document.title = 'ok';</script>",
contentScript: "self.postMessage(document.title)",
@ -485,7 +484,7 @@ exports.testConstructor = function(assert, done) {
}));
tests.push(function testExplicitAllow() testSingleWidget({
id: "allow-explicit",
id: "allow",
label: "allow.script attribute",
allow: {script: true},
content: "<script>document.title = 'ok';</script>",
@ -498,7 +497,7 @@ exports.testConstructor = function(assert, done) {
}));
tests.push(function testExplicitDisallow() testSingleWidget({
id: "allow-explicit-disallow",
id: "allow",
label: "allow.script attribute",
content: "<script>document.title = 'ok';</script>",
allow: {script: false},
@ -522,11 +521,11 @@ exports.testConstructor = function(assert, done) {
function widgetCount2() container() ? container().querySelectorAll('[id^="widget\:"]').length : 0;
let widgetStartCount2 = widgetCount2();
let w1Opts = {id:"first-multi-window", label: "first widget", content: "first content"};
let w1Opts = {id:"first", label: "first widget", content: "first content"};
let w1 = testSingleWidget(w1Opts);
assert.equal(widgetCount2(), widgetStartCount2 + 1, "2nd window has correct number of child elements after first widget");
let w2Opts = {id:"second-multi-window", label: "second widget", content: "second content"};
let w2Opts = {id:"second", label: "second widget", content: "second content"};
let w2 = testSingleWidget(w2Opts);
assert.equal(widgetCount2(), widgetStartCount2 + 2, "2nd window has correct number of child elements after second widget");
@ -543,7 +542,7 @@ exports.testConstructor = function(assert, done) {
tests.push(function testWindowClosing() {
// 1/ Create a new widget
let w1Opts = {
id:"first-win-closing",
id:"first",
label: "first widget",
content: "first content",
contentScript: "self.port.on('event', function () self.port.emit('event'))"
@ -596,7 +595,7 @@ exports.testConstructor = function(assert, done) {
});
});
if (false) {
if (!australis) {
tests.push(function testAddonBarHide() {
const tabBrowser = require("sdk/deprecated/tab-browser");
@ -615,13 +614,11 @@ exports.testConstructor = function(assert, done) {
assert.ok(container2().collapsed,
"2nd window starts with an hidden addon-bar");
let w1Opts = {id:"first-addonbar-hide", label: "first widget", content: "first content"};
let w1Opts = {id:"first", label: "first widget", content: "first content"};
let w1 = testSingleWidget(w1Opts);
assert.equal(widgetCount2(), widgetStartCount2 + 1,
"2nd window has correct number of child elements after" +
"widget creation");
assert.ok(!container().collapsed, "1st window has a visible addon-bar");
assert.ok(!container2().collapsed, "2nd window has a visible addon-bar");
w1.destroy();
assert.equal(widgetCount2(), widgetStartCount2,
"2nd window has correct number of child elements after" +
@ -640,7 +637,7 @@ exports.testConstructor = function(assert, done) {
// test widget.width
tests.push(function testWidgetWidth() testSingleWidget({
id: "text-test-width",
id: "text",
label: "test widget.width",
content: "test width",
width: 200,
@ -664,7 +661,7 @@ exports.testConstructor = function(assert, done) {
// test click handler not respond to right-click
let clickCount = 0;
tests.push(function testNoRightClick() testSingleWidget({
id: "right-click-content",
id: "click-content",
label: "click test widget - content",
content: "<div id='me'>foo</div>",
contentScript: // Left click
@ -765,7 +762,7 @@ exports.testWidgetMessaging = function testWidgetMessaging(assert, done) {
let origMessage = "foo";
const widgets = require("sdk/widget");
let widget = widgets.Widget({
id: "widget-messaging",
id: "foo",
label: "foo",
content: "<bar>baz</bar>",
contentScriptWhen: "end",
@ -785,7 +782,7 @@ exports.testWidgetMessaging = function testWidgetMessaging(assert, done) {
exports.testWidgetViews = function testWidgetViews(assert, done) {
const widgets = require("sdk/widget");
let widget = widgets.Widget({
id: "widget-views",
id: "foo",
label: "foo",
content: "<bar>baz</bar>",
contentScriptWhen: "ready",
@ -808,7 +805,7 @@ exports.testWidgetViewsUIEvents = function testWidgetViewsUIEvents(assert, done)
const widgets = require("sdk/widget");
let view = null;
let widget = widgets.Widget({
id: "widget-view-ui-events",
id: "foo",
label: "foo",
content: "<div id='me'>foo</div>",
contentScript: "var evt = new MouseEvent('click', {button: 0});" +
@ -833,7 +830,7 @@ exports.testWidgetViewsUIEvents = function testWidgetViewsUIEvents(assert, done)
exports.testWidgetViewsCustomEvents = function testWidgetViewsCustomEvents(assert, done) {
const widgets = require("sdk/widget");
let widget = widgets.Widget({
id: "widget-view-custom-events",
id: "foo",
label: "foo",
content: "<div id='me'>foo</div>",
contentScript: "self.port.emit('event', 'ok');",
@ -856,7 +853,7 @@ exports.testWidgetViewsTooltip = function testWidgetViewsTooltip(assert, done) {
const widgets = require("sdk/widget");
let widget = new widgets.Widget({
id: "widget-views-tooltip",
id: "foo",
label: "foo",
content: "foo"
});
@ -882,7 +879,7 @@ exports.testWidgetMove = function testWidgetMove(assert, done) {
let gotFirstReady = false;
let widget = widgets.Widget({
id: "widget-move",
id: "foo",
label: label,
content: "<bar>baz</bar>",
contentScriptWhen: "ready",
@ -950,7 +947,7 @@ exports.testWidgetWithPound = function testWidgetWithPound(assert, done) {
exports.testContentScriptOptionsOption = function(assert, done) {
let widget = require("sdk/widget").Widget({
id: "widget-script-options",
id: "fooz",
label: "fooz",
content: "fooz",
contentScript: "self.postMessage( [typeof self.options.d, self.options] );",
@ -1054,34 +1051,6 @@ exports.testSVGWidget = function(assert, done) {
});
};
exports.testReinsertion = function(assert, done) {
const WIDGETID = "test-reinsertion";
let windowUtils = require("sdk/deprecated/window-utils");
let browserWindow = windowUtils.activeBrowserWindow;
let widget = require("sdk/widget").Widget({
id: "test-reinsertion",
label: "test reinsertion",
content: "Test",
});
let realWidgetId = "widget:" + jetpackID + "-" + WIDGETID;
// Remove the widget:
if (australis) {
browserWindow.CustomizableUI.removeWidgetFromArea(realWidgetId);
} else {
let widget = browserWindow.document.getElementById(realWidgetId);
let container = widget.parentNode;
container.currentSet = container.currentSet.replace("," + realWidgetId, "");
container.setAttribute("currentset", container.currentSet);
container.ownerDocument.persist(container.id, "currentset");
}
const tabBrowser = require("sdk/deprecated/tab-browser");
tabBrowser.addTab("about:blank", { inNewWindow: true, onLoad: function(e) {
assert.equal(e.target.defaultView.document.getElementById(realWidgetId), null);
close(e.target.defaultView).then(done);
}});
};
if (!australis) {
exports.testNavigationBarWidgets = function testNavigationBarWidgets(assert, done) {
let w1 = widgets.Widget({id: "1st", label: "1st widget", content: "1"});