|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Test for DataStore - install/uninstall apps</title> |
|
6 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
8 </head> |
|
9 <body> |
|
10 <div id="container"></div> |
|
11 <script type="application/javascript;version=1.7"> |
|
12 |
|
13 if (SpecialPowers.isMainProcess()) { |
|
14 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); |
|
15 } |
|
16 |
|
17 SimpleTest.waitForExplicitFinish(); |
|
18 |
|
19 var gBaseURL = 'http://test/tests/dom/datastore/tests/'; |
|
20 var gHostedManifestURL = gBaseURL + 'file_app.sjs?testToken=file_app_install.html'; |
|
21 var gGenerator = runTest(); |
|
22 |
|
23 SpecialPowers.pushPermissions( |
|
24 [{ "type": "browser", "allow": 1, "context": document }, |
|
25 { "type": "embed-apps", "allow": 1, "context": document }, |
|
26 { "type": "webapps-manage", "allow": 1, "context": document }], |
|
27 function() { |
|
28 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], |
|
29 ["dom.testing.ignore_ipc_principal", true], |
|
30 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, function() { |
|
31 gGenerator.next(); }); |
|
32 }); |
|
33 |
|
34 function continueTest() { |
|
35 try { |
|
36 gGenerator.next(); |
|
37 } catch (e if e instanceof StopIteration) { } |
|
38 } |
|
39 |
|
40 function cbError() { |
|
41 ok(false, "Error callback invoked"); |
|
42 finish(); |
|
43 } |
|
44 |
|
45 function runTest() { |
|
46 ok("getDataStores" in navigator, "getDataStores exists"); |
|
47 is(typeof navigator.getDataStores, "function", "getDataStores exists and it's a function"); |
|
48 |
|
49 SpecialPowers.setAllAppsLaunchable(true); |
|
50 SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); |
|
51 |
|
52 SpecialPowers.autoConfirmAppInstall(continueTest); |
|
53 yield undefined; |
|
54 |
|
55 var request = navigator.mozApps.install(gHostedManifestURL); |
|
56 request.onerror = cbError; |
|
57 request.onsuccess = continueTest; |
|
58 yield undefined; |
|
59 |
|
60 var app = request.result; |
|
61 isnot(app, null, "App is non-null"); |
|
62 is(app.manifest.description, "Updated even faster than Firefox, just to annoy slashdotters.", |
|
63 "Manifest is HTML-sanitized"); |
|
64 |
|
65 var ifr = document.createElement('iframe'); |
|
66 ifr.setAttribute('mozbrowser', 'true'); |
|
67 ifr.setAttribute('mozapp', app.manifestURL); |
|
68 ifr.setAttribute('src', app.manifest.launch_path); |
|
69 var domParent = document.getElementById('container'); |
|
70 |
|
71 // Set us up to listen for messages from the app. |
|
72 var listener = function(e) { |
|
73 var message = e.detail.message; |
|
74 if (/^OK/.exec(message)) { |
|
75 ok(true, "Message from app: " + message); |
|
76 } else if (/KO/.exec(message)) { |
|
77 ok(false, "Message from app: " + message); |
|
78 } else if (/DONE/.exec(message)) { |
|
79 ok(true, "Messaging from app complete"); |
|
80 ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
|
81 domParent.removeChild(ifr); |
|
82 |
|
83 // Uninstall the app. |
|
84 request = navigator.mozApps.mgmt.uninstall(app); |
|
85 request.onerror = cbError; |
|
86 request.onsuccess = function() { |
|
87 // All done. |
|
88 finish(); |
|
89 } |
|
90 } |
|
91 } |
|
92 |
|
93 // This event is triggered when the app calls "alert". |
|
94 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
|
95 |
|
96 domParent.appendChild(ifr); |
|
97 } |
|
98 |
|
99 function finish() { |
|
100 SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled"); |
|
101 SimpleTest.finish(); |
|
102 } |
|
103 |
|
104 </script> |
|
105 </body> |
|
106 </html> |