gecko-dev/dom/apps/tests/test_langpacks.html

317 lines
8.9 KiB
HTML

<!DOCTYPE HTML><!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1108096
-->
<html>
<head>
<meta charset="utf-8">
<title>Test for Bug 1108096 - Langpack support</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<script type="application/javascript;version=1.7">
/**
* Test for Bug 1108096
* This file covers testing langpacks.
*
* The setup is as follows:
* - app is the localizable application.
* - langpack1 provides the French locale.
* - langpack2 provides the German and Polish locales.
*/
SimpleTest.waitForExplicitFinish();
const uriPrefix = "http://mochi.test:8888/tests/dom/apps/tests/langpack/";
let appManifestURL = uriPrefix + "manifest.webapp";
let lang1ManifestURL = uriPrefix + "lang1.webapp";
let lang2ManifestURL = uriPrefix + "lang2.webapp";
let gGenerator = runTest();
function go() {
gGenerator.next();
}
function continueTest() {
try {
gGenerator.next();
} catch (e if e instanceof StopIteration) {
SimpleTest.finish();
}
}
function mozAppsError() {
ok(false, "mozApps error: " + this.error.name);
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 the app url in an iframe.
ifr.setAttribute("mozapp", appManifestURL);
ifr.setAttribute("mozbrowser", "true");
ifr.setAttribute("src", uriPrefix + pageURL);
document.getElementById("container").appendChild(ifr);
}
let apps = [];
function installApp(manifestURL) {
info("About to install app at " + manifestURL);
let req = navigator.mozApps.install(manifestURL);
req.onsuccess = function() {
is(req.result.manifestURL, manifestURL, "app installed");
if (req.result.installState == "installed") {
is(req.result.installState, "installed", "app downloaded");
continueTest();
} else {
req.result.ondownloadapplied = function() {
is(req.result.installState, "installed", "app downloaded");
continueTest();
}
}
}
req.onerror = mozAppsError;
}
function runTest() {
// Set up.
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.pushPrefEnv({'set': [
["dom.mozBrowserFramesEnabled", true],
["dom.apps.allow_unsigned_langpacks", true] ]},continueTest);
yield undefined;
SpecialPowers.pushPermissions(
[{ "type": "webapps-manage", "allow": 1, "context": document },
{ "type": "embed-apps", "allow": 1, "context": document },
{ "type": "browser", "allow": 1, "context": document } ],
continueTest);
yield undefined;
navigator.mozApps.mgmt.oninstall = function(evt) {
apps.push(evt.application);
};
let _ = JSON.stringify;
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
// Install test app.
installApp(appManifestURL);
yield undefined;
// Opens the iframe to the test page, initial state.
// No locale is available.
openPage("index.html", [_({})]);
yield undefined;
// Install the fr langpack.
installApp(lang1ManifestURL);
yield undefined;
// Opens the iframe to the test page.
// Only the French locale is available.
openPage("index.html",
[_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}]})]);
yield undefined;
// Install the de and pl langpack.
installApp(lang2ManifestURL);
yield undefined;
// Opens the iframe to the test page.
// French, German and Polish locales are available.
openPage("index.html",
[_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}],"de":[{"revision":201411051234,"name":"Deutsch","target":"2.2"}],"pl":[{"revision":201411051234,"name":"Polski","target":"2.2"}]})]);
yield undefined;
// Uninstall the second langpack.
{
let app = apps.pop();
info("Uninstalling " + app.manifestURL);
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Opens the iframe to the test page.
// Only the French locale is available.
openPage("index.html",
[_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}]})]);
yield undefined;
// Uninstall the first langpack.
{
let app = apps.pop();
info("Uninstalling " + app.manifestURL);
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Opens the iframe to the test page, initial state.
// No locale is available.
openPage("index.html",
["{}"]);
yield undefined;
// Opens the iframe to the event test page.
// Will get additionallanguageschange events.
openPage("event.html",
[_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}]}),
_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}],"de":[{"revision":201411051234,"name":"Deutsch","target":"2.2"}]}),
_({"fr":[{"revision":201411051234,"name":"Français","target":"2.2"}],"de":[{"revision":201411051234,"name":"Deutsch","target":"2.2"}],"pl":[{"revision":201411051234,"name":"Polski","target":"2.2"}]})]);
yield undefined;
// Opens the iframe to the resource test page.
openPage("resources.html",
["UnavailableResource",
"UnavailableLanguage",
"UnavailableVersion",
"BadUrl",
"hello=Bonjour",
"hello=Bonjour",
_({"hello":"Bonjour"})]);
yield undefined;
// Clean up after ourselves by uninstalling apps.
info(apps.length + " applications to uninstall.");
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Test localized values with a x.y manifest version.
installApp(appManifestURL);
yield undefined;
// Install the fr langpack.
installApp(lang1ManifestURL);
yield undefined;
// Install the de and pl langpack.
installApp(lang2ManifestURL);
yield undefined;
// Opens the iframe to the localized values test page.
openPage("localizedvalues.html",
["Localization test app",
"UnknownProperty",
"Version française.",
"dialer",
"téléphone"]);
yield undefined;
// Clean up after ourselves by uninstalling apps.
info(apps.length + " applications to uninstall.");
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Test localized values with versionless manifest.
appManifestURL = uriPrefix + "manifest_no_version.webapp";
installApp(appManifestURL);
yield undefined;
// Install the fr langpack.
installApp(lang1ManifestURL);
yield undefined;
// Install the de and pl langpack.
installApp(lang2ManifestURL);
yield undefined;
// Opens the iframe to the localized values test page.
openPage("localizedvalues.html",
["Localization test app",
"UnknownProperty",
"Localization test app",
"dialer",
"dialer"]);
yield undefined;
// Clean up after ourselves by uninstalling apps.
info(apps.length + " applications to uninstall.");
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
// Test localized values with a x.y.z manifest version.
appManifestURL = uriPrefix + "manifest_version_xyz.webapp"
installApp(appManifestURL);
yield undefined;
// Install the fr langpack.
installApp(lang1ManifestURL);
yield undefined;
// Install the de and pl langpack.
installApp(lang2ManifestURL);
yield undefined;
// Opens the iframe to the localized values test page.
openPage("localizedvalues.html",
["Localization test app",
"UnknownProperty",
"Version française.",
"dialer",
"téléphone"]);
yield undefined;
// Clean up after ourselves by uninstalling apps.
info(apps.length + " applications to uninstall.");
while (apps.length) {
let app = apps.pop();
req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = continueTest;
req.onerror = mozAppsError;
yield undefined;
}
}
</script>
</head>
<body onload="go()">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<div id="container"></div>
</body>
</html>