toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.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 // This verifies that app upgrades produce the expected behaviours,
     6 // with strict compatibility checking enabled.
     8 // Enable loading extensions from the application scope
     9 Services.prefs.setIntPref("extensions.enabledScopes",
    10                           AddonManager.SCOPE_PROFILE +
    11                           AddonManager.SCOPE_APPLICATION);
    13 const profileDir = gProfD.clone();
    14 profileDir.append("extensions");
    16 const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile);
    17 globalDir.append("extensions");
    19 var gGlobalExisted = globalDir.exists();
    20 var gInstallTime = Date.now();
    22 function run_test() {
    23   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    25   // Will be enabled in the first version and disabled in subsequent versions
    26   writeInstallRDFForExtension({
    27     id: "addon1@tests.mozilla.org",
    28     version: "1.0",
    29     targetApplications: [{
    30       id: "xpcshell@tests.mozilla.org",
    31       minVersion: "1",
    32       maxVersion: "1"
    33     }],
    34     name: "Test Addon 1",
    35     targetPlatforms: [
    36       "XPCShell",
    37       "WINNT_x86",
    38     ]
    39   }, profileDir);
    41   // Works in all tested versions
    42   writeInstallRDFForExtension({
    43     id: "addon2@tests.mozilla.org",
    44     version: "1.0",
    45     targetApplications: [{
    46       id: "xpcshell@tests.mozilla.org",
    47       minVersion: "1",
    48       maxVersion: "2"
    49     }],
    50     name: "Test Addon 2",
    51     targetPlatforms: [
    52       "XPCShell_noarch-spidermonkey"
    53     ]
    54   }, profileDir);
    56   // Will be disabled in the first version and enabled in the second.
    57   writeInstallRDFForExtension({
    58     id: "addon3@tests.mozilla.org",
    59     version: "1.0",
    60     targetApplications: [{
    61       id: "xpcshell@tests.mozilla.org",
    62       minVersion: "2",
    63       maxVersion: "2"
    64     }],
    65     name: "Test Addon 3",
    66   }, profileDir);
    68   // Will be enabled in both versions but will change version in between
    69   var dest = writeInstallRDFForExtension({
    70     id: "addon4@tests.mozilla.org",
    71     version: "1.0",
    72     targetApplications: [{
    73       id: "xpcshell@tests.mozilla.org",
    74       minVersion: "1",
    75       maxVersion: "1"
    76     }],
    77     name: "Test Addon 4",
    78   }, globalDir);
    79   setExtensionModifiedTime(dest, gInstallTime);
    81   do_test_pending();
    83   Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
    85   run_test_1();
    86 }
    88 function end_test() {
    89   if (!gGlobalExisted) {
    90     globalDir.remove(true);
    91   }
    92   else {
    93     globalDir.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
    94     globalDir.remove(true);
    95   }
    97   Services.prefs.clearUserPref(PREF_EM_STRICT_COMPATIBILITY);
    99   do_execute_soon(do_test_finished);
   100 }
   102 // Test that the test extensions are all installed
   103 function run_test_1() {
   104   startupManager();
   106   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   107                                "addon2@tests.mozilla.org",
   108                                "addon3@tests.mozilla.org",
   109                                "addon4@tests.mozilla.org"],
   110                                function([a1, a2, a3, a4]) {
   112     do_check_neq(a1, null);
   113     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   115     do_check_neq(a2, null);
   116     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   118     do_check_neq(a3, null);
   119     do_check_false(isExtensionInAddonsList(profileDir, a3.id));
   121     do_check_neq(a4, null);
   122     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   123     do_check_eq(a4.version, "1.0");
   125     do_execute_soon(run_test_2);
   126   });
   127 }
   129 // Test that upgrading the application disables now incompatible add-ons
   130 function run_test_2() {
   131   // Upgrade the extension
   132   var dest = writeInstallRDFForExtension({
   133     id: "addon4@tests.mozilla.org",
   134     version: "2.0",
   135     targetApplications: [{
   136       id: "xpcshell@tests.mozilla.org",
   137       minVersion: "2",
   138       maxVersion: "2"
   139     }],
   140     name: "Test Addon 4",
   141   }, globalDir);
   142   setExtensionModifiedTime(dest, gInstallTime);
   144   restartManager("2");
   145   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   146                                "addon2@tests.mozilla.org",
   147                                "addon3@tests.mozilla.org",
   148                                "addon4@tests.mozilla.org"],
   149                                function([a1, a2, a3, a4]) {
   151     do_check_neq(a1, null);
   152     do_check_false(isExtensionInAddonsList(profileDir, a1.id));
   154     do_check_neq(a2, null);
   155     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   157     do_check_neq(a3, null);
   158     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   160     do_check_neq(a4, null);
   161     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   162     do_check_eq(a4.version, "2.0");
   164     do_execute_soon(run_test_3);
   165   });
   166 }
   168 // Test that nothing changes when only the build ID changes.
   169 function run_test_3() {
   170   // Upgrade the extension
   171   var dest = writeInstallRDFForExtension({
   172     id: "addon4@tests.mozilla.org",
   173     version: "3.0",
   174     targetApplications: [{
   175       id: "xpcshell@tests.mozilla.org",
   176       minVersion: "3",
   177       maxVersion: "3"
   178     }],
   179     name: "Test Addon 4",
   180   }, globalDir);
   181   setExtensionModifiedTime(dest, gInstallTime);
   183   // Simulates a simple Build ID change, the platform deletes extensions.ini
   184   // whenever the application is changed.
   185   gExtensionsINI.remove(true);
   186   restartManager();
   188   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   189                                "addon2@tests.mozilla.org",
   190                                "addon3@tests.mozilla.org",
   191                                "addon4@tests.mozilla.org"],
   192                                function([a1, a2, a3, a4]) {
   194     do_check_neq(a1, null);
   195     do_check_false(isExtensionInAddonsList(profileDir, a1.id));
   197     do_check_neq(a2, null);
   198     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   200     do_check_neq(a3, null);
   201     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   203     do_check_neq(a4, null);
   204     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   205     do_check_eq(a4.version, "2.0");
   207     end_test();
   208   });
   209 }

mercurial