OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 import 'dart:async'; |
| 6 import 'dart:convert'; |
| 7 import 'dart:io'; |
| 8 |
| 9 import "package:args/args.dart"; |
| 10 import "package:path/path.dart" as path; |
| 11 import "package:test/test.dart"; |
| 12 |
| 13 void main(List<String> args) { |
| 14 final ArgParser parser = new ArgParser(); |
| 15 parser.addOption('mojo-shell', |
| 16 help: 'Path to the Mojo shell.'); |
| 17 final ArgResults results = parser.parse(args); |
| 18 final String shellPath = results['mojo-shell']; |
| 19 final List<String> devtoolsFlags = results.rest; |
| 20 |
| 21 test("Hello, .mojo!", () async { |
| 22 final String mojoUrl = 'http://core.mojoapps.io/dart_hello.mojo'; |
| 23 final List<String> args = new List.from(devtoolsFlags)..add(mojoUrl); |
| 24 final ProcessResult result = await Process.run(shellPath, args); |
| 25 expect(result.exitCode, equals(0)); |
| 26 expect(result.stdout.contains('Hello'), isTrue); |
| 27 expect(result.stdout.contains('World'), isTrue); |
| 28 }); |
| 29 |
| 30 test("Hello, .dart!", () async { |
| 31 final HttpServer server = await HttpServer.bind('127.0.0.1', 0); |
| 32 final String scriptOrigin = path.normalize( |
| 33 path.join(path.dirname(Platform.script.path), '..', '..')); |
| 34 final String packageOrigin = path.normalize( |
| 35 path.join(path.fromUri(Platform.packageRoot), '..')); |
| 36 |
| 37 server.listen((HttpRequest request) async { |
| 38 final String requestPath = request.uri.toFilePath(); |
| 39 |
| 40 String origin; |
| 41 if (requestPath.startsWith('/packages')) { |
| 42 origin = packageOrigin; |
| 43 } else { |
| 44 origin = scriptOrigin; |
| 45 } |
| 46 |
| 47 final String filePath = |
| 48 path.join(origin, path.relative(requestPath, from: '/'));; |
| 49 final File file = new File(filePath); |
| 50 if (await file.exists()) { |
| 51 try { |
| 52 await file.openRead().pipe(request.response); |
| 53 } catch (e) { |
| 54 print(e); |
| 55 } |
| 56 } else { |
| 57 request.response.statusCode = HttpStatus.NOT_FOUND; |
| 58 request.response.close(); |
| 59 } |
| 60 }); |
| 61 |
| 62 final String dartUrl = |
| 63 'http://127.0.0.1:${server.port}/hello/lib/main.dart'; |
| 64 |
| 65 final List<String> args = new List.from(devtoolsFlags)..add(dartUrl); |
| 66 final ProcessResult result = await Process.run(shellPath, args); |
| 67 expect(result.exitCode, equals(0)); |
| 68 expect(result.stdout.contains('Hello'), isTrue); |
| 69 expect(result.stdout.contains('World'), isTrue); |
| 70 server.close(); |
| 71 }); |
| 72 } |
OLD | NEW |