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
Родитель 8af67672f4
Коммит 9ada7e9b9c
6 изменённых файлов: 19 добавлений и 2 удалений

Просмотреть файл

@ -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();

Просмотреть файл

@ -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);

Просмотреть файл

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

Просмотреть файл

@ -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"
}
],

Просмотреть файл

@ -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',

Просмотреть файл

@ -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();