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

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

Issue 2897903003: Support loading binary data in dart2js (Closed)
Patch Set: Updated cf. comments 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 uri = Uri.parse('memory:mock1.dart');
55 } 55 }
56 if (uri == mock2LibraryUri) { 56 if (uri == mock2LibraryUri) {
57 return provider.readUtf8BytesFromUri(Uri.parse('memory:mock2.dart')); 57 uri = Uri.parse('memory:mock2.dart');
58 } 58 }
59 return provider.readUtf8BytesFromUri(uri); 59 Input input = await provider.readBytesFromUri(uri, InputKind.utf8);
60 return input.data;
60 } 61 }
61 62
62 String expectedMessage = MessageTemplate 63 String expectedMessage = MessageTemplate
63 .TEMPLATES[MessageKind.LIBRARY_NOT_FOUND] 64 .TEMPLATES[MessageKind.LIBRARY_NOT_FOUND]
64 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage(); 65 .message({'resolvedUri': 'dart:mock2.dart'}).computeMessage();
65 66
66 int actualMessageCount = 0; 67 int actualMessageCount = 0;
67 68
68 wrappedHandler(Uri uri, int begin, int end, String message, kind) { 69 wrappedHandler(Uri uri, int begin, int end, String message, kind) {
69 if (message == expectedMessage) { 70 if (message == expectedMessage) {
(...skipping 21 matching lines...) Expand all
91 var libraries = 92 var libraries =
92 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1")); 93 await compiler.libraryLoader.loadLibrary(Uri.parse("dart:m_o_c_k_1"));
93 await checkLibraries(libraries); 94 await checkLibraries(libraries);
94 asyncSuccess(null); 95 asyncSuccess(null);
95 } 96 }
96 97
97 const Map MEMORY_SOURCE_FILES = const { 98 const Map MEMORY_SOURCE_FILES = const {
98 "mock1.dart": "library mock1; import 'mock2.dart';", 99 "mock1.dart": "library mock1; import 'mock2.dart';",
99 "mock2.dart": "library mock2;", 100 "mock2.dart": "library mock2;",
100 }; 101 };
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/library_env_test.dart ('k') | tests/compiler/dart2js/memory_source_file_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698