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

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: Changing import paths for unit test Created 8 years, 4 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, [], (SQLTransaction tx, SQLResultSet rs) {
27 completer.complete(transaction);
28 }, (SQLTransaction tx, SQLError error) {
29 fail(error.message);
30 });
sra1 2012/08/23 17:52:39 Indentation of these things is tricky. The } shou
blois 2012/08/23 18:15:31 Done.
31
32 return completer.future;
33 };
34
35 insert(tableName, columnName, value) => (SQLTransaction transaction) {
36 final completer = new Completer<SQLTransaction>();
37
38 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)';
39 transaction.executeSql(sql, [value], (SQLTransaction tx, SQLResultSet rs) {
40 completer.complete(tx);
41 }, (SQLTransaction tx, SQLError error) {
42 fail(error.message);
43 });
44
45 return completer.future;
46 };
47
48 queryTable(tableName, callback) => (SQLTransaction transaction) {
49 final completer = new Completer<SQLTransaction>();
50
51 final sql = 'SELECT * FROM $tableName';
52 transaction.executeSql(sql, [], (SQLTransaction tx, SQLResultSet rs) {
53 callback(rs);
54 completer.complete(tx);
55 }, (SQLTransaction tx, SQLError error) {
56 fail(error.message);
57 });
58
59 return completer.future;
60 };
61
62 dropTable(tableName, [bool ignoreFailure = false]) =>
63 (SQLTransaction transaction) {
64 final completer = new Completer<SQLTransaction>();
65
66 final sql = 'DROP TABLE $tableName';
67 transaction.executeSql(sql, [], (SQLTransaction tx, SQLResultSet rs) {
68 completer.complete(tx);
69 }, (SQLTransaction tx, SQLError error) {
70 if (ignoreFailure) {
71 completer.complete(tx);
72 } else {
73 fail(error.message);
74 }
75 });
76
77 return completer.future;
78 };
79
80 main() {
81 useHtmlConfiguration();
82
83 test('Web Database', () {
84 final tableName = 'test_table';
85 final columnName = 'test_data';
86
87 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024);
88
89 Expect.isNotNull(db, 'Unable to open database');
90
91 createTransaction(db)
92 // Attempt to clear out any tables which may be lurking from previous runs .
sra1 2012/08/23 17:52:39 Line length
blois 2012/08/23 18:15:31 Done.
93 .chain(dropTable(tableName, true))
94 .chain(createTable(tableName, columnName))
95 .chain(insert(tableName, columnName, 'Some text data'))
96 .chain(queryTable(tableName, (resultSet) {
97 guardAsync(() {
98 Expect.equals(1, resultSet.rows.length);
99
100 // Should validate the rowData contents- need to be able to map the JS
101 // object back to regular types.
102 });
103 }))
104 .chain(dropTable(tableName))
105 .then(expectAsync1((tx) {}));
106 });
107 }
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