<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script src="resources/shared.js"></script>
<script>
description("Ensure IndexedDB's write operations invalidate cursor prefetch caches");
indexedDBTest(prepareDatabase, onOpenSuccess);
function prepareDatabase(evt)
{
preamble(evt);
evalAndLog("db = event.target.result");
evalAndLog("store = db.createObjectStore('store')");
}
function onOpenSuccess(evt)
{
preamble(evt);
evalAndLog("db = event.target.result");
var steps = [
deleteRange,
clearStore
];
(function nextStep() {
var step = steps.shift();
if (step) {
doPrefetchInvalidationTest(step, nextStep);
} else {
finishJSTest();
return;
}
}());
}
function doPrefetchInvalidationTest(operation, callback)
{
debug("");
debug("-------------------------------------------");
preamble();
evalAndLog("store = db.transaction('store', 'readwrite', {durability: 'relaxed'}).objectStore('store')");
debug("Populate the store with 200 records.");
for (var i = 0; i < 200; ++i)
store.put(i, i);
evalAndLog("cursorRequest = store.openCursor()");
continue100Times(operation, callback);
}
function continue100Times(operation, callback)
{
preamble();
var count = 0;
cursorRequest.onsuccess = function() {
var cursor = cursorRequest.result;
++count;
if (count < 100) {
cursor.continue();
return;
}
shouldBeNonNull("cursorRequest.result");
doOperationAndContinue(operation, callback);
}
}
function doOperationAndContinue(operation, callback)
{
preamble();
operation();
evalAndLog("cursor = cursorRequest.result");
evalAndLog("cursor.continue()")
cursorRequest.onsuccess = function onContinueSuccess() {
preamble();
shouldBeNull("cursorRequest.result");
callback();
};
}
function deleteRange()
{
return evalAndLog("store.delete(IDBKeyRange.bound(-Infinity, +Infinity))");
}
function clearStore()
{
return evalAndLog("store.clear()");
}
</script>