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 | const name = this.window ? window.location.pathname : "Splendid Test"; |
michael@0 | 11 | |
michael@0 | 12 | var data = [ |
michael@0 | 13 | { name: "inline key; key generator", |
michael@0 | 14 | autoIncrement: true, |
michael@0 | 15 | storedObject: {name: "Lincoln"}, |
michael@0 | 16 | keyName: "id", |
michael@0 | 17 | keyValue: undefined, |
michael@0 | 18 | }, |
michael@0 | 19 | { name: "inline key; no key generator", |
michael@0 | 20 | autoIncrement: false, |
michael@0 | 21 | storedObject: {id: 1, name: "Lincoln"}, |
michael@0 | 22 | keyName: "id", |
michael@0 | 23 | keyValue: undefined, |
michael@0 | 24 | }, |
michael@0 | 25 | { name: "out of line key; key generator", |
michael@0 | 26 | autoIncrement: true, |
michael@0 | 27 | storedObject: {name: "Lincoln"}, |
michael@0 | 28 | keyName: undefined, |
michael@0 | 29 | keyValue: undefined, |
michael@0 | 30 | }, |
michael@0 | 31 | { name: "out of line key; no key generator", |
michael@0 | 32 | autoIncrement: false, |
michael@0 | 33 | storedObject: {name: "Lincoln"}, |
michael@0 | 34 | keyName: null, |
michael@0 | 35 | keyValue: 1, |
michael@0 | 36 | } |
michael@0 | 37 | ]; |
michael@0 | 38 | |
michael@0 | 39 | for (let i = 0; i < data.length; i++) { |
michael@0 | 40 | let test = data[i]; |
michael@0 | 41 | |
michael@0 | 42 | let request = indexedDB.open(name, i+1); |
michael@0 | 43 | request.onerror = errorHandler; |
michael@0 | 44 | request.onupgradeneeded = grabEventAndContinueHandler; |
michael@0 | 45 | let event = yield undefined; |
michael@0 | 46 | |
michael@0 | 47 | let db = event.target.result; |
michael@0 | 48 | |
michael@0 | 49 | let objectStore = db.createObjectStore(test.name, |
michael@0 | 50 | { keyPath: test.keyName, |
michael@0 | 51 | autoIncrement: test.autoIncrement }); |
michael@0 | 52 | |
michael@0 | 53 | request = objectStore.add(test.storedObject, test.keyValue); |
michael@0 | 54 | request.onerror = errorHandler; |
michael@0 | 55 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 56 | event = yield undefined; |
michael@0 | 57 | |
michael@0 | 58 | let id = event.target.result; |
michael@0 | 59 | request = objectStore.get(id); |
michael@0 | 60 | request.onerror = errorHandler; |
michael@0 | 61 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 62 | event = yield undefined; |
michael@0 | 63 | |
michael@0 | 64 | // Sanity check! |
michael@0 | 65 | is(test.storedObject.name, event.target.result.name, |
michael@0 | 66 | "The correct object was stored."); |
michael@0 | 67 | |
michael@0 | 68 | request = objectStore.delete(id); |
michael@0 | 69 | request.onerror = errorHandler; |
michael@0 | 70 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 71 | event = yield undefined; |
michael@0 | 72 | |
michael@0 | 73 | // Make sure it was removed. |
michael@0 | 74 | request = objectStore.get(id); |
michael@0 | 75 | request.onerror = errorHandler; |
michael@0 | 76 | request.onsuccess = grabEventAndContinueHandler; |
michael@0 | 77 | event = yield undefined; |
michael@0 | 78 | |
michael@0 | 79 | ok(event.target.result === undefined, "Object was deleted"); |
michael@0 | 80 | db.close(); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | finishTest(); |
michael@0 | 84 | yield undefined; |
michael@0 | 85 | } |
michael@0 | 86 |