|
1 <?xml version="1.0"?> |
|
2 |
|
3 <!-- Any copyright is dedicated to the Public Domain. |
|
4 - http://creativecommons.org/publicdomain/zero/1.0/ --> |
|
5 |
|
6 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
7 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
8 |
|
9 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
|
10 title="Mozilla Bug 741549"> |
|
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
12 <script type="application/javascript" src="head.js"/> |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549" |
|
16 target="_blank">Mozilla Bug 741549</a> |
|
17 </body> |
|
18 |
|
19 <script> |
|
20 |
|
21 var steps = [ |
|
22 noArgs, |
|
23 parseError, |
|
24 invalidManifest, |
|
25 permissionDenied, |
|
26 invalidContent, |
|
27 invalidLaunchPath, |
|
28 invalidLaunchPath2, |
|
29 invalidEntryPoint, |
|
30 invalidLocaleEntryPoint, |
|
31 invalidActivityHref, |
|
32 invalidActivityHref2, |
|
33 invalidMessage, |
|
34 fileURL, |
|
35 originNotAllowed, |
|
36 originAllowed, |
|
37 ]; |
|
38 |
|
39 runAll(steps); |
|
40 |
|
41 function noArgs(next) { |
|
42 try { |
|
43 navigator.mozApps.install(); |
|
44 } catch (e) { |
|
45 is(e.message, "Not enough arguments \[mozIDOMApplicationRegistry.install\]", |
|
46 "install without arguments throws exception"); |
|
47 next(); |
|
48 } |
|
49 } |
|
50 |
|
51 function parseError(next) { |
|
52 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/json_syntax_error.webapp"; |
|
53 |
|
54 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
55 is(this.error.name, "MANIFEST_PARSE_ERROR", "manifest with syntax error"); |
|
56 next(); |
|
57 }; |
|
58 } |
|
59 |
|
60 function invalidManifest(next) { |
|
61 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/missing_required_field.webapp"; |
|
62 |
|
63 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
64 is(this.error.name, "INVALID_MANIFEST", "manifest missing required field"); |
|
65 next(); |
|
66 }; |
|
67 } |
|
68 |
|
69 function permissionDenied(next) { |
|
70 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/no_delegated_install.webapp"; |
|
71 |
|
72 confirmNextInstall(); |
|
73 var request = navigator.mozApps.install(url, null); |
|
74 |
|
75 request.onerror = function onInstallError() { |
|
76 is(this.error.name, "DENIED", "manifest without installs_allowed_from"); |
|
77 next(); |
|
78 }; |
|
79 |
|
80 request.onsuccess = function onInstall() { |
|
81 todo(false, "manifest without installs_allowed_from fails"); |
|
82 navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() { |
|
83 next(); |
|
84 }; |
|
85 }; |
|
86 } |
|
87 |
|
88 function invalidContent(next) { |
|
89 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/bad_content_type.webapp"; |
|
90 |
|
91 var request = navigator.mozApps.install(url, null); |
|
92 |
|
93 request.onerror = function onInstallError() { |
|
94 is(this.error.name, "INVALID_MANIFEST", "manifest with bad content type"); |
|
95 next(); |
|
96 }; |
|
97 |
|
98 request.onsuccess = function onInstall() { |
|
99 ok(false, "manifest with bad content type should fail"); |
|
100 navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() { |
|
101 next(); |
|
102 }; |
|
103 }; |
|
104 } |
|
105 |
|
106 function invalidLaunchPath(next) { |
|
107 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path.webapp"; |
|
108 |
|
109 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
110 is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest"); |
|
111 next(); |
|
112 }; |
|
113 } |
|
114 |
|
115 function invalidLaunchPath2(next) { |
|
116 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path2.webapp"; |
|
117 |
|
118 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
119 is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest"); |
|
120 next(); |
|
121 }; |
|
122 } |
|
123 |
|
124 function invalidEntryPoint(next) { |
|
125 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_entry_point.webapp"; |
|
126 |
|
127 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
128 is(this.error.name, "INVALID_MANIFEST", "manifest missing required field"); |
|
129 next(); |
|
130 }; |
|
131 } |
|
132 |
|
133 function invalidLocaleEntryPoint(next) { |
|
134 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_locale_entry_point.webapp"; |
|
135 |
|
136 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
137 is(this.error.name, "INVALID_MANIFEST", "manifest missing required field"); |
|
138 next(); |
|
139 }; |
|
140 } |
|
141 |
|
142 function invalidActivityHref(next) { |
|
143 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href.webapp"; |
|
144 |
|
145 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
146 is(this.error.name, "INVALID_MANIFEST", "Manifest has non-relative URI for activity href"); |
|
147 next(); |
|
148 }; |
|
149 } |
|
150 |
|
151 function invalidActivityHref2(next) { |
|
152 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href2.webapp"; |
|
153 |
|
154 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
155 is(this.error.name, "INVALID_MANIFEST", "Manifest has data: URI for activity href"); |
|
156 next(); |
|
157 }; |
|
158 } |
|
159 |
|
160 function invalidMessage(next) { |
|
161 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_message.webapp"; |
|
162 |
|
163 navigator.mozApps.install(url, null).onerror = function onInstallError() { |
|
164 is(this.error.name, "INVALID_MANIFEST", "Manifest has absolute message href"); |
|
165 next(); |
|
166 }; |
|
167 } |
|
168 |
|
169 function fileURL(next) { |
|
170 try { |
|
171 var req = navigator.mozApps.install("file:///nonexistent"); |
|
172 req.onsuccess = function() { |
|
173 ok(false, "Unexpected success installing non existent file"); |
|
174 }; |
|
175 req.onerror = function() { |
|
176 is(this.error.name, "INVALID_URL", "Expected INVALID_URL"); |
|
177 }; |
|
178 } catch(ex) { |
|
179 ok(false, "Unexpected exception " + ex.message); |
|
180 } |
|
181 |
|
182 try { |
|
183 req = navigator.mozApps.install("file:///"); |
|
184 req.onsuccess = function() { |
|
185 ok(false, "Unexpected success installing file: URL"); |
|
186 }; |
|
187 req.onerror = function() { |
|
188 is(this.error.name, "INVALID_URL", "Expected INVALID_URL"); |
|
189 }; |
|
190 } catch(ex) { |
|
191 ok(false, "Unexpected exception " + ex.message); |
|
192 } |
|
193 |
|
194 next(); |
|
195 } |
|
196 |
|
197 function originNotAllowed(next) { |
|
198 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_example.com.webapp"; |
|
199 |
|
200 var request = navigator.mozApps.install(url, null); |
|
201 |
|
202 request.onerror = function onInstallError() { |
|
203 is(this.error.name, "INSTALL_FROM_DENIED", "origin is not in installs_allowed_from"); |
|
204 next(); |
|
205 }; |
|
206 |
|
207 request.onsuccess = function onInstall() { |
|
208 ok(false, "test should fail because of installs_allowed_from"); |
|
209 navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() { |
|
210 next(); |
|
211 }; |
|
212 }; |
|
213 } |
|
214 |
|
215 function originAllowed(next) { |
|
216 var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_chrome_mochitests.webapp"; |
|
217 |
|
218 confirmNextInstall(); |
|
219 var request = navigator.mozApps.install(url, null); |
|
220 |
|
221 request.onerror = function onInstallError() { |
|
222 ok(false, "installation error: " + this.error.name); |
|
223 next(); |
|
224 }; |
|
225 |
|
226 request.onsuccess = function onInstall() { |
|
227 ok(true, "test origin is in installs_allowed_from"); |
|
228 navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() { |
|
229 next(); |
|
230 }; |
|
231 }; |
|
232 } |
|
233 |
|
234 </script> |
|
235 </window> |