|
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 let request = indexedDB.open(this.window ? window.location.pathname : "Splendid Test", 1); |
|
11 request.onerror = errorHandler; |
|
12 request.onupgradeneeded = grabEventAndContinueHandler; |
|
13 request.onsuccess = unexpectedSuccessHandler; |
|
14 let event = yield undefined; |
|
15 |
|
16 let db = event.target.result; |
|
17 db.onerror = errorHandler; |
|
18 |
|
19 event.target.transaction.onerror = errorHandler; |
|
20 event.target.transaction.oncomplete = grabEventAndContinueHandler; |
|
21 |
|
22 let os = db.createObjectStore("foo", { autoIncrement: true }); |
|
23 let index = os.createIndex("bar", "foo.bar"); |
|
24 event = yield undefined; |
|
25 |
|
26 is(request.transaction, event.target, |
|
27 "request.transaction should still be set"); |
|
28 |
|
29 request.onsuccess = grabEventAndContinueHandler; |
|
30 event = yield undefined; |
|
31 |
|
32 is(request.transaction, null, "request.transaction should be cleared"); |
|
33 |
|
34 let transaction = db.transaction("foo", "readwrite"); |
|
35 |
|
36 os = transaction.objectStore("foo"); |
|
37 // Place a request to keep the transaction alive long enough for our |
|
38 // executeSoon. |
|
39 let requestComplete = false; |
|
40 |
|
41 let wasAbleToGrabObjectStoreOutsideOfCallback = false; |
|
42 let wasAbleToGrabIndexOutsideOfCallback = false; |
|
43 executeSoon(function() { |
|
44 ok(!requestComplete, "Ordering is correct."); |
|
45 wasAbleToGrabObjectStoreOutsideOfCallback = !!transaction.objectStore("foo"); |
|
46 wasAbleToGrabIndexOutsideOfCallback = |
|
47 !!transaction.objectStore("foo").index("bar"); |
|
48 }); |
|
49 |
|
50 request = os.add({}); |
|
51 request.onerror = errorHandler; |
|
52 request.onsuccess = grabEventAndContinueHandler; |
|
53 |
|
54 event = yield undefined; |
|
55 |
|
56 requestComplete = true; |
|
57 |
|
58 ok(wasAbleToGrabObjectStoreOutsideOfCallback, |
|
59 "Should be able to get objectStore"); |
|
60 ok(wasAbleToGrabIndexOutsideOfCallback, |
|
61 "Should be able to get index"); |
|
62 |
|
63 transaction.oncomplete = grabEventAndContinueHandler; |
|
64 yield undefined; |
|
65 |
|
66 try { |
|
67 transaction.objectStore("foo"); |
|
68 ok(false, "Should have thrown!"); |
|
69 } |
|
70 catch (e) { |
|
71 ok(e instanceof DOMException, "Got database exception."); |
|
72 is(e.name, "InvalidStateError", "Good error."); |
|
73 is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); |
|
74 } |
|
75 |
|
76 continueToNextStep(); |
|
77 yield undefined; |
|
78 |
|
79 try { |
|
80 transaction.objectStore("foo"); |
|
81 ok(false, "Should have thrown!"); |
|
82 } |
|
83 catch (e) { |
|
84 ok(e instanceof DOMException, "Got database exception."); |
|
85 is(e.name, "InvalidStateError", "Good error."); |
|
86 is(e.code, DOMException.INVALID_STATE_ERR, "Good error code."); |
|
87 } |
|
88 |
|
89 finishTest(); |
|
90 yield undefined; |
|
91 } |