dom/datastore/tests/test_changes.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/datastore/tests/test_changes.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,183 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test for DataStore - basic operation on a readonly db</title>
     1.9 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +</head>
    1.12 +<body>
    1.13 +<p id="display"></p>
    1.14 +<div id="content" style="display: none">
    1.15 +
    1.16 +</div>
    1.17 +<pre id="test">
    1.18 +  <script type="application/javascript;version=1.7">
    1.19 +
    1.20 +  var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes.html';
    1.21 +  var gHostedManifestURL2 = 'http://example.com/tests/dom/datastore/tests/file_app.sjs?testToken=file_changes2.html&template=file_app2.template.webapp';
    1.22 +  var gApps = [];
    1.23 +  var gApp2Events = 0;
    1.24 +  var gStore;
    1.25 +
    1.26 +  function cbError() {
    1.27 +    ok(false, "Error callback invoked");
    1.28 +    finish();
    1.29 +  }
    1.30 +
    1.31 +  function installApp(aApp) {
    1.32 +    var request = navigator.mozApps.install(aApp);
    1.33 +    request.onerror = cbError;
    1.34 +    request.onsuccess = function() {
    1.35 +      gApps.push(request.result);
    1.36 +      runTest();
    1.37 +    }
    1.38 +  }
    1.39 +
    1.40 +  function uninstallApps() {
    1.41 +    if (!gApps.length) {
    1.42 +      ok(true, "All done!");
    1.43 +      runTest();
    1.44 +      return;
    1.45 +    }
    1.46 +
    1.47 +    var app = gApps.pop();
    1.48 +    var request = navigator.mozApps.mgmt.uninstall(app);
    1.49 +    request.onerror = cbError;
    1.50 +    request.onsuccess = uninstallApps;
    1.51 +  }
    1.52 +
    1.53 +  function setupApp2() {
    1.54 +    var ifr = document.createElement('iframe');
    1.55 +    ifr.setAttribute('mozbrowser', 'true');
    1.56 +    ifr.setAttribute('mozapp', gApps[1].manifestURL);
    1.57 +    ifr.setAttribute('src', gApps[1].manifest.launch_path);
    1.58 +    var domParent = document.getElementById('content');
    1.59 +
    1.60 +    // Set us up to listen for messages from the app.
    1.61 +    var listener = function(e) {
    1.62 +      var message = e.detail.message;
    1.63 +      if (/^OK/.exec(message)) {
    1.64 +        ok(true, "Message from app: " + message);
    1.65 +      } else if (/KO/.exec(message)) {
    1.66 +        ok(false, "Message from app: " + message);
    1.67 +      } else if (/READY/.exec(message)) {
    1.68 +        ok(true, "App2 ready");
    1.69 +        runTest();
    1.70 +      } else if (/DONE/.exec(message)) {
    1.71 +        ok(true, "Messaging from app complete");
    1.72 +        ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    1.73 +        domParent.removeChild(ifr);
    1.74 +        gApp2Events++;
    1.75 +      }
    1.76 +    }
    1.77 +
    1.78 +    // This event is triggered when the app calls "alert".
    1.79 +    ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    1.80 +    domParent.appendChild(ifr);
    1.81 +  }
    1.82 +
    1.83 +  function testApp1() {
    1.84 +    var ifr = document.createElement('iframe');
    1.85 +    ifr.setAttribute('mozbrowser', 'true');
    1.86 +    ifr.setAttribute('mozapp', gApps[0].manifestURL);
    1.87 +    ifr.setAttribute('src', gApps[0].manifest.launch_path);
    1.88 +    var domParent = document.getElementById('content');
    1.89 +
    1.90 +    // Set us up to listen for messages from the app.
    1.91 +    var listener = function(e) {
    1.92 +      var message = e.detail.message;
    1.93 +      if (/^OK/.exec(message)) {
    1.94 +        ok(true, "Message from app: " + message);
    1.95 +      } else if (/KO/.exec(message)) {
    1.96 +        ok(false, "Message from app: " + message);
    1.97 +      } else if (/DONE/.exec(message)) {
    1.98 +        ok(true, "Messaging from app complete");
    1.99 +        ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
   1.100 +        domParent.removeChild(ifr);
   1.101 +        runTest();
   1.102 +      }
   1.103 +    }
   1.104 +
   1.105 +    // This event is triggered when the app calls "alert".
   1.106 +    ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
   1.107 +    domParent.appendChild(ifr);
   1.108 +  }
   1.109 +
   1.110 +  function checkApp2() {
   1.111 +    ok(gApp2Events, "App2 received events");
   1.112 +    runTest();
   1.113 +  }
   1.114 +
   1.115 +  var tests = [
   1.116 +    // Permissions
   1.117 +    function() {
   1.118 +      SpecialPowers.pushPermissions(
   1.119 +        [{ "type": "browser", "allow": 1, "context": document },
   1.120 +         { "type": "embed-apps", "allow": 1, "context": document },
   1.121 +         { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
   1.122 +    },
   1.123 +
   1.124 +    // Preferences
   1.125 +    function() {
   1.126 +      SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
   1.127 +                                         ["dom.testing.ignore_ipc_principal", true],
   1.128 +                                         ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
   1.129 +    },
   1.130 +
   1.131 +    // Enabling mozBrowser
   1.132 +    function() {
   1.133 +      SpecialPowers.setAllAppsLaunchable(true);
   1.134 +      SpecialPowers.pushPrefEnv({"set": [["dom.mozBrowserFramesEnabled", true]]}, runTest);
   1.135 +    },
   1.136 +
   1.137 +    // No confirmation needed when an app is installed
   1.138 +    function() {
   1.139 +      SpecialPowers.autoConfirmAppInstall(runTest);
   1.140 +    },
   1.141 +
   1.142 +    // Installing the app1
   1.143 +    function() { installApp(gHostedManifestURL); },
   1.144 +
   1.145 +    // Installing the app2
   1.146 +    function() { installApp(gHostedManifestURL2); },
   1.147 +
   1.148 +    // Setup app2 for receving events
   1.149 +    setupApp2,
   1.150 +
   1.151 +    // Run tests in app
   1.152 +    testApp1,
   1.153 +
   1.154 +    // Check app2
   1.155 +    checkApp2,
   1.156 +
   1.157 +    // Uninstall the apps
   1.158 +    uninstallApps,
   1.159 +  ];
   1.160 +
   1.161 +  function runTest() {
   1.162 +    if (!tests.length) {
   1.163 +      finish();
   1.164 +      return;
   1.165 +    }
   1.166 +
   1.167 +    var test = tests.shift();
   1.168 +    test();
   1.169 +  }
   1.170 +
   1.171 +  function finish() {
   1.172 +    SimpleTest.finish();
   1.173 +  }
   1.174 +
   1.175 +  if (SpecialPowers.isMainProcess()) {
   1.176 +    SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   1.177 +  }
   1.178 +
   1.179 +  SimpleTest.waitForExplicitFinish();
   1.180 +  runTest();
   1.181 +  </script>
   1.182 +</pre>
   1.183 +</body>
   1.184 +</html>
   1.185 +
   1.186 +

mercurial