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

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

Issue 397733003: mojo: kill app_thread before unloading main app library and add tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review + hack Created 6 years, 5 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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 EXPECT_FALSE(service.encountered_error()); 101 EXPECT_FALSE(service.encountered_error());
102 102
103 service.reset(); 103 service.reset();
104 104
105 // This will run until the test app has actually quit (which it will, 105 // This will run until the test app has actually quit (which it will,
106 // since we killed the only connection to it). 106 // since we killed the only connection to it).
107 message_loop()->Run(); 107 message_loop()->Run();
108 } 108 }
109 109
110 // Tests that trying to connect to a service fails properly if the service 110 // Tests that trying to connect to a service fails properly if the service
111 // doesn't exist. 111 // doesn't exist. Implicit in this test is verification that the shell
112 // terminates if no services are running.
112 TEST_F(ShellTestBaseTest, ConnectInvalidService) { 113 TEST_F(ShellTestBaseTest, ConnectInvalidService) {
113 InterfacePtr<TestService> test_service; 114 InterfacePtr<TestService> test_service;
114 test_service.Bind(ConnectToService(GURL("mojo:non_existent_service"), 115 test_service.Bind(ConnectToService(GURL("mojo:non_existent_service"),
115 TestService::Name_).Pass()); 116 TestService::Name_).Pass());
116 117
117 bool was_run = false; 118 bool was_run = false;
118 test_service->Ping(SetAndQuit<bool>(&was_run, true)); 119 test_service->Ping(SetAndQuit<bool>(&was_run, true));
119 120
120 // This will quit because there's nothing running. 121 // This will quit because there's nothing running.
121 message_loop()->Run(); 122 message_loop()->Run();
122 EXPECT_FALSE(was_run); 123 EXPECT_FALSE(was_run);
123 124
124 // It may have quit before an error was processed. 125 // It may have quit before an error was processed.
125 if (!test_service.encountered_error()) { 126 if (!test_service.encountered_error()) {
126 QuitMessageLoopErrorHandler quitter; 127 QuitMessageLoopErrorHandler quitter;
127 test_service.set_error_handler(&quitter); 128 test_service.set_error_handler(&quitter);
128 message_loop()->Run(); 129 message_loop()->Run();
129 EXPECT_TRUE(test_service.encountered_error()); 130 EXPECT_TRUE(test_service.encountered_error());
130 } 131 }
131 132
132 test_service.reset(); 133 test_service.reset();
133 } 134 }
134 135
136 // Tests that we can connect to a single service within a single app using
137 // a network based loader instead of local files.
138 TEST_F(ShellTestBaseTest, ConnectBasicNetwork) {
139 InterfacePtr<TestService> service;
140 service.Bind(ConnectToServiceViaNetwork(
141 test_app_url(), TestService::Name_).Pass());
142
143 bool was_run = false;
144 service->Ping(SetAndQuit<bool>(&was_run, true));
145 message_loop()->Run();
146 EXPECT_TRUE(was_run);
147 EXPECT_FALSE(service.encountered_error());
148
149 // 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 // magically exit when TestService is destroyed (unlike ConnectBasic).
152 // Tearing down the shell context will kill connections. The shell loop will
153 // exit as soon as no more apps are connected.
154 shell_context()->Shutdown();
tim (not reviewing) 2014/07/19 02:11:37 Considering moving these two lines to ShellTestBas
155 message_loop()->Run();
156 }
157
158 // Tests that trying to connect to a service over network fails preoprly
159 // if the service doesn't exist.
160 TEST_F(ShellTestBaseTest, ConnectInvalidServiceNetwork) {
161 InterfacePtr<TestService> test_service;
162 test_service.Bind(ConnectToServiceViaNetwork(
163 GURL("mojo:non_existent_service"), TestService::Name_).Pass());
164 QuitMessageLoopErrorHandler quitter;
165 test_service.set_error_handler(&quitter);
166 bool was_run = false;
167 test_service->Ping(SetAndQuit<bool>(&was_run, true));
168 message_loop()->Run();
169 EXPECT_TRUE(test_service.encountered_error());
170
171 shell_context()->Shutdown();
172 message_loop()->Run();
173 }
174
135 // Similar to ConnectBasic, but causes the app to instantiate multiple 175 // Similar to ConnectBasic, but causes the app to instantiate multiple
136 // service implementation objects and verifies the shell can reach both. 176 // service implementation objects and verifies the shell can reach both.
137 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) { 177 TEST_F(ShellTestBaseTest, ConnectMultipleInstancesPerApp) {
138 { 178 {
139 TestServicePtr service1, service2; 179 TestServicePtr service1, service2;
140 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); 180 service1.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass());
141 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass()); 181 service2.Bind(ConnectToService(test_app_url(), TestService::Name_).Pass());
142 182
143 bool was_run1 = false; 183 bool was_run1 = false;
144 bool was_run2 = false; 184 bool was_run2 = false;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); 299 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name);
260 EXPECT_EQ(1U, reports[1].total_requests); 300 EXPECT_EQ(1U, reports[1].total_requests);
261 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); 301 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name);
262 EXPECT_EQ(20U, reports[2].total_requests); 302 EXPECT_EQ(20U, reports[2].total_requests);
263 } 303 }
264 304
265 } // namespace 305 } // namespace
266 } // namespace test 306 } // namespace test
267 } // namespace shell 307 } // namespace shell
268 } // namespace mojo 308 } // namespace mojo
OLDNEW
« mojo/shell/in_process_dynamic_service_runner.cc ('K') | « mojo/shell/shell_test_base.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698