Bug 850947 - make social use of addon install panel work as an osx panel, r=felipe,markh

This commit is contained in:
Shane Caraveo 2013-03-21 13:34:26 -07:00
Родитель f32082015a
Коммит 77b112f435
7 изменённых файлов: 98 добавлений и 73 удалений

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

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

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

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist">
<emItems>
<emItem blockID="s1" id="bad.com@services.mozilla.org"></emItem>
<emItem blockID="s1" id="test1.example.com@services.mozilla.org"></emItem>
</emItems>
</blocklist>

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

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

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

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

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

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

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

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

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

@ -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":