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/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 test_service.set_error_handler(&quitter); | 128 test_service.set_error_handler(&quitter); |
129 message_loop()->Run(); | 129 message_loop()->Run(); |
130 EXPECT_TRUE(test_service.encountered_error()); | 130 EXPECT_TRUE(test_service.encountered_error()); |
131 } | 131 } |
132 | 132 |
133 test_service.reset(); | 133 test_service.reset(); |
134 } | 134 } |
135 | 135 |
136 // Tests that we can connect to a single service within a single app using | 136 // Tests that we can connect to a single service within a single app using |
137 // a network based loader instead of local files. | 137 // a network based loader instead of local files. |
138 TEST_F(ShellTestBaseTest, ConnectBasicNetwork) { | 138 // TODO(tim): Bug 394477. NetworkService doesn't currently terminate. |
| 139 TEST_F(ShellTestBaseTest, DISABLED_ConnectBasicNetwork) { |
139 InterfacePtr<TestService> service; | 140 InterfacePtr<TestService> service; |
140 service.Bind(ConnectToServiceViaNetwork( | 141 service.Bind(ConnectToServiceViaNetwork( |
141 test_app_url(), TestService::Name_).Pass()); | 142 test_app_url(), TestService::Name_).Pass()); |
142 | 143 |
143 bool was_run = false; | 144 bool was_run = false; |
144 service->Ping(SetAndQuit<bool>(&was_run, true)); | 145 service->Ping(SetAndQuit<bool>(&was_run, true)); |
145 message_loop()->Run(); | 146 message_loop()->Run(); |
146 EXPECT_TRUE(was_run); | 147 EXPECT_TRUE(was_run); |
147 EXPECT_FALSE(service.encountered_error()); | 148 EXPECT_FALSE(service.encountered_error()); |
148 | 149 |
149 // Note that use of the network service is implicit in this test. | 150 // Note that use of the network service is implicit in this test. |
150 // Since TestService is not the only service in use, the shell won't auto | 151 // Since TestService is not the only service in use, the shell won't auto |
151 // magically exit when TestService is destroyed (unlike ConnectBasic). | 152 // magically exit when TestService is destroyed (unlike ConnectBasic). |
152 // Tearing down the shell context will kill connections. The shell loop will | 153 // Tearing down the shell context will kill connections. The shell loop will |
153 // exit as soon as no more apps are connected. | 154 // exit as soon as no more apps are connected. |
154 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be | 155 shell_context()->Shutdown(); |
155 // necessary once the shell terminates if the primordial app exits, which | 156 message_loop()->Run(); |
156 // we could enforce here by resetting |service|. | |
157 shell_context()->service_manager()->TerminateShellConnections(); | |
158 message_loop()->Run(); // Waits for all connections to die. | |
159 } | 157 } |
160 | 158 |
161 // Tests that trying to connect to a service over network fails preoprly | 159 // Tests that trying to connect to a service over network fails preoprly |
162 // if the service doesn't exist. | 160 // if the service doesn't exist. |
163 TEST_F(ShellTestBaseTest, ConnectInvalidServiceNetwork) { | 161 // TODO(tim): Bug 394477. NetworkService doesn't currently terminate. |
| 162 TEST_F(ShellTestBaseTest, DISABLED_ConnectInvalidServiceNetwork) { |
164 InterfacePtr<TestService> test_service; | 163 InterfacePtr<TestService> test_service; |
165 test_service.Bind(ConnectToServiceViaNetwork( | 164 test_service.Bind(ConnectToServiceViaNetwork( |
166 GURL("mojo:non_existent_service"), TestService::Name_).Pass()); | 165 GURL("mojo:non_existent_service"), TestService::Name_).Pass()); |
167 QuitMessageLoopErrorHandler quitter; | 166 QuitMessageLoopErrorHandler quitter; |
168 test_service.set_error_handler(&quitter); | 167 test_service.set_error_handler(&quitter); |
169 bool was_run = false; | 168 bool was_run = false; |
170 test_service->Ping(SetAndQuit<bool>(&was_run, true)); | 169 test_service->Ping(SetAndQuit<bool>(&was_run, true)); |
171 message_loop()->Run(); | 170 message_loop()->Run(); |
172 EXPECT_TRUE(test_service.encountered_error()); | 171 EXPECT_TRUE(test_service.encountered_error()); |
173 | 172 |
174 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be | 173 shell_context()->Shutdown(); |
175 // necessary once the shell terminates if the primordial app exits, which | 174 message_loop()->Run(); |
176 // we could enforce here by resetting |service|. | |
177 shell_context()->service_manager()->TerminateShellConnections(); | |
178 message_loop()->Run(); // Waits for all connections to die. | |
179 } | 175 } |
180 | 176 |
181 // Similar to ConnectBasic, but causes the app to instantiate multiple | 177 // Similar to ConnectBasic, but causes the app to instantiate multiple |
182 // service implementation objects and verifies the shell can reach both. | 178 // service implementation objects and verifies the shell can reach both. |
183 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { | 179 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { |
184 { | 180 { |
185 TestServicePtr service1, service2; | 181 TestServicePtr service1, service2; |
186 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 182 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
187 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); | 183 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); |
188 | 184 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); | 301 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
306 EXPECT_EQ(1U, reports[1].total_requests); | 302 EXPECT_EQ(1U, reports[1].total_requests); |
307 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 303 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
308 EXPECT_EQ(20U, reports[2].total_requests); | 304 EXPECT_EQ(20U, reports[2].total_requests); |
309 } | 305 } |
310 | 306 |
311 } // namespace | 307 } // namespace |
312 } // namespace test | 308 } // namespace test |
313 } // namespace shell | 309 } // namespace shell |
314 } // namespace mojo | 310 } // namespace mojo |
OLD | NEW |