Sat, 03 Jan 2015 20:18:00 +0100
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 trying to upgrade or uninstall an extension that has a file locked
6 // will roll back the upgrade or uninstall and retry at the next restart
8 const profileDir = gProfD.clone();
9 profileDir.append("extensions");
11 function run_test() {
12 // This is only an issue on windows.
13 if (!("nsIWindowsRegKey" in AM_Ci))
14 return;
16 do_test_pending();
17 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
19 startupManager();
20 run_test_1();
21 }
23 function check_addon(aAddon, aVersion) {
24 do_check_neq(aAddon, null);
25 do_check_eq(aAddon.version, aVersion);
26 do_check_true(aAddon.isActive);
27 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
29 do_check_true(aAddon.hasResource("testfile"));
30 if (aVersion == "1.0") {
31 do_check_true(aAddon.hasResource("testfile1"));
32 do_check_false(aAddon.hasResource("testfile2"));
33 }
34 else {
35 do_check_false(aAddon.hasResource("testfile1"));
36 do_check_true(aAddon.hasResource("testfile2"));
37 }
39 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_NONE);
40 }
42 function check_addon_upgrading(aAddon) {
43 do_check_neq(aAddon, null);
44 do_check_eq(aAddon.version, "1.0");
45 do_check_true(aAddon.isActive);
46 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
48 do_check_true(aAddon.hasResource("testfile"));
49 do_check_true(aAddon.hasResource("testfile1"));
50 do_check_false(aAddon.hasResource("testfile2"));
52 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UPGRADE);
54 do_check_eq(aAddon.pendingUpgrade.version, "2.0");
55 }
57 function check_addon_uninstalling(aAddon, aAfterRestart) {
58 do_check_neq(aAddon, null);
59 do_check_eq(aAddon.version, "1.0");
61 if (aAfterRestart) {
62 do_check_false(aAddon.isActive);
63 do_check_false(isExtensionInAddonsList(profileDir, aAddon.id));
64 }
65 else {
66 do_check_true(aAddon.isActive);
67 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
68 }
70 do_check_true(aAddon.hasResource("testfile"));
71 do_check_true(aAddon.hasResource("testfile1"));
72 do_check_false(aAddon.hasResource("testfile2"));
74 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UNINSTALL);
75 }
77 function run_test_1() {
78 installAllFiles([do_get_addon("test_bug587088_1")], function() {
79 restartManager();
81 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
82 check_addon(a1, "1.0");
84 // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
85 let uri = a1.getResourceURI("install.rdf");
86 if (uri.schemeIs("jar"))
87 uri = a1.getResourceURI();
89 let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
90 createInstance(AM_Ci.nsIFileInputStream);
91 fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
93 installAllFiles([do_get_addon("test_bug587088_2")], function() {
95 check_addon_upgrading(a1);
97 restartManager();
99 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
100 check_addon_upgrading(a1);
102 restartManager();
104 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
105 check_addon_upgrading(a1);
107 fstream.close();
109 restartManager();
111 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
112 check_addon(a1, "2.0");
114 a1.uninstall();
115 do_execute_soon(run_test_2);
116 });
117 }));
118 }));
119 });
120 });
121 });
122 }
124 // Test that a failed uninstall gets rolled back
125 function run_test_2() {
126 restartManager();
128 installAllFiles([do_get_addon("test_bug587088_1")], function() {
129 restartManager();
131 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
132 check_addon(a1, "1.0");
134 // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
135 let uri = a1.getResourceURI("install.rdf");
136 if (uri.schemeIs("jar"))
137 uri = a1.getResourceURI();
139 let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
140 createInstance(AM_Ci.nsIFileInputStream);
141 fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
143 a1.uninstall();
145 check_addon_uninstalling(a1);
147 restartManager();
149 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
150 check_addon_uninstalling(a1, true);
152 restartManager();
154 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
155 check_addon_uninstalling(a1, true);
157 fstream.close();
159 restartManager();
161 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
162 do_check_eq(a1, null);
163 var dir = profileDir.clone();
164 dir.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
165 do_check_false(dir.exists());
166 do_check_false(isExtensionInAddonsList(profileDir, "addon1@tests.mozilla.org"));
168 do_execute_soon(do_test_finished);
169 });
170 }));
171 }));
172 }));
173 });
174 }