summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/IndexedDB/idbobjectstore_createIndex7-event_order.htm
blob: f564f6611d6b196d99de4d2a406f16e57374a8d6 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<meta charset="utf-8">
<title>IDBObjectStore.createIndex() - Event ordering for ConstraintError on request</title>
<link rel="author" href="mailto:odinho@opera.com" title="Odin Hørthe Omdal">
<meta rel=help href=http://odinho.html5.org/IndexedDB/spec/Overview.html#dfn-steps-for-aborting-a-transaction>
<meta rel=assert title="Unless error was set to null, create a DOMError object and set its name to error. Set transaction's error property to this newly created DOMError.">
<meta rel=assert title="If the transaction's request list contain any requests whose done flag is still false, abort the steps for asynchronously executing a request for each such request and queue a task to perform the following steps:">
<meta rel=assert title="set the request's error attribute to a DOMError with a type of AbortError.">
<meta rel=assert title="Dispatch an event at request. The event must use the Event interface and have its type set to 'error'. The event bubbles and is cancelable. The propagation path for the event is transaction's connection, then transaction and finally the request. There is no default action for the event.">
<meta rel=assert title="Queue up an operation to dispatch an event at transaction. The event must use the Event interface and have its type set to 'abort'. The event does bubble but is not cancelable. The propagation path for the event is transaction's connection and then transaction.">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
    // Transaction may fire window.onerror in some implementations.
    setup({allow_uncaught_exception:true});

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

    var open_rq = createdb(t);
    open_rq.onupgradeneeded = function(e) {
        db = e.target.result;
        var txn = e.target.transaction;
        db.onerror = log("db.error");
        db.onabort = log("db.abort");
        txn.onabort = log("transaction.abort")
        txn.onerror = log("transaction.error")
        txn.oncomplete = log("transaction.complete")

        var objStore = db.createObjectStore("store");

        var rq_add1 = objStore.add({ animal: "Unicorn" }, 1);
        rq_add1.onsuccess = log("rq_add1.success");
        rq_add1.onerror   = log("rq_add1.error");

        objStore.createIndex("index", "animal", { unique: true })

        var rq_add2 = objStore.add({ animal: "Unicorn" }, 2);
        rq_add2.onsuccess = log("rq_add2.success");
        rq_add2.onerror   = log("rq_add2.error");

        var rq_add3 = objStore.add({ animal: "Horse" }, 3);
        rq_add3.onsuccess = log("rq_add3.success");
        rq_add3.onerror   = log("rq_add3.error");
    }

    open_rq.onerror = function(e) {
        log("open_rq.error")(e);
        assert_array_equals(events, [ "rq_add1.success",

                                      "rq_add2.error: ConstraintError",
                                      "transaction.error: ConstraintError",
                                      "db.error: ConstraintError",

                                      "rq_add3.error: AbortError",
                                      "transaction.error: AbortError",
                                      "db.error: AbortError",

                                      "transaction.abort: ConstraintError",
                                      "db.abort: ConstraintError",

                                      "open_rq.error: AbortError" ],
                            "events");
        t.done();
    }

    function log(msg) {
        return function(e) {
            if(e && e.target && e.target.error)
                events.push(msg + ": " + e.target.error.name);
            else
                events.push(msg);
        };
    }
</script>

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