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