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

Unified Diff: test/browser_http_test.dart

Issue 1612003002: Add browser-compatible version. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Made test run Created 4 years, 11 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 | « pubspec.yaml ('k') | test/loader_data_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/browser_http_test.dart
diff --git a/test/browser_http_test.dart b/test/browser_http_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..ecec6801100dcecefc831b67e85175cfc4153f49
--- /dev/null
+++ b/test/browser_http_test.dart
@@ -0,0 +1,56 @@
+// 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.
+
+@TestOn("browser")
+
+import "dart:async";
+import "dart:convert";
+
+import "package:resource/browser_resource.dart";
+import "package:test/test.dart";
+
+const content = "Rødgrød med fløde";
+
+main() {
+ // Assume test files located next to Uri.base.
+ // This is how "pub run test" currently works.
+
+ test("Default encoding", () async {
+ var loader = ResourceLoader.defaultLoader;
+ // The HTTPXmlRequest loader defaults to UTF-8 encoding.
+ var uri = Uri.base.resolve("testfile-utf8.txt");
+ String string = await loader.readAsString(uri);
+ expect(string, content);
+ });
+
+ test("Latin-1 encoding", () async {
+ var loader = ResourceLoader.defaultLoader;
+ var uri = Uri.base.resolve("testfile-latin1.txt");
+ String string = await loader.readAsString(uri, encoding: LATIN1);
+ expect(string, content);
+ });
+
+ test("UTF-8 encoding", () async {
+ var loader = ResourceLoader.defaultLoader;
+ var uri = Uri.base.resolve("testfile-utf8.txt");
+ String string = await loader.readAsString(uri, encoding: UTF8);
+ expect(string, content);
+ });
+
+ test("bytes", () async {
+ var loader = ResourceLoader.defaultLoader;
+ var uri = Uri.base.resolve("testfile-latin1.txt");
+ List<int> bytes = await loader.readAsBytes(uri);
+ expect(bytes, content.codeUnits);
+ });
+
+ test("byte stream", () async {
+ var loader = ResourceLoader.defaultLoader;
+ var uri = Uri.base.resolve("testfile-latin1.txt");
+ Stream<List<int>> bytes = loader.openRead(uri);
+ var buffer = [];
+ await bytes.forEach(buffer.addAll);
+ expect(buffer, content.codeUnits);
+ });
+}
« no previous file with comments | « pubspec.yaml ('k') | test/loader_data_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698