| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
| 10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 // Both lib1 and lib2 import lib3 directly and | 112 // Both lib1 and lib2 import lib3 directly and |
| 113 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should | 113 // both use lib3.foo3. Therefore a shared output unit for lib1 and lib2 should |
| 114 // be created. | 114 // be created. |
| 115 // | 115 // |
| 116 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2 | 116 // lib1 and lib2 also import lib4 deferred, but lib1 uses lib4.bar1 and lib2 |
| 117 // uses lib4.bar2. So two output units should be created for lib4, one for each | 117 // uses lib4.bar2. So two output units should be created for lib4, one for each |
| 118 // import. | 118 // import. |
| 119 const Map MEMORY_SOURCE_FILES = const { | 119 const Map MEMORY_SOURCE_FILES = const { |
| 120 "main.dart":""" | 120 "main.dart":""" |
| 121 import "dart:async"; | 121 import "dart:async"; |
| 122 @def_main_1 import 'lib1.dart' as l1; | 122 import 'lib1.dart' deferred as lib1; |
| 123 @def_main_2 import 'lib2.dart' as l2; | 123 import 'lib2.dart' deferred as lib2; |
| 124 | |
| 125 const def_main_1 = const DeferredLibrary("lib1"); | |
| 126 const def_main_2 = const DeferredLibrary("lib2"); | |
| 127 | 124 |
| 128 void main() { | 125 void main() { |
| 129 def_main_1.load().then((_) { | 126 lib1.loadLibrary().then((_) { |
| 130 l1.foo1(); | 127 lib1.foo1(); |
| 131 new l1.C(); | 128 new lib1.C(); |
| 132 def_main_2.load().then((_) { | 129 lib2.loadLibrary().then((_) { |
| 133 l2.foo2(); | 130 lib2.foo2(); |
| 134 }); | 131 }); |
| 135 }); | 132 }); |
| 136 } | 133 } |
| 137 """, | 134 """, |
| 138 "lib1.dart":""" | 135 "lib1.dart":""" |
| 139 library lib1; | 136 library lib1; |
| 140 import "dart:async"; | 137 import "dart:async"; |
| 141 import "dart:html"; | 138 import "dart:html"; |
| 142 | 139 |
| 143 import "lib3.dart" as l3; | 140 import "lib3.dart" as l3; |
| 144 @def_1_1 import "lib4.dart" as l4; | 141 import "lib4.dart" deferred as lib4_1; |
| 145 | |
| 146 const def_1_1 = const DeferredLibrary("lib4_1"); | |
| 147 | 142 |
| 148 class C {} | 143 class C {} |
| 149 | 144 |
| 150 foo1() { | 145 foo1() { |
| 151 new InputElement(); | 146 new InputElement(); |
| 152 def_1_1.load().then((_) { | 147 lib4_1.loadLibrary().then((_) { |
| 153 l4.bar1(); | 148 lib4_1.bar1(); |
| 154 }); | 149 }); |
| 155 return () {return 1 + l3.foo3();} (); | 150 return () {return 1 + l3.foo3();} (); |
| 156 } | 151 } |
| 157 """, | 152 """, |
| 158 "lib2.dart":""" | 153 "lib2.dart":""" |
| 159 library lib2; | 154 library lib2; |
| 160 import "dart:async"; | 155 import "dart:async"; |
| 161 import "lib3.dart" as l3; | 156 import "lib3.dart" as l3; |
| 162 @def_2_1 import "lib4.dart" as l4; | 157 import "lib4.dart" deferred as lib4_2; |
| 163 | |
| 164 const def_2_1 = const DeferredLibrary("lib4_2"); | |
| 165 | 158 |
| 166 foo2() { | 159 foo2() { |
| 167 def_2_1.load().then((_) { | 160 lib4_2.loadLibrary().then((_) { |
| 168 l4.bar2(); | 161 lib4_2.bar2(); |
| 169 }); | 162 }); |
| 170 return () {return 2+l3.foo3();} (); | 163 return () {return 2+l3.foo3();} (); |
| 171 } | 164 } |
| 172 """, | 165 """, |
| 173 "lib3.dart":""" | 166 "lib3.dart":""" |
| 174 library lib3; | 167 library lib3; |
| 175 | 168 |
| 176 foo3() { | 169 foo3() { |
| 177 return () {return 3;} (); | 170 return () {return 3;} (); |
| 178 } | 171 } |
| 179 """, | 172 """, |
| 180 "lib4.dart":""" | 173 "lib4.dart":""" |
| 181 library lib4; | 174 library lib4; |
| 182 | 175 |
| 183 bar1() { | 176 bar1() { |
| 184 return "hello"; | 177 return "hello"; |
| 185 } | 178 } |
| 186 | 179 |
| 187 bar2() { | 180 bar2() { |
| 188 return 2; | 181 return 2; |
| 189 } | 182 } |
| 190 """, | 183 """, |
| 191 }; | 184 }; |
| OLD | NEW |