| 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 Uri pathOfData = Platform.script.resolve('../http_launch_data/'); |
| 19 Directory tempDir; | 19 Directory tempDir; |
| 20 String outFilePath; | 20 String outFilePath; |
| 21 | 21 |
| 22 _sendNotFound(HttpResponse response) { | 22 _sendNotFound(HttpResponse response) { |
| 23 response.statusCode = HttpStatus.NOT_FOUND; | 23 response.statusCode = HttpStatus.NOT_FOUND; |
| 24 response.close(); | 24 response.close(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 Future handleRequest(HttpRequest request) { | 27 Future handleRequest(HttpRequest request) { |
| 28 final String path = request.uri.path.substring(1); | 28 final String path = request.uri.path.substring(1); |
| 29 final Uri requestPath = pathOfData.resolve(path); | 29 final Uri requestPath = pathOfData.resolve(path); |
| 30 final File file = new File(requestPath.toFilePath()); | 30 final File file = new File(requestPath.toFilePath()); |
| 31 return file.exists().then((bool found) { | 31 return file.exists().then((bool found) { |
| 32 if (found) { | 32 if (found) { |
| 33 file.openRead() | 33 file.openRead() |
| 34 .pipe(request.response) | 34 .pipe(request.response) |
| 35 .catchError((e) { _sendNotFound(request.response); }); | 35 .catchError((e) { _sendNotFound(request.response); }); |
| 36 } else { | 36 } else { |
| 37 _sendNotFound(request.response); | 37 _sendNotFound(request.response); |
| 38 } | 38 } |
| 39 }); | 39 }); |
| 40 } | 40 } |
| 41 | 41 |
| 42 Future launchDart2Js(args) { | 42 Future launchDart2Js(args) { |
| 43 String ext = Platform.isWindows ? '.bat' : ''; | 43 String ext = Platform.isWindows ? '.bat' : ''; |
| 44 String command = | 44 String command = |
| 45 path.normalize(path.join(path.fromUri(Platform.script), | 45 path.normalize(path.join(path.fromUri(Platform.script), |
| 46 '../../../../sdk/bin/dart2js${ext}')); | 46 '../../../../../sdk/bin/dart2js${ext}')); |
| 47 return Process.run(command, args); | 47 return Process.run(command, args); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void check(ProcessResult result) { | 50 void check(ProcessResult result) { |
| 51 Expect.equals(0, result.exitCode); | 51 Expect.equals(0, result.exitCode); |
| 52 File outFile = new File(outFilePath); | 52 File outFile = new File(outFilePath); |
| 53 Expect.isTrue(outFile.existsSync()); | 53 Expect.isTrue(outFile.existsSync()); |
| 54 Expect.isTrue(outFile.readAsStringSync().contains("hello http tester")); | 54 Expect.isTrue(outFile.readAsStringSync().contains("hello http tester")); |
| 55 } | 55 } |
| 56 | 56 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 certificateName: 'localhost_cert') | 172 certificateName: 'localhost_cert') |
| 173 .then((HttpServer server) => serverRunning(server, "https")); | 173 .then((HttpServer server) => serverRunning(server, "https")); |
| 174 } | 174 } |
| 175 | 175 |
| 176 main() { | 176 main() { |
| 177 asyncStart(); | 177 asyncStart(); |
| 178 testHttp() | 178 testHttp() |
| 179 .then((_) => testHttps) | 179 .then((_) => testHttps) |
| 180 .whenComplete(asyncEnd); | 180 .whenComplete(asyncEnd); |
| 181 } | 181 } |
| OLD | NEW |