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

Side by Side Diff: tests/compiler/dart2js/library_resolution_test.dart

Issue 2897903003: Support loading binary data in dart2js (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// Check that relative URIs are resolved against the canonical name of a 5 /// Check that relative URIs are resolved against the canonical name of a
6 /// library. This only matters for dart:-libraries, so this test mocks up two 6 /// library. This only matters for dart:-libraries, so this test mocks up two
7 /// dart:-libraries. 7 /// dart:-libraries.
8 8
9 import "dart:io"; 9 import "dart:io";
10 10
11 import "dart:async"; 11 import "dart:async";
12 12
13 import "memory_source_file_helper.dart"; 13 import "memory_source_file_helper.dart";
14 14
15 import "package:async_helper/async_helper.dart"; 15 import "package:async_helper/async_helper.dart";
16 16
17 import 'package:expect/expect.dart' show Expect; 17 import 'package:expect/expect.dart' show Expect;
18 18
19 import 'package:compiler/compiler_new.dart';
20
19 import 'package:compiler/src/diagnostics/messages.dart' 21 import 'package:compiler/src/diagnostics/messages.dart'
20 show MessageKind, MessageTemplate; 22 show MessageKind, MessageTemplate;
21 23
22 import 'package:compiler/src/elements/elements.dart' show LibraryElement;
23
24 import 'package:compiler/src/library_loader.dart' show LoadedLibraries; 24 import 'package:compiler/src/library_loader.dart' show LoadedLibraries;
25 25
26 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput; 26 import 'package:compiler/src/null_compiler_output.dart' show NullCompilerOutput;
27 27
28 import 'package:compiler/src/old_to_new_api.dart' 28 import 'package:compiler/src/old_to_new_api.dart'
29 show LegacyCompilerDiagnostics, LegacyCompilerInput; 29 show LegacyCompilerDiagnostics, LegacyCompilerInput;
30 import 'package:compiler/src/options.dart' show CompilerOptions; 30 import 'package:compiler/src/options.dart' show CompilerOptions;
31 31
32 Uri sdkRoot = Uri.base.resolve("sdk/"); 32 Uri sdkRoot = Uri.base.resolve("sdk/");
33 Uri mock1LibraryUri = sdkRoot.resolve("lib/mock1.dart"); 33 Uri mock1LibraryUri = sdkRoot.resolve("lib/mock1.dart");
34 Uri mock2LibraryUri = sdkRoot.resolve("lib/mock2.dart"); 34 Uri mock2LibraryUri = sdkRoot.resolve("lib/mock2.dart");
35 35
36 class CustomCompiler extends CompilerImpl { 36 class CustomCompiler extends CompilerImpl {
37 CustomCompiler(provider, handler, libraryRoot, packageConfig) 37 CustomCompiler(provider, handler, libraryRoot, packageConfig)
38 : super( 38 : super(
39 provider, 39 provider,
40 const NullCompilerOutput(), 40 const NullCompilerOutput(),
41 handler, 41 handler,
42 new CompilerOptions( 42 new CompilerOptions(
43 libraryRoot: libraryRoot, packageConfig: packageConfig)); 43 libraryRoot: libraryRoot, packageConfig: packageConfig));
44 } 44 }
45 45
46 main() async { 46 main() async {
47 Uri packageConfig = Uri.base.resolve('.packages'); 47 Uri packageConfig = Uri.base.resolve('.packages');
48 48
49 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES); 49 var provider = new MemorySourceFileProvider(MEMORY_SOURCE_FILES);
50 var handler = new FormattingDiagnosticHandler(provider); 50 var handler = new FormattingDiagnosticHandler(provider);
51 51
52 Future wrappedProvider(Uri uri) { 52 Future wrappedProvider(Uri uri) async {
53 if (uri == mock1LibraryUri) { 53 if (uri == mock1LibraryUri) {
54 return provider.readUtf8BytesFromUri(Uri.parse('memory:mock1.dart')); 54 return (await provider.readBytesFromUri(
Siggi Cherem (dart-lang) 2017/05/22 22:21:36 nit, how about just updating 'uri' instead and cal
Johnni Winther 2017/05/23 08:43:15 Done.
55 Uri.parse('memory:mock1.dart'), InputKind.utf8))
56 .data;
55 } 57 }
56 if (uri == mock2LibraryUri) { 58 if (uri == mock2LibraryUri) {
57 return provider.readUtf8BytesFromUri(Uri.parse('memory:mock2.dart')); 59 return (await provider.readBytesFromUri(
60 Uri.parse('memory:mock2.dart'), InputKind.utf8))
61 .data;
58 } 62 }
59 return provider.readUtf8BytesFromUri(uri); 63 return (await provider.readBytesFromUri(uri, InputKind.utf8)).data;
60 } 64 }
61 65
62 String expectedMessage = MessageTemplate 66 String expectedMessage = MessageTemplate
63 .TEMPLATES[MessageKind.LIBRARY_NOT_FOUND] 67 .TEMPLATES[MessageKind.LIBRARY_NOT_FOUND]
64 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage(); 68 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage();
65 69
66 int actualMessageCount = 0; 70 int actualMessageCount = 0;
67 71
68 wrappedHandler(Uri uri, int begin, int end, String message, kind) { 72 wrappedHandler(Uri uri, int begin, int end, String message, kind) {
69 if (message == expectedMessage) { 73 if (message == expectedMessage) {
(...skipping 21 matching lines...) Expand all
91 var libraries = 95 var libraries =
92 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")); 96 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1"));
93 await checkLibraries(libraries); 97 await checkLibraries(libraries);
94 asyncSuccess(null); 98 asyncSuccess(null);
95 } 99 }
96 100
97 const Map MEMORY_SOURCE_FILES = const { 101 const Map MEMORY_SOURCE_FILES = const {
98 "mock1.dart": "library mock1; import 'mock2.dart';", 102 "mock1.dart": "library mock1; import 'mock2.dart';",
99 "mock2.dart": "library mock2;", 103 "mock2.dart": "library mock2;",
100 }; 104 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698