blob: d2458f6a298b34107a4b8d0ef67bc6423d2da0df [file] [log] [blame]
<script src="../../../resources/js-test.js"></script>
<script src="../resources/shared.js"></script>
<body>
This test verifies when storage process crashes, indexedDB operation should not hang indefinitely.
</body>
<script>
var dbname = setDBNameFromPath() + Date();
var storageKey = "opendatabase-after-storage-crash.html";
function continueTest()
{
var request = window.indexedDB.open(dbname, 2);
request.onupgradeneeded = function(e) {
document.body.innerHTML = "Unexpected upgradeneeded after storage process termination. Database: name " + dbname + ", version 2.";
if (window.testRunner)
testRunner.notifyDone();
}
request.onerror = function(e) {
// Good, we received an expected error.
// Now reload to see if a new document connects successfully
if (sessionStorage[storageKey]) {
document.body.innerHTML = "Received error more than once unexpectedly. Database: name " + dbname + ", version 2.";
if (window.testRunner)
testRunner.notifyDone();
return;
}
sessionStorage[storageKey] = "Made it";
location.reload();
}
request.onsuccess = function(e) {
document.body.innerHTML = "Unexpected upgradeneeded after storage process termination. Database: name " + dbname + ", version 2. SessionStorage value: " + sessionStorage[storageKey] + ".";
if (window.testRunner)
testRunner.notifyDone();
}
}
var versionToOpen = sessionStorage.doneFirstLoad ? 3 : 1;
var request = window.indexedDB.open(dbname, versionToOpen);
request.onupgradeneeded = function(e) {
if (sessionStorage.doneFirstLoad) {
document.body.innerHTML = "Successfully opened database with version " + versionToOpen + ".";
shouldBeEqualToString('sessionStorage[storageKey]', 'Made it');
if (window.testRunner) {
testRunner.notifyDone();
return;
}
}
sessionStorage.doneFirstLoad = true;
// Set an error handler on the database connection so once the storage process terminates we know to continue the test
e.target.result.onerror = function(e) {
setTimeout(continueTest, 0);
}
if (window.testRunner) {
testRunner.waitUntilDone();
testRunner.terminateNetworkProcess();
}
}
request.onerror = function(e) {
if (versionToOpen == 1)
document.body.innerHTML = "Error on opening reuqest for database version 1. (FAIL: test should stop at opening version 3.)";
}
request.onsuccess = function(e) {
if (versionToOpen == 1)
document.body.innerHTML = "Success on opening reuqest for database version 1. (FAIL: test should stop at opening version 3.)";
}
</script>