Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 is(a, b, message) { |
michael@0 | 20 | ok(a == b, message); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function grabEventAndContinueHandler(event) { |
michael@0 | 24 | testGenerator.send(event); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function errorHandler(event) { |
michael@0 | 28 | ok(false, "indexedDB error, code " + event.target.errorCcode); |
michael@0 | 29 | finishTest(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function unexpectedSuccessHandler(event) { |
michael@0 | 33 | ok(false, "got success when it was not expected!"); |
michael@0 | 34 | finishTest(); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function finishTest() { |
michael@0 | 38 | // Let window.onerror have a chance to fire |
michael@0 | 39 | setTimeout(function() { |
michael@0 | 40 | setTimeout(function() { |
michael@0 | 41 | testGenerator.close(); |
michael@0 | 42 | window.parent.postMessage("SimpleTest.finish();", "*"); |
michael@0 | 43 | }, 0); |
michael@0 | 44 | }, 0); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | window.onerror = function(message, filename, lineno) { |
michael@0 | 48 | is(message, "ConstraintError", "Expect a constraint error"); |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | function testSteps() { |
michael@0 | 52 | let request = indexedDB.open(window.location.pathname, 1); |
michael@0 | 53 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 54 | request.onerror = grabEventAndContinueHandler; |
michael@0 | 55 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 56 | let event = yield undefined; |
michael@0 | 57 | |
michael@0 | 58 | let db = event.target.result; |
michael@0 | 59 | |
michael@0 | 60 | is(db.version, 1, "Correct version"); |
michael@0 | 61 | is(db.objectStoreNames.length, 0, "Correct objectStoreNames length"); |
michael@0 | 62 | |
michael@0 | 63 | let trans = event.target.transaction; |
michael@0 | 64 | |
michael@0 | 65 | trans.oncomplete = unexpectedSuccessHandler; |
michael@0 | 66 | trans.onabort = grabEventAndContinueHandler; |
michael@0 | 67 | |
michael@0 | 68 | let objectStore = db.createObjectStore("foo"); |
michael@0 | 69 | |
michael@0 | 70 | is(db.objectStoreNames.length, 1, "Correct objectStoreNames length"); |
michael@0 | 71 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 72 | |
michael@0 | 73 | let originalRequest = request; |
michael@0 | 74 | request = objectStore.add({}, 1); |
michael@0 | 75 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 76 | request.onerror = errorHandler; |
michael@0 | 77 | event = yield undefined; |
michael@0 | 78 | |
michael@0 | 79 | request = objectStore.add({}, 1); |
michael@0 | 80 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 81 | request.onerror = function(event) { |
michael@0 | 82 | // Don't do anything! We want this error. |
michael@0 | 83 | } |
michael@0 | 84 | event = yield undefined; |
michael@0 | 85 | |
michael@0 | 86 | is(event.type, "abort", "Got a transaction abort event"); |
michael@0 | 87 | is(db.version, 0, "Correct version"); |
michael@0 | 88 | is(db.objectStoreNames.length, 0, "Correct objectStoreNames length"); |
michael@0 | 89 | is(trans.error.name, "ConstraintError", "Right error"); |
michael@0 | 90 | ok(trans.error === request.error, "Object identity holds"); |
michael@0 | 91 | is(originalRequest.transaction, trans, "request.transaction should still be set"); |
michael@0 | 92 | |
michael@0 | 93 | event = yield undefined; |
michael@0 | 94 | is(event.type, "error", "Got request error event"); |
michael@0 | 95 | is(event.target, originalRequest, "error event has right target"); |
michael@0 | 96 | is(event.target.error.name, "ConstraintError", "Right error"); |
michael@0 | 97 | is(originalRequest.transaction, null, "request.transaction should now be null"); |
michael@0 | 98 | |
michael@0 | 99 | let request = indexedDB.open(window.location.pathname, 1); |
michael@0 | 100 | request.onerror = errorHandler; |
michael@0 | 101 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 102 | let event = yield undefined; |
michael@0 | 103 | |
michael@0 | 104 | let db = event.target.result; |
michael@0 | 105 | |
michael@0 | 106 | event.target.transaction.oncomplete = grabEventAndContinueHandler; |
michael@0 | 107 | event.target.transaction.onabort = unexpectedSuccessHandler; |
michael@0 | 108 | |
michael@0 | 109 | is(db.version, "1", "Correct version"); |
michael@0 | 110 | is(db.objectStoreNames.length, 0, "Correct objectStoreNames length"); |
michael@0 | 111 | |
michael@0 | 112 | let objectStore = db.createObjectStore("foo"); |
michael@0 | 113 | |
michael@0 | 114 | is(db.objectStoreNames.length, 1, "Correct objectStoreNames length"); |
michael@0 | 115 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 116 | |
michael@0 | 117 | objectStore.createIndex("baz", "key.path"); |
michael@0 | 118 | objectStore.createIndex("dontDeleteMe", ""); |
michael@0 | 119 | |
michael@0 | 120 | is(objectStore.indexNames.length, 2, "Correct indexNames length"); |
michael@0 | 121 | ok(objectStore.indexNames.contains("baz"), "Has correct index"); |
michael@0 | 122 | ok(objectStore.indexNames.contains("dontDeleteMe"), "Has correct index"); |
michael@0 | 123 | |
michael@0 | 124 | let objectStoreForDeletion = db.createObjectStore("bar"); |
michael@0 | 125 | |
michael@0 | 126 | is(db.objectStoreNames.length, 2, "Correct objectStoreNames length"); |
michael@0 | 127 | ok(db.objectStoreNames.contains("bar"), "Has correct objectStore"); |
michael@0 | 128 | |
michael@0 | 129 | objectStoreForDeletion.createIndex("foo", "key.path"); |
michael@0 | 130 | |
michael@0 | 131 | is(objectStoreForDeletion.indexNames.length, 1, "Correct indexNames length"); |
michael@0 | 132 | ok(objectStoreForDeletion.indexNames.contains("foo"), "Has correct index"); |
michael@0 | 133 | |
michael@0 | 134 | request = objectStore.add({}, 1); |
michael@0 | 135 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 136 | request.onerror = errorHandler; |
michael@0 | 137 | event = yield undefined; |
michael@0 | 138 | |
michael@0 | 139 | request = objectStore.add({}, 1); |
michael@0 | 140 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 141 | request.onerror = function(event) { |
michael@0 | 142 | // Expected, but prevent the abort. |
michael@0 | 143 | event.preventDefault(); |
michael@0 | 144 | } |
michael@0 | 145 | event = yield undefined; |
michael@0 | 146 | |
michael@0 | 147 | is(event.type, "complete", "Got a transaction complete event"); |
michael@0 | 148 | |
michael@0 | 149 | is(db.version, "1", "Correct version"); |
michael@0 | 150 | is(db.objectStoreNames.length, 2, "Correct objectStoreNames length"); |
michael@0 | 151 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 152 | ok(db.objectStoreNames.contains("bar"), "Has correct objectStore"); |
michael@0 | 153 | |
michael@0 | 154 | db.close(); |
michael@0 | 155 | |
michael@0 | 156 | let request = indexedDB.open(window.location.pathname, 2); |
michael@0 | 157 | request.onerror = errorHandler; |
michael@0 | 158 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 159 | let event = yield undefined; |
michael@0 | 160 | |
michael@0 | 161 | let db = event.target.result; |
michael@0 | 162 | |
michael@0 | 163 | let trans = event.target.transaction; |
michael@0 | 164 | trans.oncomplete = unexpectedSuccessHandler; |
michael@0 | 165 | |
michael@0 | 166 | is(db.version, "2", "Correct version"); |
michael@0 | 167 | is(db.objectStoreNames.length, 2, "Correct objectStoreNames length"); |
michael@0 | 168 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 169 | ok(db.objectStoreNames.contains("bar"), "Has correct objectStore"); |
michael@0 | 170 | |
michael@0 | 171 | let createdObjectStore = db.createObjectStore("newlyCreated"); |
michael@0 | 172 | let objectStore = trans.objectStore("foo"); |
michael@0 | 173 | let deletedObjectStore = trans.objectStore("bar"); |
michael@0 | 174 | deletedObjectStore.deleteIndex("foo"); |
michael@0 | 175 | db.deleteObjectStore("bar"); |
michael@0 | 176 | |
michael@0 | 177 | createdObjectStore.createIndex("newIndex", "key.path"); |
michael@0 | 178 | objectStore.createIndex("newIndex", "key.path"); |
michael@0 | 179 | objectStore.deleteIndex("baz"); |
michael@0 | 180 | |
michael@0 | 181 | is(db.objectStoreNames.length, 2, "Correct objectStoreNames length"); |
michael@0 | 182 | ok(db.objectStoreNames.contains("newlyCreated"), "Has correct objectStore"); |
michael@0 | 183 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 184 | |
michael@0 | 185 | is(createdObjectStore.indexNames.length, 1, "Correct indexNames length"); |
michael@0 | 186 | ok(createdObjectStore.indexNames.contains("newIndex"), "Has correct index"); |
michael@0 | 187 | |
michael@0 | 188 | is(objectStore.indexNames.length, 2, "Correct indexNames length"); |
michael@0 | 189 | ok(objectStore.indexNames.contains("dontDeleteMe"), "Has correct index"); |
michael@0 | 190 | ok(objectStore.indexNames.contains("newIndex"), "Has correct index"); |
michael@0 | 191 | |
michael@0 | 192 | objectStore.add({}, 1); |
michael@0 | 193 | trans.onabort = grabEventAndContinueHandler; |
michael@0 | 194 | |
michael@0 | 195 | event = yield undefined; |
michael@0 | 196 | |
michael@0 | 197 | // Test that the world has been restored. |
michael@0 | 198 | is(db.version, "1", "Correct version"); |
michael@0 | 199 | is(db.objectStoreNames.length, 2, "Correct objectStoreNames length"); |
michael@0 | 200 | ok(db.objectStoreNames.contains("foo"), "Has correct objectStore"); |
michael@0 | 201 | ok(db.objectStoreNames.contains("bar"), "Has correct objectStore"); |
michael@0 | 202 | |
michael@0 | 203 | is(objectStore.indexNames.length, 2, "Correct indexNames length"); |
michael@0 | 204 | ok(objectStore.indexNames.contains("dontDeleteMe"), "Has correct index"); |
michael@0 | 205 | ok(objectStore.indexNames.contains("baz"), "Has correct index"); |
michael@0 | 206 | |
michael@0 | 207 | is(createdObjectStore.indexNames.length, 0, "Correct indexNames length"); |
michael@0 | 208 | |
michael@0 | 209 | is(deletedObjectStore.indexNames.length, 1, "Correct indexNames length"); |
michael@0 | 210 | ok(deletedObjectStore.indexNames.contains("foo"), "Has correct index"); |
michael@0 | 211 | |
michael@0 | 212 | request.onerror = grabEventAndContinueHandler; |
michael@0 | 213 | |
michael@0 | 214 | event = yield undefined; |
michael@0 | 215 | |
michael@0 | 216 | finishTest(); |
michael@0 | 217 | yield undefined; |
michael@0 | 218 | } |
michael@0 | 219 | </script> |
michael@0 | 220 | |
michael@0 | 221 | </head> |
michael@0 | 222 | |
michael@0 | 223 | <body onload="testGenerator.next();"></body> |
michael@0 | 224 | |
michael@0 | 225 | </html> |