2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
7 <title>Indexed Database Property Test
</title>
9 <script type=
"text/javascript">
11 let testGenerator
= testSteps();
13 function ok(val
, message
) {
14 val
= val
? "true" : "false";
15 window
.parent
.postMessage("SimpleTest.ok(" + val
+ ", '" + message
+
19 function grabEventAndContinueHandler(event
) {
20 testGenerator
.next(event
);
23 function errorHandler(event
) {
24 ok(false, "indexedDB error, code " + event
.target
.error
.name
);
28 function finishTest() {
29 testGenerator
.return();
30 window
.parent
.postMessage("SimpleTest.finish();", "*");
41 let atTargetCount
= 0;
43 function errorEventCounter(event
) {
44 ok(event
.type
== "error", "Got an error event");
45 ok(event
.target
instanceof window
[eventChain
[0]],
46 "Correct event.target");
49 if (event
.eventPhase
== event
.AT_TARGET
) {
51 constructor = eventChain
[0];
53 else if (event
.eventPhase
== event
.CAPTURING_PHASE
) {
54 constructor = eventChain
[eventChain
.length
- 1 - captureCount
++];
56 else if (event
.eventPhase
== event
.BUBBLING_PHASE
) {
57 constructor = eventChain
[++bubbleCount
];
58 if (bubbleCount
== eventChain
.length
- 1) {
59 event
.preventDefault();
62 ok(event
.currentTarget
instanceof window
[constructor],
63 "Correct event.currentTarget");
65 if (bubbleCount
== eventChain
.length
- 1) {
66 ok(bubbleCount
== captureCount
,
67 "Got same number of calls for both phases");
68 ok(atTargetCount
== 1, "Got one atTarget event");
70 captureCount
= bubbleCount
= atTargetCount
= 0;
75 function* testSteps() {
76 window
.parent
.SpecialPowers
.addPermission("indexedDB", true, document
);
78 let request
= indexedDB
.open(window
.location
.pathname
, 1);
79 request
.onerror
= errorHandler
;
80 request
.onupgradeneeded
= grabEventAndContinueHandler
;
81 let event
= yield undefined;
83 let db
= event
.target
.result
;
84 db
.onerror
= errorEventCounter
;
85 db
.addEventListener("error", errorEventCounter
, true);
87 event
.target
.onsuccess
= grabEventAndContinueHandler
;
89 db
.createObjectStore("foo", { autoIncrement
: true });
92 let transaction
= db
.transaction("foo", "readwrite");
93 transaction
.addEventListener("error", errorEventCounter
);
94 transaction
.addEventListener("error", errorEventCounter
, true);
96 let objectStore
= transaction
.objectStore("foo");
98 request
= objectStore
.add({}, 1);
99 request
.onsuccess
= grabEventAndContinueHandler
;
100 request
.onerror
= errorHandler
;
101 event
= yield undefined;
103 request
= objectStore
.add({}, 1);
104 request
.onsuccess = function() {
105 ok(false, "Did not expect second add to succeed.");
107 request
.onerror
= errorEventCounter
;
110 transaction
= db
.transaction("foo", "readwrite");
111 transaction
.addEventListener("error", errorEventCounter
);
112 transaction
.addEventListener("error", errorEventCounter
, true);
114 objectStore
= transaction
.objectStore("foo");
116 request
= objectStore
.add({}, 1);
117 request
.onsuccess
= grabEventAndContinueHandler
;
118 request
.onerror
= errorHandler
;
119 event
= yield undefined;
121 request
= objectStore
.add({}, 1);
122 request
.onsuccess = function() {
123 ok(false, "Did not expect second add to succeed.");
125 request
.onerror
= errorEventCounter
;
132 <body onload=
"testGenerator.next();"></body>