Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: mojo/shell/shell_test_base_unittest.cc

Issue 394903005: mojo: terminate apps if the shell goes away (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 TEST_F(ShellTestBaseTest, ConnectBasicNetwork) {
139 TEST_F(ShellTestBaseTest, DISABLED_ConnectBasicNetwork) {
140 InterfacePtr<TestService> service; 139 InterfacePtr<TestService> service;
141 service.Bind(ConnectToServiceViaNetwork( 140 service.Bind(ConnectToServiceViaNetwork(
142 test_app_url(), TestService::Name_).Pass()); 141 test_app_url(), TestService::Name_).Pass());
143 142
144 bool was_run = false; 143 bool was_run = false;
145 service->Ping(SetAndQuit<bool>(&was_run, true)); 144 service->Ping(SetAndQuit<bool>(&was_run, true));
146 message_loop()->Run(); 145 message_loop()->Run();
147 EXPECT_TRUE(was_run); 146 EXPECT_TRUE(was_run);
148 EXPECT_FALSE(service.encountered_error()); 147 EXPECT_FALSE(service.encountered_error());
149 148
150 // Note that use of the network service is implicit in this test. 149 // 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 150 // Since TestService is not the only service in use, the shell won't auto
152 // magically exit when TestService is destroyed (unlike ConnectBasic). 151 // magically exit when TestService is destroyed (unlike ConnectBasic).
153 // Tearing down the shell context will kill connections. The shell loop will 152 // Tearing down the shell context will kill connections. The shell loop will
154 // exit as soon as no more apps are connected. 153 // exit as soon as no more apps are connected.
155 shell_context()->Shutdown(); 154 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be
156 message_loop()->Run(); 155 // necessary once the shell terminates if the primordial app exits, which
156 // we could enforce here by resetting |service|.
157 shell_context()->service_manager()->TerminateShellConnections();
158 message_loop()->Run(); // Waits for all connections to die.
157 } 159 }
158 160
159 // Tests that trying to connect to a service over network fails preoprly 161 // Tests that trying to connect to a service over network fails preoprly
160 // if the service doesn't exist. 162 // if the service doesn't exist.
161 // TODO(tim): Bug 394477. NetworkService doesn't currently terminate. 163 TEST_F(ShellTestBaseTest, ConnectInvalidServiceNetwork) {
162 TEST_F(ShellTestBaseTest, DISABLED_ConnectInvalidServiceNetwork) {
163 InterfacePtr<TestService> test_service; 164 InterfacePtr<TestService> test_service;
164 test_service.Bind(ConnectToServiceViaNetwork( 165 test_service.Bind(ConnectToServiceViaNetwork(
165 GURL("mojo:non_existent_service"), TestService::Name_).Pass()); 166 GURL("mojo:non_existent_service"), TestService::Name_).Pass());
166 QuitMessageLoopErrorHandler quitter; 167 QuitMessageLoopErrorHandler quitter;
167 test_service.set_error_handler(&quitter); 168 test_service.set_error_handler(&quitter);
168 bool was_run = false; 169 bool was_run = false;
169 test_service->Ping(SetAndQuit<bool>(&was_run, true)); 170 test_service->Ping(SetAndQuit<bool>(&was_run, true));
170 message_loop()->Run(); 171 message_loop()->Run();
171 EXPECT_TRUE(test_service.encountered_error()); 172 EXPECT_TRUE(test_service.encountered_error());
172 173
173 shell_context()->Shutdown(); 174 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be
174 message_loop()->Run(); 175 // necessary once the shell terminates if the primordial app exits, which
176 // we could enforce here by resetting |service|.
177 shell_context()->service_manager()->TerminateShellConnections();
178 message_loop()->Run(); // Waits for all connections to die.
175 } 179 }
176 180
177 // Similar to ConnectBasic, but causes the app to instantiate multiple 181 // Similar to ConnectBasic, but causes the app to instantiate multiple
178 // service implementation objects and verifies the shell can reach both. 182 // service implementation objects and verifies the shell can reach both.
179 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { 183 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) {
180 { 184 {
181 TestServicePtr service1, service2; 185 TestServicePtr service1, service2;
182 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); 186 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass());
183 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); 187 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass());
184 188
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); 305 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name);
302 EXPECT_EQ(1U, reports[1].total_requests); 306 EXPECT_EQ(1U, reports[1].total_requests);
303 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); 307 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name);
304 EXPECT_EQ(20U, reports[2].total_requests); 308 EXPECT_EQ(20U, reports[2].total_requests);
305 } 309 }
306 310
307 } // namespace 311 } // namespace
308 } // namespace test 312 } // namespace test
309 } // namespace shell 313 } // namespace shell
310 } // namespace mojo 314 } // namespace mojo
OLDNEW
« mojo/public/interfaces/service_provider/service_provider.mojom ('K') | « mojo/shell/context.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698