Bug 786710 - Tests for valid and invalid cases. r=fabrice

This commit is contained in:
Marco Castelluccio 2012-09-22 20:48:27 -04:00
parent 714421dbcd
commit 23f3300d24
12 changed files with 196 additions and 0 deletions

View File

@ -26,6 +26,7 @@ MOCHITEST_CHROME_FILES = \
test_install_utf8.xul \
test_install_receipts.xul \
test_getNotInstalled.xul \
test_launch_paths.xul \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -22,6 +22,14 @@ MOCHITEST_CHROME_FILES = \
bad_content_type.webapp \
utf8.webapp \
utf8.webapp^headers^ \
invalid_launch_path.webapp \
invalid_launch_path.webapp^headers^ \
invalid_entry_point.webapp \
invalid_entry_point.webapp^headers^ \
invalid_locale_entry_point.webapp \
invalid_locale_entry_point.webapp^headers^ \
launch_paths.webapp \
launch_paths.webapp^headers^ \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,10 @@
{
"name": "Absolute Entry Point Launch Path App",
"installs_allowed_from": [ "*" ],
"entry_points": {
"ep1": {
"name": "Entry Point 1",
"launch_path": "http://www.mozilla.org/"
}
}
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -0,0 +1,5 @@
{
"name": "Absolute Launch Path App",
"installs_allowed_from": [ "*" ],
"launch_path": "http://www.mozilla.org/"
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -0,0 +1,14 @@
{
"name": "Absolute Locale Entry Point Launch Path App",
"installs_allowed_from": [ "*" ],
"locales": {
"it": {
"entry_points": {
"ep1": {
"name": "Punto d'ingresso",
"launch_path": "http://www.mozilla.org/"
}
}
}
}
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -0,0 +1,21 @@
{
"name": "Basic App with Launch Paths",
"installs_allowed_from": [ "*" ],
"launch_path": "/lp",
"entry_points": {
"ep1": {
"name": "Entry Point 1",
"launch_path": "/test"
}
},
"locales": {
"it": {
"entry_points": {
"ep1": {
"name": "Punto d'ingresso",
"launch_path": "/prova"
}
}
}
}
}

View File

@ -0,0 +1 @@
Content-Type: application/x-web-app-manifest+json

View File

@ -25,6 +25,9 @@ var steps = [
permissionDenied,
invalidContent,
installPackageNotImplemented,
invalidLaunchPath,
invalidEntryPoint,
invalidLocaleEntryPoint,
];
runAll(steps);
@ -97,6 +100,36 @@ function invalidContent(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");

View File

@ -0,0 +1,100 @@
<?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><br/>
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=734294"
target="_blank">Mozilla Bug 734294</a>
</body>
<script>
<![CDATA[
var url = "http://test/chrome/dom/tests/mochitest/webapps/apps/launch_paths.webapp";
var app;
var steps = [
getInstalledReturnsNothing,
install,
getInstalledReturnsApp,
getSelf,
uninstall,
];
runAll(steps);
function getInstalledReturnsNothing(next) {
navigator.mozApps.getInstalled().onsuccess = function() {
is(this.result.length, 0, "getInstalled() returns nothing");
next();
};
}
function install(next) {
var beforehand = Date.now();
confirmNextInstall();
navigator.mozApps.install(url, null).onsuccess = function onInstall() {
app = this.result;
is(app.origin, "http://test", "origin");
is(app.installOrigin, "chrome://mochitests", "install origin");
ok(app.installTime >= beforehand, "install time is after install() call");
ok(app.installTime <= Date.now(), "install time is before install success");
is(app.manifestURL, url, "manifest URL");
is(app.manifest.name, "Basic App with Launch Paths", "manifest.name");
is(app.manifest.installs_allowed_from, "*",
"manifest.installs_allowed_from");
next();
}
}
function getInstalledReturnsApp(next) {
navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
// Retrieve the app we just installed from the list of installed apps.
var a = [a for each (a in this.result) if (a.manifestURL == url)][0];
// Compare the values of the two app objects to make sure install()
// and getInstalled() return identical objects.
isDeeply(a, app, "getInstalled() returns app identical to install()");
next();
};
}
function getSelf(next) {
navigator.mozApps.getSelf().onsuccess = function onGetSelf() {
is(this.result, null, "getSelf() returns nothing (different origin)");
next();
};
}
function uninstall(next) {
app.uninstall().onsuccess = function onUninstall() {
// Try to retrieve the app we just uninstalled, to make sure it no longer
// exists in the registry.
navigator.mozApps.getInstalled().onsuccess = function onGetInstalled() {
var a = [a for each (a in this.result) if (a.manifestURL == url)][0];
is(a, undefined, "getInstalled() returns nothing again after uninstall");
next();
};
};
}
]]>
</script>
</window>