Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / resources / database-wrapper.js
blob0d653a3c483d56093f6cfaa87676e43a4469fb9d
1 if (this.importScripts) {
2     importScripts('../../../resources/js-test.js');
3     importScripts('shared.js');
6 description("Ensure IDBDatabase wrapper isn't prematurely collected.");
8 test();
10 function test()
12     setDBNameFromPath();
13     var deleteRequest = evalAndLog("indexedDB.deleteDatabase(dbname)");
14     deleteRequest.onblocked = unexpectedBlockedCallback;
15     deleteRequest.onerror = unexpectedErrorCallback;
16     deleteRequest.onsuccess = openDB;
19 function openDB()
21     preamble();
23     var openRequest = evalAndLog("indexedDB.open(dbname, 1)");
24     openRequest.onblocked = unexpectedBlockedCallback;
25     openRequest.onerror = unexpectedErrorCallback;
26     openRequest.onupgradeneeded = onUpgradeNeeded;
27     openRequest.onsuccess = openSuccess;
30 function onUpgradeNeeded(evt) {
31     preamble(evt);
32     evalAndLog("db = event.target.result");
33     evalAndLog("db.createObjectStore('store').createIndex('index', 'keyPath')");
34     evalAndLog("db = null");
37 function openSuccess(evt)
39     preamble(evt);
40     var db = event.target.result;
41     db.onversionchange = onVersionChange;
42     evalAndLog("sawVersionChangeEvent = false");
44     // All these local references should get collected, but the database's
45     // wrapper shouldn't get collected before the database itself.
46     var transaction = db.transaction('store', 'readonly');
47     var objectStore = transaction.objectStore('store');
48     var request = objectStore.get(0);
49     request.onsuccess = function() {
50         setTimeout(collectGarbage, 0);
51     };
54 function onVersionChange(evt)
56     preamble(evt);
57     evalAndLog("event.target.close()");
58     evalAndLog("sawVersionChangeEvent = true");
61 function collectGarbage()
63     preamble();
64     evalAndLog("self.gc()");
66     setTimeout(openAgain, 0);
69 function openAgain()
71     preamble();
73     var openRequest = evalAndLog("indexedDB.open(dbname, 2)");
74     openRequest.onblocked = unexpectedBlockedCallback;
75     openRequest.onerror = unexpectedErrorCallback;
76     openRequest.onsuccess = openAgainSuccess;
79 function openAgainSuccess(evt)
81     preamble(evt);
82     shouldBeTrue("sawVersionChangeEvent");
83     finishJSTest();