tenfourfox/dom/apps/tests/test_app_addons.html
Cameron Kaiser c9b2922b70 hello FPR
2017-04-19 00:56:45 -07:00

218 lines
6.5 KiB
HTML

<!DOCTYPE HTML><!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1042881
-->
<html>
<head>
<meta charset="utf-8">
<title>Test for Bug 923897 - Test apps as addons</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="application/javascript;version=1.7">
/**
* Test for Bug 923897
* This file covers testing addons.
*
* The setup is as follows:
* - app is installed and offers both script and css to inject in
* http://mochi.test:8888/tests/dom/apps/tests/addons/index.html
*/
SimpleTest.waitForExplicitFinish();
const baseURL = "http://mochi.test:8888/tests/dom/apps/tests/addons/";
const appManifestURL = baseURL + "update.webapp";
const invalidAppManifestURL = baseURL + "invalid.webapp";
let gGenerator = runTest();
function go() {
gGenerator.next();
}
function continueTest() {
try {
gGenerator.next();
} catch (e if e instanceof StopIteration) {
SpecialPowers.debugUserCustomizations(false);
SimpleTest.finish();
}
}
function mozAppsError() {
ok(false, "mozApps error: " + this.error.name);
SpecialPowers.debugUserCustomizations(false);
SimpleTest.finish();
}
// Triggers one navigation test to the given page.
// Waits for alert() messages before tearing down the iframe.
function openPage(pageURL, messages) {
info("Navigating to " + pageURL);
let ifr = document.createElement("iframe");
let listener = function(event) {
let message = messages.shift();
is(event.detail.message, message, "Checking alert message for " + pageURL);
if (messages.length == 0) {
ifr.removeEventListener("mozbrowsershowmodalprompt", listener);
ifr.parentNode.removeChild(ifr);
continueTest();
}
}
ifr.addEventListener("mozbrowsershowmodalprompt", listener, false);
// Open an the app url in an iframe.
ifr.setAttribute("mozbrowser", "true");
ifr.setAttribute("src", pageURL);
document.getElementById("container").appendChild(ifr);
}
let apps = [];
function installApp(manifestURL, expectedError) {
info("About to install app at " + manifestURL);
let req = navigator.mozApps.installPackage(manifestURL);
req.onsuccess = function() {
apps.push(req.result);
is(req.result.manifestURL, manifestURL, "app installed");
if (req.result.installState == "installed") {
is(req.result.manifest.version, "1.0", "correct version");
is(req.result.installState, "installed", "app downloaded");
continueTest();
} else {
req.result.ondownloadapplied = function() {
is(req.result.manifest.version, "1.0", "correct version");
is(req.result.installState, "installed", "app downloaded");
continueTest();
}
req.result.ondownloaderror = function() {
if (expectedError) {
is(req.result.downloadError.name, "MANIFEST_MISMATCH");
} else {
ok(false, "unexpected installation error: " + req.result.downloadError.name);
}
continueTest();
}
}
}
req.onerror = mozAppsError;
}
function runTest() {
// Set up.
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.allowUnsignedAddons();
SpecialPowers.debugUserCustomizations(true);
SpecialPowers.pushPrefEnv({'set': [
["dom.mozBrowserFramesEnabled", true],
["dom.apps.customization.enabled", true],
]},continueTest);
yield undefined;
SpecialPowers.pushPermissions(
[{ "type": "webapps-manage", "allow": 1, "context": document },
{ "type": "browser", "allow": 1, "context": document } ],
continueTest);
yield undefined;
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
// Install addon app with an invalid manifest.
installApp(invalidAppManifestURL, true);
yield undefined;
// Uninstall the invalid app.
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Opens the iframe to the test page, initial state.
openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
["Lorem ipsum", "rgb(0, 0, 0)",
"Uncustomized content", "rgb(0, 0, 0)"]);
yield undefined;
// Install valid addon app.
installApp(appManifestURL, false);
yield undefined;
// Opens the iframe to the test page, customized.
openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
["Hello World!", "rgb(255, 0, 0)",
"Customized content", "rgb(0, 0, 255)"]);
yield undefined;
// Disable the app.
navigator.mozApps.mgmt.onenabledstatechange = function(event) {
ok(true, "onenabledstatechange received");
is(event.application.enabled, false, "Application is disabled");
is(apps[0].enabled, false, "Application is disabled");
continueTest();
}
navigator.mozApps.mgmt.setEnabled(apps[0], false);
yield undefined;
// Opens the iframe to the test page, back to initial state.
openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
["Lorem ipsum", "rgb(0, 0, 0)",
"Uncustomized content", "rgb(0, 0, 0)"]);
yield undefined;
// Re-enable the app.
navigator.mozApps.mgmt.onenabledstatechange = function(event) {
ok(true, "onenabledstatechange received");
is(event.application.enabled, true, "Application is enabled");
is(apps[0].enabled, true, "Application is enabled");
continueTest();
}
navigator.mozApps.mgmt.setEnabled(apps[0], true);
yield undefined;
// Opens the iframe to the test page, customized.
openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
["Hello World!", "rgb(255, 0, 0)",
"Customized content", "rgb(0, 0, 255)"]);
yield undefined;
// Clean up after ourselves by uninstalling apps.
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Opens the iframe to the test page, back to initial state.
openPage("http://mochi.test:8888/tests/dom/apps/tests/addons/index.html",
["Lorem ipsum", "rgb(0, 0, 0)",
"Uncustomized content", "rgb(0, 0, 0)"]);
yield undefined;
}
</script>
</head>
<body onload="prepareEnv(go)">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<div id="container"></div>
</body>
</html>