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