| 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_individual_config.dart'; | 3 import '../../pkg/unittest/lib/html_individual_config.dart'; |
| 4 import 'dart:async'; | 4 import 'dart:async'; |
| 5 import 'dart:html'; | 5 import 'dart:html'; |
| 6 import 'dart:web_sql'; |
| 6 | 7 |
| 7 void fail(message) { | 8 void fail(message) { |
| 8 guardAsync(() { | 9 guardAsync(() { |
| 9 expect(false, isTrue, reason: message); | 10 expect(false, isTrue, reason: message); |
| 10 }); | 11 }); |
| 11 } | 12 } |
| 12 | 13 |
| 13 Future<SqlTransaction> createTransaction(Database db) { | 14 Future<SqlTransaction> createTransaction(SqlDatabase db) { |
| 14 final completer = new Completer<SqlTransaction>(); | 15 final completer = new Completer<SqlTransaction>(); |
| 15 | 16 |
| 16 db.transaction((SqlTransaction transaction) { | 17 db.transaction((SqlTransaction transaction) { |
| 17 completer.complete(transaction); | 18 completer.complete(transaction); |
| 18 }); | 19 }); |
| 19 | 20 |
| 20 return completer.future; | 21 return completer.future; |
| 21 } | 22 } |
| 22 | 23 |
| 23 createTable(tableName, columnName) => (SqlTransaction transaction) { | 24 createTable(tableName, columnName) => (SqlTransaction transaction) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 }); | 85 }); |
| 85 | 86 |
| 86 return completer.future; | 87 return completer.future; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 main() { | 90 main() { |
| 90 useHtmlIndividualConfiguration(); | 91 useHtmlIndividualConfiguration(); |
| 91 | 92 |
| 92 group('supported', () { | 93 group('supported', () { |
| 93 test('supported', () { | 94 test('supported', () { |
| 94 expect(Database.supported, true); | 95 expect(SqlDatabase.supported, true); |
| 95 }); | 96 }); |
| 96 }); | 97 }); |
| 97 | 98 |
| 98 group('functional', () { | 99 group('functional', () { |
| 99 test('unsupported throws', () { | 100 test('unsupported throws', () { |
| 100 var expectation = Database.supported ? returnsNormally : throws; | 101 var expectation = SqlDatabase.supported ? returnsNormally : throws; |
| 101 expect(() { | 102 expect(() { |
| 102 window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); | 103 window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); |
| 103 }, expectation); | 104 }, expectation); |
| 104 | 105 |
| 105 }); | 106 }); |
| 106 test('Web Database', () { | 107 test('Web Database', () { |
| 107 // Skip if not supported. | 108 // Skip if not supported. |
| 108 if (!Database.supported) { | 109 if (!SqlDatabase.supported) { |
| 109 return; | 110 return; |
| 110 } | 111 } |
| 111 | 112 |
| 112 final tableName = 'test_table'; | 113 final tableName = 'test_table'; |
| 113 final columnName = 'test_data'; | 114 final columnName = 'test_data'; |
| 114 | 115 |
| 115 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); | 116 final db = window.openDatabase('test_db', '1.0', 'test_db', 1024 * 1024); |
| 116 | 117 |
| 117 expect(db, isNotNull, reason: 'Unable to open database'); | 118 expect(db, isNotNull, reason: 'Unable to open database'); |
| 118 | 119 |
| 119 createTransaction(db) | 120 createTransaction(db) |
| 120 // Attempt to clear out any tables which may be lurking from previous | 121 // Attempt to clear out any tables which may be lurking from previous |
| 121 // runs. | 122 // runs. |
| 122 .then(dropTable(tableName, true)) | 123 .then(dropTable(tableName, true)) |
| 123 .then(createTable(tableName, columnName)) | 124 .then(createTable(tableName, columnName)) |
| 124 .then(insert(tableName, columnName, 'Some text data')) | 125 .then(insert(tableName, columnName, 'Some text data')) |
| 125 .then(queryTable(tableName, (resultSet) { | 126 .then(queryTable(tableName, (resultSet) { |
| 126 guardAsync(() { | 127 guardAsync(() { |
| 127 expect(resultSet.rows.length, 1); | 128 expect(resultSet.rows.length, 1); |
| 128 var row = resultSet.rows.item(0); | 129 var row = resultSet.rows.item(0); |
| 129 expect(row.containsKey(columnName), isTrue); | 130 expect(row.containsKey(columnName), isTrue); |
| 130 expect(row[columnName], 'Some text data'); | 131 expect(row[columnName], 'Some text data'); |
| 131 }); | 132 }); |
| 132 })) | 133 })) |
| 133 .then(dropTable(tableName)) | 134 .then(dropTable(tableName)) |
| 134 .then(expectAsync1((tx) {})); | 135 .then(expectAsync1((tx) {})); |
| 135 }); | 136 }); |
| 136 }); | 137 }); |
| 137 } | 138 } |
| OLD | NEW |