| OLD | NEW |
| 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 // Test of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
| 6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
| 7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:async_helper/async_helper.dart'; | 11 import 'package:async_helper/async_helper.dart'; |
| 12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
| 13 import 'package:compiler/src/compiler.dart' as dart2js; | |
| 14 | 13 |
| 15 Future runTest(String mainScript, test) async { | 14 Future runTest(String mainScript, test) async { |
| 16 CompilationResult result = await runCompiler( | 15 CompilationResult result = await runCompiler( |
| 17 entryPoint: Uri.parse(mainScript), | 16 entryPoint: Uri.parse(mainScript), |
| 18 memorySourceFiles: MEMORY_SOURCE_FILES); | 17 memorySourceFiles: MEMORY_SOURCE_FILES); |
| 19 test(result.compiler); | 18 test(result.compiler); |
| 20 } | 19 } |
| 21 | 20 |
| 22 lookupLibrary(compiler, name) { | 21 lookupLibrary(compiler, name) { |
| 23 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 22 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); | 67 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); |
| 69 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); | 68 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); |
| 70 }); | 69 }); |
| 71 await runTest('memory:main4.dart', (compiler) { | 70 await runTest('memory:main4.dart', (compiler) { |
| 72 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; | 71 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
| 73 Expect.isNotNull(main, "Could not find 'main'"); | 72 Expect.isNotNull(main, "Could not find 'main'"); |
| 74 compiler.deferredLoadTask.onResolutionComplete( | 73 compiler.deferredLoadTask.onResolutionComplete( |
| 75 main, compiler.resolutionWorldBuilder.closedWorldForTesting); | 74 main, compiler.resolutionWorldBuilder.closedWorldForTesting); |
| 76 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 75 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
| 77 | 76 |
| 78 var mainLib = lookupLibrary(compiler, "memory:main4.dart"); | 77 lookupLibrary(compiler, "memory:main4.dart"); |
| 79 var lib4 = lookupLibrary(compiler, "memory:lib4.dart"); | 78 lookupLibrary(compiler, "memory:lib4.dart"); |
| 80 var lib5 = lookupLibrary(compiler, "memory:lib5.dart"); | 79 var lib5 = lookupLibrary(compiler, "memory:lib5.dart"); |
| 81 var lib6 = lookupLibrary(compiler, "memory:lib6.dart"); | 80 var lib6 = lookupLibrary(compiler, "memory:lib6.dart"); |
| 82 var foo5 = lib5.find("foo"); | 81 var foo5 = lib5.find("foo"); |
| 83 var foo6 = lib6.find("foo"); | 82 var foo6 = lib6.find("foo"); |
| 84 | 83 |
| 85 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo5)); | 84 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo5)); |
| 86 Expect.equals(outputUnitForElement(foo5), outputUnitForElement(foo6)); | 85 Expect.equals(outputUnitForElement(foo5), outputUnitForElement(foo6)); |
| 87 }); | 86 }); |
| 88 } | 87 } |
| 89 | 88 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 library lib5; | 194 library lib5; |
| 196 | 195 |
| 197 foo() {} | 196 foo() {} |
| 198 """, | 197 """, |
| 199 "lib6.dart": """ | 198 "lib6.dart": """ |
| 200 library lib6; | 199 library lib6; |
| 201 | 200 |
| 202 foo() {} | 201 foo() {} |
| 203 """, | 202 """, |
| 204 }; | 203 }; |
| OLD | NEW |