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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/html/html.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..7eff4dfd2b77fb7ad76f11dff062b8fb8dc21db7
--- /dev/null
+++ b/tests/html/websql_test.dart
@@ -0,0 +1,116 @@
+#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);
+ });
+
+ 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.
+ .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) {}));
+ });
+}
« 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