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

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

Issue 26308004: Update idb tests to verify correct number behavior. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 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 | « no previous file | 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_individual_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:math' as math;
6 import 'dart:indexed_db' as idb; 7 import 'dart:indexed_db' as idb;
7 8
8 const String STORE_NAME = 'TEST'; 9 const String STORE_NAME = 'TEST';
9 const int VERSION = 1; 10 const int VERSION = 1;
10 11
11 var databaseNameIndex = 0; 12 var databaseNameIndex = 0;
12 String nextDatabaseName() { 13 String nextDatabaseName() {
13 return 'Test1_${databaseNameIndex++}'; 14 return 'Test1_${databaseNameIndex++}';
14 } 15 }
15 16
(...skipping 14 matching lines...) Expand all
30 expect(e.oldVersion, 1); 31 expect(e.oldVersion, 1);
31 expect(e.newVersion, 2); 32 expect(e.newVersion, 2);
32 upgraded = true; 33 upgraded = true;
33 }); 34 });
34 }).then((_) { 35 }).then((_) {
35 expect(upgraded, isTrue); 36 expect(upgraded, isTrue);
36 }); 37 });
37 } 38 }
38 39
39 testReadWrite(key, value, matcher, 40 testReadWrite(key, value, matcher,
40 [dbName, storeName = STORE_NAME, version = VERSION]) => () { 41 [dbName, storeName = STORE_NAME, version = VERSION,
42 stringifyResult = false]) => () {
41 if (dbName == null) { 43 if (dbName == null) {
42 dbName = nextDatabaseName(); 44 dbName = nextDatabaseName();
43 } 45 }
44 createObjectStore(e) { 46 createObjectStore(e) {
45 var store = e.target.result.createObjectStore(storeName); 47 var store = e.target.result.createObjectStore(storeName);
46 expect(store, isNotNull); 48 expect(store, isNotNull);
47 } 49 }
48 50
49 var db; 51 var db;
50 return html.window.indexedDB.deleteDatabase(dbName).then((_) { 52 return html.window.indexedDB.deleteDatabase(dbName).then((_) {
51 return html.window.indexedDB.open(dbName, version: version, 53 return html.window.indexedDB.open(dbName, version: version,
52 onUpgradeNeeded: createObjectStore); 54 onUpgradeNeeded: createObjectStore);
53 }).then((result) { 55 }).then((result) {
54 db = result; 56 db = result;
55 var transaction = db.transactionList([storeName], 'readwrite'); 57 var transaction = db.transactionList([storeName], 'readwrite');
56 transaction.objectStore(storeName).put(value, key); 58 transaction.objectStore(storeName).put(value, key);
57 return transaction.completed; 59 return transaction.completed;
58 }).then((_) { 60 }).then((_) {
59 var transaction = db.transaction(storeName, 'readonly'); 61 var transaction = db.transaction(storeName, 'readonly');
60 return transaction.objectStore(storeName).getObject(key); 62 return transaction.objectStore(storeName).getObject(key);
61 }).then((object) { 63 }).then((object) {
62 db.close(); 64 db.close();
63 expect(object, matcher); 65 if (stringifyResult) {
66 // Stringify the numbers to verify that we're correctly returning ints
67 // as ints vs doubles.
68 expect(object.toString(), matcher);
69 } else {
70 expect(object, matcher);
71 }
64 }).whenComplete(() { 72 }).whenComplete(() {
65 if (db != null) { 73 if (db != null) {
66 db.close(); 74 db.close();
67 } 75 }
68 return html.window.indexedDB.deleteDatabase(dbName); 76 return html.window.indexedDB.deleteDatabase(dbName);
69 }); 77 });
70 }; 78 };
71 79
72 testReadWriteTyped(key, value, matcher, 80 testReadWriteTyped(key, value, matcher,
73 [dbName, storeName = STORE_NAME, version = VERSION]) => () { 81 [dbName, storeName = STORE_NAME, version = VERSION,
82 stringifyResult = false]) => () {
74 if (dbName == null) { 83 if (dbName == null) {
75 dbName = nextDatabaseName(); 84 dbName = nextDatabaseName();
76 } 85 }
77 void createObjectStore(e) { 86 void createObjectStore(e) {
78 var store = e.target.result.createObjectStore(storeName); 87 var store = e.target.result.createObjectStore(storeName);
79 expect(store, isNotNull); 88 expect(store, isNotNull);
80 } 89 }
81 90
82 idb.Database db; 91 idb.Database db;
83 // Delete any existing DBs. 92 // Delete any existing DBs.
84 return html.window.indexedDB.deleteDatabase(dbName).then((_) { 93 return html.window.indexedDB.deleteDatabase(dbName).then((_) {
85 return html.window.indexedDB.open(dbName, version: version, 94 return html.window.indexedDB.open(dbName, version: version,
86 onUpgradeNeeded: createObjectStore); 95 onUpgradeNeeded: createObjectStore);
87 }).then((idb.Database result) { 96 }).then((idb.Database result) {
88 db = result; 97 db = result;
89 idb.Transaction transaction = db.transactionList([storeName], 'readwrite') ; 98 idb.Transaction transaction = db.transactionList([storeName], 'readwrite') ;
90 transaction.objectStore(storeName).put(value, key); 99 transaction.objectStore(storeName).put(value, key);
91 100
92 return transaction.completed; 101 return transaction.completed;
93 }).then((idb.Database result) { 102 }).then((idb.Database result) {
94 idb.Transaction transaction = db.transaction(storeName, 'readonly'); 103 idb.Transaction transaction = db.transaction(storeName, 'readonly');
95 return transaction.objectStore(storeName).getObject(key); 104 return transaction.objectStore(storeName).getObject(key);
96 }).then((object) { 105 }).then((object) {
97 db.close(); 106 db.close();
98 expect(object, matcher); 107 if (stringifyResult) {
108 // Stringify the numbers to verify that we're correctly returning ints
109 // as ints vs doubles.
110 expect(object.toString(), matcher);
111 } else {
112 expect(object, matcher);
113 }
99 }).whenComplete(() { 114 }).whenComplete(() {
100 if (db != null) { 115 if (db != null) {
101 db.close(); 116 db.close();
102 } 117 }
103 return html.window.indexedDB.deleteDatabase(dbName); 118 return html.window.indexedDB.deleteDatabase(dbName);
104 }); 119 });
105 }; 120 };
106 121
107 void testTypes(testFunction) { 122 void testTypes(testFunction) {
108 test('String', testFunction(123, 'Hoot!', equals('Hoot!'))); 123 test('String', testFunction(123, 'Hoot!', equals('Hoot!')));
109 test('int', testFunction(123, 12345, equals(12345))); 124 test('int', testFunction(123, 12345, equals(12345)));
110 test('List', testFunction(123, [1, 2, 3], equals([1, 2, 3]))); 125 test('List', testFunction(123, [1, 2, 3], equals([1, 2, 3])));
111 test('List 2', testFunction(123, [2, 3, 4], equals([2, 3, 4]))); 126 test('List 2', testFunction(123, [2, 3, 4], equals([2, 3, 4])));
112 test('bool', testFunction(123, [true, false], equals([true, false]))); 127 test('bool', testFunction(123, [true, false], equals([true, false])));
128 test('largeInt', testFunction(123, 1371854424211,
129 equals("1371854424211"), null, STORE_NAME, VERSION, true));
130 test('largeDoubleConvertedToInt', testFunction(123, 1371854424211.0,
131 equals("1371854424211"), null, STORE_NAME, VERSION, true));
132 test('double', testFunction(123, math.pow(2, 53),
133 equals("9007199254740992.0"), null, STORE_NAME, VERSION, true));
134 test('largeIntInMap', testFunction(123, {'time': 4503599627370492},
135 equals("{time: 4503599627370492}"), null, STORE_NAME, VERSION, true));
113 var now = new DateTime.now(); 136 var now = new DateTime.now();
114 test('DateTime', testFunction(123, now, 137 test('DateTime', testFunction(123, now,
115 predicate((date) => 138 predicate((date) =>
116 date.millisecondsSinceEpoch == now.millisecondsSinceEpoch))); 139 date.millisecondsSinceEpoch == now.millisecondsSinceEpoch)));
117 } 140 }
118 141
119 main() { 142 main() {
120 useHtmlIndividualConfiguration(); 143 useHtmlIndividualConfiguration();
121 144
122 // Test that indexed_db is properly flagged as supported or not. 145 // Test that indexed_db is properly flagged as supported or not.
(...skipping 26 matching lines...) Expand all
149 test('upgrade', testUpgrade); 172 test('upgrade', testUpgrade);
150 group('dynamic', () { 173 group('dynamic', () {
151 testTypes(testReadWrite); 174 testTypes(testReadWrite);
152 }); 175 });
153 group('typed', () { 176 group('typed', () {
154 testTypes(testReadWriteTyped); 177 testTypes(testReadWriteTyped);
155 }); 178 });
156 } 179 }
157 }); 180 });
158 } 181 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698