dom/tests/mochitest/webapps/test_install_errors.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_errors.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,235 @@
     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>
    1.20 +  </body>
    1.21 +
    1.22 +<script>
    1.23 +
    1.24 +var steps = [
    1.25 +  noArgs,
    1.26 +  parseError,
    1.27 +  invalidManifest,
    1.28 +  permissionDenied,
    1.29 +  invalidContent,
    1.30 +  invalidLaunchPath,
    1.31 +  invalidLaunchPath2,
    1.32 +  invalidEntryPoint,
    1.33 +  invalidLocaleEntryPoint,
    1.34 +  invalidActivityHref,
    1.35 +  invalidActivityHref2,
    1.36 +  invalidMessage,
    1.37 +  fileURL,
    1.38 +  originNotAllowed,
    1.39 +  originAllowed,
    1.40 +];
    1.41 +
    1.42 +runAll(steps);
    1.43 +
    1.44 +function noArgs(next) {
    1.45 +  try {
    1.46 +    navigator.mozApps.install();
    1.47 +  } catch (e) {
    1.48 +    is(e.message, "Not enough arguments \[mozIDOMApplicationRegistry.install\]",
    1.49 +       "install without arguments throws exception");
    1.50 +    next();
    1.51 +  }
    1.52 +}
    1.53 +
    1.54 +function parseError(next) {
    1.55 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/json_syntax_error.webapp";
    1.56 +
    1.57 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    1.58 +    is(this.error.name, "MANIFEST_PARSE_ERROR", "manifest with syntax error");
    1.59 +    next();
    1.60 +  };
    1.61 +}
    1.62 +
    1.63 +function invalidManifest(next) {
    1.64 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/missing_required_field.webapp";
    1.65 +
    1.66 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
    1.67 +    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
    1.68 +    next();
    1.69 +  };
    1.70 +}
    1.71 +
    1.72 +function permissionDenied(next) {
    1.73 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/no_delegated_install.webapp";
    1.74 +
    1.75 +  confirmNextInstall();
    1.76 +  var request = navigator.mozApps.install(url, null);
    1.77 +
    1.78 +  request.onerror = function onInstallError() {
    1.79 +    is(this.error.name, "DENIED", "manifest without installs_allowed_from");
    1.80 +    next();
    1.81 +  };
    1.82 +
    1.83 +  request.onsuccess = function onInstall() {
    1.84 +    todo(false, "manifest without installs_allowed_from fails");
    1.85 +    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
    1.86 +      next();
    1.87 +    };
    1.88 +  };
    1.89 +}
    1.90 +
    1.91 +function invalidContent(next) {
    1.92 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/bad_content_type.webapp";
    1.93 +
    1.94 +  var request = navigator.mozApps.install(url, null);
    1.95 +
    1.96 +  request.onerror = function onInstallError() {
    1.97 +    is(this.error.name, "INVALID_MANIFEST", "manifest with bad content type");
    1.98 +    next();
    1.99 +  };
   1.100 +
   1.101 +  request.onsuccess = function onInstall() {
   1.102 +    ok(false, "manifest with bad content type should fail");
   1.103 +    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
   1.104 +      next();
   1.105 +    };
   1.106 +  };
   1.107 +}
   1.108 +
   1.109 +function invalidLaunchPath(next) {
   1.110 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path.webapp";
   1.111 +
   1.112 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.113 +    is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest");
   1.114 +    next();
   1.115 +  };
   1.116 +}
   1.117 +
   1.118 +function invalidLaunchPath2(next) {
   1.119 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path2.webapp";
   1.120 +
   1.121 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.122 +    is(this.error.name, "INVALID_MANIFEST", "Invalid Manifest");
   1.123 +    next();
   1.124 +  };
   1.125 +}
   1.126 +
   1.127 +function invalidEntryPoint(next) {
   1.128 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_entry_point.webapp";
   1.129 +
   1.130 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.131 +    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
   1.132 +    next();
   1.133 +  };
   1.134 +}
   1.135 +
   1.136 +function invalidLocaleEntryPoint(next) {
   1.137 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_locale_entry_point.webapp";
   1.138 +
   1.139 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.140 +    is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
   1.141 +    next();
   1.142 +  };
   1.143 +}
   1.144 +
   1.145 +function invalidActivityHref(next) {
   1.146 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href.webapp";
   1.147 +
   1.148 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.149 +    is(this.error.name, "INVALID_MANIFEST", "Manifest has non-relative URI for activity href");
   1.150 +    next();
   1.151 +  };
   1.152 +}
   1.153 +
   1.154 +function invalidActivityHref2(next) {
   1.155 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_activity_href2.webapp";
   1.156 +
   1.157 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.158 +    is(this.error.name, "INVALID_MANIFEST", "Manifest has data: URI for activity href");
   1.159 +    next();
   1.160 +  };
   1.161 +}
   1.162 +
   1.163 +function invalidMessage(next) {
   1.164 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_message.webapp";
   1.165 +
   1.166 +  navigator.mozApps.install(url, null).onerror = function onInstallError() {
   1.167 +    is(this.error.name, "INVALID_MANIFEST", "Manifest has absolute message href");
   1.168 +    next();
   1.169 +  };
   1.170 +}
   1.171 +
   1.172 +function fileURL(next) {
   1.173 +  try {
   1.174 +    var req = navigator.mozApps.install("file:///nonexistent");
   1.175 +    req.onsuccess = function() {
   1.176 +      ok(false, "Unexpected success installing non existent file");
   1.177 +    };
   1.178 +    req.onerror = function() {
   1.179 +      is(this.error.name, "INVALID_URL", "Expected INVALID_URL");
   1.180 +    };
   1.181 +  } catch(ex) {
   1.182 +    ok(false, "Unexpected exception " + ex.message);
   1.183 +  }
   1.184 +
   1.185 +  try {
   1.186 +    req = navigator.mozApps.install("file:///");
   1.187 +    req.onsuccess = function() {
   1.188 +      ok(false, "Unexpected success installing file: URL");
   1.189 +    };
   1.190 +    req.onerror = function() {
   1.191 +      is(this.error.name, "INVALID_URL", "Expected INVALID_URL");
   1.192 +    };
   1.193 +  } catch(ex) {
   1.194 +    ok(false, "Unexpected exception " + ex.message);
   1.195 +  }
   1.196 +
   1.197 +  next();
   1.198 +}
   1.199 +
   1.200 +function originNotAllowed(next) {
   1.201 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_example.com.webapp";
   1.202 +
   1.203 +  var request = navigator.mozApps.install(url, null);
   1.204 +
   1.205 +  request.onerror = function onInstallError() {
   1.206 +    is(this.error.name, "INSTALL_FROM_DENIED", "origin is not in installs_allowed_from");
   1.207 +    next();
   1.208 +  };
   1.209 +
   1.210 +  request.onsuccess = function onInstall() {
   1.211 +    ok(false, "test should fail because of installs_allowed_from");
   1.212 +    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
   1.213 +      next();
   1.214 +    };
   1.215 +  };
   1.216 +}
   1.217 +
   1.218 +function originAllowed(next) {
   1.219 +  var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/installs_allowed_from_chrome_mochitests.webapp";
   1.220 +
   1.221 +  confirmNextInstall();
   1.222 +  var request = navigator.mozApps.install(url, null);
   1.223 +
   1.224 +  request.onerror = function onInstallError() {
   1.225 +    ok(false, "installation error: " + this.error.name);
   1.226 +    next();
   1.227 +  };
   1.228 +
   1.229 +  request.onsuccess = function onInstall() {
   1.230 +    ok(true, "test origin is in installs_allowed_from");
   1.231 +    navigator.mozApps.mgmt.uninstall(this.result).onsuccess = function onUninstall() {
   1.232 +      next();
   1.233 +    };
   1.234 +  };
   1.235 +}
   1.236 +
   1.237 +</script>
   1.238 +</window>

mercurial