toolkit/mozapps/extensions/test/xpcshell/test_registry.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_registry.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,151 @@
     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 +// Tests that extensions installed through the registry work as expected
     1.9 +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.10 +
    1.11 +// Enable loading extensions from the user and system scopes
    1.12 +Services.prefs.setIntPref("extensions.enabledScopes",
    1.13 +                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
    1.14 +                          AddonManager.SCOPE_SYSTEM);
    1.15 +
    1.16 +var addon1 = {
    1.17 +  id: "addon1@tests.mozilla.org",
    1.18 +  version: "1.0",
    1.19 +  name: "Test 1",
    1.20 +  targetApplications: [{
    1.21 +    id: "xpcshell@tests.mozilla.org",
    1.22 +    minVersion: "1",
    1.23 +    maxVersion: "1"
    1.24 +  }]
    1.25 +};
    1.26 +
    1.27 +var addon2 = {
    1.28 +  id: "addon2@tests.mozilla.org",
    1.29 +  version: "2.0",
    1.30 +  name: "Test 2",
    1.31 +  targetApplications: [{
    1.32 +    id: "xpcshell@tests.mozilla.org",
    1.33 +    minVersion: "1",
    1.34 +    maxVersion: "2"
    1.35 +  }]
    1.36 +};
    1.37 +
    1.38 +const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1");
    1.39 +const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2");
    1.40 +
    1.41 +function run_test() {
    1.42 +  // This test only works where there is a registry.
    1.43 +  if (!("nsIWindowsRegKey" in AM_Ci))
    1.44 +    return;
    1.45 +
    1.46 +  do_test_pending();
    1.47 +
    1.48 +  run_test_1();
    1.49 +}
    1.50 +
    1.51 +// Tests whether basic registry install works
    1.52 +function run_test_1() {
    1.53 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
    1.54 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    1.55 +                        "addon1@tests.mozilla.org", addon1Dir.path);
    1.56 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    1.57 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    1.58 +                        "addon2@tests.mozilla.org", addon2Dir.path);
    1.59 +
    1.60 +  startupManager();
    1.61 +
    1.62 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
    1.63 +                               "addon2@tests.mozilla.org"], function([a1, a2]) {
    1.64 +    do_check_neq(a1, null);
    1.65 +    do_check_true(a1.isActive);
    1.66 +    do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL));
    1.67 +    do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM);
    1.68 +
    1.69 +    do_check_neq(a2, null);
    1.70 +    do_check_true(a2.isActive);
    1.71 +    do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
    1.72 +    do_check_eq(a2.scope, AddonManager.SCOPE_USER);
    1.73 +
    1.74 +    do_execute_soon(run_test_2);
    1.75 +  });
    1.76 +}
    1.77 +
    1.78 +// Tests whether uninstalling from the registry works
    1.79 +function run_test_2() {
    1.80 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
    1.81 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    1.82 +                        "addon1@tests.mozilla.org", null);
    1.83 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    1.84 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    1.85 +                        "addon2@tests.mozilla.org", null);
    1.86 +
    1.87 +  restartManager();
    1.88 +
    1.89 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
    1.90 +                               "addon2@tests.mozilla.org"], function([a1, a2]) {
    1.91 +    do_check_eq(a1, null);
    1.92 +    do_check_eq(a2, null);
    1.93 +
    1.94 +    do_execute_soon(run_test_3);
    1.95 +  });
    1.96 +}
    1.97 +
    1.98 +// Checks that the ID in the registry must match that in the install manifest
    1.99 +function run_test_3() {
   1.100 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   1.101 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.102 +                        "addon1@tests.mozilla.org", addon2Dir.path);
   1.103 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   1.104 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.105 +                        "addon2@tests.mozilla.org", addon1Dir.path);
   1.106 +
   1.107 +  restartManager();
   1.108 +
   1.109 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.110 +                               "addon2@tests.mozilla.org"], function([a1, a2]) {
   1.111 +    do_check_eq(a1, null);
   1.112 +    do_check_eq(a2, null);
   1.113 +
   1.114 +    do_execute_soon(run_test_4);
   1.115 +  });
   1.116 +}
   1.117 +
   1.118 +// Tests whether an extension's ID can change without its directory changing
   1.119 +function run_test_4() {
   1.120 +  // Restarting with bad items in the registry should not force an EM restart
   1.121 +  restartManager();
   1.122 +
   1.123 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   1.124 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.125 +                        "addon1@tests.mozilla.org", null);
   1.126 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   1.127 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.128 +                        "addon2@tests.mozilla.org", null);
   1.129 +
   1.130 +  restartManager();
   1.131 +
   1.132 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   1.133 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.134 +                        "addon1@tests.mozilla.org", addon1Dir.path);
   1.135 +  restartManager();
   1.136 +
   1.137 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   1.138 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.139 +                        "addon1@tests.mozilla.org", null);
   1.140 +  MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   1.141 +                        "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   1.142 +                        "addon2@tests.mozilla.org", addon1Dir.path);
   1.143 +  writeInstallRDFForExtension(addon2, gProfD, "addon1");
   1.144 +
   1.145 +  restartManager();
   1.146 +
   1.147 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.148 +                               "addon2@tests.mozilla.org"], function([a1, a2]) {
   1.149 +    do_check_eq(a1, null);
   1.150 +    do_check_neq(a2, null);
   1.151 +
   1.152 +    do_execute_soon(do_test_finished);
   1.153 +  });
   1.154 +}

mercurial