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
|
/**
* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
var testGenerator = testSteps();
function testSteps()
{
const name = this.window ? window.location.pathname : "Splendid Test";
let requests = [];
function doOpen(version, errorCallback, upgradeNeededCallback, successCallback) {
let request = indexedDB.open(name, version);
request.onerror = errorCallback;
request.onupgradeneeded = upgradeNeededCallback;
request.onsuccess = successCallback;
requests.push(request);
}
doOpen(1, errorHandler, grabEventAndContinueHandler, grabEventAndContinueHandler);
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
let event = yield undefined;
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
is(event.target, requests[0], "fired at the right request");
let db = event.target.result;
db.createObjectStore("foo");
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
doOpen(2, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
doOpen(3, errorHandler, unexpectedSuccessHandler, unexpectedSuccessHandler);
event.target.transaction.oncomplete = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "complete", "expect a complete event");
is(event.target, requests[0].transaction, "expect it to be fired at the transaction");
event = yield undefined;
is(event.type, "success", "expect a success event");
is(event.target, requests[0], "fired at the right request");
event.target.result.close();
requests[1].onupgradeneeded = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
is(event.target, requests[1], "fired at the right request");
requests[1].onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "success", "expect a success event");
is(event.target, requests[1], "fired at the right request");
event.target.result.close();
requests[2].onupgradeneeded = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "upgradeneeded", "expect an upgradeneeded event");
is(event.target, requests[2], "fired at the right request");
requests[2].onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "success", "expect a success event");
is(event.target, requests[2], "fired at the right request");
event.target.result.close();
requests[3].onerror = null;
requests[3].addEventListener("error", new ExpectError("VersionError", true));
event = yield undefined;
requests[4].onsuccess = grabEventAndContinueHandler;
event = yield undefined;
is(event.type, "success", "expect a success event");
is(event.target, requests[4], "fired at the right request");
event.target.result.close();
finishTest();
yield undefined;
}
|