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"/>
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';
18 ok(false,
"Error callback invoked");
22 function installApp() {
23 var request = navigator.mozApps.install(gHostedManifestURL);
24 request.onerror = cbError;
25 request.onsuccess = function() {
26 gApp = request.result;
31 function uninstallApp() {
33 var request = navigator.mozApps.mgmt.uninstall(gApp);
34 request.onerror = cbError;
35 request.onsuccess = function() {
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);
64 // This event is triggered when the app calls
"alert".
65 ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
66 domParent.appendChild(ifr);
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);
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);
90 SpecialPowers.setAllAppsLaunchable(true);
91 // No confirmation needed when an app is installed.
92 SpecialPowers.autoConfirmAppInstall(() =
> {
93 SpecialPowers.autoConfirmAppUninstall(runTest);
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));
112 // Installing the app.
118 // Uninstall the app.
128 var test = tests.shift();
136 SimpleTest.waitForExplicitFinish();