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> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
7 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
8 #include "services/shell/background/tests/test.mojom.h" | 11 #include "services/shell/background/tests/test.mojom.h" |
9 #include "services/shell/background/tests/test_catalog_store.h" | 12 #include "services/shell/background/tests/test_catalog_store.h" |
10 #include "services/shell/public/cpp/connector.h" | 13 #include "services/shell/public/cpp/connector.h" |
11 #include "services/shell/public/cpp/shell_client.h" | 14 #include "services/shell/public/cpp/shell_client.h" |
12 #include "services/shell/public/cpp/shell_connection.h" | 15 #include "services/shell/public/cpp/shell_connection.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 namespace mojo { | |
16 namespace shell { | 18 namespace shell { |
17 namespace { | 19 namespace { |
18 | 20 |
19 const char kTestName[] = "mojo:test-app"; | 21 const char kTestName[] = "mojo:test-app"; |
20 | 22 |
21 class ShellClientImpl : public ShellClient { | 23 class ShellClientImpl : public ShellClient { |
22 public: | 24 public: |
23 ShellClientImpl() {} | 25 ShellClientImpl() {} |
24 ~ShellClientImpl() override {} | 26 ~ShellClientImpl() override {} |
25 | 27 |
26 private: | 28 private: |
27 DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); | 29 DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); |
28 }; | 30 }; |
29 | 31 |
30 scoped_ptr<TestCatalogStore> BuildTestCatalogStore() { | 32 std::unique_ptr<TestCatalogStore> BuildTestCatalogStore() { |
31 scoped_ptr<base::ListValue> apps(new base::ListValue); | 33 std::unique_ptr<base::ListValue> apps(new base::ListValue); |
32 apps->Append(BuildPermissiveSerializedAppInfo(kTestName, "test")); | 34 apps->Append(BuildPermissiveSerializedAppInfo(kTestName, "test")); |
33 return make_scoped_ptr(new TestCatalogStore(std::move(apps))); | 35 return base::WrapUnique(new TestCatalogStore(std::move(apps))); |
34 } | 36 } |
35 | 37 |
36 } // namespace | 38 } // namespace |
37 | 39 |
38 // Uses BackgroundShell to start the shell in the background and connects to | 40 // Uses BackgroundShell to start the shell in the background and connects to |
39 // background_shell_test_app, verifying we can send a message to the app. | 41 // background_shell_test_app, verifying we can send a message to the app. |
40 // An ApplicationCatalogStore is supplied to avoid using a manifest. | 42 // An ApplicationCatalogStore is supplied to avoid using a manifest. |
41 #if defined(OS_ANDROID) | 43 #if defined(OS_ANDROID) |
42 // TODO(crbug.com/589784): This test is disabled, as it fails | 44 // TODO(crbug.com/589784): This test is disabled, as it fails |
43 // on the Android GN bot. | 45 // on the Android GN bot. |
44 #define MAYBE_Basic DISABLED_Basic | 46 #define MAYBE_Basic DISABLED_Basic |
45 #else | 47 #else |
46 #define MAYBE_Basic Basic | 48 #define MAYBE_Basic Basic |
47 #endif | 49 #endif |
48 TEST(BackgroundShellTest, MAYBE_Basic) { | 50 TEST(BackgroundShellTest, MAYBE_Basic) { |
49 base::MessageLoop message_loop; | 51 base::MessageLoop message_loop; |
50 BackgroundShell background_shell; | 52 BackgroundShell background_shell; |
51 scoped_ptr<BackgroundShell::InitParams> init_params( | 53 std::unique_ptr<BackgroundShell::InitParams> init_params( |
52 new BackgroundShell::InitParams); | 54 new BackgroundShell::InitParams); |
53 scoped_ptr<TestCatalogStore> store_ptr = BuildTestCatalogStore(); | 55 std::unique_ptr<TestCatalogStore> store_ptr = BuildTestCatalogStore(); |
54 TestCatalogStore* store = store_ptr.get(); | 56 TestCatalogStore* store = store_ptr.get(); |
55 init_params->catalog_store = std::move(store_ptr); | 57 init_params->catalog_store = std::move(store_ptr); |
56 background_shell.Init(std::move(init_params)); | 58 background_shell.Init(std::move(init_params)); |
57 ShellClientImpl shell_client; | 59 ShellClientImpl shell_client; |
58 ShellConnection shell_connection( | 60 ShellConnection shell_connection( |
59 &shell_client, background_shell.CreateShellClientRequest(kTestName)); | 61 &shell_client, background_shell.CreateShellClientRequest(kTestName)); |
60 mojom::TestServicePtr test_service; | 62 mojom::TestServicePtr test_service; |
61 shell_connection.connector()->ConnectToInterface( | 63 shell_connection.connector()->ConnectToInterface( |
62 "mojo:background_shell_test_app", &test_service); | 64 "mojo:background_shell_test_app", &test_service); |
63 base::RunLoop run_loop; | 65 base::RunLoop run_loop; |
64 bool got_result = false; | 66 bool got_result = false; |
65 test_service->Test([&run_loop, &got_result]() { | 67 test_service->Test([&run_loop, &got_result]() { |
66 got_result = true; | 68 got_result = true; |
67 run_loop.Quit(); | 69 run_loop.Quit(); |
68 }); | 70 }); |
69 run_loop.Run(); | 71 run_loop.Run(); |
70 EXPECT_TRUE(got_result); | 72 EXPECT_TRUE(got_result); |
71 EXPECT_TRUE(store->get_store_called()); | 73 EXPECT_TRUE(store->get_store_called()); |
72 } | 74 } |
73 | 75 |
74 } // namespace shell | 76 } // namespace shell |
75 } // namespace mojo | |
OLD | NEW |