|
1 <!DOCTYPE html> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id=989806 |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug 989806</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> |
|
15 |
|
16 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=989806">Mozilla Bug 989806</a> |
|
17 <p id="display"></p> |
|
18 <div id="content" style="display: none"> |
|
19 |
|
20 </div> |
|
21 <pre id="test"> |
|
22 <script class="testbody" type="application/javascript;version=1.7"> |
|
23 |
|
24 "use strict"; |
|
25 |
|
26 let gApp = null; |
|
27 |
|
28 let gExternalInstallOrigin = "http://mochi.test:8888/"; |
|
29 let gExternalAppsPath = gExternalInstallOrigin + "tests/dom/apps/tests/marketplace/"; |
|
30 |
|
31 let gMarketplaceInstallOrigin = "https://marketplace.firefox.com/"; |
|
32 let gMarketplaceAppsPath = gMarketplaceInstallOrigin + "tests/dom/apps/tests/marketplace/"; |
|
33 |
|
34 SimpleTest.waitForExplicitFinish(); |
|
35 |
|
36 function checkAppOnInstallSuccess(aExpected) { |
|
37 navigator.mozApps.mgmt.oninstall = function(evt) { |
|
38 info("Got oninstall event"); |
|
39 gApp = evt.application; |
|
40 gApp.ondownloaderror = function() { |
|
41 ok(false, "Download should succeed (got error: " + |
|
42 gApp.downloadError.name + ")"); |
|
43 PackagedTestHelper.finish(); |
|
44 }; |
|
45 gApp.ondownloadsuccess = function() { |
|
46 info("App downloaded"); |
|
47 PackagedTestHelper.checkAppState(gApp, aExpected.version, aExpected, |
|
48 true, true, PackagedTestHelper.next); |
|
49 }; |
|
50 }; |
|
51 } |
|
52 |
|
53 function checkAppOnInstallError(aExpectedError) { |
|
54 navigator.mozApps.mgmt.oninstall = function(evt) { |
|
55 info("Got oninstall event"); |
|
56 gApp = evt.application; |
|
57 gApp.ondownloaderror = function() { |
|
58 is(gApp.downloadError.name, aExpectedError, |
|
59 "Download fails with expected error: " + aExpectedError); |
|
60 if (gApp.downloadError.name != aExpectedError) { |
|
61 PackagedTestHelper.finish(); |
|
62 } else { |
|
63 PackagedTestHelper.next(); |
|
64 } |
|
65 }; |
|
66 gApp.ondownloadsuccess = function() { |
|
67 ok(false, "App download should fail"); |
|
68 PackagedTestHelper.finish(); |
|
69 }; |
|
70 }; |
|
71 } |
|
72 |
|
73 function checkUninstallApp(aApp) { |
|
74 let req = navigator.mozApps.mgmt.uninstall(aApp); |
|
75 |
|
76 req.onsuccess = function() { |
|
77 info("App uninstalled"); |
|
78 aApp.ondownloadsuccess = null; |
|
79 aApp.ondownloaderror = null; |
|
80 aApp.onprogress = null; |
|
81 PackagedTestHelper.next(); |
|
82 }; |
|
83 req.onerror = function(evt) { |
|
84 ok(false, "App uninstallation should succeed (got unexpected " + |
|
85 evt.target.error.name + ")"); |
|
86 PackagedTestHelper.finish(); |
|
87 }; |
|
88 } |
|
89 |
|
90 function installApp(installOrigin, manifestURL) { |
|
91 let domParent = document.getElementById('container'); |
|
92 |
|
93 let ifr = document.createElement('iframe'); |
|
94 ifr.setAttribute('mozbrowser', 'true'); |
|
95 ifr.setAttribute("src", installOrigin + "tests/dom/apps/tests/pkg_install_iframe.html"); |
|
96 |
|
97 ifr.addEventListener("load", function onIFrameLoad() { |
|
98 ifr.removeEventListener("load", onIFrameLoad, false); |
|
99 |
|
100 ifr.contentWindow.postMessage(manifestURL, "*"); |
|
101 }, false); |
|
102 |
|
103 ifr.addEventListener("mozbrowsererror", function onCertError(e) { |
|
104 ifr.removeEventListener("mozbrowsererror", onCertError); |
|
105 |
|
106 ok(false, "mozbrowsererror: " + e.detail.type); |
|
107 domParent.removeChild(ifr); |
|
108 PackagedTestHelper.finish(); |
|
109 }); |
|
110 |
|
111 window.addEventListener("message", function onMessage(event) { |
|
112 window.removeEventListener("message", onMessage); |
|
113 |
|
114 is(event.data, "Application installed", "Application installed"); |
|
115 |
|
116 domParent.removeChild(ifr); |
|
117 }); |
|
118 |
|
119 domParent.appendChild(ifr); |
|
120 } |
|
121 |
|
122 PackagedTestHelper.setSteps([ |
|
123 function() { |
|
124 SpecialPowers.setAllAppsLaunchable(true); |
|
125 SpecialPowers.addPermission("webapps-manage", true, document); |
|
126 SpecialPowers.addPermission("browser", true, document); |
|
127 SpecialPowers.autoConfirmAppInstall(() => |
|
128 SpecialPowers.pushPrefEnv({set: [["dom.mozBrowserFramesEnabled", true]]}, |
|
129 PackagedTestHelper.next)); |
|
130 }, |
|
131 function() { |
|
132 info("== TEST == Marketplace packaged app from https://marketplace.firefox.com/"); |
|
133 let miniManifestURL = gMarketplaceAppsPath + "marketplace_app.webapp" |
|
134 let expected = { |
|
135 name: "Flashlight (Linterna)", |
|
136 manifestURL: miniManifestURL, |
|
137 installOrigin: gMarketplaceInstallOrigin.slice(0, -1), |
|
138 progress: 0, |
|
139 installState: "installed", |
|
140 downloadAvailable: false, |
|
141 downloading: false, |
|
142 readyToApplyDownload: false, |
|
143 launch_path: "/index.html", |
|
144 version: "2.0", |
|
145 }; |
|
146 checkAppOnInstallSuccess(expected); |
|
147 installApp(gMarketplaceInstallOrigin, miniManifestURL); |
|
148 }, |
|
149 function() { |
|
150 info("== TEST == Marketplace privileged app from https://marketplace.firefox.com/"); |
|
151 let miniManifestURL = gMarketplaceAppsPath + "marketplace_privileged_app.webapp" |
|
152 let expected = { |
|
153 name: "KitchenSink", |
|
154 manifestURL: miniManifestURL, |
|
155 installOrigin: gMarketplaceInstallOrigin.slice(0, -1), |
|
156 progress: 0, |
|
157 installState: "installed", |
|
158 downloadAvailable: false, |
|
159 downloading: false, |
|
160 readyToApplyDownload: false, |
|
161 launch_path: "/index.html", |
|
162 version: "0.2.2", |
|
163 }; |
|
164 checkAppOnInstallSuccess(expected); |
|
165 installApp(gMarketplaceInstallOrigin, miniManifestURL); |
|
166 }, |
|
167 function() { |
|
168 info("== TEST == Marketplace reviewers packaged app from https://marketplace.firefox.com/"); |
|
169 checkAppOnInstallError("INVALID_SIGNATURE"); |
|
170 installApp(gMarketplaceInstallOrigin, gMarketplaceAppsPath + "marketplace_reviewers_app.webapp"); |
|
171 }, |
|
172 function() { |
|
173 info("== TEST == Marketplace packaged app not from https://marketplace.firefox.com/"); |
|
174 checkAppOnInstallError("INSTALL_FROM_DENIED"); |
|
175 installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_app.webapp"); |
|
176 }, |
|
177 function() { |
|
178 info("== TEST == Marketplace privileged app not from https://marketplace.firefox.com/"); |
|
179 checkAppOnInstallError("INSTALL_FROM_DENIED"); |
|
180 installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_privileged_app.webapp"); |
|
181 }, |
|
182 function() { |
|
183 info("== TEST == Marketplace reviewers packaged app not from https://marketplace.firefox.com/"); |
|
184 checkAppOnInstallError("INVALID_SIGNATURE"); |
|
185 installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_reviewers_app.webapp"); |
|
186 }, |
|
187 function() { |
|
188 PackagedTestHelper.finish(); |
|
189 } |
|
190 ]); |
|
191 |
|
192 addLoadEvent(PackagedTestHelper.start); |
|
193 |
|
194 </script> |
|
195 </pre> |
|
196 <div id="container"></div> |
|
197 </body> |
|
198 </html> |