Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / version-change-exclusive.js
blob6a034736f50b28205d7532bae78f31fb736e97a8
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Ensure pending open waits for version change transaction to complete.");
8 indexedDBTest(prepareDatabase, null, {"runAfterOpen": concurrentOpen});
10 function concurrentOpen()
12     debug("calling open() - callback should wait until VERSION_CHANGE transaction is complete");
13     var openRequest = evalAndLog("indexedDB.open(dbname)");
14     openRequest.onsuccess = openAgainSuccess;
15     openRequest.onerror = unexpectedErrorCallback;
18 function prepareDatabase()
20     db = event.target.result;
21     debug("setVersion() callback");
22     debug("starting work in VERSION_CHANGE transaction");
23     evalAndLog("self.state = 'VERSION_CHANGE started'");
25     self.store = evalAndLog("store = db.createObjectStore('test-store')");
26     evalAndExpectException("db.transaction('test-store')", "DOMException.INVALID_STATE_ERR", "'InvalidStateError'");
27     self.count = 0;
28     do_async_puts();
30     function do_async_puts()
31     {
32         var req = evalAndLog("store.put(" + count + ", " + count + ")");
33         req.onerror = unexpectedErrorCallback;
34         req.onsuccess = function (e) {
35             debug("in put's onsuccess");
36             if (++self.count < 10) {
37                 do_async_puts();
38             } else {
39                 debug("ending work in VERSION_CHANGE transaction");
40                 evalAndLog("self.state = 'VERSION_CHANGE finished'");
41             }
42         };
43     }
46 function openAgainSuccess()
48     debug("open() callback - this should appear after VERSION_CHANGE transaction ends");
49     shouldBeEqualToString("self.state", "VERSION_CHANGE finished");
50     finishJSTest();