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

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

Issue 12421005: Attempting to fix IndexedDB test on IE10 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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_1_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 library IndexedDB1Test; 1 library IndexedDB1Test;
2 import '../../pkg/unittest/lib/unittest.dart'; 2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_individual_config.dart'; 3 import '../../pkg/unittest/lib/html_config.dart';
4 import 'dart:async'; 4 import 'dart:async';
5 import 'dart:html' as html; 5 import 'dart:html' as html;
6 import 'dart:indexed_db' as idb; 6 import 'dart:indexed_db' as idb;
7 7
8 main() { 8 main() {
9 useHtmlIndividualConfiguration(); 9 useHtmlConfiguration();
10
11 group('supportsDatabaseNames', () {
12 test('supported', () {
13 expect(html.window.indexedDB.supportsDatabaseNames, isTrue);
14 });
15 });
16 10
17 if (!idb.IdbFactory.supported) { 11 if (!idb.IdbFactory.supported) {
18 return; 12 return;
19 } 13 }
20 14
21 group('functional', () { 15 var dbName = 'test_db_5';
22 var dbName = 'test_db'; 16 var storeName = 'test_store';
23 var storeName = 'test_store'; 17 var indexName = 'name_index';
24 var indexName = 'name_index'; 18 var db;
25 var db;
26 19
27 test('init', () { 20 test('init', () {
28 return html.window.indexedDB.deleteDatabase(dbName).then((_) { 21 return html.window.indexedDB.deleteDatabase(dbName).then((_) {
29 return html.window.indexedDB.open(dbName, version: 1, 22 return html.window.indexedDB.open(dbName, version: 1,
30 onUpgradeNeeded: (e) { 23 onUpgradeNeeded: (e) {
31 var db = e.target.result; 24 var db = e.target.result;
32 var objectStore = db.createObjectStore(storeName, 25 var objectStore = db.createObjectStore(storeName,
33 autoIncrement: true); 26 autoIncrement: true);
34 var index = objectStore.createIndex(indexName, 'name_index', 27 var index = objectStore.createIndex(indexName, 'name_index',
35 unique: false); 28 unique: false);
36 }); 29 });
37 }).then((database) { 30 }).then((database) {
38 db = database; 31 db = database;
32 });
33 });
34
35 if (html.window.indexedDB.supportsDatabaseNames) {
36 test('getDatabaseNames', () {
37 return html.window.indexedDB.getDatabaseNames().then((names) {
38 expect(names.contains(dbName), isTrue);
39 }); 39 });
40 }); 40 });
41 }
41 42
42 if (html.window.indexedDB.supportsDatabaseNames) { 43 var value = {'name_index': 'one', 'value': 'add_value'};
43 test('getDatabaseNames', () { 44 test('add/delete', () {
44 return html.window.indexedDB.getDatabaseNames().then((names) { 45 var transaction = db.transaction([storeName], 'readwrite');
45 expect(names.contains(dbName), isTrue); 46 var key;
46 }); 47 return transaction.objectStore(storeName).add(value).then((addedKey) {
48 key = addedKey;
49 }).then((_) {
50 return transaction.completed;
51 }).then((_) {
52 transaction = db.transaction([storeName], 'readonly');
53 return transaction.objectStore(storeName).getObject(key);
54 }).then((readValue) {
55 expect(readValue['value'], value['value']);
56 return transaction.completed;
57 }).then((_) {
58 transaction = db.transaction([storeName], 'readwrite');
59 return transaction.objectStore(storeName).delete(key);
60 }).then((_) {
61 return transaction.completed;
62 }).then((_) {
63 var transaction = db.transaction([storeName], 'readonly');
64 return transaction.objectStore(storeName).count();
65 }).then((count) {
66 expect(count, 0);
67 });
68 });
69
70 test('clear/count', () {
71 var transaction = db.transaction([storeName], 'readwrite');
72 transaction.objectStore(storeName).add(value);
73
74 return transaction.completed.then((_) {
75 transaction = db.transaction([storeName], 'readonly');
76 return transaction.objectStore(storeName).count();
77 }).then((count) {
78 expect(count, 1);
79 }).then((_) {
80 return transaction.completed;
81 }).then((_) {
82 transaction = db.transaction([storeName], 'readwrite');
83 transaction.objectStore(storeName).clear();
84 return transaction.completed;
85 }).then((_) {
86 var transaction = db.transaction([storeName], 'readonly');
87 return transaction.objectStore(storeName).count();
88 }).then((count) {
89 expect(count, 0);
90 });
91 });
92
93 test('index', () {
94 var transaction = db.transaction([storeName], 'readwrite');
95 transaction.objectStore(storeName).add(value);
96 transaction.objectStore(storeName).add(value);
97 transaction.objectStore(storeName).add(value);
98 transaction.objectStore(storeName).add(value);
99
100 return transaction.completed.then((_) {
101 transaction = db.transaction([storeName], 'readonly');
102 var index = transaction.objectStore(storeName).index(indexName);
103 return index.count();
104 }).then((count) {
105 expect(count, 4);
106 return transaction.completed;
107 }).then((_) {
108 transaction = db.transaction([storeName], 'readonly');
109 var index = transaction.objectStore(storeName).index(indexName);
110 return index.openCursor(autoAdvance: true).length;
111 }).then((cursorsLength) {
112 expect(cursorsLength, 4);
113 return transaction.completed;
114 }).then((_) {
115 transaction = db.transaction([storeName], 'readonly');
116 var index = transaction.objectStore(storeName).index(indexName);
117 return index.openKeyCursor(autoAdvance: true).length;
118 }).then((cursorsLength) {
119 expect(cursorsLength, 4);
120 return transaction.completed;
121 }).then((_) {
122 transaction = db.transaction([storeName], 'readonly');
123 var index = transaction.objectStore(storeName).index(indexName);
124 return index.get('one');
125 }).then((readValue) {
126 expect(readValue['value'], value['value']);
127 return transaction.completed;
128 }).then((_) {
129 transaction = db.transaction([storeName], 'readwrite');
130 transaction.objectStore(storeName).clear();
131 return transaction.completed;
132 });
133 });
134
135 var deleteValue = {'name_index': 'two', 'value': 'delete_value'};
136 var updateValue = {'name_index': 'three', 'value': 'update_value'};
137 var updatedValue = {'name_index': 'three', 'value': 'updated_value'};
138 test('cursor', () {
139 var transaction = db.transaction([storeName], 'readwrite');
140 transaction.objectStore(storeName).add(value);
141 transaction.objectStore(storeName).add(deleteValue);
142 transaction.objectStore(storeName).add(updateValue);
143
144 return transaction.completed.then((_) {
145 transaction = db.transaction([storeName], 'readwrite');
146 var index = transaction.objectStore(storeName).index(indexName);
147 var cursors = index.openCursor().asBroadcastStream();
148
149 cursors.listen((cursor) {
150 var value = cursor.value;
151 if (value['value'] == 'delete_value') {
152 cursor.delete().then((_) {
153 cursor.next();
154 });
155 } else if (value['value'] == 'update_value') {
156 cursor.update(updatedValue).then((_) {
157 cursor.next();
158 });
159 } else {
160 cursor.next();
161 }
47 }); 162 });
48 } 163 return cursors.last;
49 164
50 var value = {'name_index': 'one', 'value': 'add_value'}; 165 }).then((_) {
51 test('add/delete', () { 166 return transaction.completed;
52 var transaction = db.transaction([storeName], 'readwrite'); 167 }).then((_) {
53 var key; 168 transaction = db.transaction([storeName], 'readonly');
54 return transaction.objectStore(storeName).add(value).then((addedKey) { 169 var index = transaction.objectStore(storeName).index(indexName);
55 key = addedKey; 170 return index.get('three');
56 }).then((_) { 171 }).then((readValue) {
57 return transaction.completed; 172 expect(readValue['value'], 'updated_value');
58 }).then((_) { 173 return transaction.completed;
59 transaction = db.transaction([storeName], 'readonly'); 174 }).then((_) {
60 return transaction.objectStore(storeName).getObject(key); 175 transaction = db.transaction([storeName], 'readonly');
61 }).then((readValue) { 176 var index = transaction.objectStore(storeName).index(indexName);
62 expect(readValue['value'], value['value']); 177 return index.get('two');
63 return transaction.completed; 178 }).then((readValue) {
64 }).then((_) { 179 expect(readValue, isNull);
65 transaction = db.transaction([storeName], 'readwrite'); 180 return transaction.completed;
66 return transaction.objectStore(storeName).delete(key);
67 }).then((_) {
68 return transaction.completed;
69 }).then((_) {
70 var transaction = db.transaction([storeName], 'readonly');
71 return transaction.objectStore(storeName).count();
72 }).then((count) {
73 expect(count, 0);
74 });
75 });
76
77 test('clear/count', () {
78 var transaction = db.transaction([storeName], 'readwrite');
79 transaction.objectStore(storeName).add(value);
80
81 return transaction.completed.then((_) {
82 transaction = db.transaction([storeName], 'readonly');
83 return transaction.objectStore(storeName).count();
84 }).then((count) {
85 expect(count, 1);
86 }).then((_) {
87 return transaction.completed;
88 }).then((_) {
89 transaction = db.transaction([storeName], 'readwrite');
90 transaction.objectStore(storeName).clear();
91 return transaction.completed;
92 }).then((_) {
93 var transaction = db.transaction([storeName], 'readonly');
94 return transaction.objectStore(storeName).count();
95 }).then((count) {
96 expect(count, 0);
97 });
98 });
99
100 test('index', () {
101 var transaction = db.transaction([storeName], 'readwrite');
102 transaction.objectStore(storeName).add(value);
103 transaction.objectStore(storeName).add(value);
104 transaction.objectStore(storeName).add(value);
105 transaction.objectStore(storeName).add(value);
106
107 return transaction.completed.then((_) {
108 transaction = db.transaction([storeName], 'readonly');
109 var index = transaction.objectStore(storeName).index(indexName);
110 return index.count();
111 }).then((count) {
112 expect(count, 4);
113 return transaction.completed;
114 }).then((_) {
115 transaction = db.transaction([storeName], 'readonly');
116 var index = transaction.objectStore(storeName).index(indexName);
117 return index.openCursor(autoAdvance: true).length;
118 }).then((cursorsLength) {
119 expect(cursorsLength, 4);
120 return transaction.completed;
121 }).then((_) {
122 transaction = db.transaction([storeName], 'readonly');
123 var index = transaction.objectStore(storeName).index(indexName);
124 return index.openKeyCursor(autoAdvance: true).length;
125 }).then((cursorsLength) {
126 expect(cursorsLength, 4);
127 return transaction.completed;
128 }).then((_) {
129 transaction = db.transaction([storeName], 'readonly');
130 var index = transaction.objectStore(storeName).index(indexName);
131 return index.get('one');
132 }).then((readValue) {
133 expect(readValue['value'], value['value']);
134 return transaction.completed;
135 }).then((_) {
136 transaction = db.transaction([storeName], 'readwrite');
137 transaction.objectStore(storeName).clear();
138 return transaction.completed;
139 });
140 });
141
142 var deleteValue = {'name_index': 'two', 'value': 'delete_value'};
143 var updateValue = {'name_index': 'three', 'value': 'update_value'};
144 var updatedValue = {'name_index': 'three', 'value': 'updated_value'};
145 test('cursor', () {
146 var transaction = db.transaction([storeName], 'readwrite');
147 transaction.objectStore(storeName).add(value);
148 transaction.objectStore(storeName).add(deleteValue);
149 transaction.objectStore(storeName).add(updateValue);
150
151 return transaction.completed.then((_) {
152 transaction = db.transaction([storeName], 'readwrite');
153 var index = transaction.objectStore(storeName).index(indexName);
154 var cursors = index.openCursor().asBroadcastStream();
155
156 cursors.listen((cursor) {
157 var value = cursor.value;
158 if (value['value'] == 'delete_value') {
159 cursor.delete().then((_) {
160 cursor.next();
161 });
162 } else if (value['value'] == 'update_value') {
163 cursor.update(updatedValue).then((_) {
164 cursor.next();
165 });
166 } else {
167 cursor.next();
168 }
169 });
170 return cursors.last;
171
172 }).then((_) {
173 return transaction.completed;
174 }).then((_) {
175 transaction = db.transaction([storeName], 'readonly');
176 var index = transaction.objectStore(storeName).index(indexName);
177 return index.get('three');
178 }).then((readValue) {
179 expect(readValue['value'], 'updated_value');
180 return transaction.completed;
181 }).then((_) {
182 transaction = db.transaction([storeName], 'readonly');
183 var index = transaction.objectStore(storeName).index(indexName);
184 return index.get('two');
185 }).then((readValue) {
186 expect(readValue, isNull);
187 return transaction.completed;
188 });
189 }); 181 });
190 }); 182 });
191 } 183 }
OLDNEW
« no previous file with comments | « tests/html/indexeddb_1_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698