toolkit/mozapps/extensions/test/xpcshell/test_distribution.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.

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 // This verifies that add-ons distributed with the application get installed
michael@0 6 // correctly
michael@0 7
michael@0 8 // Allow distributed add-ons to install
michael@0 9 Services.prefs.setBoolPref("extensions.installDistroAddons", true);
michael@0 10
michael@0 11 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 12
michael@0 13 const profileDir = gProfD.clone();
michael@0 14 profileDir.append("extensions");
michael@0 15 const distroDir = gProfD.clone();
michael@0 16 distroDir.append("distribution");
michael@0 17 distroDir.append("extensions");
michael@0 18 registerDirectory("XREAppDist", distroDir.parent);
michael@0 19
michael@0 20 var addon1_1 = {
michael@0 21 id: "addon1@tests.mozilla.org",
michael@0 22 version: "1.0",
michael@0 23 name: "Test version 1",
michael@0 24 targetApplications: [{
michael@0 25 id: "xpcshell@tests.mozilla.org",
michael@0 26 minVersion: "1",
michael@0 27 maxVersion: "5"
michael@0 28 }]
michael@0 29 };
michael@0 30
michael@0 31 var addon1_2 = {
michael@0 32 id: "addon1@tests.mozilla.org",
michael@0 33 version: "2.0",
michael@0 34 name: "Test version 2",
michael@0 35 targetApplications: [{
michael@0 36 id: "xpcshell@tests.mozilla.org",
michael@0 37 minVersion: "1",
michael@0 38 maxVersion: "5"
michael@0 39 }]
michael@0 40 };
michael@0 41
michael@0 42 var addon1_3 = {
michael@0 43 id: "addon1@tests.mozilla.org",
michael@0 44 version: "3.0",
michael@0 45 name: "Test version 3",
michael@0 46 targetApplications: [{
michael@0 47 id: "xpcshell@tests.mozilla.org",
michael@0 48 minVersion: "1",
michael@0 49 maxVersion: "5"
michael@0 50 }]
michael@0 51 };
michael@0 52
michael@0 53 function getActiveVersion() {
michael@0 54 return Services.prefs.getIntPref("bootstraptest.active_version");
michael@0 55 }
michael@0 56
michael@0 57 function getInstalledVersion() {
michael@0 58 return Services.prefs.getIntPref("bootstraptest.installed_version");
michael@0 59 }
michael@0 60
michael@0 61 function setOldModificationTime() {
michael@0 62 // Make sure the installed extension has an old modification time so any
michael@0 63 // changes will be detected
michael@0 64 shutdownManager()
michael@0 65 let extension = gProfD.clone();
michael@0 66 extension.append("extensions");
michael@0 67 if (Services.prefs.getBoolPref("extensions.alwaysUnpack"))
michael@0 68 extension.append("addon1@tests.mozilla.org");
michael@0 69 else
michael@0 70 extension.append("addon1@tests.mozilla.org.xpi");
michael@0 71 setExtensionModifiedTime(extension, Date.now - 10000);
michael@0 72 startupManager(false);
michael@0 73 }
michael@0 74
michael@0 75 function run_test() {
michael@0 76 do_test_pending();
michael@0 77
michael@0 78 run_test_1();
michael@0 79 }
michael@0 80
michael@0 81 // Tests that on the first startup the add-on gets installed
michael@0 82 function run_test_1() {
michael@0 83 writeInstallRDFForExtension(addon1_1, distroDir);
michael@0 84
michael@0 85 startupManager();
michael@0 86
michael@0 87 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 88 do_check_neq(a1, null);
michael@0 89 do_check_eq(a1.version, "1.0");
michael@0 90 do_check_true(a1.isActive);
michael@0 91 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 92 do_check_false(a1.foreignInstall);
michael@0 93
michael@0 94 do_execute_soon(run_test_2);
michael@0 95 });
michael@0 96 }
michael@0 97
michael@0 98 // Tests that starting with a newer version in the distribution dir doesn't
michael@0 99 // install it yet
michael@0 100 function run_test_2() {
michael@0 101 setOldModificationTime();
michael@0 102
michael@0 103 writeInstallRDFForExtension(addon1_2, distroDir);
michael@0 104
michael@0 105 restartManager();
michael@0 106
michael@0 107 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 108 do_check_neq(a1, null);
michael@0 109 do_check_eq(a1.version, "1.0");
michael@0 110 do_check_true(a1.isActive);
michael@0 111 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 112
michael@0 113 do_execute_soon(run_test_3);
michael@0 114 });
michael@0 115 }
michael@0 116
michael@0 117 // Test that an app upgrade installs the newer version
michael@0 118 function run_test_3() {
michael@0 119 restartManager("2");
michael@0 120
michael@0 121 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 122 do_check_neq(a1, null);
michael@0 123 do_check_eq(a1.version, "2.0");
michael@0 124 do_check_true(a1.isActive);
michael@0 125 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 126 do_check_false(a1.foreignInstall);
michael@0 127
michael@0 128 do_execute_soon(run_test_4);
michael@0 129 });
michael@0 130 }
michael@0 131
michael@0 132 // Test that an app upgrade doesn't downgrade the extension
michael@0 133 function run_test_4() {
michael@0 134 setOldModificationTime();
michael@0 135
michael@0 136 writeInstallRDFForExtension(addon1_1, distroDir);
michael@0 137
michael@0 138 restartManager("3");
michael@0 139
michael@0 140 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 141 do_check_neq(a1, null);
michael@0 142 do_check_eq(a1.version, "2.0");
michael@0 143 do_check_true(a1.isActive);
michael@0 144 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 145
michael@0 146 do_execute_soon(run_test_5);
michael@0 147 });
michael@0 148 }
michael@0 149
michael@0 150 // Tests that after uninstalling a restart doesn't re-install the extension
michael@0 151 function run_test_5() {
michael@0 152 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 153 a1.uninstall();
michael@0 154
michael@0 155 restartManager();
michael@0 156
michael@0 157 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 158 do_check_eq(a1, null);
michael@0 159
michael@0 160 do_execute_soon(run_test_6);
michael@0 161 });
michael@0 162 }));
michael@0 163 }
michael@0 164
michael@0 165 // Tests that upgrading the application still doesn't re-install the uninstalled
michael@0 166 // extension
michael@0 167 function run_test_6() {
michael@0 168 restartManager("4");
michael@0 169
michael@0 170 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 171 do_check_eq(a1, null);
michael@0 172
michael@0 173 do_execute_soon(run_test_7);
michael@0 174 });
michael@0 175 }
michael@0 176
michael@0 177 // Tests that a pending install of a newer version of a distributed add-on
michael@0 178 // at app change still gets applied
michael@0 179 function run_test_7() {
michael@0 180 Services.prefs.clearUserPref("extensions.installedDistroAddon.addon1@tests.mozilla.org");
michael@0 181
michael@0 182 installAllFiles([do_get_addon("test_distribution1_2")], function() {
michael@0 183 restartManager(2);
michael@0 184
michael@0 185 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 186 do_check_neq(a1, null);
michael@0 187 do_check_eq(a1.version, "2.0");
michael@0 188 do_check_true(a1.isActive);
michael@0 189 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 190
michael@0 191 a1.uninstall();
michael@0 192 do_execute_soon(run_test_8);
michael@0 193 });
michael@0 194 });
michael@0 195 }
michael@0 196
michael@0 197 // Tests that a pending install of a older version of a distributed add-on
michael@0 198 // at app change gets replaced by the distributed version
michael@0 199 function run_test_8() {
michael@0 200 restartManager();
michael@0 201
michael@0 202 writeInstallRDFForExtension(addon1_3, distroDir);
michael@0 203
michael@0 204 installAllFiles([do_get_addon("test_distribution1_2")], function() {
michael@0 205 restartManager(3);
michael@0 206
michael@0 207 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 208 do_check_neq(a1, null);
michael@0 209 do_check_eq(a1.version, "3.0");
michael@0 210 do_check_true(a1.isActive);
michael@0 211 do_check_eq(a1.scope, AddonManager.SCOPE_PROFILE);
michael@0 212
michael@0 213 a1.uninstall();
michael@0 214 do_execute_soon(run_test_9);
michael@0 215 });
michael@0 216 });
michael@0 217 }
michael@0 218
michael@0 219 // Tests that bootstrapped add-ons distributed start up correctly, also that
michael@0 220 // add-ons with multiple directories get copied fully
michael@0 221 function run_test_9() {
michael@0 222 restartManager();
michael@0 223
michael@0 224 // Copy the test add-on to the distro dir
michael@0 225 let addon = do_get_file("data/test_distribution2_2");
michael@0 226 addon.copyTo(distroDir, "addon2@tests.mozilla.org");
michael@0 227
michael@0 228 restartManager("5");
michael@0 229
michael@0 230 AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
michael@0 231 do_check_neq(a2, null);
michael@0 232 do_check_true(a2.isActive);
michael@0 233
michael@0 234 do_check_eq(getInstalledVersion(), 2);
michael@0 235 do_check_eq(getActiveVersion(), 2);
michael@0 236
michael@0 237 do_check_true(a2.hasResource("bootstrap.js"));
michael@0 238 do_check_true(a2.hasResource("subdir/dummy.txt"));
michael@0 239 do_check_true(a2.hasResource("subdir/subdir2/dummy2.txt"));
michael@0 240
michael@0 241 // Currently installs are unpacked if the source is a directory regardless
michael@0 242 // of the install.rdf property or the global preference
michael@0 243
michael@0 244 let addonDir = profileDir.clone();
michael@0 245 addonDir.append("addon2@tests.mozilla.org");
michael@0 246 do_check_true(addonDir.exists());
michael@0 247 do_check_true(addonDir.isDirectory());
michael@0 248 addonDir.append("subdir");
michael@0 249 do_check_true(addonDir.exists());
michael@0 250 do_check_true(addonDir.isDirectory());
michael@0 251 addonDir.append("subdir2");
michael@0 252 do_check_true(addonDir.exists());
michael@0 253 do_check_true(addonDir.isDirectory());
michael@0 254 addonDir.append("dummy2.txt");
michael@0 255 do_check_true(addonDir.exists());
michael@0 256 do_check_true(addonDir.isFile());
michael@0 257
michael@0 258 a2.uninstall();
michael@0 259
michael@0 260 do_execute_soon(do_test_finished);
michael@0 261 });
michael@0 262 }

mercurial