OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 import "package:async_helper/async_helper.dart"; | 6 import "package:async_helper/async_helper.dart"; |
7 | 7 |
8 // All three libraries have an HttpRequest class. | 8 // All three libraries have an HttpRequest class. |
9 import "conditional_import_test.dart" | 9 import "conditional_import_test.dart" |
10 if (dart.library.io) "dart:io" | 10 if (dart.library.io) "dart:io" |
11 if (dart.library.html) "dart:html" | 11 if (dart.library.html) "dart:html" deferred as d show HttpRequest; |
12 deferred as d show HttpRequest; | |
13 | 12 |
14 class HttpRequest {} | 13 class HttpRequest {} |
15 | 14 |
16 void main() { | 15 void main() { |
17 asyncStart(); | 16 asyncStart(); |
18 var io = const bool.fromEnvironment("dart.library.io"); | 17 var io = const bool.fromEnvironment("dart.library.io"); |
19 var html = const bool.fromEnvironment("dart.library.html"); | 18 var html = const bool.fromEnvironment("dart.library.html"); |
20 () async { | 19 () async { |
21 // Shouldn't fail. Shouldn't time out. | 20 // Shouldn't fail. Shouldn't time out. |
22 await d.loadLibrary().timeout(const Duration(seconds: 5)); | 21 await d.loadLibrary().timeout(const Duration(seconds: 5)); |
23 if (io) { | 22 if (io) { |
24 print("io"); | 23 print("io"); |
25 Expect.throws(() => new d.HttpRequest()); // Class is abstract in dart:io | 24 Expect.throws(() => new d.HttpRequest()); // Class is abstract in dart:io |
26 } else if (html) { | 25 } else if (html) { |
27 print("html"); | 26 print("html"); |
28 dynamic r = new d.HttpRequest(); // Shouldn't throw | 27 dynamic r = new d.HttpRequest(); // Shouldn't throw |
29 var o = r.open; // Shouldn't fail, the open method is there. | 28 var o = r.open; // Shouldn't fail, the open method is there. |
30 } else { | 29 } else { |
31 print("none"); | 30 print("none"); |
32 dynamic r = new d.HttpRequest(); | 31 dynamic r = new d.HttpRequest(); |
33 Expect.isTrue(r is HttpRequest); | 32 Expect.isTrue(r is HttpRequest); |
34 } | 33 } |
35 asyncEnd(); | 34 asyncEnd(); |
36 }(); | 35 }(); |
37 } | 36 } |
38 | |
OLD | NEW |