dom/tests/mochitest/webapps/test_install_app.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/webapps/test_install_app.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +<?xml version="1.0"?>
     1.5 +
     1.6 +<!-- Any copyright is dedicated to the Public Domain.
     1.7 +   - http://creativecommons.org/publicdomain/zero/1.0/ -->
     1.8 +
     1.9 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
    1.10 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
    1.11 +
    1.12 +<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
    1.13 +        title="Mozilla Bug 741549">
    1.14 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.15 +  <script type="application/javascript" src="head.js"/>
    1.16 +  <!-- test results are displayed in the html:body -->
    1.17 +  <body xmlns="http://www.w3.org/1999/xhtml">
    1.18 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
    1.19 +     target="_blank">Mozilla Bug 741549</a><br/>
    1.20 +  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=734294"
    1.21 +     target="_blank">Mozilla Bug 734294</a>
    1.22 +  </body>
    1.23 +
    1.24 +<script>
    1.25 +<![CDATA[
    1.26 +
    1.27 +var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
    1.28 +var app;
    1.29 +
    1.30 +var steps = [
    1.31 +  getInstalledReturnsNothing,
    1.32 +  install,
    1.33 +  getInstalledReturnsApp,
    1.34 +  getSelf,
    1.35 +  uninstall,
    1.36 +];
    1.37 +
    1.38 +runAll(steps);
    1.39 +
    1.40 +function getInstalledReturnsNothing(next) {
    1.41 +  navigator.mozApps.getInstalled().onsuccess = function() {
    1.42 +    is(this.result.length, 0, "getInstalled() returns nothing");
    1.43 +    next();
    1.44 +  };
    1.45 +}
    1.46 +
    1.47 +function install(next) {
    1.48 +  var beforehand = Date.now();
    1.49 +  const fuzzySpan = 250;
    1.50 +
    1.51 +  confirmNextInstall();
    1.52 +  navigator.mozApps.install(url, null).onsuccess = function onInstall() {
    1.53 +    app = this.result;
    1.54 +
    1.55 +    is(app.origin, "http://test", "origin");
    1.56 +    is(app.installOrigin, "chrome://mochitests", "install origin");
    1.57 +    ok(app.installTime + fuzzySpan >= beforehand, "install time is after install() call");
    1.58 +    ok(app.installTime <= Date.now() + fuzzySpan, "install time is before install success");
    1.59 +    is(app.manifestURL, url, "manifest URL");
    1.60 +    is(app.manifest.name, "Basic App", "manifest.name");
    1.61 +    is(app.manifest.installs_allowed_from, "*",
    1.62 +       "manifest.installs_allowed_from");
    1.63 +
    1.64 +    next();
    1.65 +  }
    1.66 +}
    1.67 +
    1.68 +function getInstalledReturnsApp(next) {
    1.69 +  navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
    1.70 +    // Retrieve the app we just installed from the list of installed apps.
    1.71 +    var a = [a for (a of this.result) if (a.manifestURL == url)][0];
    1.72 +
    1.73 +    // Compare the values of the two app objects to make sure install()
    1.74 +    // and getInstalled() return identical objects.
    1.75 +    isDeeply(a, app, "getInstalled() returns app identical to install()");
    1.76 +
    1.77 +    next();
    1.78 +  };
    1.79 +}
    1.80 +
    1.81 +function getSelf(next) {
    1.82 +  navigator.mozApps.getSelf().onsuccess = function onGetSelf() {
    1.83 +    is(this.result, null, "getSelf() returns nothing (different origin)");
    1.84 +
    1.85 +    next();
    1.86 +  };
    1.87 +}
    1.88 +
    1.89 +function uninstall(next) {
    1.90 +  navigator.mozApps.mgmt.uninstall(app).onsuccess = function onUninstall() {
    1.91 +    // Try to retrieve the app we just uninstalled, to make sure it no longer
    1.92 +    // exists in the registry.
    1.93 +    navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
    1.94 +      var a = [a for (a of this.result) if (a.manifestURL == url)][0];
    1.95 +      is(a, undefined, "getInstalled() returns nothing again after uninstall");
    1.96 +
    1.97 +      next();
    1.98 +    };
    1.99 +  };
   1.100 +}
   1.101 +
   1.102 +]]>
   1.103 +</script>
   1.104 +</window>

mercurial