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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,209 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// This verifies that app upgrades produce the expected behaviours,
     1.9 +// with strict compatibility checking enabled.
    1.10 +
    1.11 +// Enable loading extensions from the application scope
    1.12 +Services.prefs.setIntPref("extensions.enabledScopes",
    1.13 +                          AddonManager.SCOPE_PROFILE +
    1.14 +                          AddonManager.SCOPE_APPLICATION);
    1.15 +
    1.16 +const profileDir = gProfD.clone();
    1.17 +profileDir.append("extensions");
    1.18 +
    1.19 +const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile);
    1.20 +globalDir.append("extensions");
    1.21 +
    1.22 +var gGlobalExisted = globalDir.exists();
    1.23 +var gInstallTime = Date.now();
    1.24 +
    1.25 +function run_test() {
    1.26 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.27 +
    1.28 +  // Will be enabled in the first version and disabled in subsequent versions
    1.29 +  writeInstallRDFForExtension({
    1.30 +    id: "addon1@tests.mozilla.org",
    1.31 +    version: "1.0",
    1.32 +    targetApplications: [{
    1.33 +      id: "xpcshell@tests.mozilla.org",
    1.34 +      minVersion: "1",
    1.35 +      maxVersion: "1"
    1.36 +    }],
    1.37 +    name: "Test Addon 1",
    1.38 +    targetPlatforms: [
    1.39 +      "XPCShell",
    1.40 +      "WINNT_x86",
    1.41 +    ]
    1.42 +  }, profileDir);
    1.43 +
    1.44 +  // Works in all tested versions
    1.45 +  writeInstallRDFForExtension({
    1.46 +    id: "addon2@tests.mozilla.org",
    1.47 +    version: "1.0",
    1.48 +    targetApplications: [{
    1.49 +      id: "xpcshell@tests.mozilla.org",
    1.50 +      minVersion: "1",
    1.51 +      maxVersion: "2"
    1.52 +    }],
    1.53 +    name: "Test Addon 2",
    1.54 +    targetPlatforms: [
    1.55 +      "XPCShell_noarch-spidermonkey"
    1.56 +    ]
    1.57 +  }, profileDir);
    1.58 +
    1.59 +  // Will be disabled in the first version and enabled in the second.
    1.60 +  writeInstallRDFForExtension({
    1.61 +    id: "addon3@tests.mozilla.org",
    1.62 +    version: "1.0",
    1.63 +    targetApplications: [{
    1.64 +      id: "xpcshell@tests.mozilla.org",
    1.65 +      minVersion: "2",
    1.66 +      maxVersion: "2"
    1.67 +    }],
    1.68 +    name: "Test Addon 3",
    1.69 +  }, profileDir);
    1.70 +
    1.71 +  // Will be enabled in both versions but will change version in between
    1.72 +  var dest = writeInstallRDFForExtension({
    1.73 +    id: "addon4@tests.mozilla.org",
    1.74 +    version: "1.0",
    1.75 +    targetApplications: [{
    1.76 +      id: "xpcshell@tests.mozilla.org",
    1.77 +      minVersion: "1",
    1.78 +      maxVersion: "1"
    1.79 +    }],
    1.80 +    name: "Test Addon 4",
    1.81 +  }, globalDir);
    1.82 +  setExtensionModifiedTime(dest, gInstallTime);
    1.83 +
    1.84 +  do_test_pending();
    1.85 +
    1.86 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
    1.87 +
    1.88 +  run_test_1();
    1.89 +}
    1.90 +
    1.91 +function end_test() {
    1.92 +  if (!gGlobalExisted) {
    1.93 +    globalDir.remove(true);
    1.94 +  }
    1.95 +  else {
    1.96 +    globalDir.append(do_get_expected_addon_name("addon4@tests.mozilla.org"));
    1.97 +    globalDir.remove(true);
    1.98 +  }
    1.99 +
   1.100 +  Services.prefs.clearUserPref(PREF_EM_STRICT_COMPATIBILITY);
   1.101 +
   1.102 +  do_execute_soon(do_test_finished);
   1.103 +}
   1.104 +
   1.105 +// Test that the test extensions are all installed
   1.106 +function run_test_1() {
   1.107 +  startupManager();
   1.108 +
   1.109 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.110 +                               "addon2@tests.mozilla.org",
   1.111 +                               "addon3@tests.mozilla.org",
   1.112 +                               "addon4@tests.mozilla.org"],
   1.113 +                               function([a1, a2, a3, a4]) {
   1.114 +
   1.115 +    do_check_neq(a1, null);
   1.116 +    do_check_true(isExtensionInAddonsList(profileDir, a1.id));
   1.117 +
   1.118 +    do_check_neq(a2, null);
   1.119 +    do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   1.120 +
   1.121 +    do_check_neq(a3, null);
   1.122 +    do_check_false(isExtensionInAddonsList(profileDir, a3.id));
   1.123 +
   1.124 +    do_check_neq(a4, null);
   1.125 +    do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   1.126 +    do_check_eq(a4.version, "1.0");
   1.127 +
   1.128 +    do_execute_soon(run_test_2);
   1.129 +  });
   1.130 +}
   1.131 +
   1.132 +// Test that upgrading the application disables now incompatible add-ons
   1.133 +function run_test_2() {
   1.134 +  // Upgrade the extension
   1.135 +  var dest = writeInstallRDFForExtension({
   1.136 +    id: "addon4@tests.mozilla.org",
   1.137 +    version: "2.0",
   1.138 +    targetApplications: [{
   1.139 +      id: "xpcshell@tests.mozilla.org",
   1.140 +      minVersion: "2",
   1.141 +      maxVersion: "2"
   1.142 +    }],
   1.143 +    name: "Test Addon 4",
   1.144 +  }, globalDir);
   1.145 +  setExtensionModifiedTime(dest, gInstallTime);
   1.146 +
   1.147 +  restartManager("2");
   1.148 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.149 +                               "addon2@tests.mozilla.org",
   1.150 +                               "addon3@tests.mozilla.org",
   1.151 +                               "addon4@tests.mozilla.org"],
   1.152 +                               function([a1, a2, a3, a4]) {
   1.153 +
   1.154 +    do_check_neq(a1, null);
   1.155 +    do_check_false(isExtensionInAddonsList(profileDir, a1.id));
   1.156 +
   1.157 +    do_check_neq(a2, null);
   1.158 +    do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   1.159 +
   1.160 +    do_check_neq(a3, null);
   1.161 +    do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   1.162 +
   1.163 +    do_check_neq(a4, null);
   1.164 +    do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   1.165 +    do_check_eq(a4.version, "2.0");
   1.166 +
   1.167 +    do_execute_soon(run_test_3);
   1.168 +  });
   1.169 +}
   1.170 +
   1.171 +// Test that nothing changes when only the build ID changes.
   1.172 +function run_test_3() {
   1.173 +  // Upgrade the extension
   1.174 +  var dest = writeInstallRDFForExtension({
   1.175 +    id: "addon4@tests.mozilla.org",
   1.176 +    version: "3.0",
   1.177 +    targetApplications: [{
   1.178 +      id: "xpcshell@tests.mozilla.org",
   1.179 +      minVersion: "3",
   1.180 +      maxVersion: "3"
   1.181 +    }],
   1.182 +    name: "Test Addon 4",
   1.183 +  }, globalDir);
   1.184 +  setExtensionModifiedTime(dest, gInstallTime);
   1.185 +
   1.186 +  // Simulates a simple Build ID change, the platform deletes extensions.ini
   1.187 +  // whenever the application is changed.
   1.188 +  gExtensionsINI.remove(true);
   1.189 +  restartManager();
   1.190 +
   1.191 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.192 +                               "addon2@tests.mozilla.org",
   1.193 +                               "addon3@tests.mozilla.org",
   1.194 +                               "addon4@tests.mozilla.org"],
   1.195 +                               function([a1, a2, a3, a4]) {
   1.196 +
   1.197 +    do_check_neq(a1, null);
   1.198 +    do_check_false(isExtensionInAddonsList(profileDir, a1.id));
   1.199 +
   1.200 +    do_check_neq(a2, null);
   1.201 +    do_check_true(isExtensionInAddonsList(profileDir, a2.id));
   1.202 +
   1.203 +    do_check_neq(a3, null);
   1.204 +    do_check_true(isExtensionInAddonsList(profileDir, a3.id));
   1.205 +
   1.206 +    do_check_neq(a4, null);
   1.207 +    do_check_true(isExtensionInAddonsList(globalDir, a4.id));
   1.208 +    do_check_eq(a4.version, "2.0");
   1.209 +
   1.210 +    end_test();
   1.211 +  });
   1.212 +}

mercurial