OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shell_test_base.h" | 5 #include "mojo/shell/shell_test_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "mojo/public/cpp/bindings/error_handler.h" | 10 #include "mojo/public/cpp/bindings/error_handler.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler); | 35 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler); |
36 }; | 36 }; |
37 | 37 |
38 void PingCallback(base::MessageLoop* message_loop, bool* was_run) { | 38 void PingCallback(base::MessageLoop* message_loop, bool* was_run) { |
39 *was_run = true; | 39 *was_run = true; |
40 VLOG(2) << "Ping callback"; | 40 VLOG(2) << "Ping callback"; |
41 message_loop->QuitWhenIdle(); | 41 message_loop->QuitWhenIdle(); |
42 } | 42 } |
43 | 43 |
44 TEST_F(ShellTestBaseTest, LaunchServiceInProcess) { | 44 TEST_F(ShellTestBaseTest, LaunchServiceInProcess) { |
45 InitMojo(); | |
46 | |
47 InterfacePtr<mojo::test::ITestService> test_service; | 45 InterfacePtr<mojo::test::ITestService> test_service; |
48 | 46 |
49 { | 47 { |
50 MessagePipe mp; | 48 MessagePipe mp; |
51 test_service.Bind(mp.handle0.Pass()); | 49 test_service.Bind(mp.handle0.Pass()); |
52 LaunchServiceInProcess(GURL("mojo:mojo_test_service"), | 50 LaunchServiceInProcess(GURL("mojo:mojo_test_service"), |
53 mojo::test::ITestService::Name_, | 51 mojo::test::ITestService::Name_, |
54 mp.handle1.Pass()); | 52 mp.handle1.Pass()); |
55 } | 53 } |
56 | 54 |
57 bool was_run = false; | 55 bool was_run = false; |
58 test_service->Ping(base::Bind(&PingCallback, | 56 test_service->Ping(base::Bind(&PingCallback, |
59 base::Unretained(message_loop()), | 57 base::Unretained(message_loop()), |
60 base::Unretained(&was_run))); | 58 base::Unretained(&was_run))); |
61 message_loop()->Run(); | 59 message_loop()->Run(); |
62 EXPECT_TRUE(was_run); | 60 EXPECT_TRUE(was_run); |
63 EXPECT_FALSE(test_service.encountered_error()); | 61 EXPECT_FALSE(test_service.encountered_error()); |
64 | 62 |
65 test_service.reset(); | 63 test_service.reset(); |
66 | 64 |
67 // This will run until the test service has actually quit (which it will, | 65 // This will run until the test service has actually quit (which it will, |
68 // since we killed the only connection to it). | 66 // since we killed the only connection to it). |
69 message_loop()->Run(); | 67 message_loop()->Run(); |
70 } | 68 } |
71 | 69 |
72 // Tests that launching a service in process fails properly if the service | 70 // Tests that launching a service in process fails properly if the service |
73 // doesn't exist. | 71 // doesn't exist. |
74 TEST_F(ShellTestBaseTest, LaunchServiceInProcessInvalidService) { | 72 TEST_F(ShellTestBaseTest, LaunchServiceInProcessInvalidService) { |
75 InitMojo(); | |
76 | |
77 InterfacePtr<mojo::test::ITestService> test_service; | 73 InterfacePtr<mojo::test::ITestService> test_service; |
78 | 74 |
79 { | 75 { |
80 MessagePipe mp; | 76 MessagePipe mp; |
81 test_service.Bind(mp.handle0.Pass()); | 77 test_service.Bind(mp.handle0.Pass()); |
82 LaunchServiceInProcess(GURL("mojo:non_existent_service"), | 78 LaunchServiceInProcess(GURL("mojo:non_existent_service"), |
83 mojo::test::ITestService::Name_, | 79 mojo::test::ITestService::Name_, |
84 mp.handle1.Pass()); | 80 mp.handle1.Pass()); |
85 } | 81 } |
86 | 82 |
(...skipping 14 matching lines...) Expand all Loading... |
101 EXPECT_TRUE(test_service.encountered_error()); | 97 EXPECT_TRUE(test_service.encountered_error()); |
102 } | 98 } |
103 | 99 |
104 test_service.reset(); | 100 test_service.reset(); |
105 } | 101 } |
106 | 102 |
107 } // namespace | 103 } // namespace |
108 } // namespace test | 104 } // namespace test |
109 } // namespace shell | 105 } // namespace shell |
110 } // namespace mojo | 106 } // namespace mojo |
OLD | NEW |