2013-02-26 14:50:24 -08:00
|
|
|
|
|
|
|
|
|
|
|
let AddonManager = Cu.import("resource://gre/modules/AddonManager.jsm", {}).AddonManager;
|
|
|
|
let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
|
|
|
|
|
|
|
|
const ADDON_TYPE_SERVICE = "service";
|
|
|
|
const ID_SUFFIX = "@services.mozilla.org";
|
|
|
|
const STRING_TYPE_NAME = "type.%ID%.name";
|
2013-03-05 11:24:30 -08:00
|
|
|
const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
|
2013-02-26 14:50:24 -08:00
|
|
|
|
2013-04-03 20:39:37 -07:00
|
|
|
let manifest = { // builtin provider
|
2013-02-26 14:50:24 -08:00
|
|
|
name: "provider 1",
|
|
|
|
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",
|
2013-09-18 23:06:20 -07:00
|
|
|
iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
|
2013-02-26 14:50:24 -08:00
|
|
|
};
|
2013-03-05 11:24:30 -08:00
|
|
|
let manifest2 = { // used for testing install
|
|
|
|
name: "provider 2",
|
2013-03-21 13:34:26 -07:00
|
|
|
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",
|
2013-09-18 23:06:20 -07:00
|
|
|
iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png",
|
2013-07-03 10:24:16 -07:00
|
|
|
version: 1
|
2013-03-05 11:24:30 -08:00
|
|
|
};
|
2013-02-26 14:50:24 -08:00
|
|
|
|
|
|
|
function test() {
|
|
|
|
waitForExplicitFinish();
|
|
|
|
|
2013-04-03 20:39:37 -07:00
|
|
|
let prefname = getManifestPrefname(manifest);
|
|
|
|
setBuiltinManifestPref(prefname, manifest);
|
|
|
|
// ensure that manifest2 is NOT showing as builtin
|
|
|
|
is(SocialService.getOriginActivationType(manifest.origin), "builtin", "manifest is builtin");
|
|
|
|
is(SocialService.getOriginActivationType(manifest2.origin), "foreign", "manifest2 is not builtin");
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
Services.prefs.setBoolPref("social.remote-install.enabled", true);
|
2013-02-26 14:50:24 -08:00
|
|
|
runSocialTests(tests, undefined, undefined, function () {
|
2013-03-05 11:24:30 -08:00
|
|
|
Services.prefs.clearUserPref("social.remote-install.enabled");
|
2013-04-03 20:39:37 -07:00
|
|
|
// clear our builtin pref
|
|
|
|
ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
|
2013-04-05 15:48:48 -07:00
|
|
|
resetBuiltinManifestPref(prefname);
|
2013-03-05 11:24:30 -08:00
|
|
|
// just in case the tests failed, clear these here as well
|
|
|
|
Services.prefs.clearUserPref("social.whitelist");
|
|
|
|
Services.prefs.clearUserPref("social.directories");
|
2013-02-26 14:50:24 -08:00
|
|
|
finish();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-04-03 20:39:37 -07:00
|
|
|
function installListener(next, aManifest) {
|
2013-03-05 11:24:30 -08:00
|
|
|
let expectEvent = "onInstalling";
|
2013-04-03 20:39:37 -07:00
|
|
|
let prefname = getManifestPrefname(aManifest);
|
2013-06-25 07:04:31 -07:00
|
|
|
// wait for the actual removal to call next
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialService.registerProviderListener(function providerListener(topic, origin, providers) {
|
|
|
|
if (topic == "provider-disabled") {
|
2013-06-25 07:04:31 -07:00
|
|
|
SocialService.unregisterProviderListener(providerListener);
|
2013-09-04 10:01:38 -07:00
|
|
|
is(origin, aManifest.origin, "provider disabled");
|
2013-06-25 07:04:31 -07:00
|
|
|
executeSoon(next);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-03-05 11:24:30 -08:00
|
|
|
return {
|
|
|
|
onInstalling: function(addon) {
|
|
|
|
is(expectEvent, "onInstalling", "install started");
|
2013-04-03 20:39:37 -07:00
|
|
|
is(addon.manifest.origin, aManifest.origin, "provider about to be installed");
|
|
|
|
ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
|
2013-03-05 11:24:30 -08:00
|
|
|
expectEvent = "onInstalled";
|
|
|
|
},
|
|
|
|
onInstalled: function(addon) {
|
2013-04-03 20:39:37 -07:00
|
|
|
is(addon.manifest.origin, aManifest.origin, "provider installed");
|
2013-04-29 13:09:10 -07:00
|
|
|
ok(addon.installDate.getTime() > 0, "addon has installDate");
|
|
|
|
ok(addon.updateDate.getTime() > 0, "addon has updateDate");
|
2013-04-03 20:39:37 -07:00
|
|
|
ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
|
2013-03-05 11:24:30 -08:00
|
|
|
expectEvent = "onUninstalling";
|
|
|
|
},
|
|
|
|
onUninstalling: function(addon) {
|
|
|
|
is(expectEvent, "onUninstalling", "uninstall started");
|
2013-04-03 20:39:37 -07:00
|
|
|
is(addon.manifest.origin, aManifest.origin, "provider about to be uninstalled");
|
|
|
|
ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
|
2013-03-05 11:24:30 -08:00
|
|
|
expectEvent = "onUninstalled";
|
|
|
|
},
|
|
|
|
onUninstalled: function(addon) {
|
|
|
|
is(expectEvent, "onUninstalled", "provider has been uninstalled");
|
2013-04-03 20:39:37 -07:00
|
|
|
is(addon.manifest.origin, aManifest.origin, "provider uninstalled");
|
|
|
|
ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
|
2013-03-05 11:24:30 -08:00
|
|
|
AddonManager.removeAddonListener(this);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2013-02-26 14:50:24 -08:00
|
|
|
var tests = {
|
|
|
|
testAddonEnableToggle: function(next) {
|
|
|
|
let expectEvent;
|
2013-04-03 20:39:37 -07:00
|
|
|
let prefname = getManifestPrefname(manifest);
|
2013-02-26 14:50:24 -08:00
|
|
|
let listener = {
|
|
|
|
onEnabled: function(addon) {
|
|
|
|
is(expectEvent, "onEnabled", "provider onEnabled");
|
|
|
|
ok(!addon.userDisabled, "provider enabled");
|
|
|
|
executeSoon(function() {
|
|
|
|
expectEvent = "onDisabling";
|
2013-05-27 15:46:11 -07:00
|
|
|
addon.userDisabled = true;
|
2013-02-26 14:50:24 -08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onEnabling: function(addon) {
|
|
|
|
is(expectEvent, "onEnabling", "provider onEnabling");
|
|
|
|
expectEvent = "onEnabled";
|
|
|
|
},
|
|
|
|
onDisabled: function(addon) {
|
|
|
|
is(expectEvent, "onDisabled", "provider onDisabled");
|
|
|
|
ok(addon.userDisabled, "provider disabled");
|
2013-05-27 15:46:11 -07:00
|
|
|
AddonManager.removeAddonListener(listener);
|
|
|
|
// clear the provider user-level pref
|
|
|
|
Services.prefs.clearUserPref(prefname);
|
|
|
|
executeSoon(next);
|
2013-02-26 14:50:24 -08:00
|
|
|
},
|
|
|
|
onDisabling: function(addon) {
|
|
|
|
is(expectEvent, "onDisabling", "provider onDisabling");
|
|
|
|
expectEvent = "onDisabled";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AddonManager.addAddonListener(listener);
|
|
|
|
|
2013-04-03 20:39:37 -07:00
|
|
|
// we're only testing enable disable, so we quickly set the user-level pref
|
|
|
|
// for this provider and test enable/disable toggling
|
|
|
|
setManifestPref(prefname, manifest);
|
|
|
|
ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
|
2013-02-26 14:50:24 -08:00
|
|
|
AddonManager.getAddonsByTypes([ADDON_TYPE_SERVICE], function(addons) {
|
|
|
|
for (let addon of addons) {
|
2013-05-27 15:46:11 -07:00
|
|
|
if (addon.userDisabled) {
|
|
|
|
expectEvent = "onEnabling";
|
|
|
|
addon.userDisabled = false;
|
|
|
|
// only test with one addon
|
|
|
|
return;
|
|
|
|
}
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
ok(false, "no addons toggled");
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
testProviderEnableToggle: function(next) {
|
|
|
|
// enable and disabel a provider from the SocialService interface, check
|
|
|
|
// that the addon manager is updated
|
|
|
|
|
|
|
|
let expectEvent;
|
2013-04-03 20:39:37 -07:00
|
|
|
let prefname = getManifestPrefname(manifest);
|
2013-02-26 14:50:24 -08:00
|
|
|
|
|
|
|
let listener = {
|
|
|
|
onEnabled: function(addon) {
|
|
|
|
is(expectEvent, "onEnabled", "provider onEnabled");
|
|
|
|
is(addon.manifest.origin, manifest.origin, "provider enabled");
|
|
|
|
ok(!addon.userDisabled, "provider !userDisabled");
|
|
|
|
},
|
|
|
|
onEnabling: function(addon) {
|
|
|
|
is(expectEvent, "onEnabling", "provider onEnabling");
|
|
|
|
is(addon.manifest.origin, manifest.origin, "provider about to be enabled");
|
|
|
|
expectEvent = "onEnabled";
|
|
|
|
},
|
|
|
|
onDisabled: function(addon) {
|
|
|
|
is(expectEvent, "onDisabled", "provider onDisabled");
|
|
|
|
is(addon.manifest.origin, manifest.origin, "provider disabled");
|
|
|
|
ok(addon.userDisabled, "provider userDisabled");
|
|
|
|
},
|
|
|
|
onDisabling: function(addon) {
|
|
|
|
is(expectEvent, "onDisabling", "provider onDisabling");
|
|
|
|
is(addon.manifest.origin, manifest.origin, "provider about to be disabled");
|
|
|
|
expectEvent = "onDisabled";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
AddonManager.addAddonListener(listener);
|
|
|
|
|
|
|
|
expectEvent = "onEnabling";
|
2013-04-03 20:39:37 -07:00
|
|
|
setManifestPref(prefname, manifest);
|
2013-02-26 14:50:24 -08:00
|
|
|
SocialService.addBuiltinProvider(manifest.origin, function(provider) {
|
|
|
|
expectEvent = "onDisabling";
|
|
|
|
SocialService.removeProvider(provider.origin, function() {
|
|
|
|
AddonManager.removeAddonListener(listener);
|
2013-04-03 20:39:37 -07:00
|
|
|
Services.prefs.clearUserPref(prefname);
|
2013-02-26 14:50:24 -08:00
|
|
|
next();
|
|
|
|
});
|
|
|
|
});
|
2013-03-05 11:24:30 -08:00
|
|
|
},
|
|
|
|
testForeignInstall: function(next) {
|
2013-04-03 20:39:37 -07:00
|
|
|
AddonManager.addAddonListener(installListener(next, manifest2));
|
2013-03-05 11:24:30 -08:00
|
|
|
|
|
|
|
// we expect the addon install dialog to appear, we need to accept the
|
|
|
|
// install from the dialog.
|
2013-03-21 13:34:26 -07:00
|
|
|
info("Waiting for install dialog");
|
2013-04-02 16:28:30 -07:00
|
|
|
let panel = document.getElementById("servicesInstall-notification");
|
|
|
|
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() {
|
|
|
|
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
|
|
|
|
info("servicesInstall-notification panel opened");
|
|
|
|
panel.button.click();
|
|
|
|
})
|
2013-03-21 13:34:26 -07:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
2013-03-05 11:24:30 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2013-04-05 15:48:48 -07:00
|
|
|
testBuiltinInstallWithoutManifest: function(next) {
|
|
|
|
// send installProvider null for the manifest
|
|
|
|
AddonManager.addAddonListener(installListener(next, manifest));
|
|
|
|
|
|
|
|
let prefname = getManifestPrefname(manifest);
|
|
|
|
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
|
|
|
addTab(activationURL, function(tab) {
|
|
|
|
let doc = tab.linkedBrowser.contentDocument;
|
|
|
|
let installFrom = doc.nodePrincipal.origin;
|
|
|
|
is(SocialService.getOriginActivationType(installFrom), "builtin", "testing builtin install");
|
|
|
|
ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
|
|
|
|
Social.installProvider(doc, null, function(addonManifest) {
|
|
|
|
ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
|
|
|
|
SocialService.addBuiltinProvider(addonManifest.origin, function(provider) {
|
|
|
|
Social.uninstallProvider(addonManifest.origin);
|
|
|
|
gBrowser.removeTab(tab);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2013-04-03 20:39:37 -07:00
|
|
|
testBuiltinInstall: function(next) {
|
2013-04-05 15:48:48 -07:00
|
|
|
// send installProvider a json object for the manifest
|
2013-04-03 20:39:37 -07:00
|
|
|
AddonManager.addAddonListener(installListener(next, manifest));
|
|
|
|
|
|
|
|
let prefname = getManifestPrefname(manifest);
|
|
|
|
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
|
|
|
|
addTab(activationURL, function(tab) {
|
|
|
|
let doc = tab.linkedBrowser.contentDocument;
|
|
|
|
let installFrom = doc.nodePrincipal.origin;
|
|
|
|
is(SocialService.getOriginActivationType(installFrom), "builtin", "testing builtin install");
|
|
|
|
ok(!Services.prefs.prefHasUserValue(prefname), "manifest is not in user-prefs");
|
|
|
|
Social.installProvider(doc, manifest, function(addonManifest) {
|
|
|
|
ok(Services.prefs.prefHasUserValue(prefname), "manifest is in user-prefs");
|
|
|
|
SocialService.addBuiltinProvider(addonManifest.origin, function(provider) {
|
|
|
|
Social.uninstallProvider(addonManifest.origin);
|
|
|
|
gBrowser.removeTab(tab);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2013-03-05 11:24:30 -08:00
|
|
|
testWhitelistInstall: function(next) {
|
2013-04-03 20:39:37 -07:00
|
|
|
AddonManager.addAddonListener(installListener(next, manifest2));
|
2013-03-05 11:24:30 -08:00
|
|
|
|
2013-03-21 13:34:26 -07:00
|
|
|
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);
|
|
|
|
});
|
2013-03-05 11:24:30 -08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
testDirectoryInstall: function(next) {
|
2013-04-03 20:39:37 -07:00
|
|
|
AddonManager.addAddonListener(installListener(next, manifest2));
|
2013-03-05 11:24:30 -08:00
|
|
|
|
2013-03-21 13:34:26 -07:00
|
|
|
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);
|
|
|
|
});
|
2013-03-05 11:24:30 -08:00
|
|
|
});
|
|
|
|
});
|
2013-07-03 10:24:16 -07:00
|
|
|
},
|
|
|
|
testUpgradeProviderFromWorker: function(next) {
|
|
|
|
// add the provider, change the pref, add it again. The provider at that
|
|
|
|
// point should be upgraded
|
|
|
|
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);
|
|
|
|
Social.installProvider(doc, manifest2, function(addonManifest) {
|
|
|
|
SocialService.addBuiltinProvider(addonManifest.origin, function(provider) {
|
2013-07-29 09:03:19 -07:00
|
|
|
is(provider.manifest.version, 1, "manifest version is 1");
|
2013-07-03 10:24:16 -07:00
|
|
|
Social.enabled = true;
|
2013-07-29 09:03:19 -07:00
|
|
|
|
|
|
|
// watch for the provider-update and test the new version
|
2013-09-04 10:01:38 -07:00
|
|
|
SocialService.registerProviderListener(function providerListener(topic, origin, providers) {
|
2013-07-03 10:24:16 -07:00
|
|
|
if (topic != "provider-update")
|
|
|
|
return;
|
2013-09-04 10:01:38 -07:00
|
|
|
is(origin, addonManifest.origin, "provider updated")
|
2013-07-03 10:24:16 -07:00
|
|
|
SocialService.unregisterProviderListener(providerListener);
|
2013-07-29 09:03:19 -07:00
|
|
|
Services.prefs.clearUserPref("social.whitelist");
|
2013-09-04 10:01:38 -07:00
|
|
|
let provider = Social._getProviderFromOrigin(origin);
|
2013-07-29 09:03:19 -07:00
|
|
|
is(provider.manifest.version, 2, "manifest version is 2");
|
2013-09-04 10:01:38 -07:00
|
|
|
Social.uninstallProvider(origin, function() {
|
2013-08-27 09:18:35 -07:00
|
|
|
gBrowser.removeTab(tab);
|
|
|
|
next();
|
|
|
|
});
|
2013-07-03 10:24:16 -07:00
|
|
|
});
|
2013-07-29 09:03:19 -07:00
|
|
|
|
|
|
|
let port = provider.getWorkerPort();
|
|
|
|
port.onmessage = function (e) {
|
|
|
|
let topic = e.data.topic;
|
|
|
|
switch (topic) {
|
|
|
|
case "got-sidebar-message":
|
|
|
|
ok(true, "got the sidebar message from provider 1");
|
|
|
|
port.postMessage({topic: "worker.update", data: true});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
port.postMessage({topic: "test-init"});
|
|
|
|
|
2013-07-03 10:24:16 -07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2013-02-26 14:50:24 -08:00
|
|
|
}
|
|
|
|
}
|