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/shell/background/background_shell.h" | 5 #include "services/shell/background/background_shell.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/shell/background/tests/test.mojom.h" | 11 #include "services/shell/background/tests/test.mojom.h" |
12 #include "services/shell/background/tests/test_catalog_store.h" | 12 #include "services/shell/background/tests/test_catalog_store.h" |
13 #include "services/shell/public/cpp/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
14 #include "services/shell/public/cpp/shell_client.h" | 14 #include "services/shell/public/cpp/service.h" |
15 #include "services/shell/public/cpp/shell_connection.h" | 15 #include "services/shell/public/cpp/shell_connection.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace shell { | 18 namespace shell { |
19 namespace { | 19 namespace { |
20 | 20 |
21 const char kTestName[] = "mojo:test-app"; | 21 const char kTestName[] = "mojo:test-app"; |
22 | 22 |
23 class ShellClientImpl : public ShellClient { | 23 class ServiceImpl : public Service { |
24 public: | 24 public: |
25 ShellClientImpl() {} | 25 ServiceImpl() {} |
26 ~ShellClientImpl() override {} | 26 ~ServiceImpl() override {} |
27 | 27 |
28 private: | 28 private: |
29 DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); | 29 DISALLOW_COPY_AND_ASSIGN(ServiceImpl); |
30 }; | 30 }; |
31 | 31 |
32 std::unique_ptr<TestCatalogStore> BuildTestCatalogStore() { | 32 std::unique_ptr<TestCatalogStore> BuildTestCatalogStore() { |
33 std::unique_ptr<base::ListValue> apps(new base::ListValue); | 33 std::unique_ptr<base::ListValue> apps(new base::ListValue); |
34 apps->Append(BuildPermissiveSerializedAppInfo(kTestName, "test")); | 34 apps->Append(BuildPermissiveSerializedAppInfo(kTestName, "test")); |
35 return base::WrapUnique(new TestCatalogStore(std::move(apps))); | 35 return base::WrapUnique(new TestCatalogStore(std::move(apps))); |
36 } | 36 } |
37 | 37 |
38 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { | 38 void SetFlagAndRunClosure(bool* flag, const base::Closure& closure) { |
39 *flag = true; | 39 *flag = true; |
(...skipping 14 matching lines...) Expand all Loading... |
54 #endif | 54 #endif |
55 TEST(BackgroundShellTest, MAYBE_Basic) { | 55 TEST(BackgroundShellTest, MAYBE_Basic) { |
56 base::MessageLoop message_loop; | 56 base::MessageLoop message_loop; |
57 BackgroundShell background_shell; | 57 BackgroundShell background_shell; |
58 std::unique_ptr<BackgroundShell::InitParams> init_params( | 58 std::unique_ptr<BackgroundShell::InitParams> init_params( |
59 new BackgroundShell::InitParams); | 59 new BackgroundShell::InitParams); |
60 std::unique_ptr<TestCatalogStore> store_ptr = BuildTestCatalogStore(); | 60 std::unique_ptr<TestCatalogStore> store_ptr = BuildTestCatalogStore(); |
61 TestCatalogStore* store = store_ptr.get(); | 61 TestCatalogStore* store = store_ptr.get(); |
62 init_params->catalog_store = std::move(store_ptr); | 62 init_params->catalog_store = std::move(store_ptr); |
63 background_shell.Init(std::move(init_params)); | 63 background_shell.Init(std::move(init_params)); |
64 ShellClientImpl shell_client; | 64 ServiceImpl service; |
65 ShellConnection shell_connection( | 65 ShellConnection shell_connection( |
66 &shell_client, background_shell.CreateShellClientRequest(kTestName)); | 66 &service, background_shell.CreateServiceRequest(kTestName)); |
67 mojom::TestServicePtr test_service; | 67 mojom::TestServicePtr test_service; |
68 shell_connection.connector()->ConnectToInterface( | 68 shell_connection.connector()->ConnectToInterface( |
69 "mojo:background_shell_test_app", &test_service); | 69 "mojo:background_shell_test_app", &test_service); |
70 base::RunLoop run_loop; | 70 base::RunLoop run_loop; |
71 bool got_result = false; | 71 bool got_result = false; |
72 test_service->Test(base::Bind(&SetFlagAndRunClosure, &got_result, | 72 test_service->Test(base::Bind(&SetFlagAndRunClosure, &got_result, |
73 run_loop.QuitClosure())); | 73 run_loop.QuitClosure())); |
74 run_loop.Run(); | 74 run_loop.Run(); |
75 EXPECT_TRUE(got_result); | 75 EXPECT_TRUE(got_result); |
76 EXPECT_TRUE(store->get_store_called()); | 76 EXPECT_TRUE(store->get_store_called()); |
77 } | 77 } |
78 | 78 |
79 } // namespace shell | 79 } // namespace shell |
OLD | NEW |