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