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

Unified Diff: test/resource_test.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Address comments. 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 | « test/loader_http_test.dart ('k') | tool/travis.sh » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/resource_test.dart
diff --git a/test/resource_test.dart b/test/resource_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..f5f2345c1e5125fcf270888ccf5c1c9054d74e4c
--- /dev/null
+++ b/test/resource_test.dart
@@ -0,0 +1,70 @@
+// 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.
+
+import "dart:async" show Future, Stream;
+import "dart:isolate" show Isolate;
+import "dart:convert" show Encoding, ASCII;
+import "package:package_config/packages.dart";
+import "package:package_config/discovery.dart";
+import "package:resource/resource.dart";
+import "package:test/test.dart";
+
+main() {
+ pkguri(path) => new Uri(scheme: "package", path: path);
+
+ Future<Uri> resolve(Uri source) async {
+ if (source.scheme == "package") {
+ return Isolate.resolvePackageUri(source);
+ }
+ return Uri.base.resolveUri(source);
+ }
+
+ group("loading", () {
+ testLoad(Uri uri) async {
+ LogLoader loader = new LogLoader();
+ var resource = new Resource(uri, loader: loader);
+ var res = await resource.openRead().toList();
+ var resolved = await resolve(uri);
+ expect(res, [[0, 0, 0]]);
+ res = await resource.readAsBytes();
+ expect(res, [0, 0, 0]);
+ res = await resource.readAsString(encoding: ASCII);
+ expect(res, "\x00\x00\x00");
+
+ expect(loader.requests, [["Stream", resolved],
+ ["Bytes", resolved],
+ ["String", resolved, ASCII]]);
+ }
+
+ test("load package: URIs", () async {
+ await testLoad(pkguri("foo/bar/baz"));
+ await testLoad(pkguri("bar/foo/baz"));
+ });
+ test("load non-pkgUri", () async {
+ await testLoad(Uri.parse("file://localhost/something?x#y"));
+ await testLoad(Uri.parse("http://auth/something?x#y"));
+ await testLoad(Uri.parse("https://auth/something?x#y"));
+ await testLoad(Uri.parse("data:,something?x"));
+ await testLoad(Uri.parse("unknown:/something"));
+ });
+ });
+}
+
+
+class LogLoader implements ResourceLoader {
+ final List requests = [];
+ void reset() { requests.clear(); }
+ Stream<List<int>> openRead(Uri uri) async* {
+ requests.add(["Stream", uri]);
+ yield [0x00, 0x00, 0x00];
+ }
+ Future<List<int>> readAsBytes(Uri uri) async {
+ requests.add(["Bytes", uri]);
+ return [0x00, 0x00, 0x00];
+ }
+ Future<String> readAsString(Uri uri, {Encoding encoding}) async {
+ requests.add(["String", uri, encoding]);
+ return "\x00\x00\x00";
+ }
+}
« no previous file with comments | « test/loader_http_test.dart ('k') | tool/travis.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698