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 // VMOptions= | 4 // VMOptions= |
5 // VMOptions=--short_socket_read | 5 // VMOptions=--short_socket_read |
6 // VMOptions=--short_socket_write | 6 // VMOptions=--short_socket_write |
7 // VMOptions=--short_socket_read --short_socket_write | 7 // VMOptions=--short_socket_read --short_socket_write |
8 // | 8 // |
9 // Test: | 9 // Test: |
10 // *) Launching a script fetched over HTTP. | 10 // *) Launching a script fetched over HTTP. |
11 // *) Importing a library fetched over HTTP. | 11 // *) Importing a library fetched over HTTP. |
12 // *) Automatically resolving package_root when script is fetched over HTTP. | 12 // *) Automatically resolving package_root when script is fetched over HTTP. |
13 // *) Spawning a URI over HTTP. | 13 // *) Spawning a URI over HTTP. |
14 | 14 |
15 library http_launch_test; | 15 library http_launch_test; |
16 | 16 |
17 import 'dart:async'; | 17 import 'dart:async'; |
18 import 'dart:io'; | 18 import 'dart:io'; |
19 import 'package:expect/expect.dart'; | 19 import 'package:expect/expect.dart'; |
20 | 20 |
21 String pathToExecutable = Platform.executable; | 21 String pathToExecutable = Platform.executable; |
22 Uri pathOfData = Platform.script.resolve('http_launch_data/'); | 22 String pathOfData = new File(Platform.script).parent.path + |
| 23 '/http_launch_data'; |
23 int port; | 24 int port; |
24 | 25 |
25 _sendNotFound(HttpResponse response) { | 26 _sendNotFound(HttpResponse response) { |
26 response.statusCode = HttpStatus.NOT_FOUND; | 27 response.statusCode = HttpStatus.NOT_FOUND; |
27 response.close(); | 28 response.close(); |
28 } | 29 } |
29 | 30 |
30 handleRequest(HttpRequest request) { | 31 handleRequest(HttpRequest request) { |
31 final String path = request.uri.path.substring(1); | 32 final String path = request.uri.path; |
32 final Uri requestPath = pathOfData.resolve(path); | 33 final String requestPath = '$pathOfData$path'; |
33 final File file = new File(requestPath.toFilePath()); | 34 final File file = new File(requestPath); |
34 file.exists().then((bool found) { | 35 file.exists().then((bool found) { |
35 if (found) { | 36 if (found) { |
36 file.openRead() | 37 file.openRead() |
37 .pipe(request.response) | 38 .pipe(request.response) |
38 .catchError((e) { _sendNotFound(request.response); }); | 39 .catchError((e) { _sendNotFound(request.response); }); |
39 } else { | 40 } else { |
40 _sendNotFound(request.response); | 41 _sendNotFound(request.response); |
41 } | 42 } |
42 }); | 43 }); |
43 } | 44 } |
44 | 45 |
45 serverRunning(HttpServer server) { | 46 serverRunning(HttpServer server) { |
46 port = server.port; | 47 port = server.port; |
47 server.listen(handleRequest); | 48 server.listen(handleRequest); |
48 Future<ProcessResult> no_http_run = | 49 Future<ProcessResult> no_http_run = |
49 Process.run(pathToExecutable, | 50 Process.run(pathToExecutable, ['${pathOfData}/http_launch_main.dart']); |
50 [pathOfData.resolve('http_launch_main.dart').toFilePath()]); | |
51 Future<ProcessResult> http_run = | 51 Future<ProcessResult> http_run = |
52 Process.run(pathToExecutable, | 52 Process.run(pathToExecutable, |
53 ['http://127.0.0.1:$port/http_launch_main.dart']); | 53 ['http://127.0.0.1:$port/http_launch_main.dart']); |
54 Future<ProcessResult> http_pkg_root_run = | 54 Future<ProcessResult> http_pkg_root_run = |
55 Process.run(pathToExecutable, | 55 Process.run(pathToExecutable, |
56 ['--package-root=http://127.0.0.1:$port/packages/', | 56 ['--package-root=http://127.0.0.1:$port/packages/', |
57 'http://127.0.0.1:$port/http_launch_main.dart']); | 57 'http://127.0.0.1:$port/http_launch_main.dart']); |
58 Future<ProcessResult> isolate_run = | 58 Future<ProcessResult> isolate_run = |
59 Process.run(pathToExecutable, | 59 Process.run(pathToExecutable, |
60 ['http://127.0.0.1:$port/http_spawn_main.dart', '$port']); | 60 ['http://127.0.0.1:$port/http_spawn_main.dart', '$port']); |
(...skipping 20 matching lines...) Expand all Loading... |
81 Expect.isTrue(stdout.startsWith('hello')); | 81 Expect.isTrue(stdout.startsWith('hello')); |
82 // Same output from all three process runs. | 82 // Same output from all three process runs. |
83 for (int i = 0; i < results.length; i++) { | 83 for (int i = 0; i < results.length; i++) { |
84 Expect.equals(stdout, results[i].stdout); | 84 Expect.equals(stdout, results[i].stdout); |
85 } | 85 } |
86 } | 86 } |
87 | 87 |
88 main() { | 88 main() { |
89 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning); | 89 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0).then(serverRunning); |
90 } | 90 } |
OLD | NEW |