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 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=880043
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 880043 Packaged apps installation and update</title>
9 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
10 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
11 <script type="text/javascript" src="test_packaged_app_common.js"></script>
12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
13 </head>
14 <body>
16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=880043">Mozilla Bug 880043</a>
17 <p id="display"></p>
18 <div id="content" style="display: none">
20 </div>
21 <pre id="test">
22 <script class="testbody" type="text/javascript">
24 "use strict";
26 const Ci = SpecialPowers.Ci;
27 const Cc = SpecialPowers.Cc;
28 const Cu = SpecialPowers.Cu;
30 var index = -1;
31 var gDebug = false;
32 var gApp = null;
33 var gAppName = "Simple App";
34 var gInstallOrigin = "http://mochi.test:8888/";
35 var gSJSPath = "tests/dom/apps/tests/signed_app.sjs";
36 var gSJS = gInstallOrigin + gSJSPath;
37 var gPackagePath = gInstallOrigin + "tests/dom/apps/tests/";
38 var gSignedAppOriginsStr ="";
40 SimpleTest.waitForExplicitFinish();
42 function checkAppOnInstallError(aMiniManifestURL, aExpectedError) {
43 navigator.mozApps.mgmt.oninstall = function(evt) {
44 info("Got oninstall event");
45 gApp = evt.application;
46 gApp.ondownloaderror = function() {
47 is(gApp.downloadError.name, aExpectedError,
48 "Download fails with expected error: " + aExpectedError);
49 if (gApp.downloadError.name != aExpectedError) {
50 PackagedTestHelper.finish();
51 } else {
52 PackagedTestHelper.next();
53 }
54 };
55 gApp.ondownloadsuccess = function() {
56 ok(false, "App download should fail");
57 PackagedTestHelper.finish();
58 };
59 };
60 var request = navigator.mozApps.installPackage(aMiniManifestURL);
61 request.onerror = function(evt) {
62 ok(false, "Application should throw the error inside oninstall: " + evt.error.name);
63 PackagedTestHelper.finish();
64 };
65 request.onsuccess = function() {
66 info("Application install returns successfully");
67 };
68 }
70 function checkUninstallApp(aApp) {
71 var req = navigator.mozApps.mgmt.uninstall(aApp);
73 req.onsuccess = function() {
74 info("App uninstalled");
75 aApp.ondownloadsuccess = null;
76 aApp.ondownloaderror = null;
77 aApp.onprogress = null;
78 PackagedTestHelper.next();
79 };
80 req.onerror = function(evt) {
81 ok(false, "App uninstallation should succeed (got unexpected " +
82 evt.target.error.name + ")");
83 PackagedTestHelper.finish();
84 };
85 }
87 var steps = [
88 function() {
89 // Set up
90 info("Test Initial Setup");
91 gSignedAppOriginsStr = SpecialPowers.getCharPref("dom.mozApps.signed_apps_installable_from");
92 var signedAppOriginsStr = gSignedAppOriginsStr.concat("," + gInstallOrigin.slice(0, -1));
93 SpecialPowers.pushPrefEnv({'set': [['dom.mozApps.signed_apps_installable_from', signedAppOriginsStr]]}, function() {
94 var url = SimpleTest.getTestFileURL("chromeAddCert.js");
95 var script = SpecialPowers.loadChromeScript(url);
96 script.addMessageListener("addCertCompleted", function() {
97 SpecialPowers.setAllAppsLaunchable(true);
98 SpecialPowers.addPermission("webapps-manage", true, document);
99 info("Test CA Certificate Selected");
100 PackagedTestHelper.next();
101 script.destroy();
102 });
103 });
104 },
105 function() {
106 info("autoConfirmAppInstall");
107 SpecialPowers.autoConfirmAppInstall(PackagedTestHelper.next);
108 },
109 function() {
110 info("== TEST == Install packaged app");
111 var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1";
113 navigator.mozApps.mgmt.oninstall = function(evt) {
114 info("Got oninstall event");
115 gApp = evt.application;
116 gApp.ondownloaderror = function() {
117 ok(false, "Download should succeed (got error: " +
118 gApp.downloadError.name + ")");
119 PackagedTestHelper.finish();
120 };
121 gApp.ondownloadsuccess = function() {
122 info("App downloaded");
123 var expected = {
124 name: gAppName,
125 manifestURL: miniManifestURL,
126 installOrigin: gInstallOrigin.slice(0, -1),
127 progress: 0,
128 installState: "installed",
129 downloadAvailable: false,
130 downloading: false,
131 readyToApplyDownload: false,
132 };
133 PackagedTestHelper.checkAppState(gApp, 1, expected,
134 true, false, PackagedTestHelper.next);
135 };
136 };
137 info("Installing app: " + miniManifestURL);
138 var request = navigator.mozApps.installPackage(miniManifestURL);
139 request.onerror = function(evt) {
140 ok(false, "Application should have been correctly installed (error: " +
141 JSON.stringify(evt));
142 };
143 request.onsuccess = function() {
144 info("Application installed");
145 };
146 },
147 function() {
148 info("== TEST == Uninstall a signed app");
149 // Uninstall App
150 checkUninstallApp(gApp);
151 },
152 function() {
153 info("== TEST == Install a corrupted package");
154 //Scenario: Corrupted package
155 var miniManifestURL = gSJS + "?" + "app=corrupt&" + "version=1";
156 checkAppOnInstallError(miniManifestURL, "APP_PACKAGE_CORRUPTED");
157 },
158 function() {
159 info("== TEST == Install a unsigned app from a trusted store");
160 //Scenario: Unsigned App from an origin that requires signed apps
161 var miniManifestURL = gSJS + "?" + "app=unknown_issuer&" + "version=1";
162 checkAppOnInstallError(miniManifestURL, "INVALID_SIGNATURE");
163 },
164 function() {
165 info("== TEST == Install packaged app with origin");
166 var miniManifestURL = gSJS + "?" +
167 "app=origin&" +
168 "version=1";
170 navigator.mozApps.mgmt.oninstall = function(evt) {
171 info("Got oninstall event");
172 gApp = evt.application;
173 gApp.ondownloaderror = function() {
174 ok(false, "Download should succeed (got error: " +
175 gApp.downloadError.name + ")");
176 PackagedTestHelper.finish();
177 };
178 gApp.ondownloadsuccess = function() {
179 info("App downloaded");
180 var expected = {
181 name: gAppName,
182 manifestURL: miniManifestURL,
183 installOrigin: gInstallOrigin.slice(0, -1),
184 progress: 0,
185 installState: "installed",
186 downloadAvailable: false,
187 downloading: false,
188 origin: "app://test.origin.privileged.app",
189 readyToApplyDownload: false,
190 };
191 PackagedTestHelper.checkAppState(gApp, 1, expected,
192 true, false, PackagedTestHelper.next);
193 };
194 };
195 info("Installing app: " + miniManifestURL);
196 var request = navigator.mozApps.installPackage(miniManifestURL);
197 request.onerror = function(evt) {
198 ok(false, "Application should have been correctly installed (error: " +
199 JSON.stringify(evt));
200 };
201 request.onsuccess = function() {
202 info("Application installed");
203 };
204 },
205 function() {
206 info("== TEST == Install app from an invalid source");
207 // Scenario: This is where an unexpected store is signing packages and
208 // attempting to install. Please note that after this test you cannot
209 // add new successful tests without changing the preference again
210 SpecialPowers.pushPrefEnv(
211 {'set': [['dom.mozApps.signed_apps_installable_from',
212 gSignedAppOriginsStr]]},
213 function() {
214 var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1";
215 checkAppOnInstallError(miniManifestURL, "INSTALL_FROM_DENIED");
216 });
217 },
218 function() {
219 info("all done!");
220 PackagedTestHelper.finish();
221 }
222 ];
224 PackagedTestHelper.setSteps(steps);
225 PackagedTestHelper.gSJSPath = gSJSPath;
227 addLoadEvent(PackagedTestHelper.start);
229 </script>
230 </pre>
231 </body>
232 </html>