toolkit/mozapps/extensions/test/xpcshell/test_strictcompatibility.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_strictcompatibility.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,203 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Tests AddonManager.strictCompatibility and it's related preference,
     1.8 +// extensions.strictCompatibility, and the strictCompatibility option in
     1.9 +// install.rdf
    1.10 +
    1.11 +
    1.12 +// Always compatible
    1.13 +var addon1 = {
    1.14 +  id: "addon1@tests.mozilla.org",
    1.15 +  version: "1.0",
    1.16 +  name: "Test 1",
    1.17 +  targetApplications: [{
    1.18 +    id: "xpcshell@tests.mozilla.org",
    1.19 +    minVersion: "1",
    1.20 +    maxVersion: "1"
    1.21 +  }]
    1.22 +};
    1.23 +
    1.24 +// Incompatible in strict compatibility mode
    1.25 +var addon2 = {
    1.26 +  id: "addon2@tests.mozilla.org",
    1.27 +  version: "1.0",
    1.28 +  name: "Test 2",
    1.29 +  targetApplications: [{
    1.30 +    id: "xpcshell@tests.mozilla.org",
    1.31 +    minVersion: "0.7",
    1.32 +    maxVersion: "0.8"
    1.33 +  }]
    1.34 +};
    1.35 +
    1.36 +// Theme - always uses strict compatibility, so is always incompatible
    1.37 +var addon3 = {
    1.38 +  id: "addon3@tests.mozilla.org",
    1.39 +  version: "1.0",
    1.40 +  name: "Test 3",
    1.41 +  internalName: "test-theme-3",
    1.42 +  targetApplications: [{
    1.43 +    id: "xpcshell@tests.mozilla.org",
    1.44 +    minVersion: "0.8",
    1.45 +    maxVersion: "0.9"
    1.46 +  }]
    1.47 +};
    1.48 +
    1.49 +// Opt-in to strict compatibility - always incompatible
    1.50 +var addon4 = {
    1.51 +  id: "addon4@tests.mozilla.org",
    1.52 +  version: "1.0",
    1.53 +  name: "Test 4",
    1.54 +  strictCompatibility: true,
    1.55 +  targetApplications: [{
    1.56 +    id: "xpcshell@tests.mozilla.org",
    1.57 +    minVersion: "0.8",
    1.58 +    maxVersion: "0.9"
    1.59 +  }]
    1.60 +};
    1.61 +
    1.62 +// Addon from the future - would be marked as compatibile-by-default,
    1.63 +// but minVersion is higher than the app version
    1.64 +var addon5 = {
    1.65 +  id: "addon5@tests.mozilla.org",
    1.66 +  version: "1.0",
    1.67 +  name: "Test 5",
    1.68 +  targetApplications: [{
    1.69 +    id: "xpcshell@tests.mozilla.org",
    1.70 +    minVersion: "3",
    1.71 +    maxVersion: "5"
    1.72 +  }]
    1.73 +};
    1.74 +
    1.75 +// Extremely old addon - maxVersion is less than the mimimum compat version
    1.76 +// set in extensions.minCompatibleVersion
    1.77 +var addon6 = {
    1.78 +  id: "addon6@tests.mozilla.org",
    1.79 +  version: "1.0",
    1.80 +  name: "Test 6",
    1.81 +  targetApplications: [{
    1.82 +    id: "xpcshell@tests.mozilla.org",
    1.83 +    minVersion: "0.1",
    1.84 +    maxVersion: "0.2"
    1.85 +  }]
    1.86 +};
    1.87 +
    1.88 +// Dictionary - incompatible in strict compatibility mode
    1.89 +var addon7= {
    1.90 +  id: "addon7@tests.mozilla.org",
    1.91 +  version: "1.0",
    1.92 +  name: "Test 7",
    1.93 +  type: "64",
    1.94 +  targetApplications: [{
    1.95 +    id: "xpcshell@tests.mozilla.org",
    1.96 +    minVersion: "0.8",
    1.97 +    maxVersion: "0.9"
    1.98 +  }]
    1.99 +};
   1.100 +
   1.101 +
   1.102 +
   1.103 +const profileDir = gProfD.clone();
   1.104 +profileDir.append("extensions");
   1.105 +
   1.106 +
   1.107 +function do_check_compat_status(aStrict, aAddonCompat, aCallback) {
   1.108 +  do_check_eq(AddonManager.strictCompatibility, aStrict);
   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 +                               "addon5@tests.mozilla.org",
   1.114 +                               "addon6@tests.mozilla.org",
   1.115 +                               "addon7@tests.mozilla.org"],
   1.116 +                              function([a1, a2, a3, a4, a5, a6, a7]) {
   1.117 +    do_check_neq(a1, null);
   1.118 +    do_check_eq(a1.isCompatible, aAddonCompat[0]);
   1.119 +    do_check_eq(a1.appDisabled, !aAddonCompat[0]);
   1.120 +    do_check_false(a1.strictCompatibility);
   1.121 +
   1.122 +    do_check_neq(a2, null);
   1.123 +    do_check_eq(a2.isCompatible, aAddonCompat[1]);
   1.124 +    do_check_eq(a2.appDisabled, !aAddonCompat[1]);
   1.125 +    do_check_false(a2.strictCompatibility);
   1.126 +
   1.127 +    do_check_neq(a3, null);
   1.128 +    do_check_eq(a3.isCompatible, aAddonCompat[2]);
   1.129 +    do_check_eq(a3.appDisabled, !aAddonCompat[2]);
   1.130 +    do_check_true(a3.strictCompatibility);
   1.131 +
   1.132 +    do_check_neq(a4, null);
   1.133 +    do_check_eq(a4.isCompatible, aAddonCompat[3]);
   1.134 +    do_check_eq(a4.appDisabled, !aAddonCompat[3]);
   1.135 +    do_check_true(a4.strictCompatibility);
   1.136 +
   1.137 +    do_check_neq(a5, null);
   1.138 +    do_check_eq(a5.isCompatible, aAddonCompat[4]);
   1.139 +    do_check_eq(a5.appDisabled, !aAddonCompat[4]);
   1.140 +    do_check_false(a5.strictCompatibility);
   1.141 +
   1.142 +    do_check_neq(a6, null);
   1.143 +    do_check_eq(a6.isCompatible, aAddonCompat[5]);
   1.144 +    do_check_eq(a6.appDisabled, !aAddonCompat[5]);
   1.145 +    do_check_false(a6.strictCompatibility);
   1.146 +
   1.147 +    do_check_neq(a7, null);
   1.148 +    do_check_eq(a7.isCompatible, aAddonCompat[6]);
   1.149 +    do_check_eq(a7.appDisabled, !aAddonCompat[6]);
   1.150 +    do_check_false(a7.strictCompatibility);
   1.151 +
   1.152 +    do_execute_soon(aCallback);
   1.153 +  });
   1.154 +}
   1.155 +
   1.156 +
   1.157 +function run_test() {
   1.158 +  do_test_pending();
   1.159 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   1.160 +  
   1.161 +  writeInstallRDFForExtension(addon1, profileDir);
   1.162 +  writeInstallRDFForExtension(addon2, profileDir);
   1.163 +  writeInstallRDFForExtension(addon3, profileDir);
   1.164 +  writeInstallRDFForExtension(addon4, profileDir);
   1.165 +  writeInstallRDFForExtension(addon5, profileDir);
   1.166 +  writeInstallRDFForExtension(addon6, profileDir);
   1.167 +  writeInstallRDFForExtension(addon7, profileDir);
   1.168 +
   1.169 +  Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.1");
   1.170 +
   1.171 +  startupManager();
   1.172 +
   1.173 +  // Should default to enabling strict compat.
   1.174 +  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_1);
   1.175 +}
   1.176 +
   1.177 +function run_test_1() {
   1.178 +  do_print("Test 1");
   1.179 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   1.180 +  do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_2);
   1.181 +}
   1.182 +
   1.183 +function run_test_2() {
   1.184 +  do_print("Test 2");
   1.185 +  restartManager();
   1.186 +  do_check_compat_status(false, [true, true, false, false, false, true, true], run_test_3);
   1.187 +}
   1.188 +
   1.189 +function run_test_3() {
   1.190 +  do_print("Test 3");
   1.191 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true);
   1.192 +  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_4);
   1.193 +}
   1.194 +
   1.195 +function run_test_4() {
   1.196 +  do_print("Test 4");
   1.197 +  restartManager();
   1.198 +  do_check_compat_status(true, [true, false, false, false, false, false, false], run_test_5);
   1.199 +}
   1.200 +
   1.201 +function run_test_5() {
   1.202 +  do_print("Test 5");
   1.203 +  Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false);
   1.204 +  Services.prefs.setCharPref(PREF_EM_MIN_COMPAT_APP_VERSION, "0.4");
   1.205 +  do_check_compat_status(false, [true, true, false, false, false, false, true], do_test_finished);
   1.206 +}

mercurial