OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 #ifndef MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_ | |
6 #define MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_ | |
7 | |
8 #include "mojo/public/cpp/application/application_delegate.h" | |
9 #include "mojo/public/cpp/bindings/array.h" | |
10 #include "mojo/public/cpp/bindings/string.h" | |
11 #include "mojo/public/cpp/system/macros.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 namespace mojo { | |
15 | |
16 class ApplicationImpl; | |
17 | |
18 namespace test { | |
19 | |
20 // Access the command line arguments passed to the application test. | |
21 const Array<String>& Args(); | |
22 | |
23 // Run all application tests. This must be called after the environment is | |
24 // initialized, to support construction of a default run loop. | |
25 MojoResult RunAllTests(MojoHandle shell_handle); | |
26 | |
27 // A GTEST base class for application testing executed in mojo_shell. | |
28 class ApplicationTestBase : public testing::Test { | |
29 public: | |
30 ApplicationTestBase(); | |
31 ~ApplicationTestBase() override; | |
32 | |
33 protected: | |
34 ApplicationImpl* application_impl() { return application_impl_; } | |
35 | |
36 // Get the ApplicationDelegate for the application to be tested. | |
37 virtual ApplicationDelegate* GetApplicationDelegate(); | |
38 | |
39 // A testing::Test::SetUp helper to override the application command | |
40 // line arguments. | |
41 void SetUpWithArgs(const Array<String>& args); | |
42 | |
43 // testing::Test: | |
44 void SetUp() override; | |
45 void TearDown() override; | |
46 | |
47 // True by default, which indicates a MessageLoop will automatically be | |
48 // created for the application. Tests may override this function to prevent | |
49 // a default loop from being created. | |
50 virtual bool ShouldCreateDefaultRunLoop(); | |
51 | |
52 private: | |
53 // The application implementation instance, reconstructed for each test. | |
54 ApplicationImpl* application_impl_; | |
55 // The application delegate used if GetApplicationDelegate is not overridden. | |
56 ApplicationDelegate default_application_delegate_; | |
57 | |
58 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase); | |
59 }; | |
60 | |
61 } // namespace test | |
62 | |
63 } // namespace mojo | |
64 | |
65 #endif // MOJO_PUBLIC_CPP_APPLICATION_APPLICATION_TEST_BASE_H_ | |
OLD | NEW |