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