| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 library http_load_test; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:convert'; | |
| 9 import 'dart:io'; | |
| 10 | |
| 11 class Launcher { | |
| 12 /// Launch [executable] with [arguments]. Returns a [String] containing | |
| 13 /// the standard output from the launched executable. | |
| 14 static Future<String> launch(String executable, | |
| 15 List<String> arguments) async { | |
| 16 var process = await Process.start(executable, arguments); | |
| 17 | |
| 18 // Completer completes once the child process exits. | |
| 19 var completer = new Completer(); | |
| 20 String output = ''; | |
| 21 process.stdout.transform(UTF8.decoder) | |
| 22 .transform(new LineSplitter()).listen((line) { | |
| 23 output = '$output\n$line'; | |
| 24 print(line); | |
| 25 }); | |
| 26 process.stderr.transform(UTF8.decoder) | |
| 27 .transform(new LineSplitter()).listen((line) { | |
| 28 output = '$output\n$line'; | |
| 29 print(line); | |
| 30 }); | |
| 31 process.exitCode.then((ec) { | |
| 32 output = '$output\nEXIT_CODE=$ec\n'; | |
| 33 completer.complete(output); | |
| 34 }); | |
| 35 return completer.future; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 main(List<String> args) async { | |
| 40 var mojo_shell_executable = args[0]; | |
| 41 var directory = args[1]; | |
| 42 | |
| 43 HttpServer server = await HttpServer.bind('127.0.0.1', 0); | |
| 44 | |
| 45 server.listen((HttpRequest request) async { | |
| 46 final String path = request.uri.toFilePath(); | |
| 47 final File file = new File('${directory}/${path}'); | |
| 48 if (await file.exists()) { | |
| 49 try { | |
| 50 await file.openRead().pipe(request.response); | |
| 51 } catch (e) { | |
| 52 print(e); | |
| 53 } | |
| 54 } else { | |
| 55 request.response.statusCode = HttpStatus.NOT_FOUND; | |
| 56 request.response.close(); | |
| 57 } | |
| 58 }); | |
| 59 | |
| 60 var launchUrl = 'http://127.0.0.1:${server.port}/lib/main.dart'; | |
| 61 var output = await Launcher.launch(mojo_shell_executable, [launchUrl]); | |
| 62 | |
| 63 server.close(); | |
| 64 | |
| 65 if (output.contains("ERROR")) { | |
| 66 throw "test failed."; | |
| 67 } | |
| 68 if (!output.contains("\nEXIT_CODE=0\n")) { | |
| 69 throw "Test failed."; | |
| 70 } | |
| 71 if (!output.contains("\nPASS")) { | |
| 72 throw "Test failed."; | |
| 73 } | |
| 74 } | |
| OLD | NEW |