mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 07:42:04 +00:00
Bug 1275139 (part 2) - change tests to demonstrate the problems with system addons. r=rhelmer
MozReview-Commit-ID: Jhi4WyBYX8t
This commit is contained in:
parent
31b43265c9
commit
d2219304ce
27
services/sync/tests/unit/systemaddon-search.xml
Normal file
27
services/sync/tests/unit/systemaddon-search.xml
Normal file
@ -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>system1@tests.mozilla.org</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>xpcshell@tests.mozilla.org</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>
|
@ -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;
|
||||
|
||||
@ -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 = "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);
|
||||
@ -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;
|
||||
@ -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;
|
||||
|
||||
@ -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.");
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user