Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); |
michael@0 | 11 | request.onerror = errorHandler; |
michael@0 | 12 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 13 | request.onsuccess = unexpectedSuccessHandler; |
michael@0 | 14 | let event = yield undefined; |
michael@0 | 15 | |
michael@0 | 16 | let db = event.target.result; |
michael@0 | 17 | db.onerror = errorHandler; |
michael@0 | 18 | |
michael@0 | 19 | event.target.transaction.onerror = errorHandler; |
michael@0 | 20 | event.target.transaction.oncomplete = grabEventAndContinueHandler; |
michael@0 | 21 | |
michael@0 | 22 | let os = db.createObjectStore("foo", { autoIncrement: true }); |
michael@0 | 23 | let index = os.createIndex("bar", "foo.bar"); |
michael@0 | 24 | event = yield undefined; |
michael@0 | 25 | |
michael@0 | 26 | is(request.transaction, event.target, |
michael@0 | 27 | "request.transaction should still be set"); |
michael@0 | 28 | |
michael@0 | 29 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 30 | event = yield undefined; |
michael@0 | 31 | |
michael@0 | 32 | is(request.transaction, null, "request.transaction should be cleared"); |
michael@0 | 33 | |
michael@0 | 34 | let transaction = db.transaction("foo", "readwrite"); |
michael@0 | 35 | |
michael@0 | 36 | os = transaction.objectStore("foo"); |
michael@0 | 37 | // Place a request to keep the transaction alive long enough for our |
michael@0 | 38 | // executeSoon. |
michael@0 | 39 | let requestComplete = false; |
michael@0 | 40 | |
michael@0 | 41 | let wasAbleToGrabObjectStoreOutsideOfCallback = false; |
michael@0 | 42 | let wasAbleToGrabIndexOutsideOfCallback = false; |
michael@0 | 43 | executeSoon(function() { |
michael@0 | 44 | ok(!requestComplete, "Ordering is correct."); |
michael@0 | 45 | wasAbleToGrabObjectStoreOutsideOfCallback = !!transaction.objectStore("foo"); |
michael@0 | 46 | wasAbleToGrabIndexOutsideOfCallback = |
michael@0 | 47 | !!transaction.objectStore("foo").index("bar"); |
michael@0 | 48 | }); |
michael@0 | 49 | |
michael@0 | 50 | request = os.add({}); |
michael@0 | 51 | request.onerror = errorHandler; |
michael@0 | 52 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 53 | |
michael@0 | 54 | event = yield undefined; |
michael@0 | 55 | |
michael@0 | 56 | requestComplete = true; |
michael@0 | 57 | |
michael@0 | 58 | ok(wasAbleToGrabObjectStoreOutsideOfCallback, |
michael@0 | 59 | "Should be able to get objectStore"); |
michael@0 | 60 | ok(wasAbleToGrabIndexOutsideOfCallback, |
michael@0 | 61 | "Should be able to get index"); |
michael@0 | 62 | |
michael@0 | 63 | transaction.oncomplete = grabEventAndContinueHandler; |
michael@0 | 64 | yield undefined; |
michael@0 | 65 | |
michael@0 | 66 | try { |
michael@0 | 67 | transaction.objectStore("foo"); |
michael@0 | 68 | ok(false, "Should have thrown!"); |
michael@0 | 69 | } |
michael@0 | 70 | catch (e) { |
michael@0 | 71 | ok(e instanceof DOMException, "Got database exception."); |
michael@0 | 72 | is(e.name, "InvalidStateError", "Good error."); |
michael@0 | 73 | is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | continueToNextStep(); |
michael@0 | 77 | yield undefined; |
michael@0 | 78 | |
michael@0 | 79 | try { |
michael@0 | 80 | transaction.objectStore("foo"); |
michael@0 | 81 | ok(false, "Should have thrown!"); |
michael@0 | 82 | } |
michael@0 | 83 | catch (e) { |
michael@0 | 84 | ok(e instanceof DOMException, "Got database exception."); |
michael@0 | 85 | is(e.name, "InvalidStateError", "Good error."); |
michael@0 | 86 | is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | finishTest(); |
michael@0 | 90 | yield undefined; |
michael@0 | 91 | } |