summaryrefslogtreecommitdiffstats
path: root/LayoutTests/storage/indexeddb/set_version_queue.html
blob: b00a69a2ea8afb13484e0c78efd8fbc59f4452d4 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="../../fast/js/resources/js-test-post-function.js"></script>
<script src="resources/shared.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>

description("4 open connections try to setVersion at the same time.  3 connections eventually close, allowing 1 setVersion call to proceed.");
if (window.layoutTestController)
    layoutTestController.waitUntilDone();

connections = []
function test()
{
    if ('webkitIndexedDB' in window)
        IndexedDB = webkitIndexedDB;
    else if ('mozIndexedDB' in window)
        IndexedDB = mozIndexedDB;
    shouldBeFalse("IndexedDB == null");
    openDBConnection();
}

function openDBConnection()
{
    result = evalAndLog("IndexedDB.open('set-version-queue')");
    result.onsuccess = openSuccess;
    result.onerror = unexpectedErrorCallback;
}

function openSuccess()
{
    connection = event.target.result;
    connection.onversionchange = generateVersionChangeHandler();
    connections.push(connection);
    if (connections.length < 4)
        openDBConnection();
    else {
        request = evalAndLog("connections[0].setVersion('version 0')");
        request.onerror = function(event){ connectionError(event, 0) };
        request.onsuccess = unexpectedSuccessCallback;
        request.onblocked = blocked0;
        request1 = evalAndLog("connections[1].setVersion('version 1')");
        request1.onerror = unexpectedErrorCallback;
        request1.onsuccess = inSetVersion1;
        request1.onblocked = blocked1;
        request2 = evalAndLog("connections[2].setVersion('version 2')");
        request2.onerror = function(event){ connectionError(event, 2) };
        request2.onsuccess = unexpectedSuccessCallback;
        request2.onblocked = blocked2;
        request3 = evalAndLog("connections[3].setVersion('version 3')");
        request3.onerror = function(event){ connectionError(event, 3) };
        request3.onsuccess = unexpectedSuccessCallback;
        request3.onblocked = blocked3;
        debug("");
    }
}

function generateVersionChangeHandler()
{
    var connectionNum = connections.length;
    return function(event)
    {
        shouldBeTrue("event.version.length > 0");
        debug("connection[" + connectionNum + "] received versionChangeEvent: " + event.version);
    }
}

blocked0fired = false;
blocked2fired = false;
function blocked0(event)
{
    debug("");
    testPassed("connection[0] got blocked event");
    shouldBeEqualToString("event.version", "version 0");
    debug("Close the connection that received the block event:");
    evalAndLog("connections[0].close()");
    debug("Close another connection as well, to test 4.7.4-note:");
    evalAndLog("connections[3].close()");
    evalAndLog("blocked0fired = true");
    debug("");
}

function blocked1(event)
{
    debug("")
    testPassed("connection[1] got blocked event");
    debug("Ensure that this blocked event is in order:");
    shouldBeTrue("blocked0fired");
    shouldBeFalse("blocked2fired");
    debug("")
}

function blocked2(event)
{
    debug("")
    testPassed("connection[2] got blocked event");
    shouldBeEqualToString("event.version", "version 2");
    evalAndLog("connections[2].close()");
    evalAndLog("blocked2fired = true");
    debug("")
}

function blocked3(event)
{
    debug("")
    testPassed("connection[3] got blocked event");
    debug("Note: This means that a connection can receive a blocked event after its close() method has been called.  Spec is silent on the issue and this is easiest to implement.");
    shouldBeEqualToString("event.version", "version 3");
}

function connectionError(event, connectionId)
{
    debug("")
    testPassed("connection[" + connectionId + "] got error event");
    shouldBe("event.target.errorCode", "13")
    if ('webkitIndexedDB' in window) {
        shouldBe("event.target.webkitErrorMessage.length > 0", "true");
        debug(event.target.webkitErrorMessage);
    }
}

function inSetVersion1(event)
{
    debug("")
    testPassed("connection[1] got into SetVersion");
    done();
}

var successfullyParsed = true;

test();

</script>
</body>
</html>