dom/apps/tests/test_signed_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_signed_pkg_install.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,232 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=880043
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset="utf-8">
    1.11 +  <title>Test for Bug 880043 Packaged apps installation and update</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=880043">Mozilla Bug 880043</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="text/javascript">
    1.26 +
    1.27 +"use strict";
    1.28 +
    1.29 +const Ci = SpecialPowers.Ci;
    1.30 +const Cc = SpecialPowers.Cc;
    1.31 +const Cu = SpecialPowers.Cu;
    1.32 +
    1.33 +var index = -1;
    1.34 +var gDebug = false;
    1.35 +var gApp = null;
    1.36 +var gAppName = "Simple App";
    1.37 +var gInstallOrigin = "http://mochi.test:8888/";
    1.38 +var gSJSPath = "tests/dom/apps/tests/signed_app.sjs";
    1.39 +var gSJS = gInstallOrigin + gSJSPath;
    1.40 +var gPackagePath = gInstallOrigin + "tests/dom/apps/tests/";
    1.41 +var gSignedAppOriginsStr ="";
    1.42 +
    1.43 +SimpleTest.waitForExplicitFinish();
    1.44 +
    1.45 +function checkAppOnInstallError(aMiniManifestURL, aExpectedError) {
    1.46 +  navigator.mozApps.mgmt.oninstall = function(evt) {
    1.47 +    info("Got oninstall event");
    1.48 +    gApp = evt.application;
    1.49 +    gApp.ondownloaderror = function() {
    1.50 +      is(gApp.downloadError.name, aExpectedError,
    1.51 +        "Download fails with expected error: " + aExpectedError);
    1.52 +      if (gApp.downloadError.name != aExpectedError) {
    1.53 +        PackagedTestHelper.finish();
    1.54 +      } else {
    1.55 +        PackagedTestHelper.next();
    1.56 +      }
    1.57 +    };
    1.58 +    gApp.ondownloadsuccess = function() {
    1.59 +      ok(false, "App download should fail");
    1.60 +      PackagedTestHelper.finish();
    1.61 +    };
    1.62 +  };
    1.63 +  var request = navigator.mozApps.installPackage(aMiniManifestURL);
    1.64 +  request.onerror = function(evt) {
    1.65 +    ok(false, "Application should throw the error inside oninstall: " + evt.error.name);
    1.66 +    PackagedTestHelper.finish();
    1.67 +  };
    1.68 +  request.onsuccess = function() {
    1.69 +    info("Application install returns successfully");
    1.70 +  };
    1.71 +}
    1.72 +
    1.73 +function checkUninstallApp(aApp) {
    1.74 +  var req = navigator.mozApps.mgmt.uninstall(aApp);
    1.75 +
    1.76 +  req.onsuccess = function() {
    1.77 +    info("App uninstalled");
    1.78 +    aApp.ondownloadsuccess = null;
    1.79 +    aApp.ondownloaderror = null;
    1.80 +    aApp.onprogress = null;
    1.81 +    PackagedTestHelper.next();
    1.82 +  };
    1.83 +  req.onerror = function(evt) {
    1.84 +    ok(false, "App uninstallation should succeed (got unexpected " +
    1.85 +              evt.target.error.name + ")");
    1.86 +    PackagedTestHelper.finish();
    1.87 +  };
    1.88 +}
    1.89 +
    1.90 +var steps = [
    1.91 +  function() {
    1.92 +    // Set up
    1.93 +    info("Test Initial Setup");
    1.94 +    gSignedAppOriginsStr = SpecialPowers.getCharPref("dom.mozApps.signed_apps_installable_from");
    1.95 +    var signedAppOriginsStr = gSignedAppOriginsStr.concat("," + gInstallOrigin.slice(0, -1));
    1.96 +    SpecialPowers.pushPrefEnv({'set': [['dom.mozApps.signed_apps_installable_from', signedAppOriginsStr]]}, function() {
    1.97 +      var url = SimpleTest.getTestFileURL("chromeAddCert.js");
    1.98 +      var script = SpecialPowers.loadChromeScript(url);
    1.99 +      script.addMessageListener("addCertCompleted", function() {
   1.100 +        SpecialPowers.setAllAppsLaunchable(true);
   1.101 +        SpecialPowers.addPermission("webapps-manage", true, document);
   1.102 +        info("Test CA Certificate Selected");
   1.103 +        PackagedTestHelper.next();
   1.104 +        script.destroy();
   1.105 +      });
   1.106 +    });
   1.107 +  },
   1.108 +  function() {
   1.109 +    info("autoConfirmAppInstall");
   1.110 +    SpecialPowers.autoConfirmAppInstall(PackagedTestHelper.next);
   1.111 +  },
   1.112 +  function() {
   1.113 +    info("== TEST == Install packaged app");
   1.114 +    var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1";
   1.115 +
   1.116 +    navigator.mozApps.mgmt.oninstall = function(evt) {
   1.117 +      info("Got oninstall event");
   1.118 +      gApp = evt.application;
   1.119 +      gApp.ondownloaderror = function() {
   1.120 +        ok(false, "Download should succeed (got error: " +
   1.121 +                  gApp.downloadError.name + ")");
   1.122 +        PackagedTestHelper.finish();
   1.123 +      };
   1.124 +      gApp.ondownloadsuccess = function() {
   1.125 +        info("App downloaded");
   1.126 +        var expected = {
   1.127 +          name: gAppName,
   1.128 +          manifestURL: miniManifestURL,
   1.129 +          installOrigin: gInstallOrigin.slice(0, -1),
   1.130 +          progress: 0,
   1.131 +          installState: "installed",
   1.132 +          downloadAvailable: false,
   1.133 +          downloading: false,
   1.134 +          readyToApplyDownload: false,
   1.135 +        };
   1.136 +        PackagedTestHelper.checkAppState(gApp, 1, expected,
   1.137 +                                         true, false, PackagedTestHelper.next);
   1.138 +      };
   1.139 +    };
   1.140 +    info("Installing app: " + miniManifestURL);
   1.141 +    var request = navigator.mozApps.installPackage(miniManifestURL);
   1.142 +    request.onerror = function(evt) {
   1.143 +      ok(false, "Application should have been correctly installed (error: " +
   1.144 +                JSON.stringify(evt));
   1.145 +    };
   1.146 +    request.onsuccess = function() {
   1.147 +      info("Application installed");
   1.148 +    };
   1.149 +  },
   1.150 +  function() {
   1.151 +    info("== TEST == Uninstall a signed app");
   1.152 +    // Uninstall App
   1.153 +    checkUninstallApp(gApp);
   1.154 +  },
   1.155 +  function() {
   1.156 +    info("== TEST == Install a corrupted package");
   1.157 +    //Scenario: Corrupted package
   1.158 +    var miniManifestURL = gSJS + "?" + "app=corrupt&" + "version=1";
   1.159 +    checkAppOnInstallError(miniManifestURL, "APP_PACKAGE_CORRUPTED");
   1.160 +  },
   1.161 +  function() {
   1.162 +    info("== TEST == Install a unsigned app from a trusted store");
   1.163 +    //Scenario: Unsigned App from an origin that requires signed apps
   1.164 +    var miniManifestURL = gSJS + "?" + "app=unknown_issuer&" + "version=1";
   1.165 +    checkAppOnInstallError(miniManifestURL, "INVALID_SIGNATURE");
   1.166 +  },
   1.167 +  function() {
   1.168 +    info("== TEST == Install packaged app with origin");
   1.169 +    var miniManifestURL = gSJS + "?" +
   1.170 +                          "app=origin&" +
   1.171 +                          "version=1";
   1.172 +
   1.173 +    navigator.mozApps.mgmt.oninstall = function(evt) {
   1.174 +      info("Got oninstall event");
   1.175 +      gApp = evt.application;
   1.176 +      gApp.ondownloaderror = function() {
   1.177 +        ok(false, "Download should succeed (got error: " +
   1.178 +                  gApp.downloadError.name + ")");
   1.179 +        PackagedTestHelper.finish();
   1.180 +      };
   1.181 +      gApp.ondownloadsuccess = function() {
   1.182 +        info("App downloaded");
   1.183 +        var expected = {
   1.184 +          name: gAppName,
   1.185 +          manifestURL: miniManifestURL,
   1.186 +          installOrigin: gInstallOrigin.slice(0, -1),
   1.187 +          progress: 0,
   1.188 +          installState: "installed",
   1.189 +          downloadAvailable: false,
   1.190 +          downloading: false,
   1.191 +          origin: "app://test.origin.privileged.app",
   1.192 +          readyToApplyDownload: false,
   1.193 +        };
   1.194 +        PackagedTestHelper.checkAppState(gApp, 1, expected,
   1.195 +                                         true, false, PackagedTestHelper.next);
   1.196 +      };
   1.197 +    };
   1.198 +    info("Installing app: " + miniManifestURL);
   1.199 +    var request = navigator.mozApps.installPackage(miniManifestURL);
   1.200 +    request.onerror = function(evt) {
   1.201 +      ok(false, "Application should have been correctly installed (error: " +
   1.202 +                JSON.stringify(evt));
   1.203 +    };
   1.204 +    request.onsuccess = function() {
   1.205 +      info("Application installed");
   1.206 +    };
   1.207 +  },
   1.208 +  function() {
   1.209 +    info("== TEST == Install app from an invalid source");
   1.210 +    // Scenario: This is where an unexpected store is signing packages and
   1.211 +    // attempting to install. Please note that after this test you cannot
   1.212 +    // add new successful tests without changing the preference again
   1.213 +    SpecialPowers.pushPrefEnv(
   1.214 +      {'set': [['dom.mozApps.signed_apps_installable_from',
   1.215 +                gSignedAppOriginsStr]]},
   1.216 +      function() {
   1.217 +        var miniManifestURL = gSJS + "?" + "app=valid&" + "version=1";
   1.218 +        checkAppOnInstallError(miniManifestURL, "INSTALL_FROM_DENIED");
   1.219 +    });
   1.220 +  },
   1.221 +  function() {
   1.222 +    info("all done!");
   1.223 +    PackagedTestHelper.finish();
   1.224 +  }
   1.225 +];
   1.226 +
   1.227 +PackagedTestHelper.setSteps(steps);
   1.228 +PackagedTestHelper.gSJSPath = gSJSPath;
   1.229 +
   1.230 +addLoadEvent(PackagedTestHelper.start);
   1.231 +
   1.232 +</script>
   1.233 +</pre>
   1.234 +</body>
   1.235 +</html>

mercurial