dom/datastore/tests/test_oop.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/datastore/tests/test_oop.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,128 @@
     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 +<div id="container"></div>
    1.14 +  <script type="application/javascript;version=1.7">
    1.15 +
    1.16 +  var gHostedManifestURL = 'http://test/tests/dom/datastore/tests/file_app.sjs?testToken=file_basic.html';
    1.17 +  var gApp;
    1.18 +
    1.19 +  function cbError() {
    1.20 +    ok(false, "Error callback invoked");
    1.21 +    finish();
    1.22 +  }
    1.23 +
    1.24 +  function installApp() {
    1.25 +    var request = navigator.mozApps.install(gHostedManifestURL);
    1.26 +    request.onerror = cbError;
    1.27 +    request.onsuccess = function() {
    1.28 +      gApp = request.result;
    1.29 +      runTest();
    1.30 +    }
    1.31 +  }
    1.32 +
    1.33 +  function uninstallApp() {
    1.34 +    // Uninstall the app.
    1.35 +    var request = navigator.mozApps.mgmt.uninstall(gApp);
    1.36 +    request.onerror = cbError;
    1.37 +    request.onsuccess = function() {
    1.38 +      // All done.
    1.39 +      info("All done");
    1.40 +      runTest();
    1.41 +    }
    1.42 +  }
    1.43 +
    1.44 +  function testApp() {
    1.45 +    var ifr = document.createElement('iframe');
    1.46 +    ifr.setAttribute('mozbrowser', 'true');
    1.47 +    ifr.setAttribute('mozapp', gApp.manifestURL);
    1.48 +    ifr.setAttribute('src', gApp.manifest.launch_path);
    1.49 +    var domParent = document.getElementById('container');
    1.50 +
    1.51 +    // Set us up to listen for messages from the app.
    1.52 +    var listener = function(e) {
    1.53 +      var message = e.detail.message;
    1.54 +      if (/^OK/.exec(message)) {
    1.55 +        ok(true, "Message from app: " + message);
    1.56 +      } else if (/KO/.exec(message)) {
    1.57 +        ok(false, "Message from app: " + message);
    1.58 +      } else if (/DONE/.exec(message)) {
    1.59 +        ok(true, "Messaging from app complete");
    1.60 +        ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    1.61 +        domParent.removeChild(ifr);
    1.62 +        runTest();
    1.63 +      }
    1.64 +    }
    1.65 +
    1.66 +    // This event is triggered when the app calls "alert".
    1.67 +    ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    1.68 +    domParent.appendChild(ifr);
    1.69 +  }
    1.70 +
    1.71 +  var tests = [
    1.72 +    // Permissions
    1.73 +    function() {
    1.74 +      SpecialPowers.pushPermissions(
    1.75 +        [{ "type": "browser", "allow": 1, "context": document },
    1.76 +         { "type": "embed-apps", "allow": 1, "context": document },
    1.77 +         { "type": "webapps-manage", "allow": 1, "context": document }], runTest);
    1.78 +    },
    1.79 +
    1.80 +    // Preferences
    1.81 +    function() {
    1.82 +      SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    1.83 +                                         ["dom.ipc.browser_frames.oop_by_default", true],
    1.84 +                                         ["dom.testing.ignore_ipc_principal", true],
    1.85 +                                         ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, runTest);
    1.86 +    },
    1.87 +
    1.88 +    function() {
    1.89 +      SpecialPowers.setAllAppsLaunchable(true);
    1.90 +      SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    1.91 +      runTest();
    1.92 +    },
    1.93 +
    1.94 +    // No confirmation needed when an app is installed
    1.95 +    function() {
    1.96 +      SpecialPowers.autoConfirmAppInstall(runTest);
    1.97 +    },
    1.98 +
    1.99 +    // Installing the app
   1.100 +    installApp,
   1.101 +
   1.102 +    // Run tests in app
   1.103 +    testApp,
   1.104 +
   1.105 +    // Uninstall the app
   1.106 +    uninstallApp
   1.107 +  ];
   1.108 +
   1.109 +  function runTest() {
   1.110 +    if (!tests.length) {
   1.111 +      finish();
   1.112 +      return;
   1.113 +    }
   1.114 +
   1.115 +    var test = tests.shift();
   1.116 +    test();
   1.117 +  }
   1.118 +
   1.119 +  function finish() {
   1.120 +    SimpleTest.finish();
   1.121 +  }
   1.122 +
   1.123 +  if (SpecialPowers.isMainProcess()) {
   1.124 +    SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
   1.125 +  }
   1.126 +
   1.127 +  SimpleTest.waitForExplicitFinish();
   1.128 +  runTest();
   1.129 +  </script>
   1.130 +</body>
   1.131 +</html>

mercurial