|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <head> |
|
4 <meta charset="utf-8"> |
|
5 <title>Test for DataStore - basic operation on a readonly db</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 var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_readonly.html'; |
|
13 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_readonly.html&template=file_app2.template.webapp'; |
|
14 var gGenerator = runTest(); |
|
15 |
|
16 SpecialPowers.pushPermissions( |
|
17 [{ "type": "browser", "allow": 1, "context": document }, |
|
18 { "type": "embed-apps", "allow": 1, "context": document }, |
|
19 { "type": "webapps-manage", "allow": 1, "context": document }], |
|
20 function() { gGenerator.next() }); |
|
21 |
|
22 function continueTest() { |
|
23 try { gGenerator.next(); } |
|
24 catch(e) {} |
|
25 } |
|
26 |
|
27 function cbError() { |
|
28 ok(false, "Error callback invoked"); |
|
29 finish(); |
|
30 } |
|
31 |
|
32 function runTest() { |
|
33 SpecialPowers.setAllAppsLaunchable(true); |
|
34 SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); |
|
35 |
|
36 SpecialPowers.autoConfirmAppInstall(continueTest); |
|
37 yield undefined; |
|
38 |
|
39 var request = navigator.mozApps.install(gHostedManifestURL); |
|
40 request.onerror = cbError; |
|
41 request.onsuccess = continueTest; |
|
42 yield undefined; |
|
43 |
|
44 var app = request.result; |
|
45 |
|
46 request = navigator.mozApps.install(gHostedManifestURL2); |
|
47 request.onerror = cbError; |
|
48 request.onsuccess = continueTest; |
|
49 yield undefined; |
|
50 |
|
51 var app2 = request.result; |
|
52 |
|
53 var ifr = document.createElement('iframe'); |
|
54 ifr.setAttribute('mozbrowser', 'true'); |
|
55 ifr.setAttribute('mozapp', app2.manifestURL); |
|
56 ifr.setAttribute('src', app2.manifest.launch_path); |
|
57 var domParent = document.getElementById('container'); |
|
58 |
|
59 // Set us up to listen for messages from the app. |
|
60 var listener = function(e) { |
|
61 var message = e.detail.message; |
|
62 if (/^OK/.exec(message)) { |
|
63 ok(true, "Message from app: " + message); |
|
64 } else if (/KO/.exec(message)) { |
|
65 ok(false, "Message from app: " + message); |
|
66 } else if (/DONE/.exec(message)) { |
|
67 ok(true, "Messaging from app complete"); |
|
68 ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
|
69 domParent.removeChild(ifr); |
|
70 |
|
71 // Uninstall the app. |
|
72 request = navigator.mozApps.mgmt.uninstall(app); |
|
73 request.onerror = cbError; |
|
74 request.onsuccess = function() { |
|
75 // Uninstall app2 |
|
76 request = navigator.mozApps.mgmt.uninstall(app2); |
|
77 request.onerror = cbError; |
|
78 request.onsuccess = function() { |
|
79 // All done. |
|
80 info("All done"); |
|
81 finish(); |
|
82 } |
|
83 } |
|
84 } |
|
85 } |
|
86 |
|
87 // This event is triggered when the app calls "alert". |
|
88 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
|
89 |
|
90 domParent.appendChild(ifr); |
|
91 } |
|
92 |
|
93 function finish() { |
|
94 SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled"); |
|
95 SimpleTest.finish(); |
|
96 } |
|
97 |
|
98 if (SpecialPowers.isMainProcess()) { |
|
99 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); |
|
100 } |
|
101 |
|
102 SimpleTest.waitForExplicitFinish(); |
|
103 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], |
|
104 ["dom.testing.ignore_ipc_principal", true], |
|
105 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); |
|
106 </script> |
|
107 </body> |
|
108 </html> |