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_application_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 #include "url/gurl.h" | |
15 | 14 |
16 namespace mojo { | 15 namespace mojo { |
17 namespace shell { | 16 namespace shell { |
18 namespace { | 17 namespace { |
19 | 18 |
20 const char kTestUrl[] = "mojo:test-app"; | 19 const char kTestName[] = "mojo:test-app"; |
21 | 20 |
22 class ShellClientImpl : public ShellClient { | 21 class ShellClientImpl : public ShellClient { |
23 public: | 22 public: |
24 ShellClientImpl() {} | 23 ShellClientImpl() {} |
25 ~ShellClientImpl() override {} | 24 ~ShellClientImpl() override {} |
26 | 25 |
27 private: | 26 private: |
28 DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); | 27 DISALLOW_COPY_AND_ASSIGN(ShellClientImpl); |
29 }; | 28 }; |
30 | 29 |
31 scoped_ptr<TestApplicationCatalogStore> BuildTestApplicationCatalogStore() { | 30 scoped_ptr<TestApplicationCatalogStore> BuildTestApplicationCatalogStore() { |
32 scoped_ptr<base::ListValue> apps(new base::ListValue); | 31 scoped_ptr<base::ListValue> apps(new base::ListValue); |
33 apps->Append(BuildPermissiveSerializedAppInfo(GURL(kTestUrl), "test")); | 32 apps->Append(BuildPermissiveSerializedAppInfo(kTestName, "test")); |
34 return make_scoped_ptr(new TestApplicationCatalogStore(std::move(apps))); | 33 return make_scoped_ptr(new TestApplicationCatalogStore(std::move(apps))); |
35 } | 34 } |
36 | 35 |
37 } // namespace | 36 } // namespace |
38 | 37 |
39 // 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 |
40 // 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. |
41 // An ApplicationCatalogStore is supplied to avoid using a manifest. | 40 // An ApplicationCatalogStore is supplied to avoid using a manifest. |
42 // TODO(crbug.com/589784): This test is disabled, as it fails | 41 // TODO(crbug.com/589784): This test is disabled, as it fails |
43 // on the Android GN bot. | 42 // on the Android GN bot. |
44 TEST(BackgroundShellTest, DISABLED_Basic) { | 43 TEST(BackgroundShellTest, DISABLED_Basic) { |
45 base::MessageLoop message_loop; | 44 base::MessageLoop message_loop; |
46 BackgroundShell background_shell; | 45 BackgroundShell background_shell; |
47 scoped_ptr<BackgroundShell::InitParams> init_params( | 46 scoped_ptr<BackgroundShell::InitParams> init_params( |
48 new BackgroundShell::InitParams); | 47 new BackgroundShell::InitParams); |
49 scoped_ptr<TestApplicationCatalogStore> store_ptr = | 48 scoped_ptr<TestApplicationCatalogStore> store_ptr = |
50 BuildTestApplicationCatalogStore(); | 49 BuildTestApplicationCatalogStore(); |
51 TestApplicationCatalogStore* store = store_ptr.get(); | 50 TestApplicationCatalogStore* store = store_ptr.get(); |
52 init_params->app_catalog = std::move(store_ptr); | 51 init_params->app_catalog = std::move(store_ptr); |
53 background_shell.Init(std::move(init_params)); | 52 background_shell.Init(std::move(init_params)); |
54 ShellClientImpl shell_client; | 53 ShellClientImpl shell_client; |
55 ShellConnection shell_connection( | 54 ShellConnection shell_connection( |
56 &shell_client, background_shell.CreateShellClientRequest(GURL(kTestUrl))); | 55 &shell_client, background_shell.CreateShellClientRequest(kTestName)); |
57 shell_connection.WaitForInitialize(); | 56 shell_connection.WaitForInitialize(); |
58 mojom::TestServicePtr test_service; | 57 mojom::TestServicePtr test_service; |
59 shell_connection.connector()->ConnectToInterface( | 58 shell_connection.connector()->ConnectToInterface( |
60 "mojo:background_shell_test_app", &test_service); | 59 "mojo:background_shell_test_app", &test_service); |
61 base::RunLoop run_loop; | 60 base::RunLoop run_loop; |
62 bool got_result = false; | 61 bool got_result = false; |
63 test_service->Test([&run_loop, &got_result]() { | 62 test_service->Test([&run_loop, &got_result]() { |
64 got_result = true; | 63 got_result = true; |
65 run_loop.Quit(); | 64 run_loop.Quit(); |
66 }); | 65 }); |
67 run_loop.Run(); | 66 run_loop.Run(); |
68 EXPECT_TRUE(got_result); | 67 EXPECT_TRUE(got_result); |
69 EXPECT_TRUE(store->get_store_called()); | 68 EXPECT_TRUE(store->get_store_called()); |
70 } | 69 } |
71 | 70 |
72 } // namespace shell | 71 } // namespace shell |
73 } // namespace mojo | 72 } // namespace mojo |
OLD | NEW |