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 | const indexName = "My Test Index"; |
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 = event.target.result; |
michael@0 | 19 | is(db.objectStoreNames.length, 0, "Correct objectStoreNames list"); |
michael@0 | 20 | |
michael@0 | 21 | let objectStore = db.createObjectStore("test store", { keyPath: "foo" }); |
michael@0 | 22 | is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); |
michael@0 | 23 | is(db.objectStoreNames.item(0), objectStore.name, "Correct name"); |
michael@0 | 24 | |
michael@0 | 25 | is(objectStore.indexNames.length, 0, "Correct indexNames list"); |
michael@0 | 26 | |
michael@0 | 27 | let index = objectStore.createIndex(indexName, "foo"); |
michael@0 | 28 | |
michael@0 | 29 | is(objectStore.indexNames.length, 1, "Correct indexNames list"); |
michael@0 | 30 | is(objectStore.indexNames.item(0), indexName, "Correct name"); |
michael@0 | 31 | is(objectStore.index(indexName), index, "Correct instance"); |
michael@0 | 32 | |
michael@0 | 33 | objectStore.deleteIndex(indexName); |
michael@0 | 34 | |
michael@0 | 35 | is(objectStore.indexNames.length, 0, "Correct indexNames list"); |
michael@0 | 36 | try { |
michael@0 | 37 | objectStore.index(indexName); |
michael@0 | 38 | ok(false, "should have thrown"); |
michael@0 | 39 | } |
michael@0 | 40 | catch(ex) { |
michael@0 | 41 | ok(ex instanceof DOMException, "Got a DOMException"); |
michael@0 | 42 | is(ex.name, "NotFoundError", "expect a NotFoundError"); |
michael@0 | 43 | is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR"); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | let index2 = objectStore.createIndex(indexName, "foo"); |
michael@0 | 47 | isnot(index, index2, "New instance should be created"); |
michael@0 | 48 | |
michael@0 | 49 | is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list"); |
michael@0 | 50 | is(objectStore.indexNames.item(0), indexName, "Correct recreacted name"); |
michael@0 | 51 | is(objectStore.index(indexName), index2, "Correct instance"); |
michael@0 | 52 | |
michael@0 | 53 | finishTest(); |
michael@0 | 54 | yield undefined; |
michael@0 | 55 | } |