Backed out changeset 5c8bf24bb247 (bug 1923942) for causing generate failures. CLOSED...
[gecko.git] / dom / indexedDB / test / event_propagation_iframe.html
blob2d852b3b98299ec3cee2bd7291583c7542f42ed8
1 <!--
2 Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/
4 -->
5 <html>
6 <head>
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 +
16 "');", "*");
19 function grabEventAndContinueHandler(event) {
20 testGenerator.next(event);
23 function errorHandler(event) {
24 ok(false, "indexedDB error, code " + event.target.error.name);
25 finishTest();
28 function finishTest() {
29 testGenerator.return();
30 window.parent.postMessage("SimpleTest.finish();", "*");
33 const eventChain = [
34 "IDBRequest",
35 "IDBTransaction",
36 "IDBDatabase",
39 let captureCount = 0;
40 let bubbleCount = 0;
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");
48 let constructor;
49 if (event.eventPhase == event.AT_TARGET) {
50 atTargetCount++;
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;
71 finishTest();
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 });
90 yield undefined;
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;
108 yield undefined;
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;
126 yield undefined;
128 </script>
130 </head>
132 <body onload="testGenerator.next();"></body>
134 </html>