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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // Tests that a pending upgrade during a schema update doesn't break things
     7 var addon1 = {
     8   id: "addon1@tests.mozilla.org",
     9   version: "2.0",
    10   name: "Test 1",
    11   targetApplications: [{
    12     id: "xpcshell@tests.mozilla.org",
    13     minVersion: "1",
    14     maxVersion: "1"
    15   }]
    16 };
    18 var addon2 = {
    19   id: "addon2@tests.mozilla.org",
    20   version: "2.0",
    21   name: "Test 2",
    22   targetApplications: [{
    23     id: "xpcshell@tests.mozilla.org",
    24     minVersion: "1",
    25     maxVersion: "2"
    26   }]
    27 };
    29 var addon3 = {
    30   id: "addon3@tests.mozilla.org",
    31   version: "2.0",
    32   name: "Test 3",
    33   targetApplications: [{
    34     id: "xpcshell@tests.mozilla.org",
    35     minVersion: "1",
    36     maxVersion: "1"
    37   }]
    38 };
    40 var addon4 = {
    41   id: "addon4@tests.mozilla.org",
    42   version: "2.0",
    43   name: "Test 4",
    44   targetApplications: [{
    45     id: "xpcshell@tests.mozilla.org",
    46     minVersion: "2",
    47     maxVersion: "2"
    48   }]
    49 };
    51 const profileDir = gProfD.clone();
    52 profileDir.append("extensions");
    54 function run_test() {
    55   do_test_pending();
    56   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    58   run_test_1();
    59 }
    61 // Tests whether a schema migration without app version change works
    62 function run_test_1() {
    63   writeInstallRDFForExtension(addon1, profileDir);
    64   writeInstallRDFForExtension(addon2, profileDir);
    65   writeInstallRDFForExtension(addon3, profileDir);
    66   writeInstallRDFForExtension(addon4, profileDir);
    68   startupManager();
    70   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
    71                                "addon2@tests.mozilla.org",
    72                                "addon3@tests.mozilla.org",
    73                                "addon4@tests.mozilla.org"],
    74                               function([a1, a2, a3, a4]) {
    75     do_check_neq(a1, null);
    76     do_check_eq(a1.version, "2.0");
    77     do_check_false(a1.appDisabled);
    78     do_check_false(a1.userDisabled);
    79     do_check_true(a1.isActive);
    80     do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
    82     do_check_neq(a2, null);
    83     do_check_eq(a2.version, "2.0");
    84     do_check_false(a2.appDisabled);
    85     do_check_false(a2.userDisabled);
    86     do_check_true(a2.isActive);
    87     do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
    89     do_check_neq(a3, null);
    90     do_check_eq(a3.version, "2.0");
    91     do_check_false(a3.appDisabled);
    92     do_check_false(a3.userDisabled);
    93     do_check_true(a3.isActive);
    94     do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
    96     do_check_neq(a4, null);
    97     do_check_eq(a4.version, "2.0");
    98     do_check_true(a4.appDisabled);
    99     do_check_false(a4.userDisabled);
   100     do_check_false(a4.isActive);
   101     do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
   103     // Prepare the add-on update, and a bootstrapped addon (bug 693714)
   104     installAllFiles([
   105       do_get_addon("test_bug659772"),
   106       do_get_addon("test_bootstrap1_1")
   107     ], function() {
   108       shutdownManager();
   110       // Make it look like the next time the app is started it has a new DB schema
   111       changeXPIDBVersion(1);
   112       Services.prefs.setIntPref("extensions.databaseSchema", 1);
   114       let jsonfile = gProfD.clone();
   115       jsonfile.append("extensions");
   116       jsonfile.append("staged");
   117       jsonfile.append("addon3@tests.mozilla.org.json");
   118       do_check_true(jsonfile.exists());
   120       // Remove an unnecessary property from the cached manifest
   121       let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
   122                    createInstance(AM_Ci.nsIFileInputStream);
   123       let json = AM_Cc["@mozilla.org/dom/json;1"].
   124                  createInstance(AM_Ci.nsIJSON);
   125       fis.init(jsonfile, -1, 0, 0);
   126       let addonObj = json.decodeFromStream(fis, jsonfile.fileSize);
   127       fis.close();
   128       delete addonObj.optionsType;
   130       let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
   131                    createInstance(AM_Ci.nsIFileOutputStream);
   132       let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"].
   133                       createInstance(AM_Ci.nsIConverterOutputStream);
   134       stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
   135                             FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE,
   136                             0);
   137       converter.init(stream, "UTF-8", 0, 0x0000);
   138       converter.writeString(JSON.stringify(addonObj));
   139       converter.close();
   140       stream.close();
   142       Services.prefs.clearUserPref("bootstraptest.install_reason");
   143       Services.prefs.clearUserPref("bootstraptest.uninstall_reason");
   145       startupManager(false);
   147       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   148                                    "addon2@tests.mozilla.org",
   149                                    "addon3@tests.mozilla.org",
   150                                    "addon4@tests.mozilla.org"],
   151                                   function([a1, a2, a3, a4]) {
   152         do_check_neq(a1, null);
   153         do_check_eq(a1.version, "2.0");
   154         do_check_false(a1.appDisabled);
   155         do_check_false(a1.userDisabled);
   156         do_check_true(a1.isActive);
   157         do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
   159         do_check_neq(a2, null);
   160         do_check_eq(a2.version, "2.0");
   161         do_check_false(a2.appDisabled);
   162         do_check_false(a2.userDisabled);
   163         do_check_true(a2.isActive);
   164         do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
   166         // Should stay enabled because we migrate the compat info from
   167         // the previous version of the DB
   168         do_check_neq(a3, null);
   169         do_check_eq(a3.version, "2.0");
   170         todo_check_false(a3.appDisabled); // XXX unresolved issue
   171         do_check_false(a3.userDisabled);
   172         todo_check_true(a3.isActive); // XXX same
   173         todo_check_true(isExtensionInAddonsList(profileDir, addon3.id)); // XXX same
   175         do_check_neq(a4, null);
   176         do_check_eq(a4.version, "2.0");
   177         do_check_true(a4.appDisabled);
   178         do_check_false(a4.userDisabled);
   179         do_check_false(a4.isActive);
   180         do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
   182         // Check that install and uninstall haven't been called on the bootstrapped addon
   183         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
   184         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
   186         a1.uninstall();
   187         a2.uninstall();
   188         a3.uninstall();
   189         a4.uninstall();
   190         do_execute_soon(run_test_2);
   191       });
   192     });
   193   });
   194 }
   196 // Tests whether a schema migration with app version change works
   197 function run_test_2() {
   198   restartManager();
   200   shutdownManager();
   202   writeInstallRDFForExtension(addon1, profileDir);
   203   writeInstallRDFForExtension(addon2, profileDir);
   204   writeInstallRDFForExtension(addon3, profileDir);
   205   writeInstallRDFForExtension(addon4, profileDir);
   207   startupManager();
   209   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   210                                "addon2@tests.mozilla.org",
   211                                "addon3@tests.mozilla.org",
   212                                "addon4@tests.mozilla.org"],
   213                               function([a1, a2, a3, a4]) {
   214     do_check_neq(a1, null);
   215     do_check_eq(a1.version, "2.0");
   216     do_check_false(a1.appDisabled);
   217     do_check_false(a1.userDisabled);
   218     do_check_true(a1.isActive);
   219     do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
   221     do_check_neq(a2, null);
   222     do_check_eq(a2.version, "2.0");
   223     do_check_false(a2.appDisabled);
   224     do_check_false(a2.userDisabled);
   225     do_check_true(a2.isActive);
   226     do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
   228     do_check_neq(a3, null);
   229     do_check_eq(a3.version, "2.0");
   230     do_check_false(a3.appDisabled);
   231     do_check_false(a3.userDisabled);
   232     do_check_true(a3.isActive);
   233     do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
   235     do_check_neq(a4, null);
   236     do_check_eq(a4.version, "2.0");
   237     do_check_true(a4.appDisabled);
   238     do_check_false(a4.userDisabled);
   239     do_check_false(a4.isActive);
   240     do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
   242     // Prepare the add-on update, and a bootstrapped addon (bug 693714)
   243     installAllFiles([
   244       do_get_addon("test_bug659772"),
   245       do_get_addon("test_bootstrap1_1")
   246     ], function() { do_execute_soon(prepare_schema_migrate); });
   248     function prepare_schema_migrate() {
   249       shutdownManager();
   251       // Make it look like the next time the app is started it has a new DB schema
   252       changeXPIDBVersion(1);
   253       Services.prefs.setIntPref("extensions.databaseSchema", 1);
   255       let jsonfile = gProfD.clone();
   256       jsonfile.append("extensions");
   257       jsonfile.append("staged");
   258       jsonfile.append("addon3@tests.mozilla.org.json");
   259       do_check_true(jsonfile.exists());
   261       // Remove an unnecessary property from the cached manifest
   262       let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
   263                    createInstance(AM_Ci.nsIFileInputStream);
   264       let json = AM_Cc["@mozilla.org/dom/json;1"].
   265                  createInstance(AM_Ci.nsIJSON);
   266       fis.init(jsonfile, -1, 0, 0);
   267       let addonObj = json.decodeFromStream(fis, jsonfile.fileSize);
   268       fis.close();
   269       delete addonObj.optionsType;
   271       let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
   272                    createInstance(AM_Ci.nsIFileOutputStream);
   273       let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"].
   274                       createInstance(AM_Ci.nsIConverterOutputStream);
   275       stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
   276                             FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE,
   277                             0);
   278       converter.init(stream, "UTF-8", 0, 0x0000);
   279       converter.writeString(JSON.stringify(addonObj));
   280       converter.close();
   281       stream.close();
   283       Services.prefs.clearUserPref("bootstraptest.install_reason");
   284       Services.prefs.clearUserPref("bootstraptest.uninstall_reason");
   286       gAppInfo.version = "2";
   287       startupManager(true);
   289       AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   290                                    "addon2@tests.mozilla.org",
   291                                    "addon3@tests.mozilla.org",
   292                                    "addon4@tests.mozilla.org"],
   293                                   callback_soon(function([a1, a2, a3, a4]) {
   294         do_check_neq(a1, null);
   295         do_check_eq(a1.version, "2.0");
   296         do_check_true(a1.appDisabled);
   297         do_check_false(a1.userDisabled);
   298         do_check_false(a1.isActive);
   299         do_check_false(isExtensionInAddonsList(profileDir, addon1.id));
   301         do_check_neq(a2, null);
   302         do_check_eq(a2.version, "2.0");
   303         do_check_false(a2.appDisabled);
   304         do_check_false(a2.userDisabled);
   305         do_check_true(a2.isActive);
   306         do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
   308         // Should become appDisabled because we migrate the compat info from
   309         // the previous version of the DB
   310         do_check_neq(a3, null);
   311         do_check_eq(a3.version, "2.0");
   312         todo_check_true(a3.appDisabled);
   313         do_check_false(a3.userDisabled);
   314         todo_check_false(a3.isActive);
   315         todo_check_false(isExtensionInAddonsList(profileDir, addon3.id));
   317         do_check_neq(a4, null);
   318         do_check_eq(a4.version, "2.0");
   319         do_check_false(a4.appDisabled);
   320         do_check_false(a4.userDisabled);
   321         do_check_true(a4.isActive);
   322         do_check_true(isExtensionInAddonsList(profileDir, addon4.id));
   324         // Check that install and uninstall haven't been called on the bootstrapped addon
   325         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
   326         do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
   328         a1.uninstall();
   329         a2.uninstall();
   330         a3.uninstall();
   331         a4.uninstall();
   332         restartManager();
   334         shutdownManager();
   336         do_test_finished();
   337       }));
   338     };
   339   });
   340 }

mercurial