| OLD | NEW |
| 1 library WebDBTest; | 1 library WebDBTest; |
| 2 import '../../pkg/unittest/lib/unittest.dart'; | 2 import '../../pkg/unittest/lib/unittest.dart'; |
| 3 import '../../pkg/unittest/lib/html_config.dart'; | 3 import '../../pkg/unittest/lib/html_config.dart'; |
| 4 import 'dart:html'; | 4 import 'dart:html'; |
| 5 | 5 |
| 6 void fail(message) { | 6 void fail(message) { |
| 7 guardAsync(() { | 7 guardAsync(() { |
| 8 expect(false, isTrue, reason: message); | 8 expect(false, isTrue, reason: message); |
| 9 }); | 9 }); |
| 10 } | 10 } |
| 11 | 11 |
| 12 Future<SQLTransaction> createTransaction(Database db) { | 12 Future<SqlTransaction> createTransaction(Database db) { |
| 13 final completer = new Completer<SQLTransaction>(); | 13 final completer = new Completer<SqlTransaction>(); |
| 14 | 14 |
| 15 db.transaction((SQLTransaction transaction) { | 15 db.transaction((SqlTransaction transaction) { |
| 16 completer.complete(transaction); | 16 completer.complete(transaction); |
| 17 }); | 17 }); |
| 18 | 18 |
| 19 return completer.future; | 19 return completer.future; |
| 20 } | 20 } |
| 21 | 21 |
| 22 createTable(tableName, columnName) => (SQLTransaction transaction) { | 22 createTable(tableName, columnName) => (SqlTransaction transaction) { |
| 23 final completer = new Completer<SQLTransaction>(); | 23 final completer = new Completer<SqlTransaction>(); |
| 24 | 24 |
| 25 final sql = 'CREATE TABLE $tableName ($columnName)'; | 25 final sql = 'CREATE TABLE $tableName ($columnName)'; |
| 26 transaction.executeSql(sql, [], | 26 transaction.executeSql(sql, [], |
| 27 (SQLTransaction tx, SQLResultSet rs) { | 27 (SqlTransaction tx, SqlResultSet rs) { |
| 28 completer.complete(transaction); | 28 completer.complete(transaction); |
| 29 }, | 29 }, |
| 30 (SQLTransaction tx, SQLError error) { | 30 (SqlTransaction tx, SqlError error) { |
| 31 fail(error.message); | 31 fail(error.message); |
| 32 }); | 32 }); |
| 33 | 33 |
| 34 return completer.future; | 34 return completer.future; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 insert(tableName, columnName, value) => (SQLTransaction transaction) { | 37 insert(tableName, columnName, value) => (SqlTransaction transaction) { |
| 38 final completer = new Completer<SQLTransaction>(); | 38 final completer = new Completer<SqlTransaction>(); |
| 39 | 39 |
| 40 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)'; | 40 final sql = 'INSERT INTO $tableName ($columnName) VALUES (?)'; |
| 41 transaction.executeSql(sql, [value], | 41 transaction.executeSql(sql, [value], |
| 42 (SQLTransaction tx, SQLResultSet rs) { | 42 (SqlTransaction tx, SqlResultSet rs) { |
| 43 completer.complete(tx); | 43 completer.complete(tx); |
| 44 }, | 44 }, |
| 45 (SQLTransaction tx, SQLError error) { | 45 (SqlTransaction tx, SqlError error) { |
| 46 fail(error.message); | 46 fail(error.message); |
| 47 }); | 47 }); |
| 48 | 48 |
| 49 return completer.future; | 49 return completer.future; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 queryTable(tableName, callback) => (SQLTransaction transaction) { | 52 queryTable(tableName, callback) => (SqlTransaction transaction) { |
| 53 final completer = new Completer<SQLTransaction>(); | 53 final completer = new Completer<SqlTransaction>(); |
| 54 | 54 |
| 55 final sql = 'SELECT * FROM $tableName'; | 55 final sql = 'SELECT * FROM $tableName'; |
| 56 transaction.executeSql(sql, [], | 56 transaction.executeSql(sql, [], |
| 57 (SQLTransaction tx, SQLResultSet rs) { | 57 (SqlTransaction tx, SqlResultSet rs) { |
| 58 callback(rs); | 58 callback(rs); |
| 59 completer.complete(tx); | 59 completer.complete(tx); |
| 60 }, | 60 }, |
| 61 (SQLTransaction tx, SQLError error) { | 61 (SqlTransaction tx, SqlError error) { |
| 62 fail(error.message); | 62 fail(error.message); |
| 63 }); | 63 }); |
| 64 | 64 |
| 65 return completer.future; | 65 return completer.future; |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 dropTable(tableName, [bool ignoreFailure = false]) => | 68 dropTable(tableName, [bool ignoreFailure = false]) => |
| 69 (SQLTransaction transaction) { | 69 (SqlTransaction transaction) { |
| 70 final completer = new Completer<SQLTransaction>(); | 70 final completer = new Completer<SqlTransaction>(); |
| 71 | 71 |
| 72 final sql = 'DROP TABLE $tableName'; | 72 final sql = 'DROP TABLE $tableName'; |
| 73 transaction.executeSql(sql, [], | 73 transaction.executeSql(sql, [], |
| 74 (SQLTransaction tx, SQLResultSet rs) { | 74 (SqlTransaction tx, SqlResultSet rs) { |
| 75 completer.complete(tx); | 75 completer.complete(tx); |
| 76 }, | 76 }, |
| 77 (SQLTransaction tx, SQLError error) { | 77 (SqlTransaction tx, SqlError error) { |
| 78 if (ignoreFailure) { | 78 if (ignoreFailure) { |
| 79 completer.complete(tx); | 79 completer.complete(tx); |
| 80 } else { | 80 } else { |
| 81 fail(error.message); | 81 fail(error.message); |
| 82 } | 82 } |
| 83 }); | 83 }); |
| 84 | 84 |
| 85 return completer.future; | 85 return completer.future; |
| 86 }; | 86 }; |
| 87 | 87 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 107 expect(resultSet.rows.length, 1); | 107 expect(resultSet.rows.length, 1); |
| 108 var row = resultSet.rows.item(0); | 108 var row = resultSet.rows.item(0); |
| 109 expect(row.containsKey(columnName), isTrue); | 109 expect(row.containsKey(columnName), isTrue); |
| 110 expect(row[columnName], 'Some text data'); | 110 expect(row[columnName], 'Some text data'); |
| 111 }); | 111 }); |
| 112 })) | 112 })) |
| 113 .chain(dropTable(tableName)) | 113 .chain(dropTable(tableName)) |
| 114 .then(expectAsync1((tx) {})); | 114 .then(expectAsync1((tx) {})); |
| 115 }); | 115 }); |
| 116 } | 116 } |
| OLD | NEW |