toolkit/mozapps/extensions/test/xpcshell/test_upgrade.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 disabled.
     8 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
    10 // Enable loading extensions from the application scope
    11 Services.prefs.setIntPref("extensions.enabledScopes",
    12                           AddonManager.SCOPE_PROFILE +
    13                           AddonManager.SCOPE_APPLICATION);
    15 const profileDir = gProfD.clone();
    16 profileDir.append("extensions");
    18 const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile);
    19 globalDir.append("extensions");
    21 var gGlobalExisted = globalDir.exists();
    22 var gInstallTime = Date.now();
    24 function run_test() {
    25   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    27   // Will be compatible in the first version and incompatible in subsequent versions
    28   writeInstallRDFForExtension({
    29     id: "addon1@tests.mozilla.org",
    30     version: "1.0",
    31     targetApplications: [{
    32       id: "xpcshell@tests.mozilla.org",
    33       minVersion: "1",
    34       maxVersion: "1"
    35     }],
    36     name: "Test Addon 1",
    37     targetPlatforms: [
    38       "XPCShell",
    39       "WINNT_x86",
    40     ]
    41   }, profileDir);
    43   // Works in all tested versions
    44   writeInstallRDFForExtension({
    45     id: "addon2@tests.mozilla.org",
    46     version: "1.0",
    47     targetApplications: [{
    48       id: "xpcshell@tests.mozilla.org",
    49       minVersion: "1",
    50       maxVersion: "2"
    51     }],
    52     name: "Test Addon 2",
    53     targetPlatforms: [
    54       "XPCShell_noarch-spidermonkey"
    55     ]
    56   }, profileDir);
    58   // Will be disabled in the first version and enabled in the second.
    59   writeInstallRDFForExtension({
    60     id: "addon3@tests.mozilla.org",
    61     version: "1.0",
    62     targetApplications: [{
    63       id: "xpcshell@tests.mozilla.org",
    64       minVersion: "2",
    65       maxVersion: "2"
    66     }],
    67     name: "Test Addon 3",
    68   }, profileDir);
    70   // Will be compatible in both versions but will change version in between
    71   var dest = writeInstallRDFForExtension({
    72     id: "addon4@tests.mozilla.org",
    73     version: "1.0",
    74     targetApplications: [{
    75       id: "xpcshell@tests.mozilla.org",
    76       minVersion: "1",
    77       maxVersion: "1"
    78     }],
    79     name: "Test Addon 4",
    80   }, globalDir);
    81   setExtensionModifiedTime(dest, gInstallTime);
    83   do_test_pending();
    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   }
    96   do_execute_soon(do_test_finished);
    97 }
    99 // Test that the test extensions are all installed
   100 function run_test_1() {
   101   startupManager();
   103   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   104                                "addon2@tests.mozilla.org",
   105                                "addon3@tests.mozilla.org",
   106                                "addon4@tests.mozilla.org"],
   107                                function([a1, a2, a3, a4]) {
   109     do_check_neq(a1, null);
   110     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   112     do_check_neq(a2, null);
   113     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   115     do_check_neq(a3, null);
   116     do_check_false(isExtensionInAddonsList(profileDir, a3.id));
   118     do_check_neq(a4, null);
   119     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   120     do_check_eq(a4.version, "1.0");
   122     do_execute_soon(run_test_2);
   123   });
   124 }
   126 // Test that upgrading the application doesn't disable now incompatible add-ons
   127 function run_test_2() {
   128   // Upgrade the extension
   129   var dest = writeInstallRDFForExtension({
   130     id: "addon4@tests.mozilla.org",
   131     version: "2.0",
   132     targetApplications: [{
   133       id: "xpcshell@tests.mozilla.org",
   134       minVersion: "2",
   135       maxVersion: "2"
   136     }],
   137     name: "Test Addon 4",
   138   }, globalDir);
   139   setExtensionModifiedTime(dest, gInstallTime);
   141   restartManager("2");
   142   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   143                                "addon2@tests.mozilla.org",
   144                                "addon3@tests.mozilla.org",
   145                                "addon4@tests.mozilla.org"],
   146                                function([a1, a2, a3, a4]) {
   148     do_check_neq(a1, null);
   149     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   151     do_check_neq(a2, null);
   152     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   154     do_check_neq(a3, null);
   155     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   157     do_check_neq(a4, null);
   158     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   159     do_check_eq(a4.version, "2.0");
   161     do_execute_soon(run_test_3);
   162   });
   163 }
   165 // Test that nothing changes when only the build ID changes.
   166 function run_test_3() {
   167   // Upgrade the extension
   168   var dest = writeInstallRDFForExtension({
   169     id: "addon4@tests.mozilla.org",
   170     version: "3.0",
   171     targetApplications: [{
   172       id: "xpcshell@tests.mozilla.org",
   173       minVersion: "3",
   174       maxVersion: "3"
   175     }],
   176     name: "Test Addon 4",
   177   }, globalDir);
   178   setExtensionModifiedTime(dest, gInstallTime);
   180   // Simulates a simple Build ID change, the platform deletes extensions.ini
   181   // whenever the application is changed.
   182   gExtensionsINI.remove(true);
   183   restartManager();
   185   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   186                                "addon2@tests.mozilla.org",
   187                                "addon3@tests.mozilla.org",
   188                                "addon4@tests.mozilla.org"],
   189                                function([a1, a2, a3, a4]) {
   191     do_check_neq(a1, null);
   192     do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   194     do_check_neq(a2, null);
   195     do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   197     do_check_neq(a3, null);
   198     do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   200     do_check_neq(a4, null);
   201     do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   202     do_check_eq(a4.version, "2.0");
   204     end_test();
   205   });
   206 }

mercurial