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 | const entryCount = 1000; |
michael@0 | 12 | |
michael@0 | 13 | let request = indexedDB.open(name, 1); |
michael@0 | 14 | request.onerror = errorHandler; |
michael@0 | 15 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 16 | let event = yield undefined; |
michael@0 | 17 | |
michael@0 | 18 | let db = request.result; |
michael@0 | 19 | |
michael@0 | 20 | event.target.onsuccess = continueToNextStep; |
michael@0 | 21 | |
michael@0 | 22 | let objectStore = db.createObjectStore("foo", { autoIncrement: true }); |
michael@0 | 23 | |
michael@0 | 24 | let firstKey; |
michael@0 | 25 | for (let i = 0; i < entryCount; i++) { |
michael@0 | 26 | request = objectStore.add({}); |
michael@0 | 27 | request.onerror = errorHandler; |
michael@0 | 28 | if (!i) { |
michael@0 | 29 | request.onsuccess = function(event) { |
michael@0 | 30 | firstKey = event.target.result; |
michael@0 | 31 | }; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | yield undefined; |
michael@0 | 35 | |
michael@0 | 36 | isnot(firstKey, undefined, "got first key"); |
michael@0 | 37 | |
michael@0 | 38 | let seenEntryCount = 0; |
michael@0 | 39 | |
michael@0 | 40 | request = db.transaction("foo").objectStore("foo").openCursor(); |
michael@0 | 41 | request.onerror = errorHandler; |
michael@0 | 42 | request.onsuccess = function(event) { |
michael@0 | 43 | let cursor = event.target.result; |
michael@0 | 44 | if (cursor) { |
michael@0 | 45 | seenEntryCount++; |
michael@0 | 46 | cursor.continue(); |
michael@0 | 47 | } |
michael@0 | 48 | else { |
michael@0 | 49 | continueToNextStep(); |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | yield undefined; |
michael@0 | 53 | |
michael@0 | 54 | is(seenEntryCount, entryCount, "Correct entry count"); |
michael@0 | 55 | |
michael@0 | 56 | try { |
michael@0 | 57 | db.transaction("foo").objectStore("foo").clear(); |
michael@0 | 58 | ok(false, "clear should throw on READ_ONLY transactions"); |
michael@0 | 59 | } |
michael@0 | 60 | catch (e) { |
michael@0 | 61 | ok(true, "clear should throw on READ_ONLY transactions"); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | request = db.transaction("foo", "readwrite").objectStore("foo").clear(); |
michael@0 | 65 | request.onerror = errorHandler; |
michael@0 | 66 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 67 | event = yield undefined; |
michael@0 | 68 | |
michael@0 | 69 | ok(event.target.result === undefined, "Correct event.target.result"); |
michael@0 | 70 | ok(request.result === undefined, "Correct request.result"); |
michael@0 | 71 | ok(request === event.target, "Correct event.target"); |
michael@0 | 72 | |
michael@0 | 73 | request = db.transaction("foo").objectStore("foo").openCursor(); |
michael@0 | 74 | request.onerror = errorHandler; |
michael@0 | 75 | request.onsuccess = function(event) { |
michael@0 | 76 | let cursor = request.result; |
michael@0 | 77 | if (cursor) { |
michael@0 | 78 | ok(false, "Shouldn't have any entries"); |
michael@0 | 79 | } |
michael@0 | 80 | continueToNextStep(); |
michael@0 | 81 | } |
michael@0 | 82 | yield undefined; |
michael@0 | 83 | |
michael@0 | 84 | request = db.transaction("foo", "readwrite").objectStore("foo").add({}); |
michael@0 | 85 | request.onerror = errorHandler; |
michael@0 | 86 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 87 | event = yield undefined; |
michael@0 | 88 | |
michael@0 | 89 | isnot(event.target.result, firstKey, "Got a different key"); |
michael@0 | 90 | |
michael@0 | 91 | finishTest(); |
michael@0 | 92 | yield undefined; |
michael@0 | 93 | } |