OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <script src="../../resources/js-test.js"></script> | |
3 <script src="resources/shared.js"></script> | |
4 <script> | |
5 | |
6 description("Ensure IndexedDB's write operations invalidate cursor prefetch cach es"); | |
7 | |
8 indexedDBTest(prepareDatabase, onOpenSuccess); | |
9 function prepareDatabase(evt) | |
10 { | |
11 preamble(evt); | |
12 evalAndLog("db = event.target.result"); | |
13 evalAndLog("store = db.createObjectStore('store')"); | |
14 } | |
15 | |
16 function onOpenSuccess(evt) | |
17 { | |
18 preamble(evt); | |
19 evalAndLog("db = event.target.result"); | |
20 | |
21 var steps = [ | |
22 deleteRange, | |
23 clearStore | |
24 ]; | |
25 | |
26 (function nextStep() { | |
27 var step = steps.shift(); | |
28 if (step) { | |
29 doPrefetchInvalidationTest(step, nextStep); | |
30 } else { | |
31 finishJSTest(); | |
32 return; | |
33 } | |
34 }()); | |
dgrogan
2013/12/19 21:53:06
What's the advantage to the (function {...}()) pat
jsbell
2013/12/19 22:04:25
Not quite it's not quite an IIFE (http://en.wikipe
dgrogan
2013/12/19 23:00:16
No, it's fine.
| |
35 } | |
36 | |
37 function doPrefetchInvalidationTest(operation, callback) | |
38 { | |
39 debug(""); | |
40 debug("-------------------------------------------"); | |
41 preamble(); | |
42 evalAndLog("store = db.transaction('store', 'readwrite').objectStore('store' )"); | |
43 debug("Populate the store with 200 records."); | |
44 for (var i = 0; i < 200; ++i) | |
45 store.put(i, i); | |
46 evalAndLog("cursorRequest = store.openCursor()"); | |
47 continue100Times(operation, callback); | |
48 } | |
49 | |
50 function continue100Times(operation, callback) | |
51 { | |
52 preamble(); | |
53 var count = 0; | |
54 | |
55 cursorRequest.onsuccess = function() { | |
56 var cursor = cursorRequest.result; | |
57 ++count; | |
58 if (count < 100) { | |
59 cursor.continue(); | |
60 return; | |
61 } | |
62 shouldBeNonNull("cursorRequest.result"); | |
63 doOperationAndContinue(operation, callback); | |
64 } | |
65 } | |
66 | |
67 function doOperationAndContinue(operation, callback) | |
68 { | |
69 preamble(); | |
70 operation(); | |
71 evalAndLog("cursor = cursorRequest.result"); | |
72 evalAndLog("cursor.continue()") | |
73 cursorRequest.onsuccess = function onContinueSuccess() { | |
74 preamble(); | |
75 shouldBeNull("cursorRequest.result"); | |
76 callback(); | |
77 }; | |
78 } | |
79 | |
80 function deleteRange() | |
81 { | |
82 return evalAndLog("store.delete(IDBKeyRange.bound(-Infinity, +Infinity))"); | |
83 } | |
84 | |
85 function clearStore() | |
86 { | |
87 return evalAndLog("store.clear()"); | |
88 } | |
89 | |
90 </script> | |
OLD | NEW |