gecko/dom/tests/mochitest/webapps/test_install_errors.xul
2012-09-24 22:41:21 -04:00

163 lines
4.7 KiB
XML

<?xml version="1.0"?>
<!-- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/ -->
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Mozilla Bug 741549">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
<script type="application/javascript" src="head.js"/>
<!-- test results are displayed in the html:body -->
<body xmlns="http://www.w3.org/1999/xhtml">
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=741549"
target="_blank">Mozilla Bug 741549</a>
</body>
<script>
var steps = [
noArgs,
parseError,
invalidManifest,
permissionDenied,
invalidContent,
installPackageNotImplemented,
invalidLaunchPath,
invalidEntryPoint,
invalidLocaleEntryPoint,
fileURL,
];
runAll(steps);
function noArgs(next) {
try {
navigator.mozApps.install();
} catch (e) {
is(e.message, "Not enough arguments \[mozIDOMApplicationRegistry.install\]",
"install without arguments throws exception");
next();
}
}
function parseError(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/json_syntax_error.webapp";
confirmNextInstall();
navigator.mozApps.install(url, null).onerror = function onInstallError() {
is(this.error.name, "MANIFEST_PARSE_ERROR", "manifest with syntax error");
next();
};
}
function invalidManifest(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/missing_required_field.webapp";
confirmNextInstall();
navigator.mozApps.install(url, null).onerror = function onInstallError() {
is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
next();
};
}
function permissionDenied(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/no_delegated_install.webapp";
confirmNextInstall();
var request = navigator.mozApps.install(url, null);
request.onerror = function onInstallError() {
is(this.error.name, "DENIED", "manifest without installs_allowed_from");
next();
};
request.onsuccess = function onInstall() {
todo(false, "manifest without installs_allowed_from fails");
this.result.uninstall().onsuccess = function onUninstall() {
next();
};
};
}
function invalidContent(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/bad_content_type.webapp";
confirmNextInstall();
var request = navigator.mozApps.install(url, null);
request.onerror = function onInstallError() {
is(this.error.name, "INVALID_MANIFEST", "manifest with bad content type");
next();
};
request.onsuccess = function onInstall() {
todo(false, "manifest with bad content type fails");
this.result.uninstall().onsuccess = function onUninstall() {
next();
};
};
}
function invalidLaunchPath(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_launch_path.webapp";
confirmNextInstall();
navigator.mozApps.install(url, null).onerror = function onInstallError() {
is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
next();
};
}
function invalidEntryPoint(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_entry_point.webapp";
confirmNextInstall();
navigator.mozApps.install(url, null).onerror = function onInstallError() {
is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
next();
};
}
function invalidLocaleEntryPoint(next) {
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/invalid_locale_entry_point.webapp";
confirmNextInstall();
navigator.mozApps.install(url, null).onerror = function onInstallError() {
is(this.error.name, "INVALID_MANIFEST", "manifest missing required field");
next();
};
}
function installPackageNotImplemented(next) {
ok(!("installPackage" in navigator.mozApps),
"installPackage not in navigator.mozApps");
next();
}
function fileURL(next) {
try {
navigator.mozApps.install("file:///nonexistent");
ok(false,
"attempt to install nonexistent file: URL doesn't throw exception");
} catch(ex) {
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
"attempt to install nonexistent file: URL throws exception");
}
try {
navigator.mozApps.install("file:///");
ok(false, "attempt to install existent file: URL doesn't throw exception");
} catch(ex) {
is(ex.message, "INVALID_URL_SCHEME: 'file'; must be 'http' or 'https'",
"attempt to install existent file: URL throws exception");
}
next();
}
</script>
</window>