From 4abbe6385a71c30e1435115e1cd4ee12eaf6be7b Mon Sep 17 00:00:00 2001 From: Erik Vold Date: Thu, 17 Apr 2014 02:07:49 -0700 Subject: [PATCH] Bug 997561 - Uplift Add-on SDK to Firefox (CLOSED TREE) r=me --- addon-sdk/source/lib/sdk/addon/installer.js | 8 +- .../source/lib/sdk/content/content-worker.js | 11 --- addon-sdk/source/lib/sdk/l10n/html.js | 8 +- addon-sdk/source/lib/sdk/panel/utils.js | 1 - addon-sdk/source/test/test-content-script.js | 3 - addon-sdk/source/test/test-content-worker.js | 81 ++++++++----------- addon-sdk/source/test/test-page-worker.js | 20 +++-- 7 files changed, 52 insertions(+), 80 deletions(-) diff --git a/addon-sdk/source/lib/sdk/addon/installer.js b/addon-sdk/source/lib/sdk/addon/installer.js index 1242ae96841..8ee7a3eac97 100644 --- a/addon-sdk/source/lib/sdk/addon/installer.js +++ b/addon-sdk/source/lib/sdk/addon/installer.js @@ -65,8 +65,12 @@ exports.install = function install(xpiPath) { // Order AddonManager to install the addon AddonManager.getInstallForFile(file, function(install) { - install.addListener(listener); - install.install(); + if (install.error != null) { + install.addListener(listener); + install.install(); + } else { + reject(install.error); + } }); return promise; diff --git a/addon-sdk/source/lib/sdk/content/content-worker.js b/addon-sdk/source/lib/sdk/content/content-worker.js index 0d7d675c285..45a78c7154d 100644 --- a/addon-sdk/source/lib/sdk/content/content-worker.js +++ b/addon-sdk/source/lib/sdk/content/content-worker.js @@ -286,17 +286,6 @@ const ContentWorker = Object.freeze({ value: self }); - // Deprecated use of on/postMessage from globals - exports.postMessage = function deprecatedPostMessage() { - console.error("DEPRECATED: The global `postMessage()` function in " + - "content scripts is deprecated in favor of the " + - "`self.postMessage()` function, which works the same. " + - "Replace calls to `postMessage()` with calls to " + - "`self.postMessage()`." + - "For more info on `self.on`, see " + - "."); - return self.postMessage.apply(null, arguments); - }; exports.on = function deprecatedOn() { console.error("DEPRECATED: The global `on()` function in content " + "scripts is deprecated in favor of the `self.on()` " + diff --git a/addon-sdk/source/lib/sdk/l10n/html.js b/addon-sdk/source/lib/sdk/l10n/html.js index 7aef4a6e7d3..cf1514fc623 100644 --- a/addon-sdk/source/lib/sdk/l10n/html.js +++ b/addon-sdk/source/lib/sdk/l10n/html.js @@ -46,9 +46,11 @@ function onDocumentReady2Translate(event) { try { // Finally display document when we finished replacing all text content - let winUtils = document.defaultView.QueryInterface(Ci.nsIInterfaceRequestor) - .getInterface(Ci.nsIDOMWindowUtils); - winUtils.removeSheet(hideSheetUri, winUtils.USER_SHEET); + if (document.defaultView) { + let winUtils = document.defaultView.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDOMWindowUtils); + winUtils.removeSheet(hideSheetUri, winUtils.USER_SHEET); + } } catch(e) { console.exception(e); diff --git a/addon-sdk/source/lib/sdk/panel/utils.js b/addon-sdk/source/lib/sdk/panel/utils.js index 6024ea3f868..b8b7c9501be 100644 --- a/addon-sdk/source/lib/sdk/panel/utils.js +++ b/addon-sdk/source/lib/sdk/panel/utils.js @@ -223,7 +223,6 @@ exports.show = show function setupPanelFrame(frame) { frame.setAttribute("flex", 1); frame.setAttribute("transparent", "transparent"); - frame.setAttribute("showcaret", true); frame.setAttribute("autocompleteenabled", true); if (platform === "darwin") { frame.style.borderRadius = "6px"; diff --git a/addon-sdk/source/test/test-content-script.js b/addon-sdk/source/test/test-content-script.js index 7bfa3123c91..682a497bdae 100644 --- a/addon-sdk/source/test/test-content-script.js +++ b/addon-sdk/source/test/test-content-script.js @@ -191,9 +191,6 @@ exports["test postMessage"] = createProxyTest(html, function (helper, assert) { helper.createWorker( 'new ' + function ContentScriptScope() { - assert(postMessage === postMessage, - "verify that we doesn't generate multiple functions for the same method"); - var json = JSON.stringify({foo : "bar\n \"escaped\"."}); document.getElementById("iframe").contentWindow.postMessage(json, "*"); diff --git a/addon-sdk/source/test/test-content-worker.js b/addon-sdk/source/test/test-content-worker.js index dbb514b6af9..520271e5510 100644 --- a/addon-sdk/source/test/test-content-worker.js +++ b/addon-sdk/source/test/test-content-worker.js @@ -26,7 +26,13 @@ const DEPRECATE_PREF = "devtools.errorconsole.deprecation_warnings"; const DEFAULT_CONTENT_URL = "data:text/html;charset=utf-8,foo"; -function makeWindow(contentURL) { +const WINDOW_SCRIPT_URL = "data:text/html;charset=utf-8," + + ""; + +function makeWindow() { let content = "" + ".", - "Should have seen the deprecation message") - } - - assert.notEqual(browser.contentWindow.location.href, "about:blank", - "window is now on the right document"); - - let window = browser.contentWindow - let worker = loader.require("sdk/content/worker").Worker({ - window: window, - contentScript: "new " + function WorkerScope() { - postMessage("success"); - }, - contentScriptWhen: "ready", - onMessage: function(msg) { - assert.equal("success", msg, "Should have seen the right postMessage call"); - assert.equal(1, seenMessages, "Should have seen the deprecation message"); - done(); - } - }); - - assert.equal(worker.url, window.location.href, - "worker.url works"); - worker.postMessage("hi!"); - } -); - exports['test:conentScriptFile as URL instance'] = WorkerTest( DEFAULT_CONTENT_URL, function(assert, browser, done) { @@ -889,8 +851,8 @@ exports["test:onDetach in contentScript on destroy"] = WorkerTest( }) }, }); - browser.contentWindow.addEventListener('hashchange', _ => { - assert.equal(browser.contentWindow.location.hash, '#detach!', + browser.contentWindow.addEventListener('hashchange', _ => { + assert.equal(browser.contentWindow.location.hash, '#detach!', "location.href is as expected"); done(); }) @@ -910,8 +872,8 @@ exports["test:onDetach in contentScript on unload"] = WorkerTest( }) }, }); - browser.contentWindow.addEventListener('hashchange', _ => { - assert.equal(browser.contentWindow.location.hash, '#detach!shutdown', + browser.contentWindow.addEventListener('hashchange', _ => { + assert.equal(browser.contentWindow.location.hash, '#detach!shutdown', "location.href is as expected"); done(); }) @@ -954,4 +916,25 @@ exports["test:console method log functions properly"] = WorkerTest( } ); +exports["test:global postMessage"] = WorkerTest( + WINDOW_SCRIPT_URL, + function(assert, browser, done) { + let contentScript = "window.addEventListener('message', function (e) {" + + " if (e.data === 'from -> window')" + + " self.port.emit('response', e.data, e.origin);" + + "});" + + "postMessage('from -> content-script', '*');"; + let { loader } = LoaderWithHookedConsole(module); + let worker = loader.require("sdk/content/worker").Worker({ + window: browser.contentWindow, + contentScriptWhen: "ready", + contentScript: contentScript + }); + + worker.port.on("response", (data, origin) => { + assert.equal(data, "from -> window", "Communication from content-script to window completed"); + done(); + }); +}); + require("test").run(exports); diff --git a/addon-sdk/source/test/test-page-worker.js b/addon-sdk/source/test/test-page-worker.js index 73beae47bf9..6c7e3e86d6e 100644 --- a/addon-sdk/source/test/test-page-worker.js +++ b/addon-sdk/source/test/test-page-worker.js @@ -1,12 +1,10 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - "use strict"; const { Loader } = require('sdk/test/loader'); -const Pages = require("sdk/page-worker"); -const Page = Pages.Page; +const { Page } = require("sdk/page-worker"); const { URL } = require("sdk/url"); const fixtures = require("./fixtures"); const testURI = fixtures.url("test.html"); @@ -93,17 +91,17 @@ exports.testPageProperties = function(assert) { exports.testConstructorAndDestructor = function(assert, done) { let loader = Loader(module); - let Pages = loader.require("sdk/page-worker"); + let { Page } = loader.require("sdk/page-worker"); let global = loader.sandbox("sdk/page-worker"); let pagesReady = 0; - let page1 = Pages.Page({ + let page1 = Page({ contentScript: "self.postMessage('')", contentScriptWhen: "end", onMessage: pageReady }); - let page2 = Pages.Page({ + let page2 = Page({ contentScript: "self.postMessage('')", contentScriptWhen: "end", onMessage: pageReady @@ -128,9 +126,9 @@ exports.testConstructorAndDestructor = function(assert, done) { exports.testAutoDestructor = function(assert, done) { let loader = Loader(module); - let Pages = loader.require("sdk/page-worker"); + let { Page } = loader.require("sdk/page-worker"); - let page = Pages.Page({ + let page = Page({ contentScript: "self.postMessage('')", contentScriptWhen: "end", onMessage: function() { @@ -316,12 +314,12 @@ exports.testPingPong = function(assert, done) { exports.testRedirect = function (assert, done) { let page = Page({ contentURL: 'data:text/html;charset=utf-8,first-page', - contentScript: '(function () {' + + contentScriptWhen: "end", + contentScript: '' + 'if (/first-page/.test(document.location.href)) ' + ' document.location.href = "data:text/html;charset=utf-8,redirect";' + 'else ' + - ' self.port.emit("redirect", document.location.href);' + - '})();' + ' self.port.emit("redirect", document.location.href);' }); page.port.on('redirect', function (url) {