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