Bug 1199698 - [webext] Fix chrome.* from content scripts (r=gabor)

This commit is contained in:
Bill McCloskey 2015-08-28 15:31:15 -07:00
parent 1c1fce4a9e
commit 828a74056a
6 changed files with 19 additions and 2 deletions

View File

@ -223,7 +223,10 @@ function ExtensionContext(extensionId, contentWindow)
{id: extensionId, frameId}, delegate);
let chromeObj = Cu.createObjectIn(this.sandbox, {defineAs: "browser"});
this.sandbox.wrappedJSObject.chrome = this.sandbox.wrappedJSObject.browser;
// Sandboxes don't get Xrays for some weird compatibility
// reason. However, we waive here anyway in case that changes.
Cu.waiveXrays(this.sandbox).chrome = Cu.waiveXrays(this.sandbox).browser;
injectAPI(api(this), chromeObj);
this.onClose = new Set();

View File

@ -1,4 +1,9 @@
browser.runtime.onMessage.addListener(([msg, expectedState, readyState], sender) => {
if (msg == "chrome-namespace-ok") {
browser.test.sendMessage(msg);
return;
}
browser.test.assertEq(msg, "script-run", "message type is correct");
browser.test.assertEq(readyState, expectedState, "readyState is correct");
browser.test.sendMessage("script-run-" + expectedState);

View File

@ -0,0 +1 @@
chrome.runtime.sendMessage(["chrome-namespace-ok"]);

View File

@ -19,6 +19,11 @@
"matches": ["http://mochi.test/tests/toolkit/components/extensions/test/mochitest/file_contentscript_*.html"],
"js": ["content_script_idle.js"],
"run_at": "document_idle"
},
{
"matches": ["http://mochi.test/tests/toolkit/components/extensions/test/mochitest/file_contentscript_*.html"],
"js": ["content_script.js"],
"run_at": "document_idle"
}
],

View File

@ -6,6 +6,7 @@
TESTING_JS_MODULES.extensions.content_script += [
'background.js',
'content_script.js',
'content_script_end.js',
'content_script_idle.js',
'content_script_start.js',

View File

@ -28,6 +28,8 @@ add_task(function* test_contentscript()
extension.onMessage("script-run-complete", () => { completeCount++; resolve(); });
});
let chromeNamespacePromise = extension.awaitMessage("chrome-namespace-ok");
yield new Promise(resolve => { setTimeout(resolve, 0); });
let win = window.open();
@ -36,7 +38,7 @@ add_task(function* test_contentscript()
ok(true, "page loaded");
yield Promise.all([waitForLoad(win), completePromise]);
yield Promise.all([waitForLoad(win), completePromise, chromeNamespacePromise]);
info("test page loaded");
win.close();