mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-09-11 02:56:06 +00:00
357 lines
13 KiB
HTML
357 lines
13 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<!--
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id={821589}
|
|
-->
|
|
<head>
|
|
<title>Test for Bug {821589} Packaged apps installation and update</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>
|
|
<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={821589}">Mozilla Bug {821589}</a>
|
|
<p id="display"></p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
"use strict";
|
|
|
|
function debug(aMsg) {
|
|
//dump("== Tests debug == " + aMsg + "\n");
|
|
}
|
|
|
|
function checkAppInstallError(aMiniManifestURL, aExpectedError) {
|
|
var req = navigator.mozApps.installPackage(aMiniManifestURL);
|
|
req.onsuccess = function() {
|
|
ok(false, "We are supposed to throw " + aExpectedError);
|
|
PackagedTestHelper.finish();
|
|
};
|
|
req.onerror = function(evt) {
|
|
var error = evt.target.error.name;
|
|
if (error == aExpectedError) {
|
|
info("Got expected " + aExpectedError);
|
|
PackagedTestHelper.next();
|
|
} else {
|
|
ok(false, "Got unexpected " + error);
|
|
PackagedTestHelper.finish();
|
|
}
|
|
};
|
|
}
|
|
|
|
function checkUninstallApp(aApp) {
|
|
var req = navigator.mozApps.mgmt.uninstall(aApp);
|
|
req.onsuccess = function() {
|
|
info("App uninstalled");
|
|
aApp.ondownloadsuccess = null;
|
|
aApp.ondownloaderror = null;
|
|
aApp.onprogress = null;
|
|
PackagedTestHelper.next();
|
|
};
|
|
req.onerror = function(evt) {
|
|
ok(false, "Got unexpected " + evt.target.error.name);
|
|
PackagedTestHelper.finish();
|
|
};
|
|
}
|
|
|
|
var gIconData =
|
|
"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0D\x49\x48\x44\x52" +
|
|
"\x00\x00\x00\x0F\x00\x00\x00\x0F\x08\x03\x00\x00\x00\x0C\x08\x65" +
|
|
"\x78\x00\x00\x00\x04\x67\x41\x4D\x41\x00\x00\xD6\xD8\xD4\x4F\x58" +
|
|
"\x32\x00\x00\x00\x19\x74\x45\x58\x74\x53\x6F\x66\x74\x77\x61\x72" +
|
|
"\x65\x00\x41\x64\x6F\x62\x65\x20\x49\x6D\x61\x67\x65\x52\x65\x61" +
|
|
"\x64\x79\x71\xC9\x65\x3C\x00\x00\x00\x39\x50\x4C\x54\x45\xB5\x42" +
|
|
"\x42\xCE\x94\x94\xCE\x84\x84\x9C\x21\x21\xAD\x21\x21\xCE\x73\x73" +
|
|
"\x9C\x10\x10\xBD\x52\x52\xEF\xD6\xD6\xB5\x63\x63\xA5\x10\x10\xB5" +
|
|
"\x00\x00\xE7\xC6\xC6\xE7\xB5\xB5\x9C\x00\x00\x8C\x00\x00\xFF\xFF" +
|
|
"\xFF\x7B\x00\x00\xAD\x00\x00\xEC\xAD\x83\x63\x00\x00\x00\x66\x49" +
|
|
"\x44\x41\x54\x78\xDA\x6C\x89\x0B\x12\xC2\x40\x08\x43\xB3\xDB\x8F" +
|
|
"\x5A\x21\x40\xEF\x7F\x58\xA1\x55\x67\xB6\xD3\xC0\x03\x42\xF0\xDE" +
|
|
"\x87\xC2\x3E\xEA\xCE\xF3\x4B\x0D\x30\x27\xAB\xCF\x03\x9C\xFB\xA3" +
|
|
"\xEB\xBC\x2D\xBA\xD4\x0F\x84\x97\x9E\x49\x67\xE5\x74\x87\x26\x70" +
|
|
"\x21\x0D\x66\xAE\xB6\x26\xB5\x8D\xE5\xE5\xCF\xB4\x9E\x79\x1C\xB9" +
|
|
"\x4C\x2E\xB0\x90\x16\x96\x84\xB6\x68\x2F\x84\x45\xF5\x0F\xC4\xA8" +
|
|
"\xAB\xFF\x08\x30\x00\x16\x91\x0C\xDD\xAB\xF1\x05\x11\x00\x00\x00" +
|
|
"\x00\x49\x45\x4E\x44\xAE\x42\x60\x82";
|
|
|
|
var gIconSize = 15;
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
SimpleTest.requestFlakyTimeout("untriaged");
|
|
|
|
var steps = [
|
|
function() {
|
|
// Set up
|
|
SpecialPowers.setAllAppsLaunchable(true);
|
|
SpecialPowers.addPermission("webapps-manage", true, document);
|
|
info("Set up");
|
|
PackagedTestHelper.next();
|
|
},
|
|
function() {
|
|
info("autoConfirmAppInstall");
|
|
SpecialPowers.autoConfirmAppInstall(PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
ok(true, "autoConfirmAppUninstall");
|
|
SpecialPowers.autoConfirmAppUninstall(PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(0, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
// Bug 927699 - navigator.mozApps.install(url) lets NS_ERROR_FAILURE onto
|
|
// the web.
|
|
info("== TEST == INVALID_URL");
|
|
checkAppInstallError("", "INVALID_URL");
|
|
},
|
|
function() {
|
|
// Test network error.
|
|
info("== TEST == Network error");
|
|
checkAppInstallError("http://notvalidurl", "NETWORK_ERROR");
|
|
},
|
|
function() {
|
|
// Test wrong mini-manifest content type.
|
|
info("== TEST == Not valid mini-manifest content type");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&noManifestContentType=true";
|
|
checkAppInstallError(miniManifestURL, "INVALID_MANIFEST_CONTENT_TYPE");
|
|
},
|
|
function() {
|
|
// Test mini-manifest 'size' value is not number. Bug 839435.
|
|
info("== TEST == Size value is not a number");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&packageSize=\"NotANumber\"";
|
|
checkAppInstallError(miniManifestURL, "INVALID_MANIFEST");
|
|
},
|
|
function() {
|
|
// Test mini-manifest negative 'size' value. Bug 839435.
|
|
info("== TEST == Negative size value");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&packageSize=-1";
|
|
checkAppInstallError(miniManifestURL, "INVALID_MANIFEST");
|
|
},
|
|
function() {
|
|
// Test wrong package path
|
|
info("== TEST == Installing app with wrong package path");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&wrongPackagePath=true";
|
|
checkAppInstallError(miniManifestURL, "INVALID_MANIFEST");
|
|
},
|
|
function() {
|
|
// Test no manifest in zip file.
|
|
info("== TEST == No manifest in the zip file");
|
|
var miniManifestURL = PackagedTestHelper.gSJS + "?getManifest=true";
|
|
PackagedTestHelper.checkAppDownloadError(miniManifestURL,
|
|
"MISSING_MANIFEST", 0, true, true,
|
|
PackagedTestHelper.gAppName);
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(1, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
// Test mini-manifest app name is different from the webapp manifest name.
|
|
// Bug 844243.
|
|
info("== TEST == Mini-manifest app name is different from webapp " +
|
|
"manifest name");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&appName=arandomname";
|
|
PackagedTestHelper.checkAppDownloadError(miniManifestURL,
|
|
"MANIFEST_MISMATCH", 1, true, true,
|
|
"arandomname");
|
|
},
|
|
function() {
|
|
// Test mini-manifest dev name is different from the webapp manifest dev
|
|
// name.
|
|
ok (true, "== TEST == Mini-manifest dev name is different from manifest " +
|
|
"dev name");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&devName=arandomdevname";
|
|
PackagedTestHelper.checkAppDownloadError(miniManifestURL,
|
|
"MANIFEST_MISMATCH", 1, true, true,
|
|
PackagedTestHelper.gAppName);
|
|
},
|
|
function() {
|
|
// Test mini-manifest dev url is different from the webapp manifest dev
|
|
// url.
|
|
ok (true, "== TEST == Mini-manifest dev url is different from manifest " +
|
|
"dev url");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true" +
|
|
"&devUrl=arandomdevurl";
|
|
PackagedTestHelper.checkAppDownloadError(miniManifestURL,
|
|
"MANIFEST_MISMATCH", 1, true, true,
|
|
PackagedTestHelper.gAppName);
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(2, PackagedTestHelper.next);
|
|
},
|
|
function() {
|
|
info("== TEST == Install packaged app");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true";
|
|
|
|
navigator.mozApps.mgmt.oninstall = function(evt) {
|
|
info("Got oninstall event");
|
|
PackagedTestHelper.gApp = evt.application;
|
|
PackagedTestHelper.gApp.ondownloaderror = function() {
|
|
ok(false, "Download error " +
|
|
PackagedTestHelper.gApp.downloadError.name);
|
|
PackagedTestHelper.finish();
|
|
};
|
|
PackagedTestHelper.gApp.ondownloadsuccess = function() {
|
|
info("App downloaded");
|
|
var expected = {
|
|
name: PackagedTestHelper.gAppName,
|
|
manifestURL: miniManifestURL,
|
|
installOrigin: PackagedTestHelper.gInstallOrigin,
|
|
progress: 0,
|
|
installState: "installed",
|
|
downloadAvailable: false,
|
|
downloading: false,
|
|
downloadSize: 0,
|
|
size: 0,
|
|
readyToApplyDownload: false
|
|
};
|
|
PackagedTestHelper.checkAppState(PackagedTestHelper.gApp, "2", expected,
|
|
true, false, PackagedTestHelper.next);
|
|
};
|
|
};
|
|
|
|
var request = navigator.mozApps.installPackage(miniManifestURL);
|
|
request.onerror = PackagedTestHelper.mozAppsError;
|
|
request.onsuccess = function() {
|
|
info("Application installed");
|
|
};
|
|
},
|
|
function() {
|
|
PackagedTestHelper.setAppVersion(3, PackagedTestHelper.next, false, true);
|
|
},
|
|
function() {
|
|
info("== TEST == Get icon");
|
|
var app = PackagedTestHelper.gApp;
|
|
|
|
navigator.mozApps.mgmt.getIcon(app, gIconSize).then((blob) => {
|
|
var reader = new FileReader();
|
|
|
|
reader.onloadend = function() {
|
|
var success = reader.result == gIconData;
|
|
ok(success, "== TEST == Icon matches expected icon");
|
|
PackagedTestHelper.next();
|
|
}
|
|
|
|
reader.readAsBinaryString(blob);
|
|
}, (err) => {
|
|
ok(false, "Can't get icon: " + err);
|
|
PackagedTestHelper.finish();
|
|
});
|
|
},
|
|
function() {
|
|
info("== TEST == Install packaged app with a cancel/resume");
|
|
var miniManifestURL = PackagedTestHelper.gSJS +
|
|
"?getManifest=true&allowCancel";
|
|
navigator.mozApps.mgmt.oninstall = function(evt) {
|
|
info("Got oninstall event");
|
|
PackagedTestHelper.gApp = evt.application;
|
|
|
|
PackagedTestHelper.gApp.onprogress = function() {
|
|
// The first onprogress event is generated *before* the actual
|
|
// download is started. And the next one will be generated too late.
|
|
// So we just try to delay the canceling a bit.
|
|
setTimeout(function() {
|
|
// Let's try cancelling and resuming the download later on.
|
|
info("Cancelling the download");
|
|
PackagedTestHelper.gApp.cancelDownload();
|
|
// And only do this once.
|
|
PackagedTestHelper.gApp.onprogress = null;
|
|
}, 10);
|
|
};
|
|
|
|
var alreadyCanceled = false;
|
|
PackagedTestHelper.gApp.ondownloaderror = function() {
|
|
info("Got a expected download error");
|
|
ok(!alreadyCanceled, "The download should be cancelled only once!");
|
|
is(PackagedTestHelper.gApp.downloadError.name, "DOWNLOAD_CANCELED",
|
|
"Download error " + PackagedTestHelper.gApp.downloadError.name);
|
|
if (!alreadyCanceled) {
|
|
PackagedTestHelper.gApp.download();
|
|
alreadyCanceled = true;
|
|
}
|
|
};
|
|
|
|
PackagedTestHelper.gApp.ondownloadsuccess = function() {
|
|
info("App downloaded");
|
|
|
|
// Sometimes we can't cancel in time (since setting a high timer on the
|
|
// sjs just doesn't work). Let's fail gracefully in that case, and just
|
|
// give a warning here.
|
|
if (!alreadyCanceled) {
|
|
todo(alreadyCanceled, "The app download wasn't cancelled in time!");
|
|
}
|
|
var expected = {
|
|
name: PackagedTestHelper.gAppName,
|
|
manifestURL: miniManifestURL,
|
|
installOrigin: PackagedTestHelper.gInstallOrigin,
|
|
progress: 0,
|
|
installState: alreadyCanceled?"pending":"installed",
|
|
downloadAvailable: false,
|
|
downloading: false,
|
|
downloadSize: 0,
|
|
size: 0,
|
|
readyToApplyDownload: alreadyCanceled
|
|
};
|
|
PackagedTestHelper.checkAppState(PackagedTestHelper.gApp, "3", expected,
|
|
true, false, function() {});
|
|
};
|
|
|
|
PackagedTestHelper.gApp.ondownloadapplied = function() {
|
|
info("App download applied.");
|
|
var expected = {
|
|
name: PackagedTestHelper.gAppName,
|
|
manifestURL: miniManifestURL,
|
|
installOrigin: PackagedTestHelper.gInstallOrigin,
|
|
progress: 0,
|
|
installState: "installed",
|
|
downloadAvailable: false,
|
|
downloading: false,
|
|
downloadSize: 0,
|
|
size: 0,
|
|
readyToApplyDownload: false
|
|
};
|
|
PackagedTestHelper.checkAppState(PackagedTestHelper.gApp, "3", expected,
|
|
true, false, PackagedTestHelper.next);
|
|
}
|
|
|
|
};
|
|
|
|
var request = navigator.mozApps.installPackage(miniManifestURL);
|
|
request.onerror = PackagedTestHelper.mozAppsError;
|
|
request.onsuccess = function() {
|
|
info("Application installed");
|
|
};
|
|
},
|
|
function() {
|
|
info("all done!\n");
|
|
PackagedTestHelper.finish();
|
|
}
|
|
];
|
|
|
|
PackagedTestHelper.setSteps(steps);
|
|
|
|
addLoadEvent(() => prepareEnv(() => PackagedTestHelper.start()));
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|