|
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 <iframe id="iframe"/> |
|
20 |
|
21 <script> |
|
22 |
|
23 var url1 = "http://test1.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp"; |
|
24 var url2 = "http://test2.example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp"; |
|
25 |
|
26 // References to the apps we install, so we can uninstall them afterward. |
|
27 // Note that app2 is set by the helper page, which throws "TypeError: can't |
|
28 // redefine non-configurable property 'app2'" if we declare it here. |
|
29 var app1 /* , app2 */; |
|
30 |
|
31 var steps = [ |
|
32 installAppFromOwnOrigin, |
|
33 installAppFromOtherOrigin, |
|
34 getInstalled, |
|
35 getAll, |
|
36 uninstall, |
|
37 ]; |
|
38 |
|
39 runAll(steps); |
|
40 |
|
41 /** |
|
42 * Install the first app from our own origin (chrome://mochitests). Note that |
|
43 * the app itself is from a different origin (http://test1.example.com). |
|
44 */ |
|
45 function installAppFromOwnOrigin(next) { |
|
46 confirmNextInstall(); |
|
47 navigator.mozApps.install(url1, null).onsuccess = function onInstall() { |
|
48 app1 = this.result; |
|
49 next(); |
|
50 }; |
|
51 } |
|
52 |
|
53 /** |
|
54 * Install the second app from another origin (http://test2.example.com) using |
|
55 * the helper page. In this case, the origin of the installing page is the same |
|
56 * as the origin of the app being installed, so the helper page can test |
|
57 * getSelf(). |
|
58 */ |
|
59 function installAppFromOtherOrigin(next) { |
|
60 document.getElementById("iframe").setAttribute("src", |
|
61 "http://test2.example.com/chrome/dom/tests/mochitest/webapps/cross_origin.html"); |
|
62 |
|
63 window.addEventListener("message", function onMessage(event) { |
|
64 if (event.data == "next") { |
|
65 window.removeEventListener("message", onMessage, false); |
|
66 next(); |
|
67 } |
|
68 }, false); |
|
69 } |
|
70 |
|
71 function getInstalled(next) { |
|
72 navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() { |
|
73 var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0]; |
|
74 ok(app1, "getInstalled() includes app installed from own origin"); |
|
75 |
|
76 var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0]; |
|
77 ok(!app2, "getInstalled() excludes app installed from other origin"); |
|
78 |
|
79 next(); |
|
80 }; |
|
81 } |
|
82 |
|
83 function getAll(next) { |
|
84 navigator.mozApps.mgmt.getAll().onsuccess = function onMgmtGetAll() { |
|
85 var app1 = [a for (a of this.result) if (a.manifestURL == url1)][0]; |
|
86 ok(app1, "mgmt.getAll() includes app installed from own origin"); |
|
87 |
|
88 var app2 = [a for (a of this.result) if (a.manifestURL == url2)][0]; |
|
89 ok(app2, "mgmt.getAll() includes app installed from other origin"); |
|
90 |
|
91 next(); |
|
92 }; |
|
93 } |
|
94 |
|
95 function uninstall(next) { |
|
96 navigator.mozApps.mgmt.uninstall(app1).onsuccess = function onUninstallApp1() { |
|
97 navigator.mozApps.mgmt.uninstall(app2).onsuccess = function onUninstallApp2() { |
|
98 next(); |
|
99 }; |
|
100 }; |
|
101 } |
|
102 |
|
103 </script> |
|
104 </window> |