dom/datastore/tests/test_changes.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:08fd9bd8e505
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 <p id="display"></p>
11 <div id="content" style="display: none">
12
13 </div>
14 <pre id="test">
15 <script type="application/javascript;version=1.7">
16
17 var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes.html';
18 var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes2.html&template=file_app2.template.webapp';
19 var gApps = [];
20 var gApp2Events = 0;
21 var gStore;
22
23 function cbError() {
24 ok(false, "Error callback invoked");
25 finish();
26 }
27
28 function installApp(aApp) {
29 var request = navigator.mozApps.install(aApp);
30 request.onerror = cbError;
31 request.onsuccess = function() {
32 gApps.push(request.result);
33 runTest();
34 }
35 }
36
37 function uninstallApps() {
38 if (!gApps.length) {
39 ok(true, "All done!");
40 runTest();
41 return;
42 }
43
44 var app = gApps.pop();
45 var request = navigator.mozApps.mgmt.uninstall(app);
46 request.onerror = cbError;
47 request.onsuccess = uninstallApps;
48 }
49
50 function setupApp2() {
51 var ifr = document.createElement('iframe');
52 ifr.setAttribute('mozbrowser', 'true');
53 ifr.setAttribute('mozapp', gApps[1].manifestURL);
54 ifr.setAttribute('src', gApps[1].manifest.launch_path);
55 var domParent = document.getElementById('content');
56
57 // Set us up to listen for messages from the app.
58 var listener = function(e) {
59 var message = e.detail.message;
60 if (/^OK/.exec(message)) {
61 ok(true, "Message from app: " + message);
62 } else if (/KO/.exec(message)) {
63 ok(false, "Message from app: " + message);
64 } else if (/READY/.exec(message)) {
65 ok(true, "App2 ready");
66 runTest();
67 } else if (/DONE/.exec(message)) {
68 ok(true, "Messaging from app complete");
69 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
70 domParent.removeChild(ifr);
71 gApp2Events++;
72 }
73 }
74
75 // This event is triggered when the app calls "alert".
76 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
77 domParent.appendChild(ifr);
78 }
79
80 function testApp1() {
81 var ifr = document.createElement('iframe');
82 ifr.setAttribute('mozbrowser', 'true');
83 ifr.setAttribute('mozapp', gApps[0].manifestURL);
84 ifr.setAttribute('src', gApps[0].manifest.launch_path);
85 var domParent = document.getElementById('content');
86
87 // Set us up to listen for messages from the app.
88 var listener = function(e) {
89 var message = e.detail.message;
90 if (/^OK/.exec(message)) {
91 ok(true, "Message from app: " + message);
92 } else if (/KO/.exec(message)) {
93 ok(false, "Message from app: " + message);
94 } else if (/DONE/.exec(message)) {
95 ok(true, "Messaging from app complete");
96 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
97 domParent.removeChild(ifr);
98 runTest();
99 }
100 }
101
102 // This event is triggered when the app calls "alert".
103 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
104 domParent.appendChild(ifr);
105 }
106
107 function checkApp2() {
108 ok(gApp2Events, "App2 received events");
109 runTest();
110 }
111
112 var tests = [
113 // Permissions
114 function() {
115 SpecialPowers.pushPermissions(
116 [{ "type": "browser", "allow": 1, "context": document },
117 { "type": "embed-apps", "allow": 1, "context": document },
118 { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
119 },
120
121 // Preferences
122 function() {
123 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
124 ["dom.testing.ignore_ipc_principal", true],
125 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
126 },
127
128 // Enabling mozBrowser
129 function() {
130 SpecialPowers.setAllAppsLaunchable(true);
131 SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
132 },
133
134 // No confirmation needed when an app is installed
135 function() {
136 SpecialPowers.autoConfirmAppInstall(runTest);
137 },
138
139 // Installing the app1
140 function() { installApp(gHostedManifestURL); },
141
142 // Installing the app2
143 function() { installApp(gHostedManifestURL2); },
144
145 // Setup app2 for receving events
146 setupApp2,
147
148 // Run tests in app
149 testApp1,
150
151 // Check app2
152 checkApp2,
153
154 // Uninstall the apps
155 uninstallApps,
156 ];
157
158 function runTest() {
159 if (!tests.length) {
160 finish();
161 return;
162 }
163
164 var test = tests.shift();
165 test();
166 }
167
168 function finish() {
169 SimpleTest.finish();
170 }
171
172 if (SpecialPowers.isMainProcess()) {
173 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
174 }
175
176 SimpleTest.waitForExplicitFinish();
177 runTest();
178 </script>
179 </pre>
180 </body>
181 </html>
182
183

mercurial