2012-08-20 10:19:56 -07:00
|
|
|
<?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 781379">
|
2012-09-05 10:08:54 -07:00
|
|
|
<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 781379</a>
|
|
|
|
</body>
|
|
|
|
|
2012-08-20 10:19:56 -07:00
|
|
|
<script type="application/javascript;version=1.8">
|
2012-09-05 10:08:54 -07:00
|
|
|
|
2012-08-20 10:19:56 -07:00
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
|
|
|
Cu.import("resource://gre/modules/Webapps.jsm");
|
|
|
|
|
2012-09-05 10:08:54 -07:00
|
|
|
// We use a different origin than other webapps test files because we compare
|
|
|
|
// the number of apps before and after installing this one; and if a test file
|
|
|
|
// installs our app and then doesn't uninstall it (f.e. because it isn't written
|
|
|
|
// to clean up after itself, or because it throws an exception or times out),
|
|
|
|
// then this test will *reinstall* the app, and the number of apps won't change,
|
|
|
|
// which will look like a failure in this test although it's actually a failure
|
|
|
|
// in the other one.
|
|
|
|
//
|
|
|
|
// Using a different origin here isn't a foolproof solution, as another test
|
|
|
|
// could start using it. Reviewer vigilance is required! And to anyone reading
|
|
|
|
// this: don't use this origin without good reason and due consideration for
|
|
|
|
// the potential consequences!
|
|
|
|
//
|
|
|
|
// Alternately, we could define a test-specific domain, getNotInstalled.com,
|
|
|
|
// in source/build/pgo/server-locations.txt. But that seems like overkill,
|
|
|
|
// and this problem will go away once we support multiple apps per origin,
|
|
|
|
// since then we can make this test install its own personal webapp from any
|
|
|
|
// origin.
|
|
|
|
//
|
|
|
|
let url = "http://example.com/chrome/dom/tests/mochitest/webapps/apps/basic.webapp";
|
|
|
|
|
|
|
|
let app, notInstalled, _isLaunchable;
|
2012-08-23 11:46:38 -07:00
|
|
|
|
2012-08-20 10:19:56 -07:00
|
|
|
let steps = [
|
2012-09-05 10:08:54 -07:00
|
|
|
monkeyPatchDOMApplicationRegistry,
|
|
|
|
getNotInstalled,
|
|
|
|
installApp,
|
|
|
|
compareNotInstalled,
|
|
|
|
unmonkeyPatchDOMApplicationRegistry,
|
|
|
|
uninstallApp,
|
2012-08-20 10:19:56 -07:00
|
|
|
];
|
2012-09-05 10:08:54 -07:00
|
|
|
|
2012-08-20 10:19:56 -07:00
|
|
|
runAll(steps);
|
|
|
|
|
|
|
|
// Monkey patch DOMApplicationRegistry._isLaunchable for testing.
|
|
|
|
// This way, we don't have to create a platform specific application with a
|
|
|
|
// status other than "installed".
|
2012-09-05 10:08:54 -07:00
|
|
|
function monkeyPatchDOMApplicationRegistry(next) {
|
2012-08-20 10:19:56 -07:00
|
|
|
_isLaunchable = DOMApplicationRegistry._isLaunchable;
|
2012-09-05 10:08:54 -07:00
|
|
|
DOMApplicationRegistry._isLaunchable = function mockIsLaunchable(aOrigin) {
|
2012-08-20 10:19:56 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2012-08-23 11:46:38 -07:00
|
|
|
// Call navigator.mozApps.mgmt.getNotInstalled and save the result.
|
2012-09-05 10:08:54 -07:00
|
|
|
function getNotInstalled(next) {
|
|
|
|
window.navigator.mozApps.mgmt.getNotInstalled().onsuccess =
|
|
|
|
function onGetNotInstalled() {
|
2012-08-23 11:46:38 -07:00
|
|
|
notInstalled = this.result.length;
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add an app to the appregistry
|
2012-09-05 10:08:54 -07:00
|
|
|
function installApp(next) {
|
|
|
|
confirmNextInstall();
|
|
|
|
navigator.mozApps.install(url, null).onsuccess = function onInstall() {
|
|
|
|
app = this.result;
|
|
|
|
next();
|
|
|
|
}
|
2012-08-23 11:46:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call navigator.mozApps.mgmt.getNotInstalled and make sure there is one more.
|
2012-09-05 10:08:54 -07:00
|
|
|
function compareNotInstalled(next) {
|
2012-08-20 10:19:56 -07:00
|
|
|
let results;
|
2012-09-05 10:08:54 -07:00
|
|
|
function getNotInstalledError() {
|
2012-08-20 10:19:56 -07:00
|
|
|
ok(false, "window.mozApps.mgmt.getNotInstalled onerror called");
|
|
|
|
next();
|
|
|
|
}
|
2012-09-05 10:08:54 -07:00
|
|
|
function getNotInstalledSuccess() {
|
2012-08-20 10:19:56 -07:00
|
|
|
ok(true, "window.mozApps.mgmt.getNotInstalled onsuccess called");
|
2012-09-05 10:08:54 -07:00
|
|
|
is(this.result.length, notInstalled + 1,
|
|
|
|
"should get one more notInstalled app");
|
2012-08-23 11:46:38 -07:00
|
|
|
|
|
|
|
if (this.result.length > 0) {
|
2012-09-05 10:08:54 -07:00
|
|
|
is(this.result[this.result.length-1].origin, "http://example.com",
|
|
|
|
"getNotInstalled returned the expected app");
|
2012-08-20 10:19:56 -07:00
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
|
|
|
let type = typeof window.navigator.mozApps.getNotInstalled;
|
|
|
|
is(type, "undefined", "getNotInstalled moved from window.navigator");
|
|
|
|
type = typeof window.navigator.mozApps.mgmt.getNotInstalled;
|
|
|
|
if (type === "function") {
|
|
|
|
is(type, "function", "getNotInstalled moved to window.navigator.mgmt");
|
|
|
|
results = window.navigator.mozApps.mgmt.getNotInstalled();
|
|
|
|
results.onerror = getNotInstalledError;
|
|
|
|
results.onsuccess = getNotInstalledSuccess;
|
|
|
|
} else {
|
|
|
|
ok(false, "getNotInstalled not a function");
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 10:08:54 -07:00
|
|
|
function unmonkeyPatchDOMApplicationRegistry(next) {
|
2012-08-20 10:19:56 -07:00
|
|
|
if (typeof _isLaunchable === "function") {
|
|
|
|
DOMApplicationRegistry._isLaunchable = _isLaunchable;
|
2012-09-05 10:08:54 -07:00
|
|
|
ok(true, "restored DOMApplicationRegistry._isLaunchable");
|
2012-08-20 10:19:56 -07:00
|
|
|
} else {
|
2012-09-05 10:08:54 -07:00
|
|
|
ok(false, "can't restore DOMApplicationRegistry._isLaunchable");
|
2012-08-20 10:19:56 -07:00
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
2012-08-23 11:46:38 -07:00
|
|
|
|
2012-09-05 10:08:54 -07:00
|
|
|
// Remove the app from the appregistry
|
|
|
|
function uninstallApp(next) {
|
|
|
|
app.uninstall().onsuccess = function onUninstall() {
|
|
|
|
app = null;
|
|
|
|
next();
|
|
|
|
}
|
2012-08-23 11:46:38 -07:00
|
|
|
}
|
|
|
|
|
2012-08-20 10:19:56 -07:00
|
|
|
</script>
|
|
|
|
</window>
|