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