summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbversionchangeevent.htm
blob: 866a8b2ebffb19765304ef0164c70a9ea13949b3 (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
63
64
65
66
<!DOCTYPE html>
<title>IDBVersionChangeEvent fired in upgradeneeded, versionchange and deleteDatabase</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<link rel=help href="http://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#versionchange--transaction-steps">
<link rel=assert title="Fire a versionchange event at each object in openDatabases that is open. The event must not be fired on objects which has the closePending flag set. The event must use the IDBVersionChangeEvent interface and have the oldVersion property set to db's version and have the newVersion property set to version.">
<link rel=assert title="Fire a upgradeneeded event targeted at request. The event must use the IDBVersionChangeEvent interface and have the oldVersion property set to old version and have the newVersion property set to version.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<div id="log"></div>

<script>

    var db,
        t = async_test(document.title, {timeout: 10000});

    t.step(function() {
        var openrq = indexedDB.open('db', 3);

        openrq.onupgradeneeded = t.step_func(function(e) {
            assert_equals(e.oldVersion, 0, "old version (upgradeneeded)");
            assert_equals(e.newVersion, 3, "new version (upgradeneeded)");
            assert_true(e instanceof IDBVersionChangeEvent, "upgradeneeded instanceof IDBVersionChangeEvent");
        });

        openrq.onsuccess = t.step_func(function(e) {
            db = e.target.result;

            db.onversionchange = t.step_func(function(e) {
                assert_equals(e.oldVersion, 3, "old version (versionchange)");
                assert_equals(e.newVersion, null, "new version (versionchange)");
                assert_true(e instanceof IDBVersionChangeEvent, "versionchange instanceof IDBVersionChangeEvent");
                db.close();
            });

            // Errors
            db.onerror = fail(t, "db.error");
            db.onabort = fail(t, "db.abort");

            setTimeout(t.step_func(deleteDB), 10);
        });

        // Errors
        openrq.onerror = fail(t, "open.error");
        openrq.onblocked = fail(t, "open.blocked");

    });

    function deleteDB (e) {
        var deleterq = indexedDB.deleteDatabase('db');

        deleterq.onsuccess = t.step_func(function(e) {
            assert_equals(e.oldVersion, 3, "old version (delete.success)");
            assert_equals(e.newVersion, null, "new version (delete.success)");
            assert_true(e instanceof IDBVersionChangeEvent, "delete.success instanceof IDBVersionChangeEvent");

            setTimeout(function() { t.done(); }, 10);
        });

        // Errors
        deleterq.onerror = fail(t, "delete.error");
        deleterq.onblocked = fail(t, "delete.blocked");
    }

</script>