Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests that a reference to a non-existent extension in the registry doesn't |
michael@0 | 6 | // break things |
michael@0 | 7 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 8 | |
michael@0 | 9 | // Enable loading extensions from the user and system scopes |
michael@0 | 10 | Services.prefs.setIntPref("extensions.enabledScopes", |
michael@0 | 11 | AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER + |
michael@0 | 12 | AddonManager.SCOPE_SYSTEM); |
michael@0 | 13 | |
michael@0 | 14 | var addon1 = { |
michael@0 | 15 | id: "addon1@tests.mozilla.org", |
michael@0 | 16 | version: "1.0", |
michael@0 | 17 | name: "Test 1", |
michael@0 | 18 | targetApplications: [{ |
michael@0 | 19 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 20 | minVersion: "1", |
michael@0 | 21 | maxVersion: "1" |
michael@0 | 22 | }] |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | var addon2 = { |
michael@0 | 26 | id: "addon2@tests.mozilla.org", |
michael@0 | 27 | version: "2.0", |
michael@0 | 28 | name: "Test 2", |
michael@0 | 29 | targetApplications: [{ |
michael@0 | 30 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 31 | minVersion: "1", |
michael@0 | 32 | maxVersion: "2" |
michael@0 | 33 | }] |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | const addon1Dir = writeInstallRDFForExtension(addon1, gProfD, "addon1"); |
michael@0 | 37 | const addon2Dir = writeInstallRDFForExtension(addon2, gProfD, "addon2"); |
michael@0 | 38 | const addon3Dir = gProfD.clone(); |
michael@0 | 39 | addon3Dir.append("addon3@tests.mozilla.org"); |
michael@0 | 40 | |
michael@0 | 41 | function run_test() { |
michael@0 | 42 | // This test only works where there is a registry. |
michael@0 | 43 | if (!("nsIWindowsRegKey" in AM_Ci)) |
michael@0 | 44 | return; |
michael@0 | 45 | |
michael@0 | 46 | do_test_pending(); |
michael@0 | 47 | |
michael@0 | 48 | run_test_1(); |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | // Tests whether starting a fresh profile with a bad entry works |
michael@0 | 52 | function run_test_1() { |
michael@0 | 53 | MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_LOCAL_MACHINE, |
michael@0 | 54 | "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
michael@0 | 55 | "addon1@tests.mozilla.org", addon1Dir.path); |
michael@0 | 56 | MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
michael@0 | 57 | "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
michael@0 | 58 | "addon2@tests.mozilla.org", addon2Dir.path); |
michael@0 | 59 | MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
michael@0 | 60 | "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
michael@0 | 61 | "addon3@tests.mozilla.org", addon3Dir.path); |
michael@0 | 62 | |
michael@0 | 63 | startupManager(); |
michael@0 | 64 | |
michael@0 | 65 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 66 | "addon2@tests.mozilla.org", |
michael@0 | 67 | "addon3@tests.mozilla.org"], function([a1, a2, a3]) { |
michael@0 | 68 | do_check_neq(a1, null); |
michael@0 | 69 | do_check_true(a1.isActive); |
michael@0 | 70 | do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 71 | do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM); |
michael@0 | 72 | |
michael@0 | 73 | do_check_neq(a2, null); |
michael@0 | 74 | do_check_true(a2.isActive); |
michael@0 | 75 | do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 76 | do_check_eq(a2.scope, AddonManager.SCOPE_USER); |
michael@0 | 77 | |
michael@0 | 78 | do_check_eq(a3, null); |
michael@0 | 79 | |
michael@0 | 80 | do_execute_soon(run_test_2); |
michael@0 | 81 | }); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | // Tests whether removing the bad entry has any effect |
michael@0 | 85 | function run_test_2() { |
michael@0 | 86 | shutdownManager(); |
michael@0 | 87 | |
michael@0 | 88 | MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
michael@0 | 89 | "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
michael@0 | 90 | "addon3@tests.mozilla.org", addon3Dir.path); |
michael@0 | 91 | |
michael@0 | 92 | startupManager(false); |
michael@0 | 93 | |
michael@0 | 94 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 95 | "addon2@tests.mozilla.org", |
michael@0 | 96 | "addon3@tests.mozilla.org"], function([a1, a2, a3]) { |
michael@0 | 97 | do_check_neq(a1, null); |
michael@0 | 98 | do_check_true(a1.isActive); |
michael@0 | 99 | do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 100 | do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM); |
michael@0 | 101 | |
michael@0 | 102 | do_check_neq(a2, null); |
michael@0 | 103 | do_check_true(a2.isActive); |
michael@0 | 104 | do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 105 | do_check_eq(a2.scope, AddonManager.SCOPE_USER); |
michael@0 | 106 | |
michael@0 | 107 | do_check_eq(a3, null); |
michael@0 | 108 | |
michael@0 | 109 | do_execute_soon(run_test_3); |
michael@0 | 110 | }); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | // Tests adding the bad entry to an existing profile has any effect |
michael@0 | 114 | function run_test_3() { |
michael@0 | 115 | shutdownManager(); |
michael@0 | 116 | |
michael@0 | 117 | MockRegistry.setValue(AM_Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, |
michael@0 | 118 | "SOFTWARE\\Mozilla\\XPCShell\\Extensions", |
michael@0 | 119 | "addon3@tests.mozilla.org", null); |
michael@0 | 120 | |
michael@0 | 121 | startupManager(false); |
michael@0 | 122 | |
michael@0 | 123 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 124 | "addon2@tests.mozilla.org", |
michael@0 | 125 | "addon3@tests.mozilla.org"], function([a1, a2, a3]) { |
michael@0 | 126 | do_check_neq(a1, null); |
michael@0 | 127 | do_check_true(a1.isActive); |
michael@0 | 128 | do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 129 | do_check_eq(a1.scope, AddonManager.SCOPE_SYSTEM); |
michael@0 | 130 | |
michael@0 | 131 | do_check_neq(a2, null); |
michael@0 | 132 | do_check_true(a2.isActive); |
michael@0 | 133 | do_check_false(hasFlag(a2.permissions, AddonManager.PERM_CAN_UNINSTALL)); |
michael@0 | 134 | do_check_eq(a2.scope, AddonManager.SCOPE_USER); |
michael@0 | 135 | |
michael@0 | 136 | do_check_eq(a3, null); |
michael@0 | 137 | |
michael@0 | 138 | do_execute_soon(do_test_finished); |
michael@0 | 139 | }); |
michael@0 | 140 | } |