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