Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / storage / indexeddb / key-cursor-request-cycle.html
blob4b24ace259f4399614251f4389b773d6bbf62bfc
1 <!DOCTYPE html>
2 <script src="../../resources/js-test.js"></script>
3 <script src="resources/shared.js"></script>
4 <script>
6 description("Verify that that key cursors weakly hold request, and work if request is GC'd");
8 indexedDBTest(prepareDatabase, onOpen);
10 function prepareDatabase(evt)
12 preamble(evt);
13 evalAndLog("db = event.target.result");
14 evalAndLog("store = db.createObjectStore('store')");
15 store.put("value1", "key1");
16 store.put("value2", "key2");
19 function onOpen(evt)
21 preamble(evt);
22 evalAndLog("db = event.target.result");
23 evalAndLog("tx = db.transaction('store')");
24 evalAndLog("store = tx.objectStore('store')");
26 evalAndLog("cursorRequest = store.openKeyCursor()");
27 cursorRequest.onsuccess = function openCursorRequestSuccess(evt) {
28 preamble(evt);
29 debug("Result will be checked later, to ensure that lazy access is safe");
32 evalAndLog("otherRequest = store.get(0)");
33 otherRequest.onsuccess = function otherRequestSuccess(evt) {
34 preamble(evt);
36 debug("Verify that the request's result can be accessed lazily:");
37 evalAndLog("gc()");
39 evalAndLog("cursor = cursorRequest.result");
40 shouldBeNonNull("cursor");
41 shouldBeEqualToString("cursor.key", "key1");
42 evalAndLog("cursorRequest.extra = 123");
43 evalAndLog("cursor.extra = 456");
45 // Assign a new handler to inspect the request and cursor indirectly.
46 cursorRequest.onsuccess = function cursorContinueSuccess(evt) {
47 preamble(evt);
48 evalAndLog("cursor = event.target.result");
49 shouldBeNonNull("cursor");
50 shouldBeEqualToString("cursor.key", "key2");
51 shouldBe("event.target.extra", "123");
52 shouldBe("cursor.extra", "456");
55 debug("Ensure request is not released if cursor is still around.");
56 cursorRequestObservation = internals.observeGC(cursorRequest);
57 evalAndLog("cursorRequest = null");
58 evalAndLog("gc()");
59 shouldBeFalse("cursorRequestObservation.wasCollected");
61 evalAndLog("cursor.continue()");
63 cursorObservation = internals.observeGC(cursor);
64 evalAndLog("cursor = null");
65 evalAndLog("gc()");
66 shouldBeFalse("cursorObservation.wasCollected");
68 evalAndLog("finalRequest = store.get(0)");
69 finalRequest.onsuccess = function finalRequestSuccess(evt) {
70 preamble(evt);
71 shouldBeEqualToString("cursor.key", "key2");
73 cursorObservation = internals.observeGC(cursor);
74 evalAndLog("cursor = null");
75 evalAndLog("gc()");
76 shouldBeTrue("cursorRequestObservation.wasCollected");
77 shouldBeTrue("cursorObservation.wasCollected");
81 tx.oncomplete = finishJSTest;
85 </script>