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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « test/loader_http_test.dart ('k') | tool/travis.sh » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "dart:async" show Future, Stream;
6 import "dart:isolate" show Isolate;
7 import "dart:convert" show Encoding, ASCII;
8 import "package:package_config/packages.dart";
9 import "package:package_config/discovery.dart";
10 import "package:resource/resource.dart";
11 import "package:test/test.dart";
12
13 main() {
14 pkguri(path) => new Uri(scheme: "package", path: path);
15
16 Future<Uri> resolve(Uri source) async {
17 if (source.scheme == "package") {
18 return Isolate.resolvePackageUri(source);
19 }
20 return Uri.base.resolveUri(source);
21 }
22
23 group("loading", () {
24 testLoad(Uri uri) async {
25 LogLoader loader = new LogLoader();
26 var resource = new Resource(uri, loader: loader);
27 var res = await resource.openRead().toList();
28 var resolved = await resolve(uri);
29 expect(res, [[0, 0, 0]]);
30 res = await resource.readAsBytes();
31 expect(res, [0, 0, 0]);
32 res = await resource.readAsString(encoding: ASCII);
33 expect(res, "\x00\x00\x00");
34
35 expect(loader.requests, [["Stream", resolved],
36 ["Bytes", resolved],
37 ["String", resolved, ASCII]]);
38 }
39
40 test("load package: URIs", () async {
41 await testLoad(pkguri("foo/bar/baz"));
42 await testLoad(pkguri("bar/foo/baz"));
43 });
44 test("load non-pkgUri", () async {
45 await testLoad(Uri.parse("file://localhost/something?x#y"));
46 await testLoad(Uri.parse("http://auth/something?x#y"));
47 await testLoad(Uri.parse("https://auth/something?x#y"));
48 await testLoad(Uri.parse("data:,something?x"));
49 await testLoad(Uri.parse("unknown:/something"));
50 });
51 });
52 }
53
54
55 class LogLoader implements ResourceLoader {
56 final List requests = [];
57 void reset() { requests.clear(); }
58 Stream<List<int>> openRead(Uri uri) async* {
59 requests.add(["Stream", uri]);
60 yield [0x00, 0x00, 0x00];
61 }
62 Future<List<int>> readAsBytes(Uri uri) async {
63 requests.add(["Bytes", uri]);
64 return [0x00, 0x00, 0x00];
65 }
66 Future<String> readAsString(Uri uri, {Encoding encoding}) async {
67 requests.add(["String", uri, encoding]);
68 return "\x00\x00\x00";
69 }
70 }
OLDNEW
« 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