dom/datastore/tests/test_certifiedApp.html

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

mercurial