Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / transaction-starvation.js
blob82d4074e0db687c1c01e7180f93dfcb2a1f4d7c1
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Check that read-only transactions don't starve read-write transactions.");
8 indexedDBTest(prepareDatabase, runTransactions);
10 function prepareDatabase(evt)
12     preamble(evt);
13     evalAndLog("db = event.target.result");
14     evalAndLog("db.createObjectStore('store')");
17 function runTransactions(evt)
19     preamble(evt);
20     evalAndLog("db = event.target.result");
21     debug("");
23     evalAndLog("readWriteTransactionStarted = false");
24     evalAndLog("readWriteTransactionComplete = false");
26     startReadOnlyTransaction();
30 function startReadOnlyTransaction()
32     preamble();
33     evalAndLog("transaction = db.transaction('store', 'readonly')");
34     transaction.onabort = unexpectedAbortCallback;
35     evalAndLog("store = transaction.objectStore('store')");
36     debug("Keep the transaction alive with an endless series of gets");
38     function doGet() {
39         request = store.get(0);
40         request.onsuccess = function() {
41             if (!readWriteTransactionStarted)
42                 startReadWriteTransaction();
44             if (!readWriteTransactionComplete)
45                 doGet();
46         };
47     }
48     doGet();
51 function startReadWriteTransaction()
53     preamble();
54     evalAndLog("transaction = db.transaction('store', 'readwrite')");
55     transaction.onabort = unexpectedAbortCallback;
56     evalAndLog("readWriteTransactionStarted = true");
57     transaction.oncomplete = function readWriteTransactionComplete() {
58         preamble();
59         testPassed("Transaction wasn't starved");
60         evalAndLog("readWriteTransactionComplete = true");
61         finishJSTest();
62     };