Index: tests/html/resource_http_test.dart |
diff --git a/tests/html/resource_http_test.dart b/tests/html/resource_http_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..44631a64ba22278cd68a995465040d2d68083032 |
--- /dev/null |
+++ b/tests/html/resource_http_test.dart |
@@ -0,0 +1,47 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library resource_http_test; |
+import 'dart:convert'; |
+import 'package:unittest/html_individual_config.dart'; |
+import 'package:unittest/unittest.dart'; |
+ |
+main() { |
+ useHtmlIndividualConfiguration(); |
+ // Cache blocker is a workaround for: |
+ // https://code.google.com/p/dart/issues/detail?id=11834 |
+ var cacheBlocker = new DateTime.now().millisecondsSinceEpoch; |
+ var url = '/root_dart/tests/html/xhr_cross_origin_data.txt?' |
Siggi Cherem (dart-lang)
2015/08/25 00:43:27
let's use a new data file specific for this test,
Harry Terkelsen
2015/08/25 17:45:06
Done.
|
+ 'cacheBlock=$cacheBlocker'; |
+ |
+ void validateResponse(d) { |
+ var data = JSON.decode(d); |
Siggi Cherem (dart-lang)
2015/08/25 00:43:27
then this could be a simple string equality check
Harry Terkelsen
2015/08/25 17:45:06
Done.
|
+ expect(data, contains('feed')); |
+ expect(data['feed'], contains('entry')); |
+ expect(data, isMap); |
+ } |
+ |
+ group('resource', () { |
+ test('readAsString', () { |
+ Resource r = new Resource(url); |
+ r.readAsString().then(expectAsync((s) { |
Siggi Cherem (dart-lang)
2015/08/25 00:43:27
either use await or return the future to ensure we
Harry Terkelsen
2015/08/25 17:45:06
Done.
|
+ validateResponse(s); |
+ })); |
+ }); |
+ test('readAsBytes', () { |
+ Resource r = new Resource(url); |
+ r.readAsBytes().then(expectAsync((b) { |
Siggi Cherem (dart-lang)
2015/08/25 00:43:27
ditto
Harry Terkelsen
2015/08/25 17:45:06
Done.
|
+ validateResponse(new String.fromCharCodes(b)); |
+ })); |
+ }); |
+ test('openRead', () async { |
+ Resource r = new Resource(url); |
+ var bytes = []; |
+ await for (var b in r.openRead()) { |
+ bytes.addAll(b); |
+ } |
+ validateResponse(new String.fromCharCodes(bytes)); |
+ }); |
+ }); |
+} |