toolkit/mozapps/extensions/test/xpcshell/test_checkcompatibility.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_checkcompatibility.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     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 the extensions.checkCompatibility.* preferences work.
     1.9 +
    1.10 +var ADDONS = [{
    1.11 +  // Cannot be enabled as it has no target app info for the applciation
    1.12 +  id: "addon1@tests.mozilla.org",
    1.13 +  version: "1.0",
    1.14 +  name: "Test 1",
    1.15 +  targetApplications: [{
    1.16 +    id: "unknown@tests.mozilla.org",
    1.17 +    minVersion: "1",
    1.18 +    maxVersion: "1"
    1.19 +  }]
    1.20 +}, {
    1.21 +  // Always appears incompatible but can be enabled if compatibility checking is
    1.22 +  // disabled
    1.23 +  id: "addon2@tests.mozilla.org",
    1.24 +  version: "1.0",
    1.25 +  name: "Test 2",
    1.26 +  targetApplications: [{
    1.27 +    id: "toolkit@mozilla.org",
    1.28 +    minVersion: "1",
    1.29 +    maxVersion: "1"
    1.30 +  }]
    1.31 +}, {
    1.32 +  // Always appears incompatible but can be enabled if compatibility checking is
    1.33 +  // disabled
    1.34 +  id: "addon3@tests.mozilla.org",
    1.35 +  version: "1.0",
    1.36 +  name: "Test 3",
    1.37 +  targetApplications: [{
    1.38 +    id: "xpcshell@tests.mozilla.org",
    1.39 +    minVersion: "1",
    1.40 +    maxVersion: "1"
    1.41 +  }]
    1.42 +}, { // Always compatible and enabled
    1.43 +  id: "addon4@tests.mozilla.org",
    1.44 +  version: "1.0",
    1.45 +  name: "Test 4",
    1.46 +  targetApplications: [{
    1.47 +    id: "toolkit@mozilla.org",
    1.48 +    minVersion: "1",
    1.49 +    maxVersion: "2"
    1.50 +  }]
    1.51 +}, { // Always compatible and enabled
    1.52 +  id: "addon5@tests.mozilla.org",
    1.53 +  version: "1.0",
    1.54 +  name: "Test 5",
    1.55 +  targetApplications: [{
    1.56 +    id: "xpcshell@tests.mozilla.org",
    1.57 +    minVersion: "1",
    1.58 +    maxVersion: "3"
    1.59 +  }]
    1.60 +}];
    1.61 +
    1.62 +const profileDir = gProfD.clone();
    1.63 +profileDir.append("extensions");
    1.64 +
    1.65 +var gIsNightly = false;
    1.66 +
    1.67 +function run_test() {
    1.68 +  do_test_pending("checkcompatibility.js");
    1.69 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2.2.3", "2");
    1.70 +
    1.71 +  ADDONS.forEach(function(a) {
    1.72 +    writeInstallRDFForExtension(a, profileDir);
    1.73 +  });
    1.74 +
    1.75 +  gIsNightly = isNightlyChannel();
    1.76 +
    1.77 +  startupManager();
    1.78 +
    1.79 +  run_test_1();
    1.80 +}
    1.81 +
    1.82 +/**
    1.83 + * Checks that the add-ons are enabled as expected.
    1.84 + * @param   overridden
    1.85 + *          A boolean indicating that compatibility checking is overridden
    1.86 + * @param   a1
    1.87 + *          The Addon for addon1@tests.mozilla.org
    1.88 + * @param   a2
    1.89 + *          The Addon for addon2@tests.mozilla.org
    1.90 + * @param   a3
    1.91 + *          The Addon for addon3@tests.mozilla.org
    1.92 + * @param   a4
    1.93 + *          The Addon for addon4@tests.mozilla.org
    1.94 + * @param   a5
    1.95 + *          The Addon for addon5@tests.mozilla.org
    1.96 + */
    1.97 +function check_state(overridden, a1, a2, a3, a4, a5) {
    1.98 +  do_check_neq(a1, null);
    1.99 +  do_check_false(a1.isActive);
   1.100 +  do_check_false(a1.isCompatible);
   1.101 +
   1.102 +  do_check_neq(a2, null);
   1.103 +  if (overridden)
   1.104 +    do_check_true(a2.isActive);
   1.105 +  else
   1.106 +    do_check_false(a2.isActive);
   1.107 +  do_check_false(a2.isCompatible);
   1.108 +
   1.109 +  do_check_neq(a3, null);
   1.110 +  if (overridden)
   1.111 +    do_check_true(a3.isActive);
   1.112 +  else
   1.113 +    do_check_false(a3.isActive);
   1.114 +  do_check_false(a3.isCompatible);
   1.115 +
   1.116 +  do_check_neq(a4, null);
   1.117 +  do_check_true(a4.isActive);
   1.118 +  do_check_true(a4.isCompatible);
   1.119 +
   1.120 +  do_check_neq(a5, null);
   1.121 +  do_check_true(a5.isActive);
   1.122 +  do_check_true(a5.isCompatible);
   1.123 +}
   1.124 +
   1.125 +// Tests that with compatibility checking enabled we see the incompatible
   1.126 +// add-ons disabled
   1.127 +function run_test_1() {
   1.128 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.129 +                               "addon2@tests.mozilla.org",
   1.130 +                               "addon3@tests.mozilla.org",
   1.131 +                               "addon4@tests.mozilla.org",
   1.132 +                               "addon5@tests.mozilla.org"],
   1.133 +                               function([a1, a2, a3, a4, a5]) {
   1.134 +    check_state(false, a1, a2, a3, a4, a5);
   1.135 +
   1.136 +    do_execute_soon(run_test_2);
   1.137 +  });
   1.138 +}
   1.139 +
   1.140 +// Tests that with compatibility checking disabled we see the incompatible
   1.141 +// add-ons enabled
   1.142 +function run_test_2() {
   1.143 +  if (gIsNightly)
   1.144 +    Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", false);
   1.145 +  else
   1.146 +    Services.prefs.setBoolPref("extensions.checkCompatibility.2.2", false);
   1.147 +  restartManager();
   1.148 +
   1.149 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.150 +                               "addon2@tests.mozilla.org",
   1.151 +                               "addon3@tests.mozilla.org",
   1.152 +                               "addon4@tests.mozilla.org",
   1.153 +                               "addon5@tests.mozilla.org"],
   1.154 +                               function([a1, a2, a3, a4, a5]) {
   1.155 +    check_state(true, a1, a2, a3, a4, a5);
   1.156 +
   1.157 +    do_execute_soon(run_test_3);
   1.158 +  });
   1.159 +}
   1.160 +
   1.161 +// Tests that with compatibility checking disabled we see the incompatible
   1.162 +// add-ons enabled.
   1.163 +function run_test_3() {
   1.164 +  if (!gIsNightly)
   1.165 +    Services.prefs.setBoolPref("extensions.checkCompatibility.2.1a", false);
   1.166 +  restartManager("2.1a4");
   1.167 +
   1.168 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.169 +                               "addon2@tests.mozilla.org",
   1.170 +                               "addon3@tests.mozilla.org",
   1.171 +                               "addon4@tests.mozilla.org",
   1.172 +                               "addon5@tests.mozilla.org"],
   1.173 +                               function([a1, a2, a3, a4, a5]) {
   1.174 +    check_state(true, a1, a2, a3, a4, a5);
   1.175 +
   1.176 +    do_execute_soon(run_test_4);
   1.177 +  });
   1.178 +}
   1.179 +
   1.180 +// Tests that with compatibility checking enabled we see the incompatible
   1.181 +// add-ons disabled.
   1.182 +function run_test_4() {
   1.183 +  if (gIsNightly)
   1.184 +    Services.prefs.setBoolPref("extensions.checkCompatibility.nightly", true);
   1.185 +  else
   1.186 +    Services.prefs.setBoolPref("extensions.checkCompatibility.2.1a", true);
   1.187 +  restartManager();
   1.188 +
   1.189 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.190 +                               "addon2@tests.mozilla.org",
   1.191 +                               "addon3@tests.mozilla.org",
   1.192 +                               "addon4@tests.mozilla.org",
   1.193 +                               "addon5@tests.mozilla.org"],
   1.194 +                               function([a1, a2, a3, a4, a5]) {
   1.195 +    check_state(false, a1, a2, a3, a4, a5);
   1.196 +
   1.197 +    do_execute_soon(do_test_finished);
   1.198 +  });
   1.199 +}

mercurial