toolkit/mozapps/extensions/test/xpcshell/test_migrate_max_version.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // Checks that we don't migrate data from SQLITE if
michael@0 6 // the "extensions.databaseSchema" preference shows we've
michael@0 7 // already upgraded to JSON
michael@0 8
michael@0 9 // Enable loading extensions from the user and system scopes
michael@0 10 Services.prefs.setIntPref("extensions.enabledScopes",
michael@0 11 AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
michael@0 12 AddonManager.SCOPE_SYSTEM);
michael@0 13
michael@0 14 var addon1 = {
michael@0 15 id: "addon1@tests.mozilla.org",
michael@0 16 version: "1.0",
michael@0 17 name: "Test 1",
michael@0 18 targetApplications: [{
michael@0 19 id: "xpcshell@tests.mozilla.org",
michael@0 20 minVersion: "1",
michael@0 21 maxVersion: "1"
michael@0 22 }]
michael@0 23 };
michael@0 24
michael@0 25 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 26 const profileDir = gProfD.clone();
michael@0 27 profileDir.append("extensions");
michael@0 28
michael@0 29 function run_test() {
michael@0 30 writeInstallRDFForExtension(addon1, profileDir);
michael@0 31
michael@0 32 // Write out a minimal database
michael@0 33 let dbfile = gProfD.clone();
michael@0 34 dbfile.append("extensions.sqlite");
michael@0 35 let db = AM_Cc["@mozilla.org/storage/service;1"].
michael@0 36 getService(AM_Ci.mozIStorageService).
michael@0 37 openDatabase(dbfile);
michael@0 38 db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
michael@0 39 "id TEXT, location TEXT, version TEXT, active INTEGER, " +
michael@0 40 "userDisabled INTEGER, installDate INTEGER");
michael@0 41 db.createTable("targetApplication", "addon_internal_id INTEGER, " +
michael@0 42 "id TEXT, minVersion TEXT, maxVersion TEXT");
michael@0 43 let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
michael@0 44 ":version, :active, :userDisabled, :installDate)");
michael@0 45
michael@0 46 let internal_ids = {};
michael@0 47
michael@0 48 let a = ["addon1@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"];
michael@0 49 stmt.params.id = a[0];
michael@0 50 stmt.params.location = a[1];
michael@0 51 stmt.params.version = a[2];
michael@0 52 stmt.params.active = a[3];
michael@0 53 stmt.params.userDisabled = a[4];
michael@0 54 stmt.params.installDate = a[5];
michael@0 55 stmt.execute();
michael@0 56 internal_ids[a[0]] = db.lastInsertRowID;
michael@0 57 stmt.finalize();
michael@0 58
michael@0 59 db.schemaVersion = 14;
michael@0 60 Services.prefs.setIntPref("extensions.databaseSchema", 14);
michael@0 61 db.close();
michael@0 62
michael@0 63 startupManager();
michael@0 64 run_next_test();
michael@0 65 }
michael@0 66
michael@0 67 add_test(function before_rebuild() {
michael@0 68 AddonManager.getAddonByID("addon1@tests.mozilla.org",
michael@0 69 function check_before_rebuild (a1) {
michael@0 70 // First check that it migrated OK once
michael@0 71 // addon1 was disabled in the database
michael@0 72 do_check_neq(a1, null);
michael@0 73 do_check_true(a1.userDisabled);
michael@0 74 do_check_false(a1.appDisabled);
michael@0 75 do_check_false(a1.isActive);
michael@0 76 do_check_false(a1.strictCompatibility);
michael@0 77 do_check_false(a1.foreignInstall);
michael@0 78
michael@0 79 run_next_test();
michael@0 80 });
michael@0 81 });
michael@0 82
michael@0 83 // now shut down, remove the JSON database,
michael@0 84 // start up again, and make sure the data didn't migrate this time
michael@0 85 add_test(function rebuild_again() {
michael@0 86 shutdownManager();
michael@0 87 gExtensionsJSON.remove(true);
michael@0 88 startupManager();
michael@0 89
michael@0 90 AddonManager.getAddonByID("addon1@tests.mozilla.org",
michael@0 91 function check_after_rebuild(a1) {
michael@0 92 // addon1 was rebuilt from extensions directory,
michael@0 93 // so it appears enabled as a foreign install
michael@0 94 do_check_neq(a1, null);
michael@0 95 do_check_false(a1.userDisabled);
michael@0 96 do_check_false(a1.appDisabled);
michael@0 97 do_check_true(a1.isActive);
michael@0 98 do_check_false(a1.strictCompatibility);
michael@0 99 do_check_true(a1.foreignInstall);
michael@0 100
michael@0 101 run_next_test();
michael@0 102 });
michael@0 103 });

mercurial