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

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

Issue 12334081: Fixing web_sql SqlResultSetRowList row accessor. (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 | « sdk/lib/web_sql/dart2js/web_sql_dart2js.dart ('k') | tools/dom/scripts/systemhtml.py » ('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 WebDBTest; 1 library WebDBTest;
2 import '../../pkg/unittest/lib/unittest.dart';
3 import '../../pkg/unittest/lib/html_individual_config.dart';
4 import 'dart:async'; 2 import 'dart:async';
5 import 'dart:html'; 3 import 'dart:html';
6 import 'dart:web_sql'; 4 import 'dart:web_sql';
5 import '../../pkg/unittest/lib/unittest.dart';
6 import '../../pkg/unittest/lib/html_individual_config.dart';
7 import 'utils.dart';
7 8
8 void fail(message) { 9 void fail(message) {
9 guardAsync(() { 10 guardAsync(() {
10 expect(false, isTrue, reason: message); 11 expect(false, isTrue, reason: message);
11 }); 12 });
12 } 13 }
13 14
14 Future<SqlTransaction> createTransaction(SqlDatabase db) { 15 Future<SqlTransaction> transaction(SqlDatabase db) {
15 final completer = new Completer<SqlTransaction>(); 16 final completer = new Completer<SqlTransaction>();
16 17
17 db.transaction((SqlTransaction transaction) { 18 db.transaction((SqlTransaction transaction) {
18 completer.complete(transaction); 19 completer.complete(transaction);
20 }, (SqlError error) {
21 completer.completeError(error);
19 }); 22 });
20 23
21 return completer.future; 24 return completer.future;
22 } 25 }
23 26
24 createTable(tableName, columnName) => (SqlTransaction transaction) { 27 Future<SqlResultSet> createTable(SqlTransaction transaction, String tableName,
25 final completer = new Completer<SqlTransaction>(); 28 String columnName) {
29 final completer = new Completer<SqlResultSet>();
26 30
27 final sql = 'CREATE TABLE $tableName ($columnName)'; 31 final sql = 'CREATE TABLE $tableName ($columnName)';
28 transaction.executeSql(sql, [], 32 transaction.executeSql(sql, [],
29 (SqlTransaction tx, SqlResultSet rs) { 33 (SqlTransaction tx, SqlResultSet rs) {
30 completer.complete(transaction); 34 completer.complete(rs);
31 }, 35 },
32 (SqlTransaction tx, SqlError error) { 36 (SqlTransaction tx, SqlError error) {
33 fail(error.message); 37 completer.completeError(error);
34 }); 38 });
35 39
36 return completer.future; 40 return completer.future;
37 }; 41 }
38 42
39 insert(tableName, columnName, value) => (SqlTransaction transaction) { 43 Future<SqlResultSet> insert(SqlTransaction transaction, String tableName,
40 final completer = new Completer<SqlTransaction>(); 44 String columnName, value) {
45 final completer = new Completer<SqlResultSet>();
41 46
42 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)'; 47 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)';
43 transaction.executeSql(sql, [value], 48 transaction.executeSql(sql, [value],
44 (SqlTransaction tx, SqlResultSet rs) { 49 (SqlTransaction tx, SqlResultSet rs) {
45 completer.complete(tx); 50 completer.complete(tx);
46 }, 51 },
47 (SqlTransaction tx, SqlError error) { 52 (SqlTransaction tx, SqlError error) {
48 fail(error.message); 53 completer.completeError(error);
49 }); 54 });
50 55
51 return completer.future; 56 return completer.future;
52 }; 57 }
53 58
54 queryTable(tableName, callback) => (SqlTransaction transaction) { 59 Future<SqlResultSet> queryTable(SqlTransaction transaction, String tableName) {
55 final completer = new Completer<SqlTransaction>(); 60 final completer = new Completer<SqlResultSet>();
56 61
57 final sql = 'SELECT * FROM $tableName'; 62 final sql = 'SELECT * FROM $tableName';
58 transaction.executeSql(sql, [], 63 transaction.executeSql(sql, [],
59 (SqlTransaction tx, SqlResultSet rs) { 64 (SqlTransaction tx, SqlResultSet rs) {
60 callback(rs); 65 completer.complete(rs);
61 completer.complete(tx);
62 }, 66 },
63 (SqlTransaction tx, SqlError error) { 67 (SqlTransaction tx, SqlError error) {
64 fail(error.message); 68 completer.completeError(error);
65 }); 69 });
66 70
67 return completer.future; 71 return completer.future;
68 }; 72 }
69 73
70 dropTable(tableName, [bool ignoreFailure = false]) => 74 Future<SqlResultSet> dropTable(SqlTransaction transaction, String tableName,
71 (SqlTransaction transaction) { 75 [bool ignoreFailure = false]) {
72 final completer = new Completer<SqlTransaction>(); 76 final completer = new Completer<SqlResultSet>();
73 77
74 final sql = 'DROP TABLE $tableName'; 78 final sql = 'DROP TABLE $tableName';
75 transaction.executeSql(sql, [], 79 transaction.executeSql(sql, [],
76 (SqlTransaction tx, SqlResultSet rs) { 80 (SqlTransaction tx, SqlResultSet rs) {
77 completer.complete(tx); 81 completer.complete(rs);
78 }, 82 },
79 (SqlTransaction tx, SqlError error) { 83 (SqlTransaction tx, SqlError error) {
80 if (ignoreFailure) { 84 if (ignoreFailure) {
81 completer.complete(tx); 85 completer.complete(null);
82 } else { 86 } else {
83 fail(error.message); 87 completer.completeError(error);
84 } 88 }
85 }); 89 });
86 90
87 return completer.future; 91 return completer.future;
88 }; 92 }
89 93
90 main() { 94 main() {
91 useHtmlIndividualConfiguration(); 95 useHtmlIndividualConfiguration();
92 96
93 group('supported', () { 97 group('supported', () {
94 test('supported', () { 98 test('supported', () {
95 expect(SqlDatabase.supported, true); 99 expect(SqlDatabase.supported, true);
96 }); 100 });
97 }); 101 });
98 102
99 group('functional', () { 103 group('functional', () {
100 test('unsupported throws', () { 104 test('unsupported throws', () {
101 var expectation = SqlDatabase.supported ? returnsNormally : throws; 105 var expectation = SqlDatabase.supported ? returnsNormally : throws;
102 expect(() { 106 expect(() {
103 window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); 107 window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024);
104 }, expectation); 108 }, expectation);
105 109
106 }); 110 });
107 test('Web Database', () { 111 futureTest('Web Database', () {
108 // Skip if not supported. 112 // Skip if not supported.
109 if (!SqlDatabase.supported) { 113 if (!SqlDatabase.supported) {
110 return; 114 return;
111 } 115 }
112 116
113 final tableName = 'test_table'; 117 final tableName = 'test_table';
114 final columnName = 'test_data'; 118 final columnName = 'test_data';
115 119
116 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); 120 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024);
117 121
118 expect(db, isNotNull, reason: 'Unable to open database'); 122 expect(db, isNotNull, reason: 'Unable to open database');
119 123
120 createTransaction(db) 124 var tx;
125 return transaction(db).then((transaction) {
126 tx = transaction;
127 }).then((_) {
121 // Attempt to clear out any tables which may be lurking from previous 128 // Attempt to clear out any tables which may be lurking from previous
122 // runs. 129 // runs.
123 .then(dropTable(tableName, true)) 130 return dropTable(tx, tableName, true);
124 .then(createTable(tableName, columnName)) 131 }).then((_) {
125 .then(insert(tableName, columnName, 'Some text data')) 132 return createTable(tx, tableName, columnName);
126 .then(queryTable(tableName, (resultSet) { 133 }).then((_) {
127 guardAsync(() { 134 return insert(tx, tableName, columnName, 'Some text data');
128 expect(resultSet.rows.length, 1); 135 }).then((_) {
129 var row = resultSet.rows.item(0); 136 return queryTable(tx, tableName);
130 expect(row.containsKey(columnName), isTrue); 137 }).then((resultSet) {
131 expect(row[columnName], 'Some text data'); 138 expect(resultSet.rows.length, 1);
132 }); 139 var row = resultSet.rows.item(0);
133 })) 140 expect(row.containsKey(columnName), isTrue);
134 .then(dropTable(tableName)) 141 expect(row[columnName], 'Some text data');
135 .then(expectAsync1((tx) {})); 142 expect(resultSet.rows[0], row);
blois 2013/02/25 23:48:31 This is actually the only line needed to update th
143 }).then((_) {
144 return dropTable(tx, tableName);
145 });
136 }); 146 });
137 }); 147 });
138 } 148 }
OLDNEW
« no previous file with comments | « sdk/lib/web_sql/dart2js/web_sql_dart2js.dart ('k') | tools/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698