summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_addons_store.js
diff options
context:
space:
mode:
Diffstat (limited to 'services/sync/tests/unit/test_addons_store.js')
-rw-r--r--services/sync/tests/unit/test_addons_store.js127
1 files changed, 31 insertions, 96 deletions
diff --git a/services/sync/tests/unit/test_addons_store.js b/services/sync/tests/unit/test_addons_store.js
index b52cfab31..b21f6afe1 100644
--- a/services/sync/tests/unit/test_addons_store.js
+++ b/services/sync/tests/unit/test_addons_store.js
@@ -3,47 +3,25 @@
"use strict";
-Cu.import("resource://gre/modules/Log.jsm");
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://services-sync/addonutils.js");
Cu.import("resource://services-sync/engines/addons.js");
Cu.import("resource://services-sync/service.js");
Cu.import("resource://services-sync/util.js");
-Cu.import("resource://testing-common/services/sync/utils.js");
-Cu.import("resource://gre/modules/FileUtils.jsm");
const HTTP_PORT = 8888;
-var prefs = new Preferences();
+let prefs = new Preferences();
prefs.set("extensions.getAddons.get.url", "http://localhost:8888/search/guid:%IDS%");
-prefs.set("extensions.install.requireSecureOrigin", false);
-
-const SYSTEM_ADDON_ID = "system1@tests.mozilla.org";
-let systemAddonFile;
-
-// The system add-on must be installed before AddonManager is started.
-function loadSystemAddon() {
- let addonFilename = SYSTEM_ADDON_ID + ".xpi";
- const distroDir = FileUtils.getDir("ProfD", ["sysfeatures", "app0"], true);
- do_get_file(ExtensionsTestPath("/data/system_addons/system1_1.xpi")).copyTo(distroDir, addonFilename);
- systemAddonFile = FileUtils.File(distroDir.path);
- systemAddonFile.append(addonFilename);
- systemAddonFile.lastModifiedTime = Date.now();
- // As we're not running in application, we need to setup the features directory
- // used by system add-ons.
- registerDirectory("XREAppFeat", distroDir);
-}
-
loadAddonTestFunctions();
-loadSystemAddon();
startupManager();
Service.engineManager.register(AddonsEngine);
-var engine = Service.engineManager.get("addons");
-var tracker = engine._tracker;
-var store = engine._store;
-var reconciler = engine._reconciler;
+let engine = Service.engineManager.get("addons");
+let tracker = engine._tracker;
+let store = engine._store;
+let reconciler = engine._reconciler;
/**
* Create a AddonsRec for this application with the fields specified.
@@ -77,16 +55,12 @@ function createAndStartHTTPServer(port) {
server.registerFile("/search/guid:missing-xpi%40tests.mozilla.org",
do_get_file("missing-xpi-search.xml"));
- server.registerFile("/search/guid:system1%40tests.mozilla.org",
- do_get_file("systemaddon-search.xml"));
- server.registerFile("/system.xpi", systemAddonFile);
-
server.start(port);
return server;
} catch (ex) {
_("Got exception starting HTTP server on port " + port);
- _("Error: " + Log.exceptionStr(ex));
+ _("Error: " + Utils.exceptionStr(ex));
do_throw(ex);
}
}
@@ -94,7 +68,6 @@ function createAndStartHTTPServer(port) {
function run_test() {
initTestLogging("Trace");
Log.repository.getLogger("Sync.Engine.Addons").level = Log.Level.Trace;
- Log.repository.getLogger("Sync.Tracker.Addons").level = Log.Level.Trace;
Log.repository.getLogger("Sync.AddonsRepository").level =
Log.Level.Trace;
@@ -219,6 +192,7 @@ add_test(function test_apply_uninstall() {
add_test(function test_addon_syncability() {
_("Ensure isAddonSyncable functions properly.");
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
Svc.Prefs.set("addons.trustedSourceHostnames",
"addons.mozilla.org,other.example.com");
@@ -228,8 +202,8 @@ add_test(function test_addon_syncability() {
do_check_true(store.isAddonSyncable(addon));
let dummy = {};
- const KEYS = ["id", "syncGUID", "type", "scope", "foreignInstall", "isSyncable"];
- for (let k of KEYS) {
+ const KEYS = ["id", "syncGUID", "type", "scope", "foreignInstall"];
+ for each (let k in KEYS) {
dummy[k] = addon[k];
}
@@ -243,10 +217,6 @@ add_test(function test_addon_syncability() {
do_check_false(store.isAddonSyncable(dummy));
dummy.scope = addon.scope;
- dummy.isSyncable = false;
- do_check_false(store.isAddonSyncable(dummy));
- dummy.isSyncable = addon.isSyncable;
-
dummy.foreignInstall = true;
do_check_false(store.isAddonSyncable(dummy));
dummy.foreignInstall = false;
@@ -272,16 +242,16 @@ add_test(function test_addon_syncability() {
"https://untrusted.example.com/foo", // non-trusted hostname`
];
- for (let uri of trusted) {
+ for each (let uri in trusted) {
do_check_true(store.isSourceURITrusted(createURI(uri)));
}
- for (let uri of untrusted) {
+ for each (let uri in untrusted) {
do_check_false(store.isSourceURITrusted(createURI(uri)));
}
Svc.Prefs.set("addons.trustedSourceHostnames", "");
- for (let uri of trusted) {
+ for each (let uri in trusted) {
do_check_false(store.isSourceURITrusted(createURI(uri)));
}
@@ -296,6 +266,8 @@ add_test(function test_addon_syncability() {
add_test(function test_ignore_hotfixes() {
_("Ensure that hotfix extensions are ignored.");
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
+
// A hotfix extension is one that has the id the same as the
// extensions.hotfix.id pref.
let prefs = new Preferences("extensions.");
@@ -304,8 +276,8 @@ add_test(function test_ignore_hotfixes() {
do_check_true(store.isAddonSyncable(addon));
let dummy = {};
- const KEYS = ["id", "syncGUID", "type", "scope", "foreignInstall", "isSyncable"];
- for (let k of KEYS) {
+ const KEYS = ["id", "syncGUID", "type", "scope", "foreignInstall"];
+ for each (let k in KEYS) {
dummy[k] = addon[k];
}
@@ -327,6 +299,7 @@ add_test(function test_ignore_hotfixes() {
uninstallAddon(addon);
+ Svc.Prefs.reset("addons.ignoreRepositoryChecking");
prefs.reset("hotfix.id");
run_next_test();
@@ -336,6 +309,8 @@ add_test(function test_ignore_hotfixes() {
add_test(function test_get_all_ids() {
_("Ensures that getAllIDs() returns an appropriate set.");
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
+
_("Installing two addons.");
let addon1 = installAddon("test_install1");
let addon2 = installAddon("test_bootstrap1_1");
@@ -354,6 +329,7 @@ add_test(function test_get_all_ids() {
addon1.install.cancel();
uninstallAddon(addon2);
+ Svc.Prefs.reset("addons.ignoreRepositoryChecking");
run_next_test();
});
@@ -379,6 +355,9 @@ add_test(function test_change_item_id() {
add_test(function test_create() {
_("Ensure creating/installing an add-on from a record works.");
+ // Set this so that getInstallFromSearchResult doesn't end up
+ // failing the install due to an insecure source URI scheme.
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
let server = createAndStartHTTPServer(HTTP_PORT);
let addon = installAddon("test_bootstrap1_1");
@@ -398,6 +377,7 @@ add_test(function test_create() {
uninstallAddon(newAddon);
+ Svc.Prefs.reset("addons.ignoreRepositoryChecking");
server.stop(run_next_test);
});
@@ -432,18 +412,8 @@ add_test(function test_create_bad_install() {
let record = createRecordForThisApp(guid, id, true, false);
let failed = store.applyIncomingBatch([record]);
- // This addon had no source URI so was skipped - but it's not treated as
- // failure.
- // XXX - this test isn't testing what we thought it was. Previously the addon
- // was not being installed due to requireSecureURL checking *before* we'd
- // attempted to get the XPI.
- // With requireSecureURL disabled we do see a download failure, but the addon
- // *does* get added to |failed|.
- // FTR: onDownloadFailed() is called with ERROR_NETWORK_FAILURE, so it's going
- // to be tricky to distinguish a 404 from other transient network errors
- // where we do want the addon to end up in |failed|.
- // This is being tracked in bug 1284778.
- //do_check_eq(0, failed.length);
+ do_check_eq(1, failed.length);
+ do_check_eq(guid, failed[0]);
let addon = getAddonFromAddonManagerByID(id);
do_check_eq(null, addon);
@@ -451,56 +421,19 @@ add_test(function test_create_bad_install() {
server.stop(run_next_test);
});
-add_test(function test_ignore_system() {
- _("Ensure we ignore system addons");
- // Our system addon should not appear in getAllIDs
- engine._refreshReconcilerState();
- let num = 0;
- for (let guid in store.getAllIDs()) {
- num += 1;
- let addon = reconciler.getAddonStateFromSyncGUID(guid);
- do_check_neq(addon.id, SYSTEM_ADDON_ID);
- }
- do_check_true(num > 1, "should have seen at least one.")
- run_next_test();
-});
-
-add_test(function test_incoming_system() {
- _("Ensure we handle incoming records that refer to a system addon");
- // eg, loop initially had a normal addon but it was then "promoted" to be a
- // system addon but wanted to keep the same ID. The server record exists due
- // to this.
-
- // before we start, ensure the system addon isn't disabled.
- do_check_false(getAddonFromAddonManagerByID(SYSTEM_ADDON_ID).userDisabled);
-
- // Now simulate an incoming record with the same ID as the system addon,
- // but flagged as disabled - it should not be applied.
- let server = createAndStartHTTPServer(HTTP_PORT);
- // We make the incoming record flag the system addon as disabled - it should
- // be ignored.
- let guid = Utils.makeGUID();
- let record = createRecordForThisApp(guid, SYSTEM_ADDON_ID, false, false);
-
- let failed = store.applyIncomingBatch([record]);
- do_check_eq(0, failed.length);
-
- // The system addon should still not be userDisabled.
- do_check_false(getAddonFromAddonManagerByID(SYSTEM_ADDON_ID).userDisabled);
-
- server.stop(run_next_test);
-});
-
add_test(function test_wipe() {
_("Ensures that wiping causes add-ons to be uninstalled.");
let addon1 = installAddon("test_bootstrap1_1");
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
store.wipe();
let addon = getAddonFromAddonManagerByID(addon1.id);
do_check_eq(null, addon);
+ Svc.Prefs.reset("addons.ignoreRepositoryChecking");
+
run_next_test();
});
@@ -515,6 +448,7 @@ add_test(function test_wipe_and_install() {
let record = createRecordForThisApp(installed.syncGUID, installed.id, true,
false);
+ Svc.Prefs.set("addons.ignoreRepositoryChecking", true);
store.wipe();
let deleted = getAddonFromAddonManagerByID(installed.id);
@@ -528,6 +462,7 @@ add_test(function test_wipe_and_install() {
let fetched = getAddonFromAddonManagerByID(record.addonID);
do_check_true(!!fetched);
+ Svc.Prefs.reset("addons.ignoreRepositoryChecking");
server.stop(run_next_test);
});