dom/apps/tests/test_marketplace_pkg_install.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/apps/tests/test_marketplace_pkg_install.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,198 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=989806
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 989806</title>
    1.12 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <script type="text/javascript" src="test_packaged_app_common.js"></script>
    1.15 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.16 +</head>
    1.17 +<body>
    1.18 +
    1.19 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=989806">Mozilla Bug 989806</a>
    1.20 +<p id="display"></p>
    1.21 +<div id="content" style="display: none">
    1.22 +
    1.23 +</div>
    1.24 +<pre id="test">
    1.25 +<script class="testbody" type="application/javascript;version=1.7">
    1.26 +
    1.27 +"use strict";
    1.28 +
    1.29 +let gApp = null;
    1.30 +
    1.31 +let gExternalInstallOrigin = "http://mochi.test:8888/";
    1.32 +let gExternalAppsPath = gExternalInstallOrigin + "tests/dom/apps/tests/marketplace/";
    1.33 +
    1.34 +let gMarketplaceInstallOrigin = "https://marketplace.firefox.com/";
    1.35 +let gMarketplaceAppsPath = gMarketplaceInstallOrigin + "tests/dom/apps/tests/marketplace/";
    1.36 +
    1.37 +SimpleTest.waitForExplicitFinish();
    1.38 +
    1.39 +function checkAppOnInstallSuccess(aExpected) {
    1.40 +  navigator.mozApps.mgmt.oninstall = function(evt) {
    1.41 +    info("Got oninstall event");
    1.42 +    gApp = evt.application;
    1.43 +    gApp.ondownloaderror = function() {
    1.44 +      ok(false, "Download should succeed (got error: " +
    1.45 +                gApp.downloadError.name + ")");
    1.46 +      PackagedTestHelper.finish();
    1.47 +    };
    1.48 +    gApp.ondownloadsuccess = function() {
    1.49 +      info("App downloaded");
    1.50 +      PackagedTestHelper.checkAppState(gApp, aExpected.version, aExpected,
    1.51 +                                       true, true, PackagedTestHelper.next);
    1.52 +    };
    1.53 +  };
    1.54 +}
    1.55 +
    1.56 +function checkAppOnInstallError(aExpectedError) {
    1.57 +  navigator.mozApps.mgmt.oninstall = function(evt) {
    1.58 +    info("Got oninstall event");
    1.59 +    gApp = evt.application;
    1.60 +    gApp.ondownloaderror = function() {
    1.61 +      is(gApp.downloadError.name, aExpectedError,
    1.62 +        "Download fails with expected error: " + aExpectedError);
    1.63 +      if (gApp.downloadError.name != aExpectedError) {
    1.64 +        PackagedTestHelper.finish();
    1.65 +      } else {
    1.66 +        PackagedTestHelper.next();
    1.67 +      }
    1.68 +    };
    1.69 +    gApp.ondownloadsuccess = function() {
    1.70 +      ok(false, "App download should fail");
    1.71 +      PackagedTestHelper.finish();
    1.72 +    };
    1.73 +  };
    1.74 +}
    1.75 +
    1.76 +function checkUninstallApp(aApp) {
    1.77 +  let req = navigator.mozApps.mgmt.uninstall(aApp);
    1.78 +
    1.79 +  req.onsuccess = function() {
    1.80 +    info("App uninstalled");
    1.81 +    aApp.ondownloadsuccess = null;
    1.82 +    aApp.ondownloaderror = null;
    1.83 +    aApp.onprogress = null;
    1.84 +    PackagedTestHelper.next();
    1.85 +  };
    1.86 +  req.onerror = function(evt) {
    1.87 +    ok(false, "App uninstallation should succeed (got unexpected " +
    1.88 +              evt.target.error.name + ")");
    1.89 +    PackagedTestHelper.finish();
    1.90 +  };
    1.91 +}
    1.92 +
    1.93 +function installApp(installOrigin, manifestURL) {
    1.94 +  let domParent = document.getElementById('container');
    1.95 +
    1.96 +  let ifr = document.createElement('iframe');
    1.97 +  ifr.setAttribute('mozbrowser', 'true');
    1.98 +  ifr.setAttribute("src", installOrigin + "tests/dom/apps/tests/pkg_install_iframe.html");
    1.99 +
   1.100 +  ifr.addEventListener("load", function onIFrameLoad() {
   1.101 +    ifr.removeEventListener("load", onIFrameLoad, false);
   1.102 +
   1.103 +    ifr.contentWindow.postMessage(manifestURL, "*");
   1.104 +  }, false);
   1.105 +
   1.106 +  ifr.addEventListener("mozbrowsererror", function onCertError(e) {
   1.107 +    ifr.removeEventListener("mozbrowsererror", onCertError);
   1.108 +
   1.109 +    ok(false, "mozbrowsererror: " + e.detail.type);
   1.110 +    domParent.removeChild(ifr);
   1.111 +    PackagedTestHelper.finish();
   1.112 +  });
   1.113 +
   1.114 +  window.addEventListener("message", function onMessage(event) {
   1.115 +    window.removeEventListener("message", onMessage);
   1.116 +
   1.117 +    is(event.data, "Application installed", "Application installed");
   1.118 +
   1.119 +    domParent.removeChild(ifr);
   1.120 +  });
   1.121 +
   1.122 +  domParent.appendChild(ifr);
   1.123 +}
   1.124 +
   1.125 +PackagedTestHelper.setSteps([
   1.126 +  function() {
   1.127 +    SpecialPowers.setAllAppsLaunchable(true);
   1.128 +    SpecialPowers.addPermission("webapps-manage", true, document);
   1.129 +    SpecialPowers.addPermission("browser", true, document);
   1.130 +    SpecialPowers.autoConfirmAppInstall(() =>
   1.131 +      SpecialPowers.pushPrefEnv({set: [["dom.mozBrowserFramesEnabled", true]]},
   1.132 +                                PackagedTestHelper.next));
   1.133 +  },
   1.134 +  function() {
   1.135 +    info("== TEST == Marketplace packaged app from https://marketplace.firefox.com/");
   1.136 +    let miniManifestURL = gMarketplaceAppsPath + "marketplace_app.webapp"
   1.137 +    let expected = {
   1.138 +      name: "Flashlight (Linterna)",
   1.139 +      manifestURL: miniManifestURL,
   1.140 +      installOrigin: gMarketplaceInstallOrigin.slice(0, -1),
   1.141 +      progress: 0,
   1.142 +      installState: "installed",
   1.143 +      downloadAvailable: false,
   1.144 +      downloading: false,
   1.145 +      readyToApplyDownload: false,
   1.146 +      launch_path: "/index.html",
   1.147 +      version: "2.0",
   1.148 +    };
   1.149 +    checkAppOnInstallSuccess(expected);
   1.150 +    installApp(gMarketplaceInstallOrigin, miniManifestURL);
   1.151 +  },
   1.152 +  function() {
   1.153 +    info("== TEST == Marketplace privileged app from https://marketplace.firefox.com/");
   1.154 +    let miniManifestURL = gMarketplaceAppsPath + "marketplace_privileged_app.webapp"
   1.155 +    let expected = {
   1.156 +      name: "KitchenSink",
   1.157 +      manifestURL: miniManifestURL,
   1.158 +      installOrigin: gMarketplaceInstallOrigin.slice(0, -1),
   1.159 +      progress: 0,
   1.160 +      installState: "installed",
   1.161 +      downloadAvailable: false,
   1.162 +      downloading: false,
   1.163 +      readyToApplyDownload: false,
   1.164 +      launch_path: "/index.html",
   1.165 +      version: "0.2.2",
   1.166 +    };
   1.167 +    checkAppOnInstallSuccess(expected);
   1.168 +    installApp(gMarketplaceInstallOrigin, miniManifestURL);
   1.169 +  },
   1.170 +  function() {
   1.171 +    info("== TEST == Marketplace reviewers packaged app from https://marketplace.firefox.com/");
   1.172 +    checkAppOnInstallError("INVALID_SIGNATURE");
   1.173 +    installApp(gMarketplaceInstallOrigin, gMarketplaceAppsPath + "marketplace_reviewers_app.webapp");
   1.174 +  },
   1.175 +  function() {
   1.176 +    info("== TEST == Marketplace packaged app not from https://marketplace.firefox.com/");
   1.177 +    checkAppOnInstallError("INSTALL_FROM_DENIED");
   1.178 +    installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_app.webapp");
   1.179 +  },
   1.180 +  function() {
   1.181 +    info("== TEST == Marketplace privileged app not from https://marketplace.firefox.com/");
   1.182 +    checkAppOnInstallError("INSTALL_FROM_DENIED");
   1.183 +    installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_privileged_app.webapp");
   1.184 +  },
   1.185 +  function() {
   1.186 +    info("== TEST == Marketplace reviewers packaged app not from https://marketplace.firefox.com/");
   1.187 +    checkAppOnInstallError("INVALID_SIGNATURE");
   1.188 +    installApp(gExternalInstallOrigin, gExternalAppsPath + "marketplace_reviewers_app.webapp");
   1.189 +  },
   1.190 +  function() {
   1.191 +    PackagedTestHelper.finish();
   1.192 +  }
   1.193 +]);
   1.194 +
   1.195 +addLoadEvent(PackagedTestHelper.start);
   1.196 +
   1.197 +</script>
   1.198 +</pre>
   1.199 +<div id="container"></div>
   1.200 +</body>
   1.201 +</html>

mercurial