Bumping manifests a=b2g-bump
[gecko.git] / dom / datastore / tests / test_basic.html
blobc8637447a2f2dfbe8efa368cdc999a3dd0da249e
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">
13 var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_basic.html';
14 var gApp;
16 function cbError() {
17 ok(false, "Error callback invoked");
18 finish();
21 function installApp() {
22 var request = navigator.mozApps.install(gHostedManifestURL);
23 request.onerror = cbError;
24 request.onsuccess = function() {
25 gApp = request.result;
26 runTest();
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();
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');
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();
63 // This event is triggered when the app calls "alert".
64 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
65 domParent.appendChild(ifr);
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);
77 // Preferences
78 function() {
79 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
80 ["dom.datastore.sysMsgOnChangeShortTimeoutSec", 1],
81 ["dom.datastore.sysMsgOnChangeLongTimeoutSec", 3],
82 ["dom.testing.ignore_ipc_principal", true],
83 ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
86 function() {
87 if (SpecialPowers.isMainProcess()) {
88 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
91 SpecialPowers.setAllAppsLaunchable(true);
92 SpecialPowers.pushPrefEnv({"set":[["dom.mozBrowserFramesEnabled", true]]}, runTest);
95 // No confirmation needed when an app is installed
96 function() {
97 SpecialPowers.autoConfirmAppInstall(() =>
98 SpecialPowers.autoConfirmAppUninstall(runTest));
101 // Installing the app
102 installApp,
104 // Run tests in app
105 testApp,
107 // Uninstall the app
108 uninstallApp
111 function runTest() {
112 if (!tests.length) {
113 finish();
114 return;
117 var test = tests.shift();
118 test();
121 function finish() {
122 SimpleTest.finish();
125 SimpleTest.waitForExplicitFinish();
126 runTest();
127 </script>
128 </body>
129 </html>