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_shell.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_shell_unittest"; | 20 const char kTestName[] = "service:background_service_manager_unittest"; |
21 const char kAppName[] = "service:background_shell_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 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); | 29 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
30 }; | 30 }; |
31 | 31 |
32 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { | 32 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { |
33 *flag = true; | 33 *flag = true; |
34 closure.Run(); | 34 closure.Run(); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 // Uses BackgroundShell to start the shell in the background and connects to | 39 // Uses BackgroundServiceManager to start the service manager in the background |
40 // background_shell_test_app, verifying we can send a message to the app. | 40 // and connects to background_service_manager_test_service, verifying we can |
| 41 // send a message to the service. |
41 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
42 // TODO(crbug.com/589784): This test is disabled, as it fails | 43 // TODO(crbug.com/589784): This test is disabled, as it fails |
43 // on the Android GN bot. | 44 // on the Android GN bot. |
44 #define MAYBE_Basic DISABLED_Basic | 45 #define MAYBE_Basic DISABLED_Basic |
45 #else | 46 #else |
46 #define MAYBE_Basic Basic | 47 #define MAYBE_Basic Basic |
47 #endif | 48 #endif |
48 TEST(BackgroundShellTest, MAYBE_Basic) { | 49 TEST(BackgroundServiceManagerTest, MAYBE_Basic) { |
| 50 BackgroundServiceManager background_service_manager; |
49 base::MessageLoop message_loop; | 51 base::MessageLoop message_loop; |
50 BackgroundShell background_shell; | 52 background_service_manager.Init(nullptr); |
51 background_shell.Init(nullptr); | |
52 ServiceImpl service; | 53 ServiceImpl service; |
53 ServiceContext service_context( | 54 ServiceContext service_context( |
54 &service, background_shell.CreateServiceRequest(kTestName)); | 55 &service, background_service_manager.CreateServiceRequest(kTestName)); |
55 mojom::TestServicePtr test_service; | 56 mojom::TestServicePtr test_service; |
56 service_context.connector()->ConnectToInterface(kAppName, &test_service); | 57 service_context.connector()->ConnectToInterface(kAppName, &test_service); |
57 base::RunLoop run_loop; | 58 base::RunLoop run_loop; |
58 bool got_result = false; | 59 bool got_result = false; |
59 test_service->Test(base::Bind(&SetFlagAndRunClosure, &got_result, | 60 test_service->Test( |
60 run_loop.QuitClosure())); | 61 base::Bind(&SetFlagAndRunClosure, &got_result, run_loop.QuitClosure())); |
61 run_loop.Run(); | 62 run_loop.Run(); |
62 EXPECT_TRUE(got_result); | 63 EXPECT_TRUE(got_result); |
63 } | 64 } |
64 | 65 |
65 } // namespace service_manager | 66 } // namespace service_manager |
OLD | NEW |