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 apptest; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'mojo:application'; |
| 9 import 'mojo:bindings'; |
| 10 import 'mojo:core'; |
| 11 |
| 12 // Import and reexport the unittest package. We are a *.dartzip file designed to |
| 13 // be linked into your_apptest.mojo file and are your main entrypoint. |
| 14 import 'package:unittest/unittest.dart'; |
| 15 export 'package:unittest/unittest.dart'; |
| 16 |
| 17 // This class is an application that does nothing but tears down the connections |
| 18 // between each test. |
| 19 class _ConnectionToShellApplication extends Application { |
| 20 List<Function> testFunctions; |
| 21 |
| 22 _ConnectionToShellApplication.fromHandle(MojoHandle handle, |
| 23 this.testFunctions) |
| 24 : super.fromHandle(handle); |
| 25 |
| 26 // Only run the test suite passed in once we have received an initialize() |
| 27 // call from the shell. We need to first have a valid connection to the shell |
| 28 // so that apptests can connect to other applications. |
| 29 void initialize(List<String> args, String url) { |
| 30 for (var fun in testFunctions) { |
| 31 fun(this); |
| 32 } |
| 33 } |
| 34 } |
| 35 |
| 36 // A configuration which properly shuts down our application at the end. |
| 37 class _CleanShutdownConfiguration extends SimpleConfiguration { |
| 38 _ConnectionToShellApplication _application; |
| 39 |
| 40 _CleanShutdownConfiguration(this._application) : super() {} |
| 41 |
| 42 void onTestResult(TestCase externalTestCase) { |
| 43 super.onTestResult(externalTestCase); |
| 44 _application.resetConnections(); |
| 45 } |
| 46 |
| 47 void onDone(bool success) { |
| 48 _application.close(); |
| 49 super.onDone(success); |
| 50 } |
| 51 } |
| 52 |
| 53 // The public interface to apptests. |
| 54 // |
| 55 // In a dart mojo application, |incoming_handle| is args[0]. |testFunction| is a |
| 56 // list of functions that actually contains your testing code, and will pass |
| 57 // back an application to each of them. |
| 58 runAppTests(var incoming_handle, List<Function> testFunction) { |
| 59 MojoHandle appHandle = new MojoHandle(incoming_handle); |
| 60 var application = |
| 61 new _ConnectionToShellApplication.fromHandle(appHandle, testFunction); |
| 62 unittestConfiguration = new _CleanShutdownConfiguration(application); |
| 63 } |
OLD | NEW |