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

Side by Side Diff: shell/shell_test_base_unittest.cc

Issue 1219683015: Convert //shell/... to use set_connection_error_handler() instead of set_error_handler(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « shell/child_process_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "shell/shell_test_base.h" 5 #include "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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 private: 65 private:
66 template <typename T> 66 template <typename T>
67 void SetAndQuitImpl(T* val, T result) { 67 void SetAndQuitImpl(T* val, T result) {
68 *val = result; 68 *val = result;
69 message_loop()->QuitWhenIdle(); 69 message_loop()->QuitWhenIdle();
70 } 70 }
71 TestTrackedRequestServicePtr request_tracking_; 71 TestTrackedRequestServicePtr request_tracking_;
72 }; 72 };
73 73
74 class QuitMessageLoopErrorHandler : public mojo::ErrorHandler {
75 public:
76 QuitMessageLoopErrorHandler() {}
77 ~QuitMessageLoopErrorHandler() override {}
78
79 // |mojo::ErrorHandler| implementation:
80 void OnConnectionError() override {
81 base::MessageLoop::current()->QuitWhenIdle();
82 }
83
84 private:
85 DISALLOW_COPY_AND_ASSIGN(QuitMessageLoopErrorHandler);
86 };
87
88 // Tests that we can connect to a single service within a single app. 74 // Tests that we can connect to a single service within a single app.
89 TEST_F(ShellTestBaseTest, ConnectBasic) { 75 TEST_F(ShellTestBaseTest, ConnectBasic) {
90 TestServicePtr service; 76 TestServicePtr service;
91 ConnectToService(test_app_url(), &service); 77 ConnectToService(test_app_url(), &service);
92 78
93 bool was_run = false; 79 bool was_run = false;
94 service->Ping(SetAndQuit<bool>(&was_run, true)); 80 service->Ping(SetAndQuit<bool>(&was_run, true));
95 message_loop()->Run(); 81 message_loop()->Run();
96 EXPECT_TRUE(was_run); 82 EXPECT_TRUE(was_run);
97 EXPECT_FALSE(service.encountered_error()); 83 EXPECT_FALSE(service.encountered_error());
(...skipping 14 matching lines...) Expand all
112 98
113 bool was_run = false; 99 bool was_run = false;
114 test_service->Ping(SetAndQuit<bool>(&was_run, true)); 100 test_service->Ping(SetAndQuit<bool>(&was_run, true));
115 101
116 // This will quit because there's nothing running. 102 // This will quit because there's nothing running.
117 message_loop()->Run(); 103 message_loop()->Run();
118 EXPECT_FALSE(was_run); 104 EXPECT_FALSE(was_run);
119 105
120 // It may have quit before an error was processed. 106 // It may have quit before an error was processed.
121 if (!test_service.encountered_error()) { 107 if (!test_service.encountered_error()) {
122 QuitMessageLoopErrorHandler quitter; 108 test_service.set_connection_error_handler(
123 test_service.set_error_handler(&quitter); 109 []() { base::MessageLoop::current()->QuitWhenIdle(); });
124 message_loop()->Run(); 110 message_loop()->Run();
125 EXPECT_TRUE(test_service.encountered_error()); 111 EXPECT_TRUE(test_service.encountered_error());
126 } 112 }
127 113
128 test_service.reset(); 114 test_service.reset();
129 } 115 }
130 116
131 // Tests that we can connect to a single service within a single app using 117 // Tests that we can connect to a single service within a single app using
132 // a network based loader instead of local files. 118 // a network based loader instead of local files.
133 // TODO(tim): Disabled because network service leaks NSS at exit, meaning 119 // TODO(tim): Disabled because network service leaks NSS at exit, meaning
(...skipping 21 matching lines...) Expand all
155 } 141 }
156 142
157 // Tests that trying to connect to a service over network fails preoprly 143 // Tests that trying to connect to a service over network fails preoprly
158 // if the service doesn't exist. 144 // if the service doesn't exist.
159 // TODO(tim): Disabled because network service leaks NSS at exit, meaning 145 // TODO(tim): Disabled because network service leaks NSS at exit, meaning
160 // subsequent tests can't init properly. 146 // subsequent tests can't init properly.
161 TEST_F(ShellTestBaseTest, DISABLED_ConnectInvalidServiceNetwork) { 147 TEST_F(ShellTestBaseTest, DISABLED_ConnectInvalidServiceNetwork) {
162 TestServicePtr test_service; 148 TestServicePtr test_service;
163 ConnectToService(GURL("http://example.com/non_existent_service"), 149 ConnectToService(GURL("http://example.com/non_existent_service"),
164 &test_service); 150 &test_service);
165 QuitMessageLoopErrorHandler quitter; 151 test_service.set_connection_error_handler(
166 test_service.set_error_handler(&quitter); 152 []() { base::MessageLoop::current()->QuitWhenIdle(); });
167 bool was_run = false; 153 bool was_run = false;
168 test_service->Ping(SetAndQuit<bool>(&was_run, true)); 154 test_service->Ping(SetAndQuit<bool>(&was_run, true));
169 message_loop()->Run(); 155 message_loop()->Run();
170 EXPECT_TRUE(test_service.encountered_error()); 156 EXPECT_TRUE(test_service.encountered_error());
171 157
172 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be 158 // TODO(tim): crbug.com/392685. Calling this explicitly shouldn't be
173 // necessary once the shell terminates if the primordial app exits, which 159 // necessary once the shell terminates if the primordial app exits, which
174 // we could enforce here by resetting |service|. 160 // we could enforce here by resetting |service|.
175 shell_context()->application_manager()->TerminateShellConnections(); 161 shell_context()->application_manager()->TerminateShellConnections();
176 message_loop()->Run(); // Waits for all connections to die. 162 message_loop()->Run(); // Waits for all connections to die.
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 EXPECT_EQ(6U, reports[0].total_requests); 285 EXPECT_EQ(6U, reports[0].total_requests);
300 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); 286 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name);
301 EXPECT_EQ(1U, reports[1].total_requests); 287 EXPECT_EQ(1U, reports[1].total_requests);
302 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); 288 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name);
303 EXPECT_EQ(20U, reports[2].total_requests); 289 EXPECT_EQ(20U, reports[2].total_requests);
304 } 290 }
305 291
306 } // namespace 292 } // namespace
307 } // namespace test 293 } // namespace test
308 } // namespace shell 294 } // namespace shell
OLDNEW
« no previous file with comments | « shell/child_process_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698