gecko/dom/indexedDB/test/test_setVersion_events.html

103 lines
3.4 KiB
HTML

<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<html>
<head>
<title>Indexed Database Property Test</title>
<script type="text/javascript" src="/MochiKit/packed.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="text/javascript;version=1.7">
function testSteps()
{
const name = window.location.pathname;
const description = "My Test Database";
let request = mozIndexedDB.open(name, description);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
let event = yield;
let versionChangeEventCount = 0;
let db1, db2, db3;
db1 = event.target.result;
db1.addEventListener("versionchange", function(event) {
ok(true, "Got version change event");
is(event.target.source, null, "Correct source");
is(event.target, db1, "Correct target");
is(event.target.version, "", "Correct db version");
is(event.version, "1", "Correct event version");
is(versionChangeEventCount++, 0, "Correct count");
db1.close();
}, false);
request = mozIndexedDB.open(name, description);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
db2 = event.target.result;
db2.addEventListener("versionchange", function(event) {
ok(true, "Got version change event");
is(event.target.source, null, "Correct source");
is(event.target, db2, "Correct target");
is(event.target.version, "1", "Correct db version");
is(event.version, "2", "Correct event version");
is(versionChangeEventCount++, 1, "Correct count");
}, false);
request = db2.setVersion("1");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
request.onblocked = errorHandler;
event = yield;
ok(event.target.result === event.target.transaction, "Good result");
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
"Correct mode");
is(db2.version, "1", "Correct db version");
request = mozIndexedDB.open(name, description);
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
event = yield;
db3 = event.target.result;
request = db3.setVersion("2");
request.onerror = errorHandler;
request.onsuccess = grabEventAndContinueHandler;
request.onblocked = function(event) {
ok(true, "Got version change blocked event");
is(event.target.source, db3, "Correct source");
is(event.target, request, "Correct target");
is(event.target.source.version, "1", "Correct db version");
is(event.version, "2", "Correct event version");
versionChangeEventCount++;
db2.close();
};
event = yield;
ok(event.target.result === event.target.transaction, "Good result");
is(event.target.transaction.mode, IDBTransaction.VERSION_CHANGE,
"Correct mode");
is(db3.version, "2", "Correct db version");
is(versionChangeEventCount, 3, "Saw all expected events");
finishTest();
yield;
}
</script>
<script type="text/javascript;version=1.7" src="helpers.js"></script>
</head>
<body onload="runTest();"></body>
</html>