Chromium Code Reviews| Index: pkg/dart_messages/test/parser_test.dart |
| diff --git a/pkg/dart_messages/test/parser_test.dart b/pkg/dart_messages/test/parser_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2809bac8ffae9be35333a812996462a5a367d626 |
| --- /dev/null |
| +++ b/pkg/dart_messages/test/parser_test.dart |
| @@ -0,0 +1,66 @@ |
| +import 'dart:async'; |
| +import 'dart:io'; |
| + |
| +Future testJsParser(serverUrl) async { |
| + String drt = "../../../client/tests/drt/content_shell"; |
|
Johnni Winther
2015/12/11 11:27:29
What is this? (I don't have a file at that locatio
floitsch
2015/12/14 18:56:41
The file is downloaded when running any test with
|
| + String drtPath = Platform.script.resolve(drt).toFilePath(); |
| + String testPage = "$serverUrl/test/parser_test.html"; |
| + print("running drt $testPage"); |
| + ProcessResult result = |
| + await Process.run(drtPath, ['--dump-render-tree', testPage]); |
| + if (!result.stdout.contains("SUCCESS") || result.stdout.contains("FAILED")) { |
| + throw "Test failed"; |
| + } |
| + print(result.stdout); |
| + print(result.stderr); |
| +} |
| + |
| +Uri pathOfData = Platform.script.resolve('../'); |
| + |
| +_sendNotFound(HttpResponse response) { |
| + response.statusCode = HttpStatus.NOT_FOUND; |
| + response.close(); |
| +} |
| + |
| +Future handleRequest(HttpRequest request) { |
| + final String path = request.uri.path.substring(1); |
| + final Uri requestPath = pathOfData.resolve(path); |
| + final File file = new File(requestPath.toFilePath()); |
| + print("serving $requestPath"); |
| + if (path.endsWith("html")) { |
| + request.response.headers.add('Content-Type', 'text/html'); |
| + } else if (path.endsWith("js")) { |
| + request.response.headers.add('Content-Type', 'application/javascript'); |
| + } |
| + return file.exists().then((bool found) { |
| + if (found) { |
| + file.openRead() |
| + .pipe(request.response) |
| + .catchError((e) { _sendNotFound(request.response); }); |
| + } else { |
| + _sendNotFound(request.response); |
| + } |
| + }); |
| +} |
| + |
| +serverRunning(HttpServer server, String scheme) async { |
| + int port = server.port; |
| + String serverUrl = "$scheme://127.0.0.1:$port"; |
| + |
| + server.listen(handleRequest); |
| + |
| + try { |
| + await testJsParser(serverUrl); |
| + } finally { |
| + server.close(); |
| + } |
| +} |
| + |
| +Future runServerAndTests() { |
| + return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0) |
| + .then((HttpServer server) => serverRunning(server, "http")); |
| +} |
| + |
| +main() { |
| + runServerAndTests(); |
| +} |