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_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ | 5 #ifndef MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ |
6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ | 6 #define MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.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/shell/public/cpp/application_delegate.h" | 12 #include "mojo/shell/public/cpp/application_delegate.h" |
| 13 #include "mojo/shell/public/cpp/application_impl.h" |
13 #include "mojo/shell/public/interfaces/application.mojom.h" | 14 #include "mojo/shell/public/interfaces/application.mojom.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace mojo { | 17 namespace mojo { |
17 | 18 |
18 class ApplicationImpl; | 19 class ApplicationImpl; |
19 | 20 |
20 namespace test { | 21 namespace test { |
21 | 22 |
22 // Run all application tests. This must be called after the environment is | 23 // Run all application tests. This must be called after the environment is |
23 // initialized, to support construction of a default run loop. | 24 // initialized, to support construction of a default run loop. |
24 MojoResult RunAllTests(MojoHandle application_request_handle); | 25 MojoResult RunAllTests(MojoHandle application_request_handle); |
25 | 26 |
26 // Used to configure the ApplicationImpl. This is used internally by | 27 // Used to configure the ApplicationImpl. This is used internally by |
27 // ApplicationTestBase, but useful if you do not want to subclass | 28 // ApplicationTestBase, but useful if you do not want to subclass |
28 // ApplicationTestBase. | 29 // ApplicationTestBase. |
29 class TestHelper { | 30 class TestHelper { |
30 public: | 31 public: |
31 explicit TestHelper(ApplicationDelegate* delegate); | 32 explicit TestHelper(ApplicationDelegate* delegate); |
32 ~TestHelper(); | 33 ~TestHelper(); |
33 | 34 |
34 ApplicationImpl* application_impl() { return application_impl_.get(); } | 35 Shell* shell() { return application_impl_.get(); } |
| 36 std::string shell_url() { return url_; } |
35 | 37 |
36 private: | 38 private: |
37 // The application delegate used if GetApplicationDelegate is not overridden. | 39 // The application delegate used if GetApplicationDelegate is not overridden. |
38 ApplicationDelegate default_application_delegate_; | 40 ApplicationDelegate default_application_delegate_; |
39 | 41 |
40 // The application implementation instance, reconstructed for each test. | 42 // The application implementation instance, reconstructed for each test. |
41 scoped_ptr<ApplicationImpl> application_impl_; | 43 scoped_ptr<ApplicationImpl> application_impl_; |
42 | 44 |
| 45 std::string url_; |
| 46 |
43 MOJO_DISALLOW_COPY_AND_ASSIGN(TestHelper); | 47 MOJO_DISALLOW_COPY_AND_ASSIGN(TestHelper); |
44 }; | 48 }; |
45 | 49 |
46 // A GTEST base class for application testing executed in mojo_shell. | 50 // A GTEST base class for application testing executed in mojo_shell. |
47 class ApplicationTestBase : public testing::Test { | 51 class ApplicationTestBase : public testing::Test { |
48 public: | 52 public: |
49 ApplicationTestBase(); | 53 ApplicationTestBase(); |
50 ~ApplicationTestBase() override; | 54 ~ApplicationTestBase() override; |
51 | 55 |
52 protected: | 56 protected: |
53 ApplicationImpl* application_impl() { | 57 Shell* shell() { |
54 return test_helper_ ? test_helper_->application_impl() : nullptr; | 58 return test_helper_ ? test_helper_->shell() : nullptr; |
| 59 } |
| 60 std::string shell_url() const { |
| 61 return test_helper_ ? test_helper_->shell_url() : std::string(); |
55 } | 62 } |
56 | 63 |
57 // Get the ApplicationDelegate for the application to be tested. | 64 // Get the ApplicationDelegate for the application to be tested. |
58 virtual ApplicationDelegate* GetApplicationDelegate(); | 65 virtual ApplicationDelegate* GetApplicationDelegate(); |
59 | 66 |
60 // testing::Test: | 67 // testing::Test: |
61 void SetUp() override; | 68 void SetUp() override; |
62 void TearDown() override; | 69 void TearDown() override; |
63 | 70 |
64 // True by default, which indicates a MessageLoop will automatically be | 71 // True by default, which indicates a MessageLoop will automatically be |
65 // created for the application. Tests may override this function to prevent | 72 // created for the application. Tests may override this function to prevent |
66 // a default loop from being created. | 73 // a default loop from being created. |
67 virtual bool ShouldCreateDefaultRunLoop(); | 74 virtual bool ShouldCreateDefaultRunLoop(); |
68 | 75 |
69 private: | 76 private: |
70 scoped_ptr<TestHelper> test_helper_; | 77 scoped_ptr<TestHelper> test_helper_; |
71 | 78 |
72 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase); | 79 MOJO_DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase); |
73 }; | 80 }; |
74 | 81 |
75 } // namespace test | 82 } // namespace test |
76 | 83 |
77 } // namespace mojo | 84 } // namespace mojo |
78 | 85 |
79 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ | 86 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ |
OLD | NEW |