OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // VMOptions= |
| 5 // VMOptions=--short_socket_read |
| 6 // VMOptions=--short_socket_write |
| 7 // VMOptions=--short_socket_read --short_socket_write |
| 8 // |
| 9 // Test: |
| 10 // *) Launching a script fetched over HTTP. |
| 11 // *) Importing a library fetched over HTTP. |
| 12 // *) Automatically resolving package_root when script is fetched over HTTP. |
| 13 // *) Spawning a URI over HTTP. |
| 14 |
| 15 library http_launch_test; |
| 16 |
| 17 import 'dart:async'; |
| 18 import 'dart:io'; |
| 19 import 'package:expect/expect.dart'; |
| 20 |
| 21 String pathToExecutable = new Options().executable; |
| 22 String pathOfData = new File(new Options().script).directory.path + |
| 23 '/http_launch_data'; |
| 24 int port; |
| 25 |
| 26 _sendNotFound(HttpResponse response) { |
| 27 response.statusCode = HttpStatus.NOT_FOUND; |
| 28 response.close(); |
| 29 } |
| 30 |
| 31 handleRequest(HttpRequest request) { |
| 32 final String path = request.uri.path; |
| 33 final String requestPath = '$pathOfData$path'; |
| 34 final File file = new File(requestPath); |
| 35 file.exists().then((bool found) { |
| 36 if (found) { |
| 37 file.openRead() |
| 38 .pipe(request.response) |
| 39 .catchError((e) { _sendNotFound(request.response); }); |
| 40 } else { |
| 41 _sendNotFound(request.response); |
| 42 } |
| 43 }); |
| 44 } |
| 45 |
| 46 serverRunning(HttpServer server) { |
| 47 port = server.port; |
| 48 server.listen(handleRequest); |
| 49 Future<ProcessResult> no_http_run = |
| 50 Process.run(pathToExecutable, ['${pathOfData}/http_launch_main.dart']); |
| 51 Future<ProcessResult> http_run = |
| 52 Process.run(pathToExecutable, |
| 53 ['http://127.0.0.1:$port/http_launch_main.dart']); |
| 54 Future<ProcessResult> http_pkg_root_run = |
| 55 Process.run(pathToExecutable, |
| 56 ['--package-root=http://127.0.0.1:$port/packages/', |
| 57 'http://127.0.0.1:$port/http_launch_main.dart']); |
| 58 Future<ProcessResult> isolate_run = |
| 59 Process.run(pathToExecutable, |
| 60 ['http://127.0.0.1:$port/http_spawn_main.dart', '$port']); |
| 61 Future<List<ProcessResult>> results = Future.wait([no_http_run, http_run, |
| 62 http_pkg_root_run, |
| 63 isolate_run]); |
| 64 results.then((results) { |
| 65 // Close server. |
| 66 server.close(); |
| 67 // Check results. |
| 68 checkResults(results); |
| 69 }); |
| 70 } |
| 71 |
| 72 checkResults(List<ProcessResult> results) { |
| 73 Expect.equals(4, results.length); |
| 74 // Exited cleanly. |
| 75 for (int i = 0; i < results.length; i++) { |
| 76 ProcessResult result = results[i]; |
| 77 Expect.equals(0, result.exitCode); |
| 78 } |
| 79 String stdout = results[0].stdout; |
| 80 // Output is the string 'hello'. Use startsWith to avoid new line differences. |
| 81 Expect.isTrue(stdout.startsWith('hello')); |
| 82 // Same output from all three process runs. |
| 83 for (int i = 0; i < results.length; i++) { |
| 84 Expect.equals(stdout, results[i].stdout); |
| 85 } |
| 86 } |
| 87 |
| 88 main() { |
| 89 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning); |
| 90 } |
OLD | NEW |