From 77b112f4357cb86c1cca8fe41457a1b488fa6dc2 Mon Sep 17 00:00:00 2001 From: Shane Caraveo Date: Thu, 21 Mar 2013 13:34:26 -0700 Subject: [PATCH] Bug 850947 - make social use of addon install panel work as an osx panel, r=felipe,markh --- browser/base/content/browser-social.js | 2 +- .../base/content/test/social/blocklist.xml | 2 +- .../content/test/social/browser_addons.js | 91 +++++++++++-------- .../content/test/social/browser_blocklist.js | 52 ++++++----- browser/base/content/test/social/head.js | 8 ++ browser/modules/Social.jsm | 4 +- toolkit/components/social/SocialService.jsm | 12 +-- 7 files changed, 98 insertions(+), 73 deletions(-) diff --git a/browser/base/content/browser-social.js b/browser/base/content/browser-social.js index ffb56906d3bc..17fba595f6ac 100644 --- a/browser/base/content/browser-social.js +++ b/browser/base/content/browser-social.js @@ -226,7 +226,7 @@ let SocialUI = { return; } } - Social.installProvider(targetDoc.location.href, data, function(manifest) { + Social.installProvider(targetDoc, data, function(manifest) { this.doActivation(manifest.origin); }.bind(this)); }, diff --git a/browser/base/content/test/social/blocklist.xml b/browser/base/content/test/social/blocklist.xml index c8d72d624224..2e3665c36c2c 100644 --- a/browser/base/content/test/social/blocklist.xml +++ b/browser/base/content/test/social/blocklist.xml @@ -1,6 +1,6 @@ - + diff --git a/browser/base/content/test/social/browser_addons.js b/browser/base/content/test/social/browser_addons.js index 9c720cc90725..cb13995f5273 100644 --- a/browser/base/content/test/social/browser_addons.js +++ b/browser/base/content/test/social/browser_addons.js @@ -17,10 +17,10 @@ let manifest = { // normal provider }; let manifest2 = { // used for testing install name: "provider 2", - origin: "https://example1.com", - sidebarURL: "https://example1.com/browser/browser/base/content/test/social/social_sidebar.html", - workerURL: "https://example1.com/browser/browser/base/content/test/social/social_worker.js", - iconURL: "https://example1.com/browser/browser/base/content/test/moz.png" + origin: "https://test1.example.com", + sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html", + workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", + iconURL: "https://test1.example.com/browser/browser/base/content/test/moz.png" }; function test() { @@ -174,62 +174,73 @@ var tests = { // we expect the addon install dialog to appear, we need to accept the // install from the dialog. - let windowListener = { + info("Waiting for install dialog"); + Services.wm.addListener({ onWindowTitleChange: function() {}, onCloseWindow: function() {}, - onOpenWindow: function(window) { - var domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) + onOpenWindow: function(xulwindow) { + Services.wm.removeListener(this); + var domwindow = xulwindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIDOMWindow); - var self = this; waitForFocus(function() { - self.windowReady(domwindow); - }, domwindow); - }, - windowReady: function(window) { - if (window.document.location.href == XPINSTALL_URL) { + info("Saw install dialog"); + is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open"); // Initially the accept button is disabled on a countdown timer - var button = window.document.documentElement.getButton("accept"); + var button = domwindow.document.documentElement.getButton("accept"); button.disabled = false; - window.document.documentElement.acceptDialog(); - Services.wm.removeListener(windowListener); - } + domwindow.document.documentElement.acceptDialog(); + }, domwindow); } - }; - Services.wm.addListener(windowListener); + }); - let installFrom = "https://example1.com"; - Services.prefs.setCharPref("social.whitelist", ""); - is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install"); - Social.installProvider(installFrom, manifest2, function(addonManifest) { - Services.prefs.clearUserPref("social.whitelist"); - SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { - Social.uninstallProvider(addonManifest.origin); + let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" + addTab(activationURL, function(tab) { + let doc = tab.linkedBrowser.contentDocument; + let installFrom = doc.nodePrincipal.origin; + Services.prefs.setCharPref("social.whitelist", ""); + is(SocialService.getOriginActivationType(installFrom), "foreign", "testing foriegn install"); + Social.installProvider(doc, manifest2, function(addonManifest) { + Services.prefs.clearUserPref("social.whitelist"); + SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { + Social.uninstallProvider(addonManifest.origin); + gBrowser.removeTab(tab); + }); }); }); }, testWhitelistInstall: function(next) { AddonManager.addAddonListener(installListener(next)); - let installFrom = "https://example1.com"; - Services.prefs.setCharPref("social.whitelist", installFrom); - is(SocialService.getOriginActivationType(installFrom), "whitelist", "testing whitelist install"); - Social.installProvider(installFrom, manifest2, function(addonManifest) { - Services.prefs.clearUserPref("social.whitelist"); - SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { - Social.uninstallProvider(addonManifest.origin); + let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" + addTab(activationURL, function(tab) { + let doc = tab.linkedBrowser.contentDocument; + let installFrom = doc.nodePrincipal.origin; + Services.prefs.setCharPref("social.whitelist", installFrom); + is(SocialService.getOriginActivationType(installFrom), "whitelist", "testing whitelist install"); + Social.installProvider(doc, manifest2, function(addonManifest) { + Services.prefs.clearUserPref("social.whitelist"); + SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { + Social.uninstallProvider(addonManifest.origin); + gBrowser.removeTab(tab); + }); }); }); }, testDirectoryInstall: function(next) { AddonManager.addAddonListener(installListener(next)); - let installFrom = "https://addons.allizom.org"; - Services.prefs.setCharPref("social.directories", installFrom); - is(SocialService.getOriginActivationType(installFrom), "directory", "testing directory install"); - Social.installProvider(installFrom, manifest2, function(addonManifest) { - Services.prefs.clearUserPref("social.directories"); - SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { - Social.uninstallProvider(addonManifest.origin); + let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" + addTab(activationURL, function(tab) { + let doc = tab.linkedBrowser.contentDocument; + let installFrom = doc.nodePrincipal.origin; + Services.prefs.setCharPref("social.directories", installFrom); + is(SocialService.getOriginActivationType(installFrom), "directory", "testing directory install"); + Social.installProvider(doc, manifest2, function(addonManifest) { + Services.prefs.clearUserPref("social.directories"); + SocialService.addBuiltinProvider(addonManifest.origin, function(provider) { + Social.uninstallProvider(addonManifest.origin); + gBrowser.removeTab(tab); + }); }); }); } diff --git a/browser/base/content/test/social/browser_blocklist.js b/browser/base/content/test/social/browser_blocklist.js index b8bf5eb94916..3e4bdc5b5944 100644 --- a/browser/base/content/test/social/browser_blocklist.js +++ b/browser/base/content/test/social/browser_blocklist.js @@ -11,18 +11,18 @@ let blocklistURL = "http://test:80/browser/browser/base/content/test/social/bloc let blocklistEmpty = "http://test:80/browser/browser/base/content/test/social/blocklistEmpty.xml"; let manifest = { // normal provider - name: "provider 1", + name: "provider ok", origin: "https://example.com", sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", iconURL: "https://example.com/browser/browser/base/content/test/moz.png" }; let manifest_bad = { // normal provider - name: "provider 1", - origin: "https://bad.com", - sidebarURL: "https://bad.com/browser/browser/base/content/test/social/social_sidebar.html", - workerURL: "https://bad.com/browser/browser/base/content/test/social/social_worker.js", - iconURL: "https://bad.com/browser/browser/base/content/test/moz.png" + name: "provider blocked", + origin: "https://test1.example.com", + sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html", + workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", + iconURL: "https://test1.example.com/browser/browser/base/content/test/moz.png" }; function test() { @@ -40,10 +40,10 @@ var tests = { var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"] .getService(Components.interfaces.nsIBlocklistService); setAndUpdateBlocklist(blocklistURL, function() { - ok(blocklist.isAddonBlocklisted("bad.com@services.mozilla.org", "0", "0", "0"), "blocking 'blocked'"); - ok(!blocklist.isAddonBlocklisted("good.cpm@services.mozilla.org", "0", "0", "0"), "not blocking 'good'"); + ok(blocklist.isAddonBlocklisted("test1.example.com@services.mozilla.org", "0", "0", "0"), "blocking 'blocked'"); + ok(!blocklist.isAddonBlocklisted("example.com@services.mozilla.org", "0", "0", "0"), "not blocking 'good'"); setAndUpdateBlocklist(blocklistEmpty, function() { - ok(!blocklist.isAddonBlocklisted("bad.com@services.mozilla.org", "0", "0", "0"), "blocklist cleared"); + ok(!blocklist.isAddonBlocklisted("test1.example.com@services.mozilla.org", "0", "0", "0"), "blocklist cleared"); next(); }); }); @@ -102,20 +102,26 @@ var tests = { Services.prefs.clearUserPref("social.whitelist"); setAndUpdateBlocklist(blocklistEmpty, next); } - let installFrom = "https://bad.com"; - // whitelist to avoid the 3rd party install dialog, we only want to test - // the blocklist inside installProvider. - Services.prefs.setCharPref("social.whitelist", installFrom); - setAndUpdateBlocklist(blocklistURL, function() { - try { - // expecting an exception when attempting to install a hard blocked - // provider - Social.installProvider(installFrom, manifest_bad, function(addonManifest) { - finish(false); - }); - } catch(e) { - finish(true); - } + let activationURL = manifest_bad.origin + "/browser/browser/base/content/test/social/social_activate.html" + addTab(activationURL, function(tab) { + let doc = tab.linkedBrowser.contentDocument; + let installFrom = doc.nodePrincipal.origin; + // whitelist to avoid the 3rd party install dialog, we only want to test + // the blocklist inside installProvider. + Services.prefs.setCharPref("social.whitelist", installFrom); + setAndUpdateBlocklist(blocklistURL, function() { + try { + // expecting an exception when attempting to install a hard blocked + // provider + Social.installProvider(doc, manifest_bad, function(addonManifest) { + gBrowser.removeTab(tab); + finish(false); + }); + } catch(e) { + gBrowser.removeTab(tab); + finish(true); + } + }); }); }, testBlockingExistingProvider: function(next) { diff --git a/browser/base/content/test/social/head.js b/browser/base/content/test/social/head.js index ab34256892a4..312b0bbebf38 100644 --- a/browser/base/content/test/social/head.js +++ b/browser/base/content/test/social/head.js @@ -251,3 +251,11 @@ function addWindowListener(aURL, aCallback) { onWindowTitleChange: function(aXULWindow, aNewTitle) { } }); } + +function addTab(url, callback) { + let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true}); + tab.linkedBrowser.addEventListener("load", function tabLoad(event) { + tab.linkedBrowser.removeEventListener("load", tabLoad, true); + executeSoon(function() {callback(tab)}); + }, true); +} diff --git a/browser/modules/Social.jsm b/browser/modules/Social.jsm index 27d54a34e617..7a033d2ac510 100644 --- a/browser/modules/Social.jsm +++ b/browser/modules/Social.jsm @@ -178,8 +178,8 @@ this.Social = { return null; }, - installProvider: function(origin ,sourceURI, data, installCallback) { - SocialService.installProvider(origin ,sourceURI, data, installCallback); + installProvider: function(doc, data, installCallback) { + SocialService.installProvider(doc, data, installCallback); }, uninstallProvider: function(origin) { diff --git a/toolkit/components/social/SocialService.jsm b/toolkit/components/social/SocialService.jsm index 1318c5b2d0d1..2e2107b25cbb 100644 --- a/toolkit/components/social/SocialService.jsm +++ b/toolkit/components/social/SocialService.jsm @@ -369,10 +369,9 @@ this.SocialService = { return data; }, - installProvider: function(sourceURI, data, installCallback) { - let URI = Services.io.newURI(sourceURI, null, null); - let principal = Services.scriptSecurityManager.getNoAppCodebasePrincipal(URI); - let installOrigin = principal.origin; + installProvider: function(aDOMDocument, data, installCallback) { + let sourceURI = aDOMDocument.location.href; + let installOrigin = aDOMDocument.nodePrincipal.origin; let id = getAddonIDFromOrigin(installOrigin); let version = data && data.version ? data.version : "0"; @@ -384,7 +383,7 @@ this.SocialService = { let manifest; if (data) { // if we get data, we MUST have a valid manifest generated from the data - manifest = this._manifestFromData(installType, data, principal); + manifest = this._manifestFromData(installType, data, aDOMDocument.nodePrincipal); if (!manifest) throw new Error("SocialService.installProvider: service configuration is invalid from " + sourceURI); } @@ -400,7 +399,8 @@ this.SocialService = { args.wrappedJSObject = args; // Bug 836452, get something better than the scary addon dialog - Services.ww.openWindow(this.window, "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul", + Services.ww.openWindow(aDOMDocument.defaultView, + "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul", null, "chrome,modal,centerscreen", args); break; case "builtin":