|
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 data = { key: 5, index: 10 }; |
|
11 |
|
12 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); |
|
13 request.onerror = errorHandler; |
|
14 request.onupgradeneeded = grabEventAndContinueHandler; |
|
15 let event = yield undefined; |
|
16 |
|
17 let db = event.target.result; |
|
18 |
|
19 ok(db instanceof IDBDatabase, "Got a real database"); |
|
20 |
|
21 db.onerror = errorHandler; |
|
22 |
|
23 let objectStore = db.createObjectStore("foo", { keyPath: "key", |
|
24 autoIncrement: true }); |
|
25 let index = objectStore.createIndex("foo", "index"); |
|
26 |
|
27 event.target.onsuccess = continueToNextStep; |
|
28 yield undefined; |
|
29 |
|
30 objectStore = db.transaction("foo", "readwrite") |
|
31 .objectStore("foo"); |
|
32 request = objectStore.add(data); |
|
33 request.onsuccess = grabEventAndContinueHandler; |
|
34 event = yield undefined; |
|
35 |
|
36 let key; |
|
37 executeSoon(function() { |
|
38 key = request.result; |
|
39 continueToNextStep(); |
|
40 }); |
|
41 yield undefined; |
|
42 |
|
43 is(key, data.key, "Got the right key"); |
|
44 |
|
45 objectStore = db.transaction("foo").objectStore("foo"); |
|
46 objectStore.get(data.key).onsuccess = grabEventAndContinueHandler; |
|
47 event = yield undefined; |
|
48 |
|
49 let obj; |
|
50 executeSoon(function() { |
|
51 obj = event.target.result; |
|
52 continueToNextStep(); |
|
53 }); |
|
54 yield undefined; |
|
55 |
|
56 is(obj.key, data.key, "Got the right key"); |
|
57 is(obj.index, data.index, "Got the right property value"); |
|
58 |
|
59 objectStore = db.transaction("foo", "readwrite") |
|
60 .objectStore("foo"); |
|
61 request = objectStore.delete(data.key); |
|
62 request.onsuccess = grabEventAndContinueHandler; |
|
63 event = yield undefined; |
|
64 |
|
65 key = undefined; |
|
66 executeSoon(function() { |
|
67 key = request.result; |
|
68 continueToNextStep(); |
|
69 }, 0); |
|
70 yield undefined; |
|
71 |
|
72 ok(key === undefined, "Got the right value"); |
|
73 |
|
74 finishTest(); |
|
75 yield undefined; |
|
76 } |