Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | <!-- |
michael@0 | 2 | Any copyright is dedicated to the Public Domain. |
michael@0 | 3 | http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 4 | --> |
michael@0 | 5 | <html> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Indexed Database Property Test</title> |
michael@0 | 8 | |
michael@0 | 9 | <script type="text/javascript;version=1.7"> |
michael@0 | 10 | |
michael@0 | 11 | let testGenerator = testSteps(); |
michael@0 | 12 | |
michael@0 | 13 | function ok(val, message) { |
michael@0 | 14 | val = val ? "true" : "false"; |
michael@0 | 15 | window.parent.postMessage("SimpleTest.ok(" + val + ", '" + message + |
michael@0 | 16 | "');", "*"); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function grabEventAndContinueHandler(event) { |
michael@0 | 20 | testGenerator.send(event); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function errorHandler(event) { |
michael@0 | 24 | ok(false, "indexedDB error, code " + event.target.error.name); |
michael@0 | 25 | finishTest(); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function finishTest() { |
michael@0 | 29 | // Let window.onerror have a chance to fire |
michael@0 | 30 | setTimeout(function() { |
michael@0 | 31 | setTimeout(function() { |
michael@0 | 32 | testGenerator.close(); |
michael@0 | 33 | ok(windowErrorCount == 1, "Good window.onerror count"); |
michael@0 | 34 | window.parent.postMessage("SimpleTest.finish();", "*"); |
michael@0 | 35 | }, 0); |
michael@0 | 36 | }, 0); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | const eventChain = [ |
michael@0 | 40 | "IDBRequest", |
michael@0 | 41 | "IDBTransaction", |
michael@0 | 42 | "IDBDatabase" |
michael@0 | 43 | ]; |
michael@0 | 44 | |
michael@0 | 45 | let captureCount = 0; |
michael@0 | 46 | let bubbleCount = 0; |
michael@0 | 47 | let atTargetCount = 0; |
michael@0 | 48 | let windowErrorCount = 0; |
michael@0 | 49 | |
michael@0 | 50 | window.onerror = function(event) { |
michael@0 | 51 | ok(!windowErrorCount++, "Correct number of window.onerror events"); |
michael@0 | 52 | setTimeout(function() { testGenerator.next(); }, 0); |
michael@0 | 53 | }; |
michael@0 | 54 | |
michael@0 | 55 | function errorEventCounter(event) { |
michael@0 | 56 | ok(event.type == "error", "Got an error event"); |
michael@0 | 57 | ok(event.target instanceof window[eventChain[0]], |
michael@0 | 58 | "Correct event.target"); |
michael@0 | 59 | |
michael@0 | 60 | let constructor; |
michael@0 | 61 | if (event.eventPhase == event.AT_TARGET) { |
michael@0 | 62 | atTargetCount++; |
michael@0 | 63 | constructor = eventChain[0]; |
michael@0 | 64 | } |
michael@0 | 65 | else if (event.eventPhase == event.CAPTURING_PHASE) { |
michael@0 | 66 | constructor = eventChain[eventChain.length - 1 - captureCount++]; |
michael@0 | 67 | } |
michael@0 | 68 | else if (event.eventPhase == event.BUBBLING_PHASE) { |
michael@0 | 69 | constructor = eventChain[++bubbleCount]; |
michael@0 | 70 | if (windowErrorCount && bubbleCount == eventChain.length - 1) { |
michael@0 | 71 | event.preventDefault(); |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | ok(event.currentTarget instanceof window[constructor], |
michael@0 | 75 | "Correct event.currentTarget"); |
michael@0 | 76 | |
michael@0 | 77 | if (bubbleCount == eventChain.length - 1) { |
michael@0 | 78 | ok(bubbleCount == captureCount, |
michael@0 | 79 | "Got same number of calls for both phases"); |
michael@0 | 80 | ok(atTargetCount == 1, "Got one atTarget event"); |
michael@0 | 81 | |
michael@0 | 82 | captureCount = bubbleCount = atTargetCount = 0; |
michael@0 | 83 | if (windowErrorCount) { |
michael@0 | 84 | finishTest(); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | function testSteps() { |
michael@0 | 90 | let request = indexedDB.open(window.location.pathname, 1); |
michael@0 | 91 | request.onerror = errorHandler; |
michael@0 | 92 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 93 | let event = yield undefined; |
michael@0 | 94 | |
michael@0 | 95 | let db = event.target.result; |
michael@0 | 96 | db.onerror = errorEventCounter; |
michael@0 | 97 | db.addEventListener("error", errorEventCounter, true); |
michael@0 | 98 | |
michael@0 | 99 | event.target.onsuccess = grabEventAndContinueHandler; |
michael@0 | 100 | |
michael@0 | 101 | db.createObjectStore("foo", { autoIncrement: true }); |
michael@0 | 102 | yield undefined; |
michael@0 | 103 | |
michael@0 | 104 | let transaction = db.transaction("foo", "readwrite"); |
michael@0 | 105 | transaction.addEventListener("error", errorEventCounter, false); |
michael@0 | 106 | transaction.addEventListener("error", errorEventCounter, true); |
michael@0 | 107 | |
michael@0 | 108 | let objectStore = transaction.objectStore("foo"); |
michael@0 | 109 | |
michael@0 | 110 | request = objectStore.add({}, 1); |
michael@0 | 111 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 112 | request.onerror = errorHandler; |
michael@0 | 113 | event = yield undefined; |
michael@0 | 114 | |
michael@0 | 115 | request = objectStore.add({}, 1); |
michael@0 | 116 | request.onsuccess = function(event) { |
michael@0 | 117 | ok(false, "Did not expect second add to succeed."); |
michael@0 | 118 | }; |
michael@0 | 119 | request.onerror = errorEventCounter; |
michael@0 | 120 | yield undefined; |
michael@0 | 121 | |
michael@0 | 122 | transaction = db.transaction("foo", "readwrite"); |
michael@0 | 123 | transaction.addEventListener("error", errorEventCounter, false); |
michael@0 | 124 | transaction.addEventListener("error", errorEventCounter, true); |
michael@0 | 125 | |
michael@0 | 126 | objectStore = transaction.objectStore("foo"); |
michael@0 | 127 | |
michael@0 | 128 | request = objectStore.add({}, 1); |
michael@0 | 129 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 130 | request.onerror = errorHandler; |
michael@0 | 131 | event = yield undefined; |
michael@0 | 132 | |
michael@0 | 133 | request = objectStore.add({}, 1); |
michael@0 | 134 | request.onsuccess = function(event) { |
michael@0 | 135 | ok(false, "Did not expect second add to succeed."); |
michael@0 | 136 | }; |
michael@0 | 137 | request.onerror = errorEventCounter; |
michael@0 | 138 | yield undefined; |
michael@0 | 139 | } |
michael@0 | 140 | </script> |
michael@0 | 141 | |
michael@0 | 142 | </head> |
michael@0 | 143 | |
michael@0 | 144 | <body onload="testGenerator.next();"></body> |
michael@0 | 145 | |
michael@0 | 146 | </html> |