| 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: | 5 // Test: |
| 6 // *) Compiling a script fetched over HTTP. | 6 // *) Compiling a script fetched over HTTP. |
| 7 // *) Importing a library fetched over HTTP. | 7 // *) Importing a library fetched over HTTP. |
| 8 // *) Automatically resolving package_root when script is fetched over HTTP. | 8 // *) Automatically resolving package_root when script is fetched over HTTP. |
| 9 | 9 |
| 10 library http_launch_test; | 10 library http_launch_test; |
| 11 | 11 |
| 12 import 'dart:async'; | 12 import 'dart:async'; |
| 13 import 'dart:io'; | 13 import 'dart:io'; |
| 14 import 'package:async_helper/async_helper.dart'; | 14 import 'package:async_helper/async_helper.dart'; |
| 15 import 'package:expect/expect.dart'; | 15 import 'package:expect/expect.dart'; |
| 16 import 'package:path/path.dart' as path; | 16 import 'package:path/path.dart' as path; |
| 17 | 17 |
| 18 Uri pathOfData = Platform.script.resolve('../http_launch_data/'); | 18 import '../launch_helper.dart' show launchDart2Js; |
| 19 |
| 20 Uri pathOfData = Platform.script.resolve('http_launch_data/'); |
| 19 Directory tempDir; | 21 Directory tempDir; |
| 20 String outFilePath; | 22 String outFilePath; |
| 21 | 23 |
| 22 _sendNotFound(HttpResponse response) { | 24 _sendNotFound(HttpResponse response) { |
| 23 response.statusCode = HttpStatus.NOT_FOUND; | 25 response.statusCode = HttpStatus.NOT_FOUND; |
| 24 response.close(); | 26 response.close(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 Future handleRequest(HttpRequest request) { | 29 Future handleRequest(HttpRequest request) { |
| 28 final String path = request.uri.path.substring(1); | 30 final String path = request.uri.path.substring(1); |
| 29 final Uri requestPath = pathOfData.resolve(path); | 31 final Uri requestPath = pathOfData.resolve(path); |
| 30 final File file = new File(requestPath.toFilePath()); | 32 final File file = new File(requestPath.toFilePath()); |
| 31 return file.exists().then((bool found) { | 33 return file.exists().then((bool found) { |
| 32 if (found) { | 34 if (found) { |
| 33 file.openRead() | 35 file.openRead() |
| 34 .pipe(request.response) | 36 .pipe(request.response) |
| 35 .catchError((e) { _sendNotFound(request.response); }); | 37 .catchError((e) { _sendNotFound(request.response); }); |
| 36 } else { | 38 } else { |
| 37 _sendNotFound(request.response); | 39 _sendNotFound(request.response); |
| 38 } | 40 } |
| 39 }); | 41 }); |
| 40 } | 42 } |
| 41 | 43 |
| 42 Future launchDart2Js(args) { | |
| 43 String ext = Platform.isWindows ? '.bat' : ''; | |
| 44 String command = | |
| 45 path.normalize(path.join(path.fromUri(Platform.script), | |
| 46 '../../../../../sdk/bin/dart2js${ext}')); | |
| 47 return Process.run(command, args); | |
| 48 } | |
| 49 | |
| 50 void check(ProcessResult result) { | 44 void check(ProcessResult result) { |
| 51 Expect.equals(0, result.exitCode); | 45 Expect.equals(0, result.exitCode); |
| 52 File outFile = new File(outFilePath); | 46 File outFile = new File(outFilePath); |
| 53 Expect.isTrue(outFile.existsSync()); | 47 Expect.isTrue(outFile.existsSync()); |
| 54 Expect.isTrue(outFile.readAsStringSync().contains("hello http tester")); | 48 Expect.isTrue(outFile.readAsStringSync().contains("hello http tester")); |
| 55 } | 49 } |
| 56 | 50 |
| 57 void checkNotFound(ProcessResult result, String filename) { | 51 void checkNotFound(ProcessResult result, String filename) { |
| 58 Expect.notEquals(0, result.exitCode); | 52 Expect.notEquals(0, result.exitCode); |
| 59 File outFile = new File(outFilePath); | 53 File outFile = new File(outFilePath); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 certificateName: 'localhost_cert') | 166 certificateName: 'localhost_cert') |
| 173 .then((HttpServer server) => serverRunning(server, "https")); | 167 .then((HttpServer server) => serverRunning(server, "https")); |
| 174 } | 168 } |
| 175 | 169 |
| 176 main() { | 170 main() { |
| 177 asyncStart(); | 171 asyncStart(); |
| 178 testHttp() | 172 testHttp() |
| 179 .then((_) => testHttps) | 173 .then((_) => testHttps) |
| 180 .whenComplete(asyncEnd); | 174 .whenComplete(asyncEnd); |
| 181 } | 175 } |
| OLD | NEW |