| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // Used to configure the ShellConnection. This is used internally by | 28 // Used to configure the ShellConnection. This is used internally by |
| 29 // ApplicationTestBase, but useful if you do not want to subclass | 29 // ApplicationTestBase, but useful if you do not want to subclass |
| 30 // ApplicationTestBase. | 30 // ApplicationTestBase. |
| 31 class TestHelper { | 31 class TestHelper { |
| 32 public: | 32 public: |
| 33 explicit TestHelper(ShellClient* client); | 33 explicit TestHelper(ShellClient* client); |
| 34 ~TestHelper(); | 34 ~TestHelper(); |
| 35 | 35 |
| 36 Connector* connector() { return shell_connection_->connector(); } | 36 Connector* connector() { return shell_connection_->connector(); } |
| 37 std::string test_name() { return name_; } | 37 const std::string& test_name() { return name_; } |
| 38 const std::string& test_userid() { return userid_; } |
| 38 uint32_t test_instance_id() { return instance_id_; } | 39 uint32_t test_instance_id() { return instance_id_; } |
| 39 uint32_t test_userid() { return userid_; } | |
| 40 | 40 |
| 41 private: | 41 private: |
| 42 // The application delegate used if GetShellClient is not overridden. | 42 // The application delegate used if GetShellClient is not overridden. |
| 43 ShellClient default_shell_client_; | 43 ShellClient default_shell_client_; |
| 44 | 44 |
| 45 // The application implementation instance, reconstructed for each test. | 45 // The application implementation instance, reconstructed for each test. |
| 46 scoped_ptr<ShellConnection> shell_connection_; | 46 scoped_ptr<ShellConnection> shell_connection_; |
| 47 | 47 |
| 48 std::string name_; | 48 std::string name_; |
| 49 std::string userid_; |
| 49 uint32_t instance_id_; | 50 uint32_t instance_id_; |
| 50 uint32_t userid_; | |
| 51 | 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(TestHelper); | 52 DISALLOW_COPY_AND_ASSIGN(TestHelper); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 // A GTEST base class for application testing executed in mojo_shell. | 55 // A GTEST base class for application testing executed in mojo_shell. |
| 56 class ApplicationTestBase : public testing::Test { | 56 class ApplicationTestBase : public testing::Test { |
| 57 public: | 57 public: |
| 58 ApplicationTestBase(); | 58 ApplicationTestBase(); |
| 59 ~ApplicationTestBase() override; | 59 ~ApplicationTestBase() override; |
| 60 | 60 |
| 61 protected: | 61 protected: |
| 62 Connector* connector() { | 62 Connector* connector() { |
| 63 return test_helper_ ? test_helper_->connector() : nullptr; | 63 return test_helper_ ? test_helper_->connector() : nullptr; |
| 64 } | 64 } |
| 65 std::string test_name() const { | 65 const std::string& test_name() const { |
| 66 return test_helper_ ? test_helper_->test_name() : std::string(); | 66 return test_helper_ ? test_helper_->test_name() : empty_; |
| 67 } |
| 68 const std::string& test_userid() const { |
| 69 return test_helper_ ? test_helper_->test_userid() : inherit_user_id_; |
| 67 } | 70 } |
| 68 uint32_t test_instance_id() const { | 71 uint32_t test_instance_id() const { |
| 69 return test_helper_ ? test_helper_->test_instance_id() : | 72 return test_helper_ ? test_helper_->test_instance_id() : |
| 70 shell::mojom::Connector::kInvalidApplicationID; | 73 shell::mojom::Connector::kInvalidApplicationID; |
| 71 } | 74 } |
| 72 uint32_t test_userid() const { | |
| 73 return test_helper_ ? test_helper_->test_userid() : | |
| 74 shell::mojom::Connector::kUserInherit; | |
| 75 } | |
| 76 | 75 |
| 77 // Get the ShellClient for the application to be tested. | 76 // Get the ShellClient for the application to be tested. |
| 78 virtual ShellClient* GetShellClient(); | 77 virtual ShellClient* GetShellClient(); |
| 79 | 78 |
| 80 // testing::Test: | 79 // testing::Test: |
| 81 void SetUp() override; | 80 void SetUp() override; |
| 82 void TearDown() override; | 81 void TearDown() override; |
| 83 | 82 |
| 84 // True by default, which indicates a MessageLoop will automatically be | 83 // True by default, which indicates a MessageLoop will automatically be |
| 85 // created for the application. Tests may override this function to prevent | 84 // created for the application. Tests may override this function to prevent |
| 86 // a default loop from being created. | 85 // a default loop from being created. |
| 87 virtual bool ShouldCreateDefaultRunLoop(); | 86 virtual bool ShouldCreateDefaultRunLoop(); |
| 88 | 87 |
| 89 private: | 88 private: |
| 90 scoped_ptr<TestHelper> test_helper_; | 89 scoped_ptr<TestHelper> test_helper_; |
| 90 std::string empty_; |
| 91 std::string inherit_user_id_ = shell::mojom::kInheritUserID; |
| 91 | 92 |
| 92 DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase); | 93 DISALLOW_COPY_AND_ASSIGN(ApplicationTestBase); |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 } // namespace test | 96 } // namespace test |
| 96 | 97 |
| 97 } // namespace mojo | 98 } // namespace mojo |
| 98 | 99 |
| 99 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ | 100 #endif // MOJO_SHELL_PUBLIC_CPP_APPLICATION_TEST_BASE_H_ |
| OLD | NEW |