summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/storage/indexeddb/cursor-request-cycle.html
blob: c90d249f8015b14193712043f727e944fa7cc33b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="resources/shared.js"></script>
<script>

description("Verify that that cursors weakly hold request, and work if request is GC'd");

indexedDBTest(prepareDatabase, onOpen);

function prepareDatabase(evt)
{
    preamble(evt);
    evalAndLog("db = event.target.result");
    evalAndLog("store = db.createObjectStore('store')");
    store.put("value1", "key1");
    store.put("value2", "key2");
}

function onOpen(evt)
{
    preamble(evt);
    evalAndLog("db = event.target.result");
    evalAndLog("tx = db.transaction('store')");
    evalAndLog("store = tx.objectStore('store')");

    evalAndLog("cursorRequest = store.openCursor()");
    cursorRequest.onsuccess = function openCursorRequest(evt) {
        preamble(evt);
        evalAndLog("cursor = cursorRequest.result");
        shouldBeNonNull("cursor");
        shouldBeEqualToString("cursor.key", "key1");
        shouldBeEqualToString("cursor.value", "value1");
    };

    evalAndLog("otherRequest = store.get(0)");

    otherRequest.onsuccess = function otherRequestSuccess(evt) {
        preamble(evt);

        cursorRequestObservation = internals.observeGC(cursorRequest);
        cursorRequest = null;

        gc();
        shouldBeTrue("cursorRequestObservation.wasCollected");

        // The following call should generate a scratch request, invisible to script:
        evalAndLog("cursor.continue()");

        evalAndLog("finalRequest = store.get(0)");
        finalRequest.onsuccess = function finalRequestSuccess(evt) {
            preamble(evt);
            shouldBeEqualToString("cursor.key", "key2");
            shouldBeEqualToString("cursor.value", "value2");
        };
    };

    tx.oncomplete = finishJSTest;
}


</script>
<script src="../../fast/js/resources/js-test-post.js"></script>