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

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

Issue 10876002: Fixing up some APIs to allow Web DB to work from dart and adding tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Syncing to latest. Created 8 years, 3 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/html.status ('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
(Empty)
1 #library('WebDBTest');
2 #import('../../pkg/unittest/unittest.dart');
3 #import('../../pkg/unittest/html_config.dart');
4 #import('dart:html');
5
6 void fail(message) {
7 guardAsync(() {
8 Expect.fail(message);
9 });
10 }
11
12 Future<SQLTransaction> createTransaction(Database db) {
13 final completer = new Completer<SQLTransaction>();
14
15 db.transaction((SQLTransaction transaction) {
16 completer.complete(transaction);
17 });
18
19 return completer.future;
20 }
21
22 createTable(tableName, columnName) => (SQLTransaction transaction) {
23 final completer = new Completer<SQLTransaction>();
24
25 final sql = 'CREATE TABLE $tableName ($columnName)';
26 transaction.executeSql(sql, [],
27 (SQLTransaction tx, SQLResultSet rs) {
28 completer.complete(transaction);
29 },
30 (SQLTransaction tx, SQLError error) {
31 fail(error.message);
32 });
33
34 return completer.future;
35 };
36
37 insert(tableName, columnName, value) => (SQLTransaction transaction) {
38 final completer = new Completer<SQLTransaction>();
39
40 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)';
41 transaction.executeSql(sql, [value],
42 (SQLTransaction tx, SQLResultSet rs) {
43 completer.complete(tx);
44 },
45 (SQLTransaction tx, SQLError error) {
46 fail(error.message);
47 });
48
49 return completer.future;
50 };
51
52 queryTable(tableName, callback) => (SQLTransaction transaction) {
53 final completer = new Completer<SQLTransaction>();
54
55 final sql = 'SELECT * FROM $tableName';
56 transaction.executeSql(sql, [],
57 (SQLTransaction tx, SQLResultSet rs) {
58 callback(rs);
59 completer.complete(tx);
60 },
61 (SQLTransaction tx, SQLError error) {
62 fail(error.message);
63 });
64
65 return completer.future;
66 };
67
68 dropTable(tableName, [bool ignoreFailure = false]) =>
69 (SQLTransaction transaction) {
70 final completer = new Completer<SQLTransaction>();
71
72 final sql = 'DROP TABLE $tableName';
73 transaction.executeSql(sql, [],
74 (SQLTransaction tx, SQLResultSet rs) {
75 completer.complete(tx);
76 },
77 (SQLTransaction tx, SQLError error) {
78 if (ignoreFailure) {
79 completer.complete(tx);
80 } else {
81 fail(error.message);
82 }
83 });
84
85 return completer.future;
86 };
87
88 main() {
89 useHtmlConfiguration();
90
91 test('Web Database', () {
92 final tableName = 'test_table';
93 final columnName = 'test_data';
94
95 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024);
96
97 Expect.isNotNull(db, 'Unable to open database');
98
99 createTransaction(db)
100 // Attempt to clear out any tables which may be lurking from previous
101 // runs.
102 .chain(dropTable(tableName, true))
103 .chain(createTable(tableName, columnName))
104 .chain(insert(tableName, columnName, 'Some text data'))
105 .chain(queryTable(tableName, (resultSet) {
106 guardAsync(() {
107 Expect.equals(1, resultSet.rows.length);
108
109 // Should validate the rowData contents- need to be able to map the JS
110 // object back to regular types.
111 });
112 }))
113 .chain(dropTable(tableName))
114 .then(expectAsync1((tx) {}));
115 });
116 }
OLDNEW
« no previous file with comments | « tests/html/html.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698