Bumping manifests a=b2g-bump
[gecko.git] / dom / datastore / tests / test_notify_system_message.html
blob1312c75512cdf7c50cdd6712ef09531480a17f54
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test for DataStore - notify updates with system messages</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_notify_system_message.html';
14 var gHostedPageURL = 'http://mochi.test:8888/tests/dom/datastore/tests/file_notify_system_message.html';
15 var gApp;
17 function cbError() {
18 ok(false, "Error callback invoked");
19 finish();
22 function installApp() {
23 var request = navigator.mozApps.install(gHostedManifestURL);
24 request.onerror = cbError;
25 request.onsuccess = function() {
26 gApp = request.result;
27 runTest();
31 function uninstallApp() {
32 // Uninstall the app.
33 var request = navigator.mozApps.mgmt.uninstall(gApp);
34 request.onerror = cbError;
35 request.onsuccess = function() {
36 // All done.
37 info("All done");
38 runTest();
42 function testApp() {
43 var ifr = document.createElement('iframe');
44 ifr.setAttribute('mozbrowser', 'true');
45 ifr.setAttribute('mozapp', gApp.manifestURL);
46 ifr.setAttribute('src', gApp.manifest.launch_path);
47 var domParent = document.getElementById('container');
49 // Set us up to listen for messages from the app.
50 var listener = function(e) {
51 var message = e.detail.message;
52 if (/^OK/.exec(message)) {
53 ok(true, "Message from app: " + message);
54 } else if (/KO/.exec(message)) {
55 ok(false, "Message from app: " + message);
56 } else if (/DONE/.exec(message)) {
57 ok(true, "Messaging from app complete");
58 ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
59 domParent.removeChild(ifr);
60 runTest();
64 // This event is triggered when the app calls "alert".
65 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
66 domParent.appendChild(ifr);
69 var tests = [
70 // Permissions.
71 function() {
72 SpecialPowers.pushPermissions(
73 [{ "type": "browser", "allow": 1, "context": document },
74 { "type": "embed-apps", "allow": 1, "context": document },
75 { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
78 // Preferences.
79 function() {
80 SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
81 ["dom.datastore.sysMsgOnChangeShortTimeoutSec", 1],
82 ["dom.datastore.sysMsgOnChangeLongTimeoutSec", 3],
83 ["dom.sysmsg.enabled", true],
84 ["dom.testing.ignore_ipc_principal", true],
85 ["dom.testing.datastore_enabled_for_hosted_apps", true],
86 ["dom.mozBrowserFramesEnabled", true]]}, runTest);
89 function() {
90 SpecialPowers.setAllAppsLaunchable(true);
91 // No confirmation needed when an app is installed.
92 SpecialPowers.autoConfirmAppInstall(() => {
93 SpecialPowers.autoConfirmAppUninstall(runTest);
94 });
97 function() {
98 if (SpecialPowers.isMainProcess()) {
99 SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
100 SpecialPowers.Cu.import("resource://gre/modules/Services.jsm");
101 var ioService = SpecialPowers.Cc["@mozilla.org/network/io-service;1"]
102 .getService(SpecialPowers.Ci.nsIIOService);
103 var systemMessenger = SpecialPowers.Cc["@mozilla.org/system-message-internal;1"]
104 .getService(SpecialPowers.Ci.nsISystemMessagesInternal);
105 systemMessenger.registerPage("datastore-update-foo",
106 ioService.newURI(gHostedPageURL, null, null),
107 ioService.newURI(gHostedManifestURL, null, null));
109 runTest();
112 // Installing the app.
113 installApp,
115 // Run tests in app.
116 testApp,
118 // Uninstall the app.
119 uninstallApp
122 function runTest() {
123 if (!tests.length) {
124 finish();
125 return;
128 var test = tests.shift();
129 test();
132 function finish() {
133 SimpleTest.finish();
136 SimpleTest.waitForExplicitFinish();
137 runTest();
138 </script>
139 </body>
140 </html>