| 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 #include "services/service_manager/background/background_service_manager.h" | 5 #include "services/service_manager/background/background_service_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "services/service_manager/background/tests/test.mojom.h" | 11 #include "services/service_manager/background/tests/test.mojom.h" |
| 12 #include "services/service_manager/public/cpp/connector.h" | 12 #include "services/service_manager/public/cpp/connector.h" |
| 13 #include "services/service_manager/public/cpp/service.h" | 13 #include "services/service_manager/public/cpp/service.h" |
| 14 #include "services/service_manager/public/cpp/service_context.h" | 14 #include "services/service_manager/public/cpp/service_context.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace service_manager { | 17 namespace service_manager { |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 const char kTestName[] = "service:background_service_manager_unittest"; | 20 const char kTestName[] = "service:background_service_manager_unittest"; |
| 21 const char kAppName[] = "service:background_service_manager_test_service"; | 21 const char kAppName[] = "service:background_service_manager_test_service"; |
| 22 | 22 |
| 23 class ServiceImpl : public Service { | 23 class ServiceImpl : public Service { |
| 24 public: | 24 public: |
| 25 ServiceImpl() {} | 25 ServiceImpl() {} |
| 26 ~ServiceImpl() override {} | 26 ~ServiceImpl() override {} |
| 27 | 27 |
| 28 // Service: |
| 29 bool OnConnect(const ServiceInfo& remote_info, |
| 30 InterfaceRegistry* registry) override { |
| 31 return false; |
| 32 } |
| 33 |
| 28 private: | 34 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); | 35 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
| 30 }; | 36 }; |
| 31 | 37 |
| 32 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { | 38 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { |
| 33 *flag = true; | 39 *flag = true; |
| 34 closure.Run(); | 40 closure.Run(); |
| 35 } | 41 } |
| 36 | 42 |
| 37 } // namespace | 43 } // namespace |
| 38 | 44 |
| 39 // Uses BackgroundServiceManager to start the service manager in the background | 45 // Uses BackgroundServiceManager to start the service manager in the background |
| 40 // and connects to background_service_manager_test_service, verifying we can | 46 // and connects to background_service_manager_test_service, verifying we can |
| 41 // send a message to the service. | 47 // send a message to the service. |
| 42 #if defined(OS_ANDROID) | 48 #if defined(OS_ANDROID) |
| 43 // TODO(crbug.com/589784): This test is disabled, as it fails | 49 // TODO(crbug.com/589784): This test is disabled, as it fails |
| 44 // on the Android GN bot. | 50 // on the Android GN bot. |
| 45 #define MAYBE_Basic DISABLED_Basic | 51 #define MAYBE_Basic DISABLED_Basic |
| 46 #else | 52 #else |
| 47 #define MAYBE_Basic Basic | 53 #define MAYBE_Basic Basic |
| 48 #endif | 54 #endif |
| 49 TEST(BackgroundServiceManagerTest, MAYBE_Basic) { | 55 TEST(BackgroundServiceManagerTest, MAYBE_Basic) { |
| 50 BackgroundServiceManager background_service_manager; | 56 BackgroundServiceManager background_service_manager; |
| 51 base::MessageLoop message_loop; | 57 base::MessageLoop message_loop; |
| 52 background_service_manager.Init(nullptr); | 58 background_service_manager.Init(nullptr); |
| 53 ServiceImpl service; | |
| 54 ServiceContext service_context( | 59 ServiceContext service_context( |
| 55 &service, background_service_manager.CreateServiceRequest(kTestName)); | 60 base::MakeUnique<ServiceImpl>(), |
| 61 background_service_manager.CreateServiceRequest(kTestName)); |
| 56 mojom::TestServicePtr test_service; | 62 mojom::TestServicePtr test_service; |
| 57 service_context.connector()->ConnectToInterface(kAppName, &test_service); | 63 service_context.connector()->ConnectToInterface(kAppName, &test_service); |
| 58 base::RunLoop run_loop; | 64 base::RunLoop run_loop; |
| 59 bool got_result = false; | 65 bool got_result = false; |
| 60 test_service->Test( | 66 test_service->Test( |
| 61 base::Bind(&SetFlagAndRunClosure, &got_result, run_loop.QuitClosure())); | 67 base::Bind(&SetFlagAndRunClosure, &got_result, run_loop.QuitClosure())); |
| 62 run_loop.Run(); | 68 run_loop.Run(); |
| 63 EXPECT_TRUE(got_result); | 69 EXPECT_TRUE(got_result); |
| 64 } | 70 } |
| 65 | 71 |
| 66 } // namespace service_manager | 72 } // namespace service_manager |
| OLD | NEW |