Skip to content

Commit

Permalink
Bug 1275139 (part 2) - change tests to demonstrate the problems with …
Browse files Browse the repository at this point in the history
…system addons. r=rhelmer

MozReview-Commit-ID: Jhi4WyBYX8t
  • Loading branch information
mhammond committed Jul 29, 2016
1 parent 668397c commit db7f66c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
27 changes: 27 additions & 0 deletions services/sync/tests/unit/systemaddon-search.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<searchresults total_results="1">
<addon id="5618">
<name>System Add-on Test</name>
<type id="1">Extension</type>
<guid>[email protected]</guid>
<slug>addon11</slug>
<version>1.0</version>

<compatible_applications><application>
<name>Firefox</name>
<application_id>1</application_id>
<min_version>3.6</min_version>
<max_version>*</max_version>
<appID>[email protected]</appID>
</application></compatible_applications>
<all_compatible_os><os>ALL</os></all_compatible_os>

<install os="ALL" size="999">http://127.0.0.1:8888/system.xpi</install>
<created epoch="1252903662">
2009-09-14T04:47:42Z
</created>
<last_updated epoch="1315255329">
2011-09-05T20:42:09Z
</last_updated>
</addon>
</searchresults>
63 changes: 63 additions & 0 deletions services/sync/tests/unit/test_addons_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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;

Expand All @@ -18,7 +19,24 @@ var 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 = "[email protected]";
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);
Expand Down Expand Up @@ -59,6 +77,10 @@ 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;
Expand All @@ -72,6 +94,7 @@ 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;

Expand Down Expand Up @@ -424,6 +447,46 @@ 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.");

Expand Down
1 change: 1 addition & 0 deletions services/sync/tests/unit/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ support-files =
places_v10_from_v11.sqlite
rewrite-search.xml
sync_ping_schema.json
systemaddon-search.xml
!/services/common/tests/unit/head_helpers.js
!/toolkit/mozapps/extensions/test/xpcshell/head_addons.js

Expand Down

0 comments on commit db7f66c

Please sign in to comment.