dom/datastore/tests/test_app_install.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/datastore/tests/test_app_install.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <meta charset="utf-8">
     1.8 +  <title>Test for DataStore - install/uninstall apps</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 +  if (SpecialPowers.isMainProcess()) {
    1.17 +    SpecialPowers.Cu.import("resource://gre/modules/DataStoreChangeNotifier.jsm");
    1.18 +  }
    1.19 +
    1.20 +  SimpleTest.waitForExplicitFinish();
    1.21 +
    1.22 +  var gBaseURL = 'http://test/tests/dom/datastore/tests/';
    1.23 +  var gHostedManifestURL = gBaseURL + 'file_app.sjs?testToken=file_app_install.html';
    1.24 +  var gGenerator = runTest();
    1.25 +
    1.26 +  SpecialPowers.pushPermissions(
    1.27 +    [{ "type": "browser", "allow": 1, "context": document },
    1.28 +     { "type": "embed-apps", "allow": 1, "context": document },
    1.29 +     { "type": "webapps-manage", "allow": 1, "context": document }],
    1.30 +    function() {
    1.31 +      SpecialPowers.pushPrefEnv({"set": [["dom.datastore.enabled", true],
    1.32 +                                         ["dom.testing.ignore_ipc_principal", true],
    1.33 +                                         ["dom.testing.datastore_enabled_for_hosted_apps", true]]}, function() {
    1.34 +        gGenerator.next(); });
    1.35 +    });
    1.36 +
    1.37 +  function continueTest() {
    1.38 +    try {
    1.39 +      gGenerator.next();
    1.40 +    } catch (e if e instanceof StopIteration) { }
    1.41 +  }
    1.42 +
    1.43 +  function cbError() {
    1.44 +    ok(false, "Error callback invoked");
    1.45 +    finish();
    1.46 +  }
    1.47 +
    1.48 +  function runTest() {
    1.49 +    ok("getDataStores" in navigator, "getDataStores exists");
    1.50 +    is(typeof navigator.getDataStores, "function", "getDataStores exists and it's a function");
    1.51 +
    1.52 +    SpecialPowers.setAllAppsLaunchable(true);
    1.53 +    SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
    1.54 +
    1.55 +    SpecialPowers.autoConfirmAppInstall(continueTest);
    1.56 +    yield undefined;
    1.57 +
    1.58 +    var request = navigator.mozApps.install(gHostedManifestURL);
    1.59 +    request.onerror = cbError;
    1.60 +    request.onsuccess = continueTest;
    1.61 +    yield undefined;
    1.62 +
    1.63 +    var app = request.result;
    1.64 +    isnot(app, null, "App is non-null");
    1.65 +    is(app.manifest.description, "Updated even faster than Firefox, just to annoy slashdotters.",
    1.66 +       "Manifest is HTML-sanitized");
    1.67 +
    1.68 +    var ifr = document.createElement('iframe');
    1.69 +    ifr.setAttribute('mozbrowser', 'true');
    1.70 +    ifr.setAttribute('mozapp', app.manifestURL);
    1.71 +    ifr.setAttribute('src', app.manifest.launch_path);
    1.72 +    var domParent = document.getElementById('container');
    1.73 +
    1.74 +    // Set us up to listen for messages from the app.
    1.75 +    var listener = function(e) {
    1.76 +      var message = e.detail.message;
    1.77 +      if (/^OK/.exec(message)) {
    1.78 +        ok(true, "Message from app: " + message);
    1.79 +      } else if (/KO/.exec(message)) {
    1.80 +        ok(false, "Message from app: " + message);
    1.81 +      } else if (/DONE/.exec(message)) {
    1.82 +        ok(true, "Messaging from app complete");
    1.83 +        ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
    1.84 +        domParent.removeChild(ifr);
    1.85 +
    1.86 +        // Uninstall the app.
    1.87 +        request = navigator.mozApps.mgmt.uninstall(app);
    1.88 +        request.onerror = cbError;
    1.89 +        request.onsuccess = function() {
    1.90 +          // All done.
    1.91 +          finish();
    1.92 +        }
    1.93 +      }
    1.94 +    }
    1.95 +
    1.96 +    // This event is triggered when the app calls "alert".
    1.97 +    ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
    1.98 +
    1.99 +    domParent.appendChild(ifr);
   1.100 +  }
   1.101 +
   1.102 +  function finish() {
   1.103 +    SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled");
   1.104 +    SimpleTest.finish();
   1.105 +  }
   1.106 +
   1.107 +  </script>
   1.108 +</body>
   1.109 +</html>

mercurial