mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1011738 - Theme support for b2g/gaia, Part 5 : tests r=myk
This commit is contained in:
parent
172043d717
commit
288cda9338
@ -4,11 +4,12 @@ var gAppcacheTemplatePath = "tests/dom/apps/tests/file_cached_app.template.appca
|
||||
var gWidgetTemplatePath = "tests/dom/apps/tests/file_widget_app.template.html";
|
||||
var gDefaultIcon = "default_icon";
|
||||
|
||||
function makeResource(templatePath, version, apptype) {
|
||||
function makeResource(templatePath, version, apptype, role) {
|
||||
let icon = getState('icon') || gDefaultIcon;
|
||||
var res = readTemplate(templatePath).replace(/VERSIONTOKEN/g, version)
|
||||
.replace(/APPTYPETOKEN/g, apptype)
|
||||
.replace(/ICONTOKEN/g, icon);
|
||||
.replace(/ICONTOKEN/g, icon)
|
||||
.replace(/ROLE/g, role);
|
||||
|
||||
// Hack - This is necessary to make the tests pass, but hbambas says it
|
||||
// shouldn't be necessary. Comment it out and watch the tests fail.
|
||||
@ -49,6 +50,8 @@ function handleRequest(request, response) {
|
||||
if (apptype != 'hosted' && apptype != 'cached' && apptype != 'widget' && apptype != 'invalidWidget')
|
||||
throw "Invalid app type: " + apptype;
|
||||
|
||||
var role = query.role;
|
||||
|
||||
// Get the version from server state and handle the etag.
|
||||
var version = Number(getState('version'));
|
||||
var etag = getEtag(request, version);
|
||||
@ -70,7 +73,7 @@ function handleRequest(request, response) {
|
||||
if ('getmanifest' in query) {
|
||||
var template = gBasePath + 'file_' + apptype + '_app.template.webapp';
|
||||
response.setHeader("Content-Type", "application/x-web-app-manifest+json", false);
|
||||
response.write(makeResource(template, version, apptype));
|
||||
response.write(makeResource(template, version, apptype, role));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -80,18 +83,18 @@ function handleRequest(request, response) {
|
||||
// state is shared.
|
||||
if (apptype == 'cached' && 'getappcache' in query) {
|
||||
response.setHeader("Content-Type", "text/cache-manifest", false);
|
||||
response.write(makeResource(gAppcacheTemplatePath, version, apptype));
|
||||
response.write(makeResource(gAppcacheTemplatePath, version, apptype, role));
|
||||
return;
|
||||
}
|
||||
else if (apptype == 'widget' || apptype == 'invalidWidget')
|
||||
{
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
response.write(makeResource(gWidgetTemplatePath, version, apptype));
|
||||
response.write(makeResource(gWidgetTemplatePath, version, apptype, role));
|
||||
return;
|
||||
}
|
||||
// Generate the app.
|
||||
response.setHeader("Content-Type", "text/html", false);
|
||||
response.write(makeResource(gAppTemplatePath, version, apptype));
|
||||
response.write(makeResource(gAppTemplatePath, version, apptype, role));
|
||||
}
|
||||
|
||||
function getEtag(request, version) {
|
||||
|
@ -4,5 +4,6 @@
|
||||
"launch_path": "/tests/dom/apps/tests/file_app.sjs?apptype=hosted",
|
||||
"icons": {
|
||||
"128": "ICONTOKEN"
|
||||
}
|
||||
},
|
||||
"role": "ROLE"
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ function handleRequest(request, response) {
|
||||
var allowCancel = "allowCancel" in query;
|
||||
var getPackage = "getPackage" in query;
|
||||
var alreadyDeferred = Number(getState("alreadyDeferred"));
|
||||
var role = query.role || "";
|
||||
|
||||
if (allowCancel && getPackage && !alreadyDeferred) {
|
||||
// Only do this for the actual package delivery.
|
||||
@ -63,7 +64,7 @@ function handleRequest(request, response) {
|
||||
if (version != "0") {
|
||||
var manifestTemplate = gBasePath + gMiniManifestTemplate;
|
||||
var manifest = makeResource(manifestTemplate, version, packagePath,
|
||||
packageSize, appName, devName, devUrl);
|
||||
packageSize, appName, devName, devUrl, role);
|
||||
addZipEntry(zipWriter, manifest, "manifest.webapp");
|
||||
}
|
||||
|
||||
@ -122,7 +123,7 @@ function handleRequest(request, response) {
|
||||
}
|
||||
packagePath = "wrongPackagePath" in query ? "" : packagePath;
|
||||
var manifest = makeResource(template, version, packagePath, packageSize,
|
||||
appName, devName, devUrl);
|
||||
appName, devName, devUrl, role);
|
||||
response.write(manifest);
|
||||
return;
|
||||
}
|
||||
@ -178,13 +179,14 @@ function readFile(path, fromTmp) {
|
||||
}
|
||||
|
||||
function makeResource(templatePath, version, packagePath, packageSize,
|
||||
appName, developerName, developerUrl) {
|
||||
appName, developerName, developerUrl, role) {
|
||||
var res = readFile(templatePath, false)
|
||||
.replace(/VERSIONTOKEN/g, version)
|
||||
.replace(/PACKAGEPATHTOKEN/g, packagePath)
|
||||
.replace(/PACKAGESIZETOKEN/g, packageSize)
|
||||
.replace(/NAMETOKEN/g, appName)
|
||||
.replace(/DEVELOPERTOKEN/g, developerName)
|
||||
.replace(/DEVELOPERURLTOKEN/g, developerUrl);
|
||||
.replace(/DEVELOPERURLTOKEN/g, developerUrl)
|
||||
.replace(/ROLETOKEN/g, role);
|
||||
return res;
|
||||
}
|
||||
|
@ -16,5 +16,6 @@
|
||||
"name": "DEVELOPERTOKEN",
|
||||
"url": "DEVELOPERURLTOKEN"
|
||||
},
|
||||
"default_locale": "en-US"
|
||||
"default_locale": "en-US",
|
||||
"role": "ROLETOKEN"
|
||||
}
|
||||
|
@ -31,4 +31,5 @@ skip-if = buildapp == "b2g" || toolkit == "android" # see bug 989806
|
||||
[test_receipt_operations.html]
|
||||
[test_signed_pkg_install.html]
|
||||
[test_uninstall_errors.html]
|
||||
[test_theme_role.html]
|
||||
[test_widget.html]
|
||||
|
@ -57,7 +57,7 @@ var PackagedTestHelper = (function PackagedTestHelper() {
|
||||
finish();
|
||||
}
|
||||
|
||||
function setAppVersion(aVersion, aCb, aDontUpdatePackage, aAllowCancel) {
|
||||
function setAppVersion(aVersion, aCb, aDontUpdatePackage, aAllowCancel, aRole) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
var dontUpdate = "";
|
||||
var allowCancel = "";
|
||||
@ -68,6 +68,9 @@ var PackagedTestHelper = (function PackagedTestHelper() {
|
||||
allowCancel= "&allowCancel=1";
|
||||
}
|
||||
var url = gSJS + "?setVersion=" + aVersion + dontUpdate + allowCancel;
|
||||
if (aRole) {
|
||||
url += "&role=" + aRole;
|
||||
}
|
||||
xhr.addEventListener("load", function() {
|
||||
is(xhr.responseText, "OK", "setAppVersion OK");
|
||||
aCb();
|
||||
|
110
dom/apps/tests/test_theme_role.html
Normal file
110
dom/apps/tests/test_theme_role.html
Normal file
@ -0,0 +1,110 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id={1011738}
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug {1011738}</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="test_packaged_app_common.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id={1011738}">Mozilla Bug {1011738}</a>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="application/javascript;version=1.7">
|
||||
|
||||
var gHostedURL = "http://test/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true&role=theme";
|
||||
|
||||
var gPackageURL = PackagedTestHelper.gSJS + "?getManifest=true&test_role";
|
||||
var gGenerator = runTest();
|
||||
|
||||
function go() {
|
||||
SpecialPowers.pushPermissions(
|
||||
[{ "type": "webapps-manage", "allow": 1, "context": document }],
|
||||
function() { gGenerator.next() });
|
||||
}
|
||||
|
||||
function continueTest() {
|
||||
try {
|
||||
gGenerator.next();
|
||||
} catch (e if e instanceof StopIteration) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
function finish() {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function cbError(aEvent) {
|
||||
ok(false, "Error callback invoked " +
|
||||
aEvent.target.error.name + " " + aEvent.target.error.message);
|
||||
finish();
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
/**
|
||||
* Checks that no apps that are not certified can be installed as themes.
|
||||
*/
|
||||
function runTest() {
|
||||
SpecialPowers.setAllAppsLaunchable(true);
|
||||
|
||||
SpecialPowers.autoConfirmAppInstall(continueTest);
|
||||
yield undefined;
|
||||
|
||||
// Test that a hosted app can't be a theme.
|
||||
info("Hosted apps can't be themes.");
|
||||
var request = navigator.mozApps.install(gHostedURL, { });
|
||||
request.onerror = function() {
|
||||
is(request.error.name, "INVALID_ROLE");
|
||||
continueTest();
|
||||
};
|
||||
request.onsuccess = function() {
|
||||
ok(false, "We should not install this app!");
|
||||
};
|
||||
yield undefined;
|
||||
|
||||
info("Non certified packaged apps can't be themes.");
|
||||
|
||||
PackagedTestHelper.setAppVersion(1, continueTest, false, false, "theme");
|
||||
yield undefined;
|
||||
|
||||
request = navigator.mozApps.installPackage(gPackageURL, { });
|
||||
request.onerror = cbError;
|
||||
|
||||
request.onsuccess = function() {
|
||||
info("Installing package.");
|
||||
};
|
||||
navigator.mozApps.mgmt.oninstall = function(evt) {
|
||||
info("Got oninstall event");
|
||||
PackagedTestHelper.gApp = evt.application;
|
||||
|
||||
PackagedTestHelper.gApp.ondownloaderror = function() {
|
||||
is(PackagedTestHelper.gApp.downloadError.name, "INVALID_ROLE");
|
||||
continueTest();
|
||||
};
|
||||
|
||||
PackagedTestHelper.gApp.ondownloadapplied = function() {
|
||||
info("App download applied.");
|
||||
ok(false, "We should not install this app!");
|
||||
continueTest();
|
||||
}
|
||||
|
||||
};
|
||||
yield undefined;
|
||||
}
|
||||
|
||||
addLoadEvent(go);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user