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 | |
michael@0 | 6 | var testGenerator = testSteps(); |
michael@0 | 7 | |
michael@0 | 8 | function testSteps() |
michael@0 | 9 | { |
michael@0 | 10 | const name = this.window ? window.location.pathname : "Splendid Test"; |
michael@0 | 11 | |
michael@0 | 12 | // Open a datbase for the first time. |
michael@0 | 13 | let request = indexedDB.open(name, 1); |
michael@0 | 14 | |
michael@0 | 15 | // Sanity checks |
michael@0 | 16 | ok(request instanceof IDBRequest, "Request should be an IDBRequest"); |
michael@0 | 17 | ok(request instanceof IDBOpenDBRequest, "Request should be an IDBOpenDBRequest"); |
michael@0 | 18 | //ok(request instanceof EventTarget, "Request should be an EventTarget"); |
michael@0 | 19 | is(request.source, null, "Request should have no source"); |
michael@0 | 20 | try { |
michael@0 | 21 | request.result; |
michael@0 | 22 | ok(false, "Getter should have thrown!"); |
michael@0 | 23 | } catch (e if e.result == 0x80660006 /* NS_ERROR_DOM_INDEXEDDB_NOTALLOWED_ERR */) { |
michael@0 | 24 | ok(true, "Getter threw the right exception"); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | request.onerror = errorHandler; |
michael@0 | 28 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 29 | let event = yield undefined; |
michael@0 | 30 | |
michael@0 | 31 | let versionChangeEventCount = 0; |
michael@0 | 32 | let db1, db2, db3; |
michael@0 | 33 | |
michael@0 | 34 | db1 = event.target.result; |
michael@0 | 35 | db1.addEventListener("versionchange", function(event) { |
michael@0 | 36 | ok(true, "Got version change event"); |
michael@0 | 37 | ok(event instanceof IDBVersionChangeEvent, "Event is of the right type"); |
michael@0 | 38 | is(event.target.source, null, "Correct source"); |
michael@0 | 39 | is(event.target, db1, "Correct target"); |
michael@0 | 40 | is(event.target.version, 1, "Correct db version"); |
michael@0 | 41 | is(event.oldVersion, 1, "Correct event oldVersion"); |
michael@0 | 42 | is(event.newVersion, 2, "Correct event newVersion"); |
michael@0 | 43 | is(versionChangeEventCount++, 0, "Correct count"); |
michael@0 | 44 | db1.close(); |
michael@0 | 45 | }, false); |
michael@0 | 46 | |
michael@0 | 47 | // Open the database again and trigger an upgrade that should succeed |
michael@0 | 48 | request = indexedDB.open(name, 2); |
michael@0 | 49 | request.onerror = errorHandler; |
michael@0 | 50 | request.onsuccess = errorHandler; |
michael@0 | 51 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 52 | if (SpecialPowers.isMainProcess()) { |
michael@0 | 53 | request.onblocked = errorHandler; |
michael@0 | 54 | } |
michael@0 | 55 | else { |
michael@0 | 56 | todo(false, "Need to fix blocked events in child processes!"); |
michael@0 | 57 | } |
michael@0 | 58 | event = yield undefined; |
michael@0 | 59 | |
michael@0 | 60 | // Test the upgradeneeded event. |
michael@0 | 61 | ok(event instanceof IDBVersionChangeEvent, "Event is of the right type"); |
michael@0 | 62 | ok(event.target.result instanceof IDBDatabase, "Good result"); |
michael@0 | 63 | db2 = event.target.result; |
michael@0 | 64 | is(event.target.transaction.mode, "versionchange", |
michael@0 | 65 | "Correct mode"); |
michael@0 | 66 | is(db2.version, 2, "Correct db version"); |
michael@0 | 67 | is(event.oldVersion, 1, "Correct event oldVersion"); |
michael@0 | 68 | is(event.newVersion, 2, "Correct event newVersion"); |
michael@0 | 69 | |
michael@0 | 70 | request.onupgradeneeded = errorHandler; |
michael@0 | 71 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 72 | event = yield undefined; |
michael@0 | 73 | |
michael@0 | 74 | db2.addEventListener("versionchange", function(event) { |
michael@0 | 75 | ok(true, "Got version change event"); |
michael@0 | 76 | ok(event instanceof IDBVersionChangeEvent, "Event is of the right type"); |
michael@0 | 77 | is(event.target.source, null, "Correct source"); |
michael@0 | 78 | is(event.target, db2, "Correct target"); |
michael@0 | 79 | is(event.target.version, 2, "Correct db version"); |
michael@0 | 80 | is(event.oldVersion, 2, "Correct event oldVersion"); |
michael@0 | 81 | is(event.newVersion, 3, "Correct event newVersion"); |
michael@0 | 82 | is(versionChangeEventCount++, 1, "Correct count"); |
michael@0 | 83 | }, false); |
michael@0 | 84 | |
michael@0 | 85 | // Test opening the existing version again |
michael@0 | 86 | request = indexedDB.open(name, 2); |
michael@0 | 87 | request.onerror = errorHandler; |
michael@0 | 88 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 89 | if (SpecialPowers.isMainProcess()) { |
michael@0 | 90 | request.onblocked = errorHandler; |
michael@0 | 91 | } |
michael@0 | 92 | else { |
michael@0 | 93 | todo(false, "Need to fix blocked events in child processes!"); |
michael@0 | 94 | } |
michael@0 | 95 | event = yield undefined; |
michael@0 | 96 | |
michael@0 | 97 | db3 = event.target.result; |
michael@0 | 98 | |
michael@0 | 99 | // Test an upgrade that should fail |
michael@0 | 100 | request = indexedDB.open(name, 3); |
michael@0 | 101 | request.onerror = errorHandler; |
michael@0 | 102 | request.onsuccess = errorHandler; |
michael@0 | 103 | request.onupgradeneeded = errorHandler; |
michael@0 | 104 | request.onblocked = grabEventAndContinueHandler; |
michael@0 | 105 | |
michael@0 | 106 | event = yield undefined; |
michael@0 | 107 | ok(true, "Got version change blocked event"); |
michael@0 | 108 | ok(event instanceof IDBVersionChangeEvent, "Event is of the right type"); |
michael@0 | 109 | is(event.target.source, null, "Correct source"); |
michael@0 | 110 | is(event.target.transaction, null, "Correct transaction"); |
michael@0 | 111 | is(event.target, request, "Correct target"); |
michael@0 | 112 | is(db3.version, 2, "Correct db version"); |
michael@0 | 113 | is(event.oldVersion, 2, "Correct event oldVersion"); |
michael@0 | 114 | is(event.newVersion, 3, "Correct event newVersion"); |
michael@0 | 115 | versionChangeEventCount++; |
michael@0 | 116 | db2.close(); |
michael@0 | 117 | db3.close(); |
michael@0 | 118 | |
michael@0 | 119 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 120 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 121 | |
michael@0 | 122 | event = yield undefined; |
michael@0 | 123 | event = yield undefined; |
michael@0 | 124 | |
michael@0 | 125 | db3 = event.target.result; |
michael@0 | 126 | db3.close(); |
michael@0 | 127 | |
michael@0 | 128 | // Test another upgrade that should succeed. |
michael@0 | 129 | request = indexedDB.open(name, 4); |
michael@0 | 130 | request.onerror = errorHandler; |
michael@0 | 131 | request.onsuccess = errorHandler; |
michael@0 | 132 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 133 | if (SpecialPowers.isMainProcess()) { |
michael@0 | 134 | request.onblocked = errorHandler; |
michael@0 | 135 | } |
michael@0 | 136 | else { |
michael@0 | 137 | todo(false, "Need to fix blocked events in child processes!"); |
michael@0 | 138 | } |
michael@0 | 139 | |
michael@0 | 140 | event = yield undefined; |
michael@0 | 141 | |
michael@0 | 142 | ok(event instanceof IDBVersionChangeEvent, "Event is of the right type"); |
michael@0 | 143 | ok(event.target.result instanceof IDBDatabase, "Good result"); |
michael@0 | 144 | is(event.target.transaction.mode, "versionchange", |
michael@0 | 145 | "Correct mode"); |
michael@0 | 146 | is(event.oldVersion, 3, "Correct event oldVersion"); |
michael@0 | 147 | is(event.newVersion, 4, "Correct event newVersion"); |
michael@0 | 148 | |
michael@0 | 149 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 150 | |
michael@0 | 151 | event = yield undefined; |
michael@0 | 152 | ok(event.target.result instanceof IDBDatabase, "Expect a database here"); |
michael@0 | 153 | is(event.target.result.version, 4, "Right version"); |
michael@0 | 154 | is(db3.version, 3, "After closing the version should not change!"); |
michael@0 | 155 | is(db2.version, 2, "After closing the version should not change!"); |
michael@0 | 156 | is(db1.version, 1, "After closing the version should not change!"); |
michael@0 | 157 | |
michael@0 | 158 | is(versionChangeEventCount, 3, "Saw all expected events"); |
michael@0 | 159 | |
michael@0 | 160 | event = new IDBVersionChangeEvent("versionchange"); |
michael@0 | 161 | ok(event, "Should be able to create an event with just passing in the type"); |
michael@0 | 162 | event = new IDBVersionChangeEvent("versionchange", {oldVersion: 1}); |
michael@0 | 163 | ok(event, "Should be able to create an event with just the old version"); |
michael@0 | 164 | is(event.oldVersion, 1, "Correct old version"); |
michael@0 | 165 | is(event.newVersion, null, "Correct new version"); |
michael@0 | 166 | event = new IDBVersionChangeEvent("versionchange", {newVersion: 1}); |
michael@0 | 167 | ok(event, "Should be able to create an event with just the new version"); |
michael@0 | 168 | is(event.oldVersion, 0, "Correct old version"); |
michael@0 | 169 | is(event.newVersion, 1, "Correct new version"); |
michael@0 | 170 | event = new IDBVersionChangeEvent("versionchange", {oldVersion: 1, newVersion: 2}); |
michael@0 | 171 | ok(event, "Should be able to create an event with both versions"); |
michael@0 | 172 | is(event.oldVersion, 1, "Correct old version"); |
michael@0 | 173 | is(event.newVersion, 2, "Correct new version"); |
michael@0 | 174 | |
michael@0 | 175 | finishTest(); |
michael@0 | 176 | yield undefined; |
michael@0 | 177 | } |
michael@0 | 178 |