mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1199800 - [webext] Allow extensions to be used from chrome tests (r=gabor)
This commit is contained in:
parent
62ae881795
commit
4fe3b5000e
@ -5,3 +5,5 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
JAR_MANIFESTS += ['jar.mn']
|
||||
|
||||
BROWSER_CHROME_MANIFESTS += ['test/browser/browser.ini']
|
||||
|
1
browser/components/extensions/test/browser/browser.ini
Normal file
1
browser/components/extensions/test/browser/browser.ini
Normal file
@ -0,0 +1 @@
|
||||
[browser_extensions_simple.js]
|
@ -0,0 +1,22 @@
|
||||
add_task(function* test_simple() {
|
||||
let extension = ExtensionTestUtils.loadExtension("simple");
|
||||
info("load complete");
|
||||
yield extension.startup();
|
||||
info("startup complete");
|
||||
yield extension.unload();
|
||||
info("extension unloaded successfully");
|
||||
});
|
||||
|
||||
add_task(function* test_background() {
|
||||
let extension = ExtensionTestUtils.loadExtension("background");
|
||||
info("load complete");
|
||||
yield extension.startup();
|
||||
let x = yield extension.awaitMessage("running");
|
||||
is(x, 1, "got correct value from extension");
|
||||
info("startup complete");
|
||||
extension.sendMessage(10, 20);
|
||||
yield extension.awaitFinish();
|
||||
info("test complete");
|
||||
yield extension.unload();
|
||||
info("extension unloaded successfully");
|
||||
});
|
@ -159,6 +159,11 @@ function Tester(aTests, aDumper, aCallback) {
|
||||
this._scriptLoader.loadSubScript("chrome://mochikit/content/chrome-harness.js", simpleTestScope);
|
||||
this.SimpleTest = simpleTestScope.SimpleTest;
|
||||
|
||||
var extensionUtilsScope = {};
|
||||
extensionUtilsScope.SimpleTest = this.SimpleTest;
|
||||
this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/ExtensionTestUtils.js", extensionUtilsScope);
|
||||
this.ExtensionTestUtils = extensionUtilsScope.ExtensionTestUtils;
|
||||
|
||||
this.SimpleTest.harnessParameters = gConfig;
|
||||
|
||||
this.MemoryStats = simpleTestScope.MemoryStats;
|
||||
@ -211,6 +216,7 @@ Tester.prototype = {
|
||||
SimpleTest: {},
|
||||
Task: null,
|
||||
ContentTask: null,
|
||||
ExtensionTestUtils: null,
|
||||
Assert: null,
|
||||
|
||||
repeat: 0,
|
||||
@ -686,6 +692,7 @@ Tester.prototype = {
|
||||
this.currentTest.scope.ContentTask = this.ContentTask;
|
||||
this.currentTest.scope.BrowserTestUtils = this.BrowserTestUtils;
|
||||
this.currentTest.scope.TestUtils = this.TestUtils;
|
||||
this.currentTest.scope.ExtensionTestUtils = this.ExtensionTestUtils;
|
||||
// Pass a custom report function for mochitest style reporting.
|
||||
this.currentTest.scope.Assert = new this.Assert(function(err, message, stack) {
|
||||
let res;
|
||||
@ -1082,6 +1089,7 @@ testScope.prototype = {
|
||||
ContentTask: null,
|
||||
BrowserTestUtils: null,
|
||||
TestUtils: null,
|
||||
ExtensionTestUtils: null,
|
||||
Assert: null,
|
||||
|
||||
/**
|
||||
|
@ -15,6 +15,8 @@ function ChromePowers(window) {
|
||||
}
|
||||
|
||||
this.spObserver = new SpecialPowersObserverAPI();
|
||||
this.spObserver._sendReply = this._sendReply.bind(this);
|
||||
this.listeners = new Map();
|
||||
}
|
||||
|
||||
ChromePowers.prototype = new SpecialPowersAPI();
|
||||
@ -25,14 +27,32 @@ ChromePowers.prototype.sanityCheck = function() { return "foo"; };
|
||||
// This gets filled in in the constructor.
|
||||
ChromePowers.prototype.DOMWindowUtils = undefined;
|
||||
|
||||
ChromePowers.prototype._sendSyncMessage = function(type, msg) {
|
||||
var aMessage = {'name':type, 'json': msg};
|
||||
return [this._receiveMessage(aMessage)];
|
||||
ChromePowers.prototype._sendReply = function(aOrigMsg, aType, aMsg) {
|
||||
var msg = {'name':aType, 'json': aMsg, 'data': aMsg};
|
||||
if (!this.listeners.has(aType)) {
|
||||
throw new Error(`No listener for ${aType}`);
|
||||
}
|
||||
this.listeners.get(aType)(msg);
|
||||
};
|
||||
|
||||
ChromePowers.prototype._sendAsyncMessage = function(type, msg) {
|
||||
var aMessage = {'name':type, 'json': msg};
|
||||
this._receiveMessage(aMessage);
|
||||
ChromePowers.prototype._sendSyncMessage = function(aType, aMsg) {
|
||||
var msg = {'name':aType, 'json': aMsg, 'data': aMsg};
|
||||
return [this._receiveMessage(msg)];
|
||||
};
|
||||
|
||||
ChromePowers.prototype._sendAsyncMessage = function(aType, aMsg) {
|
||||
var msg = {'name':aType, 'json': aMsg, 'data': aMsg};
|
||||
this._receiveMessage(msg);
|
||||
};
|
||||
|
||||
ChromePowers.prototype._addMessageListener = function(aType, aCallback) {
|
||||
if (this.listeners.has(aType)) {
|
||||
throw new Error(`unable to handle multiple listeners for ${aType}`);
|
||||
}
|
||||
this.listeners.set(aType, aCallback);
|
||||
};
|
||||
ChromePowers.prototype._removeMessageListener = function(aType, aCallback) {
|
||||
this.listeners.delete(aType);
|
||||
};
|
||||
|
||||
ChromePowers.prototype.registerProcessCrashObservers = function() {
|
||||
|
@ -2055,7 +2055,7 @@ SpecialPowersAPI.prototype = {
|
||||
});
|
||||
let unloadPromise = new Promise(resolve => { resolveUnload = resolve; });
|
||||
|
||||
handler = handler.wrappedJSObject;
|
||||
handler = Cu.waiveXrays(handler);
|
||||
|
||||
let sp = this;
|
||||
let extension = {
|
||||
|
Loading…
Reference in New Issue
Block a user