Chromium Code Reviews| Index: tests/html/websql_test.dart |
| diff --git a/tests/html/websql_test.dart b/tests/html/websql_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec337446bcaa92acdb2b8953ede31f75f2d81010 |
| --- /dev/null |
| +++ b/tests/html/websql_test.dart |
| @@ -0,0 +1,107 @@ |
| +#library('WebDBTest'); |
| +#import('../../pkg/unittest/unittest.dart'); |
| +#import('../../pkg/unittest/html_config.dart'); |
| +#import('dart:html'); |
| + |
| +void fail(message) { |
| + guardAsync(() { |
| + Expect.fail(message); |
| + }); |
| +} |
| + |
| +Future<SQLTransaction> createTransaction(Database db) { |
| + final completer = new Completer<SQLTransaction>(); |
| + |
| + db.transaction((SQLTransaction transaction) { |
| + completer.complete(transaction); |
| + }); |
| + |
| + return completer.future; |
| +} |
| + |
| +createTable(tableName, columnName) => (SQLTransaction transaction) { |
| + final completer = new Completer<SQLTransaction>(); |
| + |
| + final sql = 'CREATE TABLE $tableName ($columnName)'; |
| + transaction.executeSql(sql, [], (SQLTransaction tx, SQLResultSet rs) { |
| + completer.complete(transaction); |
| + }, (SQLTransaction tx, SQLError error) { |
| + fail(error.message); |
| + }); |
|
sra1
2012/08/23 17:52:39
Indentation of these things is tricky. The } shou
blois
2012/08/23 18:15:31
Done.
|
| + |
| + return completer.future; |
| +}; |
| + |
| +insert(tableName, columnName, value) => (SQLTransaction transaction) { |
| + final completer = new Completer<SQLTransaction>(); |
| + |
| + final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)'; |
| + transaction.executeSql(sql, [value], (SQLTransaction tx, SQLResultSet rs) { |
| + completer.complete(tx); |
| + }, (SQLTransaction tx, SQLError error) { |
| + fail(error.message); |
| + }); |
| + |
| + return completer.future; |
| +}; |
| + |
| +queryTable(tableName, callback) => (SQLTransaction transaction) { |
| + final completer = new Completer<SQLTransaction>(); |
| + |
| + final sql = 'SELECT * FROM $tableName'; |
| + transaction.executeSql(sql, [], (SQLTransaction tx, SQLResultSet rs) { |
| + callback(rs); |
| + completer.complete(tx); |
| + }, (SQLTransaction tx, SQLError error) { |
| + fail(error.message); |
| + }); |
| + |
| + return completer.future; |
| +}; |
| + |
| +dropTable(tableName, [bool ignoreFailure = false]) => |
| + (SQLTransaction transaction) { |
| + final completer = new Completer<SQLTransaction>(); |
| + |
| + final sql = 'DROP TABLE $tableName'; |
| + transaction.executeSql(sql, [], (SQLTransaction tx, SQLResultSet rs) { |
| + completer.complete(tx); |
| + }, (SQLTransaction tx, SQLError error) { |
| + if (ignoreFailure) { |
| + completer.complete(tx); |
| + } else { |
| + fail(error.message); |
| + } |
| + }); |
| + |
| + return completer.future; |
| +}; |
| + |
| +main() { |
| + useHtmlConfiguration(); |
| + |
| + test('Web Database', () { |
| + final tableName = 'test_table'; |
| + final columnName = 'test_data'; |
| + |
| + final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); |
| + |
| + Expect.isNotNull(db, 'Unable to open database'); |
| + |
| + createTransaction(db) |
| + // 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.
|
| + .chain(dropTable(tableName, true)) |
| + .chain(createTable(tableName, columnName)) |
| + .chain(insert(tableName, columnName, 'Some text data')) |
| + .chain(queryTable(tableName, (resultSet) { |
| + guardAsync(() { |
| + Expect.equals(1, resultSet.rows.length); |
| + |
| + // Should validate the rowData contents- need to be able to map the JS |
| + // object back to regular types. |
| + }); |
| + })) |
| + .chain(dropTable(tableName)) |
| + .then(expectAsync1((tx) {})); |
| + }); |
| +} |