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