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

109 строки
3.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=830258
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 830258</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
<script type="text/javascript" src="common.js"></script>
<script type="application/javascript;version=1.7">
/** Test for Bug 830258 **/
SimpleTest.waitForExplicitFinish();
var url1 = 'http://test1.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
var url2 = 'http://test2.example.com/tests/dom/apps/tests/file_app.sjs?apptype=hosted&getmanifest=true';
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) {
SimpleTest.finish();
}
}
function mozAppsError() {
ok(false, "mozApps error: " + this.error.name);
SimpleTest.finish();
}
function runTest() {
// Set up.
SpecialPowers.autoConfirmAppInstall(continueTest);
yield undefined;
SpecialPowers.autoConfirmAppUninstall(continueTest);
yield undefined;
let request = navigator.mozApps.install(url1);
request.onerror = mozAppsError;
request.onsuccess = continueTest;
yield undefined;
let app1 = request.result;
ok(app1, "App1 is non-null");
request = navigator.mozApps.install(url2);
request.onerror = mozAppsError;
request.onsuccess = continueTest;
yield undefined;
let app2 = request.result;
ok(app2, "App2 is non-null");
request = navigator.mozApps.mgmt.uninstall(app1);
request.onsuccess = function() {
ok(true, "Succeed to uninstall the app1 as expected");
continueTest();
};
request.onerror = function() {
ok(false, "Fail to uninstall the app1");
continueTest();
};
yield undefined;
request = navigator.mozApps.mgmt.uninstall(app1);
request.onsuccess = function() {
ok(false, "Shouldn't be able to uninstall the app1 again");
continueTest();
};
request.onerror = function() {
is(this.error.name, "NOT_INSTALLED", "Error name should be 'NOT_INSTALLED'");
continueTest();
};
yield undefined;
request = navigator.mozApps.mgmt.uninstall(app2);
request.onsuccess = function() {
ok(true, "Succeed to uninstall the app2 as expected");
continueTest();
};
request.onerror = function() {
ok(false, "Fail to uninstall the app2");
continueTest();
};
yield undefined;
}
</script>
</head>
<body onload="prepareEnv(go)">
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=830258">Mozilla Bug 830258</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
</html>