Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: tests/standalone/http_launch_test.dart

Issue 53313007: Change dart:io Platform.script to return a URI. Change all uses of Platform.script to work with th… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix dom.py docs Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 String pathOfData = new File(Platform.script).parent.path + 22 Uri pathOfData = Platform.script.resolve('http_launch_data/');
23 '/http_launch_data';
24 int port; 23 int port;
25 24
26 _sendNotFound(HttpResponse response) { 25 _sendNotFound(HttpResponse response) {
27 response.statusCode = HttpStatus.NOT_FOUND; 26 response.statusCode = HttpStatus.NOT_FOUND;
28 response.close(); 27 response.close();
29 } 28 }
30 29
31 handleRequest(HttpRequest request) { 30 handleRequest(HttpRequest request) {
32 final String path = request.uri.path; 31 final String path = request.uri.path.substring(1);
33 final String requestPath = '$pathOfData$path'; 32 final Uri requestPath = pathOfData.resolve(path);
34 final File file = new File(requestPath); 33 final File file = new File(requestPath.toFilePath());
35 file.exists().then((bool found) { 34 file.exists().then((bool found) {
36 if (found) { 35 if (found) {
37 file.openRead() 36 file.openRead()
38 .pipe(request.response) 37 .pipe(request.response)
39 .catchError((e) { _sendNotFound(request.response); }); 38 .catchError((e) { _sendNotFound(request.response); });
40 } else { 39 } else {
41 _sendNotFound(request.response); 40 _sendNotFound(request.response);
42 } 41 }
43 }); 42 });
44 } 43 }
45 44
46 serverRunning(HttpServer server) { 45 serverRunning(HttpServer server) {
47 port = server.port; 46 port = server.port;
48 server.listen(handleRequest); 47 server.listen(handleRequest);
49 Future<ProcessResult> no_http_run = 48 Future<ProcessResult> no_http_run =
50 Process.run(pathToExecutable, ['${pathOfData}/http_launch_main.dart']); 49 Process.run(pathToExecutable,
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698