| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ | 5 #ifndef SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ |
| 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ | 6 #define SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/test/scoped_task_environment.h" |
| 11 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
| 12 #include "services/service_manager/public/cpp/service.h" | 13 #include "services/service_manager/public/cpp/service.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class MessageLoop; | |
| 17 class Thread; | 17 class Thread; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace mojo { | 20 namespace mojo { |
| 21 namespace edk { | 21 namespace edk { |
| 22 class ScopedIPCSupport; | 22 class ScopedIPCSupport; |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 namespace service_manager { | 26 namespace service_manager { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const std::string& test_name() const { return initialize_name_; } | 73 const std::string& test_name() const { return initialize_name_; } |
| 74 const std::string& test_userid() const { return initialize_userid_; } | 74 const std::string& test_userid() const { return initialize_userid_; } |
| 75 uint32_t test_instance_id() const { return initialize_instance_id_; } | 75 uint32_t test_instance_id() const { return initialize_instance_id_; } |
| 76 | 76 |
| 77 // By default, creates a simple Service that captures the metadata sent | 77 // By default, creates a simple Service that captures the metadata sent |
| 78 // via OnStart(). Override to customize, but custom implementations must | 78 // via OnStart(). Override to customize, but custom implementations must |
| 79 // call OnStartCalled() to forward the metadata so test_name() etc all | 79 // call OnStartCalled() to forward the metadata so test_name() etc all |
| 80 // work. | 80 // work. |
| 81 virtual std::unique_ptr<Service> CreateService(); | 81 virtual std::unique_ptr<Service> CreateService(); |
| 82 | 82 |
| 83 virtual std::unique_ptr<base::MessageLoop> CreateMessageLoop(); | |
| 84 | |
| 85 // Call to set OnStart() metadata when GetService() is overridden. | 83 // Call to set OnStart() metadata when GetService() is overridden. |
| 86 void OnStartCalled(Connector* connector, | 84 void OnStartCalled(Connector* connector, |
| 87 const std::string& name, | 85 const std::string& name, |
| 88 const std::string& userid); | 86 const std::string& userid); |
| 89 | 87 |
| 90 // testing::Test: | 88 // testing::Test: |
| 91 void SetUp() override; | 89 void SetUp() override; |
| 92 void TearDown() override; | 90 void TearDown() override; |
| 93 | 91 |
| 94 private: | 92 private: |
| 95 friend ServiceTestClient; | 93 friend ServiceTestClient; |
| 96 | 94 |
| 95 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 97 std::unique_ptr<ServiceContext> context_; | 96 std::unique_ptr<ServiceContext> context_; |
| 98 std::unique_ptr<base::MessageLoop> message_loop_; | |
| 99 std::unique_ptr<BackgroundServiceManager> background_service_manager_; | 97 std::unique_ptr<BackgroundServiceManager> background_service_manager_; |
| 100 | 98 |
| 101 // See constructor. | 99 // See constructor. |
| 102 std::string test_name_; | 100 std::string test_name_; |
| 103 bool init_edk_ = true; | 101 bool init_edk_; |
| 104 std::unique_ptr<base::Thread> ipc_thread_; | 102 std::unique_ptr<base::Thread> ipc_thread_; |
| 105 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; | 103 std::unique_ptr<mojo::edk::ScopedIPCSupport> ipc_support_; |
| 106 | 104 |
| 107 Connector* connector_ = nullptr; | 105 Connector* connector_ = nullptr; |
| 108 std::string initialize_name_; | 106 std::string initialize_name_; |
| 109 std::string initialize_userid_ = service_manager::mojom::kInheritUserID; | 107 std::string initialize_userid_ = service_manager::mojom::kInheritUserID; |
| 110 uint32_t initialize_instance_id_ = service_manager::mojom::kInvalidInstanceID; | 108 uint32_t initialize_instance_id_ = service_manager::mojom::kInvalidInstanceID; |
| 111 | 109 |
| 112 base::Closure initialize_called_; | 110 base::Closure initialize_called_; |
| 113 | 111 |
| 114 DISALLOW_COPY_AND_ASSIGN(ServiceTest); | 112 DISALLOW_COPY_AND_ASSIGN(ServiceTest); |
| 115 }; | 113 }; |
| 116 | 114 |
| 117 } // namespace test | 115 } // namespace test |
| 118 } // namespace service_manager | 116 } // namespace service_manager |
| 119 | 117 |
| 120 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ | 118 #endif // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_SERVICE_TEST_H_ |
| OLD | NEW |