|
1 /** |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 var testGenerator = testSteps(); |
|
7 |
|
8 function testSteps() |
|
9 { |
|
10 const name = this.window ? window.location.pathname : "Splendid Test"; |
|
11 const indexName = "My Test Index"; |
|
12 |
|
13 let request = indexedDB.open(name, 1); |
|
14 request.onerror = errorHandler; |
|
15 request.onupgradeneeded = grabEventAndContinueHandler; |
|
16 let event = yield undefined; |
|
17 |
|
18 let db = event.target.result; |
|
19 is(db.objectStoreNames.length, 0, "Correct objectStoreNames list"); |
|
20 |
|
21 let objectStore = db.createObjectStore("test store", { keyPath: "foo" }); |
|
22 is(db.objectStoreNames.length, 1, "Correct objectStoreNames list"); |
|
23 is(db.objectStoreNames.item(0), objectStore.name, "Correct name"); |
|
24 |
|
25 is(objectStore.indexNames.length, 0, "Correct indexNames list"); |
|
26 |
|
27 let index = objectStore.createIndex(indexName, "foo"); |
|
28 |
|
29 is(objectStore.indexNames.length, 1, "Correct indexNames list"); |
|
30 is(objectStore.indexNames.item(0), indexName, "Correct name"); |
|
31 is(objectStore.index(indexName), index, "Correct instance"); |
|
32 |
|
33 objectStore.deleteIndex(indexName); |
|
34 |
|
35 is(objectStore.indexNames.length, 0, "Correct indexNames list"); |
|
36 try { |
|
37 objectStore.index(indexName); |
|
38 ok(false, "should have thrown"); |
|
39 } |
|
40 catch(ex) { |
|
41 ok(ex instanceof DOMException, "Got a DOMException"); |
|
42 is(ex.name, "NotFoundError", "expect a NotFoundError"); |
|
43 is(ex.code, DOMException.NOT_FOUND_ERR, "expect a NOT_FOUND_ERR"); |
|
44 } |
|
45 |
|
46 let index2 = objectStore.createIndex(indexName, "foo"); |
|
47 isnot(index, index2, "New instance should be created"); |
|
48 |
|
49 is(objectStore.indexNames.length, 1, "Correct recreacted indexNames list"); |
|
50 is(objectStore.indexNames.item(0), indexName, "Correct recreacted name"); |
|
51 is(objectStore.index(indexName), index2, "Correct instance"); |
|
52 |
|
53 finishTest(); |
|
54 yield undefined; |
|
55 } |