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/ */
4 Cu.import("resource://gre/modules/osfile.jsm");
5 const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
6 const {require} = devtools;
7 const {installHosted, installPackaged} = require("devtools/app-actor-front");
9 let gAppId = "actor-test";
10 const APP_ORIGIN = "app://" + gAppId;
12 add_test(function testLaunchInexistantApp() {
13 let request = {type: "launch", manifestURL: "http://foo.com"};
14 webappActorRequest(request, function (aResponse) {
15 do_check_eq(aResponse.error, "NO_SUCH_APP");
16 run_next_test();
17 });
18 });
20 add_test(function testCloseInexistantApp() {
21 let request = {type: "close", manifestURL: "http://foo.com"};
22 webappActorRequest(request, function (aResponse) {
23 do_check_eq(aResponse.error, "missingParameter");
24 do_check_eq(aResponse.message, "No application for http://foo.com");
25 run_next_test();
26 });
27 });
29 // Install a test app
30 add_test(function testInstallPackaged() {
31 installTestApp("app.zip", gAppId, function () {
32 run_next_test();
33 });
34 });
36 // Now check that the app appear in getAll
37 add_test(function testGetAll() {
38 let request = {type: "getAll"};
39 webappActorRequest(request, function (aResponse) {
40 do_check_true("apps" in aResponse);
41 let apps = aResponse.apps;
42 do_check_true(apps.length > 0);
43 for (let i = 0; i < apps.length; i++) {
44 let app = apps[i];
45 if (app.id == gAppId) {
46 do_check_eq(app.name, "Test app");
47 do_check_eq(app.manifest.description, "Testing webapps actor");
48 do_check_eq(app.manifest.launch_path, "/index.html");
49 do_check_eq(app.origin, APP_ORIGIN);
50 do_check_eq(app.installOrigin, app.origin);
51 do_check_eq(app.manifestURL, app.origin + "/manifest.webapp");
52 run_next_test();
53 return;
54 }
55 }
56 do_throw("Unable to find the test app by its id");
57 });
58 });
60 add_test(function testGetApp() {
61 let manifestURL = APP_ORIGIN + "/manifest.webapp";
62 let request = {type: "getApp", manifestURL: manifestURL};
63 webappActorRequest(request, function (aResponse) {
64 do_check_true("app" in aResponse);
65 let app = aResponse.app;
66 do_check_eq(app.id, gAppId);
67 do_check_eq(app.name, "Test app");
68 do_check_eq(app.manifest.description, "Testing webapps actor");
69 do_check_eq(app.manifest.launch_path, "/index.html");
70 do_check_eq(app.origin, APP_ORIGIN);
71 do_check_eq(app.installOrigin, app.origin);
72 do_check_eq(app.manifestURL, app.origin + "/manifest.webapp");
73 run_next_test();
74 });
75 });
77 add_test(function testLaunchApp() {
78 let manifestURL = APP_ORIGIN + "/manifest.webapp";
79 let startPoint = "/index.html";
80 let request = {
81 type: "launch",
82 manifestURL: manifestURL,
83 startPoint: startPoint
84 };
85 Services.obs.addObserver(function observer(subject, topic, data) {
86 Services.obs.removeObserver(observer, topic);
87 let json = JSON.parse(data);
88 do_check_eq(json.manifestURL, manifestURL);
89 do_check_eq(json.startPoint, startPoint);
90 run_next_test();
91 }, "webapps-launch", false);
93 webappActorRequest(request, function (aResponse) {
94 do_check_false("error" in aResponse);
95 });
96 });
98 add_test(function testCloseApp() {
99 let manifestURL = APP_ORIGIN + "/manifest.webapp";
100 let request = {
101 type: "close",
102 manifestURL: manifestURL
103 };
104 Services.obs.addObserver(function observer(subject, topic, data) {
105 Services.obs.removeObserver(observer, topic);
106 let json = JSON.parse(data);
107 do_check_eq(json.manifestURL, manifestURL);
109 }, "webapps-close", false);
111 webappActorRequest(request, function (aResponse) {
112 do_check_false("error" in aResponse);
113 run_next_test();
114 });
115 });
117 // The 128px icon is a single red pixel and the 64px one is a blue one
118 // bug 899177: there is a bug with xhr and app:// and jar:// uris
119 // that ends up forcing the content type to application/xml
120 let red1px = "data:application/xml;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4z8AAAAMBAQAY3Y2wAAAAAElFTkSuQmCC";
121 let blue1px = "data:application/xml;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12MwZDgHAAFlAQBDpjhLAAAAAElFTkSuQmCC";
123 add_test(function testGetIcon() {
124 let manifestURL = APP_ORIGIN + "/manifest.webapp";
125 let request = {
126 type: "getIconAsDataURL",
127 manifestURL: manifestURL
128 };
130 webappActorRequest(request, function (aResponse) {
131 do_check_false("error" in aResponse);
133 // By default, getIconAsDataURL return the 128x128 icon
134 do_check_eq(aResponse.url, red1px);
135 run_next_test();
136 });
137 });
139 add_test(function testGetIconWithCustomSize() {
140 let manifestURL = APP_ORIGIN + "/manifest.webapp";
141 let request = {
142 type: "getIconAsDataURL",
143 manifestURL: manifestURL,
144 size: 64
145 };
147 webappActorRequest(request, function (aResponse) {
148 do_check_false("error" in aResponse);
150 do_check_eq(aResponse.url, blue1px);
151 run_next_test();
152 });
153 });
155 add_test(function testUninstall() {
156 let manifestURL = APP_ORIGIN + "/manifest.webapp";
157 let request = {
158 type: "uninstall",
159 manifestURL: manifestURL
160 };
162 Services.obs.addObserver(function observer(subject, topic, data) {
163 Services.obs.removeObserver(observer, topic);
164 let json = JSON.parse(data);
165 do_check_eq(json.manifestURL, manifestURL);
166 do_check_eq(json.origin, APP_ORIGIN);
167 do_check_eq(json.id, gAppId);
168 run_next_test();
169 }, "webapps-uninstall", false);
171 webappActorRequest(request, function (aResponse) {
172 do_check_false("error" in aResponse);
173 });
174 });
176 add_test(function testFileUploadInstall() {
177 let packageFile = do_get_file("data/app.zip");
178 installPackaged(gClient, gActor, packageFile.path, gAppId)
179 .then(function ({ appId }) {
180 do_check_eq(appId, gAppId);
181 run_next_test();
182 }, function (e) {
183 do_throw("Failed install uploaded packaged app: " + e.error + ": " + e.message);
184 });
185 });
187 add_test(function testInstallHosted() {
188 gAppId = "hosted-app";
189 let metadata = {
190 origin: "http://foo.com",
191 installOrigin: "http://metadata.foo.com",
192 manifestURL: "http://foo.com/metadata/manifest.webapp"
193 };
194 let manifest = {
195 name: "My hosted app"
196 };
197 installHosted(gClient, gActor, gAppId, metadata, manifest).then(
198 function ({ appId }) {
199 do_check_eq(appId, gAppId);
200 run_next_test();
201 },
202 function (e) {
203 do_throw("Failed installing hosted app: " + e.error + ": " + e.message);
204 }
205 );
206 });
208 add_test(function testCheckHostedApp() {
209 let request = {type: "getAll"};
210 webappActorRequest(request, function (aResponse) {
211 do_check_true("apps" in aResponse);
212 let apps = aResponse.apps;
213 do_check_true(apps.length > 0);
214 for (let i = 0; i < apps.length; i++) {
215 let app = apps[i];
216 if (app.id == gAppId) {
217 do_check_eq(app.name, "My hosted app");
218 do_check_eq(app.origin, "http://foo.com");
219 do_check_eq(app.installOrigin, "http://metadata.foo.com");
220 do_check_eq(app.manifestURL, "http://foo.com/metadata/manifest.webapp");
221 run_next_test();
222 return;
223 }
224 }
225 do_throw("Unable to find the test app by its id");
226 });
227 });
229 function run_test() {
230 setup();
232 run_next_test();
233 }