|
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 |
|
13 var gHostedManifestURL1 = 'http://test/tests/dom/datastore/tests/file_app.sjs?template=file_app2.template.webapp&testToken=file_event_receiver.html'; |
|
14 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_event_maker.html'; |
|
15 var gApps = []; |
|
16 |
|
17 function cbError() { |
|
18 ok(false, "Error callback invoked"); |
|
19 finish(); |
|
20 } |
|
21 |
|
22 function installApp(manifest) { |
|
23 var request = navigator.mozApps.install(manifest); |
|
24 request.onerror = cbError; |
|
25 request.onsuccess = function() { |
|
26 gApps.push(request.result); |
|
27 runTest(); |
|
28 } |
|
29 } |
|
30 |
|
31 function uninstallApp(app) { |
|
32 // Uninstall the app |
|
33 var request = navigator.mozApps.mgmt.uninstall(app); |
|
34 request.onerror = cbError; |
|
35 request.onsuccess = function() { |
|
36 runTest(); |
|
37 } |
|
38 } |
|
39 |
|
40 function testApp() { |
|
41 var ifr = document.createElement('iframe'); |
|
42 ifr.setAttribute('mozbrowser', 'true'); |
|
43 ifr.setAttribute('mozapp', gApps[0].manifestURL); |
|
44 ifr.setAttribute('src', gApps[0].manifest.launch_path); |
|
45 var domParent = document.getElementById('container'); |
|
46 |
|
47 // Set us up to listen for messages from the app. |
|
48 var listener = function(e) { |
|
49 var message = e.detail.message; |
|
50 if (/^OK/.exec(message)) { |
|
51 ok(true, "Message from app: " + message); |
|
52 } else if (/KO/.exec(message)) { |
|
53 ok(false, "Message from app: " + message); |
|
54 } else if (/READY/.exec(message)) { |
|
55 ok(true, "App ready"); |
|
56 testApp2(); |
|
57 } else if (/DONE/.exec(message)) { |
|
58 ok(true, "Messaging from app complete"); |
|
59 ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
|
60 domParent.removeChild(ifr); |
|
61 runTest(); |
|
62 } |
|
63 } |
|
64 |
|
65 // This event is triggered when the app calls "alert". |
|
66 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
|
67 domParent.appendChild(ifr); |
|
68 } |
|
69 |
|
70 function testApp2() { |
|
71 var ifr = document.createElement('iframe'); |
|
72 ifr.setAttribute('mozbrowser', 'true'); |
|
73 ifr.setAttribute('mozapp', gApps[1].manifestURL); |
|
74 ifr.setAttribute('src', gApps[1].manifest.launch_path); |
|
75 var domParent = document.getElementById('container'); |
|
76 |
|
77 // Set us up to listen for messages from the app. |
|
78 var listener = function(e) { |
|
79 var message = e.detail.message; |
|
80 if (/^OK/.exec(message)) { |
|
81 ok(true, "Message from app: " + message); |
|
82 } else if (/KO/.exec(message)) { |
|
83 ok(false, "Message from app: " + message); |
|
84 } else if (/DONE/.exec(message)) { |
|
85 ok(true, "Messaging from app complete"); |
|
86 ifr.removeEventListener('mozbrowsershowmodalprompt', listener); |
|
87 domParent.removeChild(ifr); |
|
88 } |
|
89 } |
|
90 |
|
91 // This event is triggered when the app calls "alert". |
|
92 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false); |
|
93 domParent.appendChild(ifr); |
|
94 } |
|
95 |
|
96 var tests = [ |
|
97 // Permissions |
|
98 function() { |
|
99 SpecialPowers.pushPermissions( |
|
100 [{ "type": "browser", "allow": 1, "context": document }, |
|
101 { "type": "embed-apps", "allow": 1, "context": document }, |
|
102 { "type": "webapps-manage", "allow": 1, "context": document }], runTest); |
|
103 }, |
|
104 |
|
105 // Preferences |
|
106 function() { |
|
107 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true], |
|
108 ["dom.ipc.browser_frames.oop_by_default", true], |
|
109 ["dom.testing.ignore_ipc_principal", true], |
|
110 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest); |
|
111 }, |
|
112 |
|
113 function() { |
|
114 SpecialPowers.setAllAppsLaunchable(true); |
|
115 SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true); |
|
116 runTest(); |
|
117 }, |
|
118 |
|
119 // No confirmation needed when an app is installed |
|
120 function() { |
|
121 SpecialPowers.autoConfirmAppInstall(runTest); |
|
122 }, |
|
123 |
|
124 // Installing the apps |
|
125 function() { installApp(gHostedManifestURL1); }, |
|
126 function() { installApp(gHostedManifestURL2); }, |
|
127 |
|
128 // Run tests in apps |
|
129 testApp, |
|
130 |
|
131 // Uninstall the apps |
|
132 function() { uninstallApp(gApps[0]); }, |
|
133 function() { uninstallApp(gApps[1]); }, |
|
134 ]; |
|
135 |
|
136 function runTest() { |
|
137 if (!tests.length) { |
|
138 finish(); |
|
139 return; |
|
140 } |
|
141 |
|
142 var test = tests.shift(); |
|
143 test(); |
|
144 } |
|
145 |
|
146 function finish() { |
|
147 SimpleTest.finish(); |
|
148 } |
|
149 |
|
150 if (SpecialPowers.isMainProcess()) { |
|
151 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm"); |
|
152 } |
|
153 |
|
154 SimpleTest.waitForExplicitFinish(); |
|
155 runTest(); |
|
156 </script> |
|
157 </body> |
|
158 </html> |