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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // Tests that extensions installed through the registry work as expected
     6 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
     8 // Enable loading extensions from the user and system scopes
     9 Services.prefs.setIntPref("extensions.enabledScopes",
    10                           AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
    11                           AddonManager.SCOPE_SYSTEM);
    13 var addon1 = {
    14   id: "addon1@tests.mozilla.org",
    15   version: "1.0",
    16   name: "Test 1",
    17   targetApplications: [{
    18     id: "xpcshell@tests.mozilla.org",
    19     minVersion: "1",
    20     maxVersion: "1"
    21   }]
    22 };
    24 var addon2 = {
    25   id: "addon2@tests.mozilla.org",
    26   version: "2.0",
    27   name: "Test 2",
    28   targetApplications: [{
    29     id: "xpcshell@tests.mozilla.org",
    30     minVersion: "1",
    31     maxVersion: "2"
    32   }]
    33 };
    35 const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1");
    36 const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2");
    38 function run_test() {
    39   // This test only works where there is a registry.
    40   if (!("nsIWindowsRegKey" in AM_Ci))
    41     return;
    43   do_test_pending();
    45   run_test_1();
    46 }
    48 // Tests whether basic registry install works
    49 function run_test_1() {
    50   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
    51                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    52                         "addon1@tests.mozilla.org", addon1Dir.path);
    53   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    54                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    55                         "addon2@tests.mozilla.org", addon2Dir.path);
    57   startupManager();
    59   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
    60                                "addon2@tests.mozilla.org"], function([a1, a2]) {
    61     do_check_neq(a1, null);
    62     do_check_true(a1.isActive);
    63     do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL));
    64     do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM);
    66     do_check_neq(a2, null);
    67     do_check_true(a2.isActive);
    68     do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL));
    69     do_check_eq(a2.scope, AddonManager.SCOPE_USER);
    71     do_execute_soon(run_test_2);
    72   });
    73 }
    75 // Tests whether uninstalling from the registry works
    76 function run_test_2() {
    77   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
    78                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    79                         "addon1@tests.mozilla.org", null);
    80   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
    81                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    82                         "addon2@tests.mozilla.org", null);
    84   restartManager();
    86   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
    87                                "addon2@tests.mozilla.org"], function([a1, a2]) {
    88     do_check_eq(a1, null);
    89     do_check_eq(a2, null);
    91     do_execute_soon(run_test_3);
    92   });
    93 }
    95 // Checks that the ID in the registry must match that in the install manifest
    96 function run_test_3() {
    97   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
    98                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
    99                         "addon1@tests.mozilla.org", addon2Dir.path);
   100   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   101                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   102                         "addon2@tests.mozilla.org", addon1Dir.path);
   104   restartManager();
   106   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   107                                "addon2@tests.mozilla.org"], function([a1, a2]) {
   108     do_check_eq(a1, null);
   109     do_check_eq(a2, null);
   111     do_execute_soon(run_test_4);
   112   });
   113 }
   115 // Tests whether an extension's ID can change without its directory changing
   116 function run_test_4() {
   117   // Restarting with bad items in the registry should not force an EM restart
   118   restartManager();
   120   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   121                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   122                         "addon1@tests.mozilla.org", null);
   123   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   124                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   125                         "addon2@tests.mozilla.org", null);
   127   restartManager();
   129   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   130                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   131                         "addon1@tests.mozilla.org", addon1Dir.path);
   132   restartManager();
   134   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE,
   135                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   136                         "addon1@tests.mozilla.org", null);
   137   MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER,
   138                         "SOFTWARE\\Mozilla\\XPCShell\\Extensions",
   139                         "addon2@tests.mozilla.org", addon1Dir.path);
   140   writeInstallRDFForExtension(addon2, gProfD, "addon1");
   142   restartManager();
   144   AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   145                                "addon2@tests.mozilla.org"], function([a1, a2]) {
   146     do_check_eq(a1, null);
   147     do_check_neq(a2, null);
   149     do_execute_soon(do_test_finished);
   150   });
   151 }

mercurial