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

Unified Diff: mojo/dart/http_load_test/tester.dart

Issue 1262493002: Enable HTTP loading in Mojo dart content handler (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/dart/http_load_test/runner.py ('k') | mojo/tools/get_test_list.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/http_load_test/tester.dart
diff --git a/mojo/dart/http_load_test/tester.dart b/mojo/dart/http_load_test/tester.dart
new file mode 100644
index 0000000000000000000000000000000000000000..70eb61bc1fb285a826f3cf59a4a3df697ae334e2
--- /dev/null
+++ b/mojo/dart/http_load_test/tester.dart
@@ -0,0 +1,70 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+library http_load_test;
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io';
+
+class Launcher {
+ /// Launch [executable] with [arguments]. Returns a [String] containing
+ /// the standard output from the launched executable.
+ static Future<String> launch(String executable,
+ List<String> arguments) async {
+ var process = await Process.start(executable, arguments);
+
+ // Completer completes once the child process exits.
+ var completer = new Completer();
+ String stdout = '';
+ process.stdout.transform(UTF8.decoder)
+ .transform(new LineSplitter()).listen((line) {
+ stdout = '$stdout\n$line';
+ print(line);
+ });
+ process.stderr.transform(UTF8.decoder)
+ .transform(new LineSplitter()).listen((line) {
+ print(line);
+ });
+ process.exitCode.then((ec) {
+ stdout = '$stdout\nEXIT_CODE=$ec\n';
+ completer.complete(stdout);
+ });
+ return completer.future;
+ }
+}
+
+main(List<String> args) async {
+ var mojo_shell_executable = args[0];
+ var directory = args[1];
+
+ HttpServer server = await HttpServer.bind('127.0.0.1', 0);
+
+ server.listen((HttpRequest request) async {
+ final String path = request.uri.toFilePath();
+ final File file = new File('${directory}/${path}');
+ if (await file.exists()) {
+ try {
+ await file.openRead().pipe(request.response);
+ } catch (e) {
+ print(e);
+ }
+ } else {
+ request.response.statusCode = HttpStatus.NOT_FOUND;
+ request.response.close();
+ }
+ });
+
+ var launchUrl = 'http://127.0.0.1:${server.port}/main.dart';
+ var stdout = await Launcher.launch(mojo_shell_executable, [launchUrl]);
+
+ server.close();
+
+ if (!stdout.contains("\nPASS")) {
+ throw "Test failed.";
+ }
+ if (!stdout.contains("\nEXIT_CODE=0\n")) {
+ throw "Test failed.";
+ }
+}
« no previous file with comments | « mojo/dart/http_load_test/runner.py ('k') | mojo/tools/get_test_list.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698