зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1131923 - Uplift Add-on SDK to Firefox a=me
This commit is contained in:
Родитель
7018bc3ed3
Коммит
20d887e8dd
|
@ -41,10 +41,9 @@ const ObserverDelegee = Class({
|
|||
this.delegate = delegate;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
const isObserver = iid.equals(Ci.nsIObserver);
|
||||
const isWeakReference = iid.equals(Ci.nsISupportsWeakReference);
|
||||
|
||||
if (!isObserver && !isWeakReference)
|
||||
if (!iid.equals(Ci.nsIObserver) &&
|
||||
!iid.equals(Ci.nsISupportsWeakReference) &&
|
||||
!iid.equals(Ci.nsISupports))
|
||||
throw Cr.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
return this;
|
||||
|
|
|
@ -295,6 +295,9 @@ let hides = filter(panelEvents, ({type}) => type === "popuphidden");
|
|||
let ready = filter(panelEvents, ({type, target}) =>
|
||||
getAttachEventType(modelFor(panelFor(target))) === type);
|
||||
|
||||
// Panel event emitted when the contents of the panel has been loaded.
|
||||
let readyToShow = filter(panelEvents, ({type}) => type === "DOMContentLoaded");
|
||||
|
||||
// Styles should be always added as soon as possible, and doesn't makes them
|
||||
// depends on `contentScriptWhen`
|
||||
let start = filter(panelEvents, ({type}) => type === "document-element-inserted");
|
||||
|
@ -317,6 +320,10 @@ on(ready, "data", ({target}) => {
|
|||
let window = domPanel.getContentDocument(target).defaultView;
|
||||
|
||||
workerFor(panel).attach(window);
|
||||
});
|
||||
|
||||
on(readyToShow, "data", ({target}) => {
|
||||
let panel = panelFor(target);
|
||||
|
||||
if (!modelFor(panel).ready) {
|
||||
modelFor(panel).ready = true;
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
const { create: makeFrame } = require("sdk/frame/utils");
|
||||
const { window } = require("sdk/addon/window");
|
||||
const { Loader } = require('sdk/test/loader');
|
||||
const loader = Loader(module);
|
||||
const Worker = loader.require("sdk/content/worker").Worker;
|
||||
|
||||
exports.testMembranelessMode = function(assert, done) {
|
||||
const loader = Loader(module);
|
||||
const Worker = loader.require("sdk/content/worker").Worker;
|
||||
|
||||
let url = "data:text/html;charset=utf-8," + encodeURIComponent(
|
||||
'<script>' +
|
||||
|
@ -48,13 +48,20 @@ exports.testMembranelessMode = function(assert, done) {
|
|||
done();
|
||||
}
|
||||
});
|
||||
worker.port.on("done", function () {
|
||||
|
||||
worker.port.on("done", () => {
|
||||
// cleanup
|
||||
element.parentNode.removeChild(element);
|
||||
worker.destroy();
|
||||
loader.unload();
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
worker.port.on("assert", function (data) {
|
||||
assert.ok(data.assertion, data.msg);
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ exports.testBufferMain = function (assert) {
|
|||
// invalid encoding for Buffer.toString
|
||||
assert.throws(() => {
|
||||
b.toString('invalid');
|
||||
}, TypeError, 'invalid encoding for Buffer.toString');
|
||||
}, RangeError, 'invalid encoding for Buffer.toString');
|
||||
|
||||
// try to toString() a 0-length slice of a buffer, both within and without the
|
||||
// valid buffer range
|
||||
|
@ -248,7 +248,7 @@ exports.testBufferWrite = function (assert) {
|
|||
|
||||
assert.throws(() => {
|
||||
b.write('test string', 0, 5, 'invalid');
|
||||
}, TypeError, 'invalid encoding with buffer write throws');
|
||||
}, RangeError, 'invalid encoding with buffer write throws');
|
||||
// try to write a 0-length string beyond the end of b
|
||||
assert.throws(function() {
|
||||
b.write('', 2048);
|
||||
|
|
|
@ -10,6 +10,7 @@ const {openWindow, closeWindow, openTab, closeTab,
|
|||
const {when} = require("sdk/dom/events");
|
||||
const {Item, Menu, Separator, Contexts, Readers } = require("sdk/context-menu@2");
|
||||
const prefs = require("sdk/preferences/service");
|
||||
const { before, after } = require('sdk/test/utils');
|
||||
|
||||
const testPageURI = require.resolve("./test-context-menu").replace(".js", ".html");
|
||||
|
||||
|
@ -1337,4 +1338,13 @@ if (require("@loader/options").isNative) {
|
|||
};
|
||||
}
|
||||
|
||||
before(exports, (name, assert) => {
|
||||
// Make sure Java doesn't activate
|
||||
prefs.set("plugin.state.java", 0);
|
||||
});
|
||||
|
||||
after(exports, (name, assert) => {
|
||||
prefs.reset("plugin.state.java");
|
||||
});
|
||||
|
||||
require("sdk/test").run(module.exports);
|
||||
|
|
|
@ -86,8 +86,9 @@ exports["test Panel API"] = test(function*(assert) {
|
|||
yield closeToolbox();
|
||||
|
||||
assert.equal(panel.readyState, "destroyed", "panel is destroyed");
|
||||
});
|
||||
|
||||
myTool.destroy();
|
||||
});
|
||||
|
||||
exports["test Panel communication"] = test(function*(assert) {
|
||||
const MyPanel = Class({
|
||||
|
@ -150,6 +151,7 @@ exports["test Panel communication"] = test(function*(assert) {
|
|||
yield closeToolbox();
|
||||
|
||||
assert.equal(panel.readyState, "destroyed", "panel is destroyed");
|
||||
myTool.destroy();
|
||||
});
|
||||
|
||||
exports["test communication with debuggee"] = test(function*(assert) {
|
||||
|
@ -233,6 +235,8 @@ exports["test communication with debuggee"] = test(function*(assert) {
|
|||
yield closeToolbox();
|
||||
|
||||
assert.equal(panel.readyState, "destroyed", "panel is destroyed");
|
||||
|
||||
myTool.destroy();
|
||||
});
|
||||
|
||||
|
||||
|
@ -267,6 +271,8 @@ exports["test viewFor panel"] = test(function*(assert) {
|
|||
assert.equal(frame.contentDocument.URL, url, "is expected iframe");
|
||||
|
||||
yield closeToolbox();
|
||||
|
||||
myTool.destroy();
|
||||
});
|
||||
|
||||
|
||||
|
@ -314,6 +320,8 @@ exports["test createView panel"] = test(function*(assert) {
|
|||
assert.equal(frame.contentDocument.URL, url, "is expected iframe");
|
||||
|
||||
yield closeToolbox();
|
||||
|
||||
myTool.destroy();
|
||||
});
|
||||
|
||||
require("sdk/test").run(exports);
|
||||
|
|
|
@ -12,6 +12,7 @@ const { Class } = require("sdk/core/heritage");
|
|||
const { Cc, Ci, Cu } = require("chrome");
|
||||
const { notifyObservers } = Cc["@mozilla.org/observer-service;1"].
|
||||
getService(Ci.nsIObserverService);
|
||||
const { defer } = require("sdk/core/promise");
|
||||
|
||||
const message = x => ({wrappedJSObject: x});
|
||||
|
||||
|
@ -120,4 +121,63 @@ exports["test weak observers are GC-ed on unload"] = (assert, end) => {
|
|||
});
|
||||
};
|
||||
|
||||
require("sdk/test").run(exports);
|
||||
exports["test weak observer unsubscribe"] = function*(assert) {
|
||||
const loader = Loader(module);
|
||||
const { Observer, observe, subscribe, unsubscribe } = loader.require("sdk/core/observer");
|
||||
const { WeakReference } = loader.require("sdk/core/reference");
|
||||
|
||||
let sawNotification = false;
|
||||
let firstWait = defer();
|
||||
let secondWait = defer();
|
||||
|
||||
const WeakObserver = Class({
|
||||
extends: Observer,
|
||||
implements: [WeakReference],
|
||||
observe: function() {
|
||||
sawNotification = true;
|
||||
firstWait.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
const StrongObserver = Class({
|
||||
extends: Observer,
|
||||
observe: function() {
|
||||
secondWait.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
observe.define(Observer, (x, ...rest) => x.observe(...rest));
|
||||
|
||||
let weakObserver = new WeakObserver;
|
||||
let strongObserver = new StrongObserver();
|
||||
subscribe(weakObserver, "test-topic");
|
||||
subscribe(strongObserver, "test-wait");
|
||||
|
||||
notifyObservers(null, "test-topic", null);
|
||||
yield firstWait.promise;
|
||||
|
||||
assert.ok(sawNotification, "Should have seen notification before GC");
|
||||
sawNotification = false;
|
||||
|
||||
yield loader.require("sdk/test/memory").gc();
|
||||
|
||||
notifyObservers(null, "test-topic", null);
|
||||
notifyObservers(null, "test-wait", null);
|
||||
yield secondWait.promise;
|
||||
|
||||
assert.ok(sawNotification, "Should have seen notification after GC");
|
||||
sawNotification = false;
|
||||
|
||||
try {
|
||||
unsubscribe(weakObserver, "test-topic");
|
||||
unsubscribe(strongObserver, "test-wait");
|
||||
assert.pass("Should not have seen an exception");
|
||||
}
|
||||
catch (e) {
|
||||
assert.fail("Should not have seen an exception");
|
||||
}
|
||||
|
||||
loader.unload();
|
||||
};
|
||||
|
||||
require("sdk/test").run(exports);
|
||||
|
|
|
@ -1297,7 +1297,6 @@ exports["test panel addon global object"] = function*(assert) {
|
|||
exports["test panel load doesn't show"] = function*(assert) {
|
||||
let loader = Loader(module);
|
||||
|
||||
let showCount = 0;
|
||||
let panel = loader.require("sdk/panel").Panel({
|
||||
contentScript: "addEventListener('load', function(event) { self.postMessage('load'); });",
|
||||
contentScriptWhen: "start",
|
||||
|
@ -1335,6 +1334,24 @@ exports["test panel load doesn't show"] = function*(assert) {
|
|||
loader.unload();
|
||||
}
|
||||
|
||||
exports["test Panel without contentURL and contentScriptWhen=start should show"] = function*(assert) {
|
||||
let loader = Loader(module);
|
||||
|
||||
let panel = loader.require("sdk/panel").Panel({
|
||||
contentScriptWhen: "start",
|
||||
// No contentURL, the bug only shows up when contentURL is not explicitly set.
|
||||
});
|
||||
|
||||
yield new Promise(resolve => {
|
||||
panel.once("show", resolve);
|
||||
panel.show();
|
||||
});
|
||||
|
||||
assert.pass("Received show event");
|
||||
|
||||
loader.unload();
|
||||
}
|
||||
|
||||
if (packaging.isNative) {
|
||||
module.exports = {
|
||||
"test skip on jpm": (assert) => assert.pass("skipping this file with jpm")
|
||||
|
|
Загрузка…
Ссылка в новой задаче