Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: tests/html/indexeddb_3_test.dart

Issue 12181021: Revert IDB optional mode parameter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/html/indexeddb_2_test.dart ('k') | tests/html/indexeddb_4_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library IndexedDB3Test; 1 library IndexedDB3Test;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:html'; 4 import 'dart:html';
5 import 'dart:indexed_db'; 5 import 'dart:indexed_db';
6 6
7 // Read with cursor. 7 // Read with cursor.
8 8
9 const String DB_NAME = 'Test'; 9 const String DB_NAME = 'Test';
10 const String STORE_NAME = 'TEST'; 10 const String STORE_NAME = 'TEST';
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 68 }
69 69
70 _createAndOpenDb(afterOpen()) { 70 _createAndOpenDb(afterOpen()) {
71 var request = window.indexedDB.deleteDatabase(DB_NAME); 71 var request = window.indexedDB.deleteDatabase(DB_NAME);
72 request.onSuccess.listen(expectAsync1((e) { _openDb(afterOpen); })); 72 request.onSuccess.listen(expectAsync1((e) { _openDb(afterOpen); }));
73 request.onError.listen(fail('delete old Db')); 73 request.onError.listen(fail('delete old Db'));
74 } 74 }
75 75
76 writeItems(int index) { 76 writeItems(int index) {
77 if (index < 100) { 77 if (index < 100) {
78 var transaction = db.transaction([STORE_NAME], mode : 'readwrite'); 78 var transaction = db.transaction([STORE_NAME], 'readwrite');
79 var request = transaction.objectStore(STORE_NAME) 79 var request = transaction.objectStore(STORE_NAME)
80 .put('Item $index', index); 80 .put('Item $index', index);
81 request.onSuccess.listen(expectAsync1((e) { 81 request.onSuccess.listen(expectAsync1((e) {
82 writeItems(index + 1); 82 writeItems(index + 1);
83 } 83 }
84 )); 84 ));
85 request.onError.listen(fail('put')); 85 request.onError.listen(fail('put'));
86 } 86 }
87 } 87 }
88 88
89 setupDb() { _createAndOpenDb(() => writeItems(0)); } 89 setupDb() { _createAndOpenDb(() => writeItems(0)); }
90 90
91 readAllViaCursor() { 91 readAllViaCursor() {
92 Transaction txn = db.transaction(STORE_NAME, mode : 'readonly'); 92 Transaction txn = db.transaction(STORE_NAME, 'readonly');
93 ObjectStore objectStore = txn.objectStore(STORE_NAME); 93 ObjectStore objectStore = txn.objectStore(STORE_NAME);
94 Request cursorRequest = objectStore.openCursor(); 94 Request cursorRequest = objectStore.openCursor();
95 int itemCount = 0; 95 int itemCount = 0;
96 int sumKeys = 0; 96 int sumKeys = 0;
97 int lastKey = null; 97 int lastKey = null;
98 cursorRequest.onSuccess.listen(expectAsync1((e) { 98 cursorRequest.onSuccess.listen(expectAsync1((e) {
99 var cursor = e.target.result; 99 var cursor = e.target.result;
100 if (cursor != null) { 100 if (cursor != null) {
101 lastKey = cursor.key; 101 lastKey = cursor.key;
102 itemCount += 1; 102 itemCount += 1;
103 sumKeys += cursor.key; 103 sumKeys += cursor.key;
104 window.console.log('${cursor.key} ${cursor.value}'); 104 window.console.log('${cursor.key} ${cursor.value}');
105 expect(cursor.value, 'Item ${cursor.key}'); 105 expect(cursor.value, 'Item ${cursor.key}');
106 cursor.continueFunction(); 106 cursor.continueFunction();
107 } else { 107 } else {
108 // Done 108 // Done
109 expect(lastKey, 99); 109 expect(lastKey, 99);
110 expect(itemCount, 100); 110 expect(itemCount, 100);
111 expect(sumKeys, (100 * 99) ~/ 2); 111 expect(sumKeys, (100 * 99) ~/ 2);
112 } 112 }
113 }, count:101)); 113 }, count:101));
114 cursorRequest.onError.listen(fail('openCursor')); 114 cursorRequest.onError.listen(fail('openCursor'));
115 } 115 }
116 116
117 readAllReversedViaCursor() { 117 readAllReversedViaCursor() {
118 Transaction txn = db.transaction(STORE_NAME, mode : 'readonly'); 118 Transaction txn = db.transaction(STORE_NAME, 'readonly');
119 ObjectStore objectStore = txn.objectStore(STORE_NAME); 119 ObjectStore objectStore = txn.objectStore(STORE_NAME);
120 // TODO: create a KeyRange(0,100) 120 // TODO: create a KeyRange(0,100)
121 Request cursorRequest = objectStore.openCursor(null, 'prev'); 121 Request cursorRequest = objectStore.openCursor(null, 'prev');
122 int itemCount = 0; 122 int itemCount = 0;
123 int sumKeys = 0; 123 int sumKeys = 0;
124 int lastKey = null; 124 int lastKey = null;
125 cursorRequest.onSuccess.listen(expectAsync1((e) { 125 cursorRequest.onSuccess.listen(expectAsync1((e) {
126 var cursor = e.target.result; 126 var cursor = e.target.result;
127 if (cursor != null) { 127 if (cursor != null) {
128 lastKey = cursor.key; 128 lastKey = cursor.key;
(...skipping 17 matching lines...) Expand all
146 146
147 // Don't bother with these tests if it's unsupported. 147 // Don't bother with these tests if it's unsupported.
148 // Support is tested in indexeddb_1_test 148 // Support is tested in indexeddb_1_test
149 if (IdbFactory.supported) { 149 if (IdbFactory.supported) {
150 var test_ = new Test(); 150 var test_ = new Test();
151 test('prepare', test_.setupDb); 151 test('prepare', test_.setupDb);
152 test('readAll1', test_.readAllViaCursor); 152 test('readAll1', test_.readAllViaCursor);
153 test('readAll2', test_.readAllReversedViaCursor); 153 test('readAll2', test_.readAllReversedViaCursor);
154 } 154 }
155 } 155 }
OLDNEW
« no previous file with comments | « tests/html/indexeddb_2_test.dart ('k') | tests/html/indexeddb_4_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698