1 if (this.importScripts) {
2 importScripts('../../../resources/js-test.js');
3 importScripts('shared.js');
6 description("Regression test for http://crbug.com/108071");
8 // Have to be at least 5 here: 1 initial, 3 continues to trigger prefetch and 1
9 // post-abort outstanding continue.
10 var names = ['Alpha', 'Bravo', 'Charlie', 'Delta', 'Echo'];
12 indexedDBTest(prepareDatabase, iterateAndDeleteFirstElement);
13 function prepareDatabase()
15 db = event.target.result;
16 event.target.transaction.onabort = unexpectedAbortCallback;
17 trans = event.target.transaction;
19 var objectStore = evalAndLog("objectStore = db.createObjectStore('store', {keyPath: 'id'})");
23 function resetObjectStore()
25 debug("\nresetObjectStore():");
27 objectStore = trans.objectStore('store');
28 evalAndLog("objectStore.clear()");
29 for (i = 0; i < names.length; i++) {
30 request = evalAndLog("objectStore.add({id: " + i + ", name: \"" + names[i] + "\"})");
31 request.onerror = unexpectedErrorCallback;
37 function iterateAndDeleteFirstElement()
39 debug("iterateAndDeleteFirstElement():");
41 evalAndLog("trans = db.transaction(['store'], 'readwrite')");
42 trans.onabort = transactionAborted;
43 trans.oncomplete = unexpectedCompleteCallback;
45 // Create the cursor and iterate over the whole thing.
46 request = evalAndLog("trans.objectStore('store').openCursor()");
47 request.onerror = unexpectedErrorCallback;
48 request.onsuccess = function () {
49 var cursor = event.target.result;
56 debug(cursor.value.id + ": " + cursor.value.name);
58 if (cursor.value.id == 0) {
59 // Delete the first element when we see it.
60 request = evalAndLog("trans.objectStore('store').delete(0)");
61 request.onerror = unexpectedErrorCallback;
62 request.onsuccess = function() { cursor.continue(); };
69 function prefetchAndAbort()
71 debug("prefetchAndAbort():");
73 request = evalAndLog("trans.objectStore('store').openCursor()");
74 request.onerror = unexpectedErrorCallback;
75 request.onsuccess = function () {
76 var cursor = event.target.result;
77 debug(cursor.value.id + ": " + cursor.value.name);
78 // Have to iterate to 3 in order to prefetch, but can't iterate past 3
79 // so that there will be a continue remaining.
80 if (cursor.value.id == 3) {
81 evalAndLog("trans.abort()");
88 function transactionAborted()
90 testPassed("Transaction aborted as expected");