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 "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 15 matching lines...) Expand all Loading... |
26 using mojo::test::TestTrackedRequestService; | 26 using mojo::test::TestTrackedRequestService; |
27 using mojo::test::TestTrackedRequestServicePtr; | 27 using mojo::test::TestTrackedRequestServicePtr; |
28 | 28 |
29 namespace mojo { | 29 namespace mojo { |
30 namespace shell { | 30 namespace shell { |
31 namespace test { | 31 namespace test { |
32 namespace { | 32 namespace { |
33 | 33 |
34 void GetReportCallback(base::MessageLoop* loop, | 34 void GetReportCallback(base::MessageLoop* loop, |
35 std::vector<ServiceReport>* reports_out, | 35 std::vector<ServiceReport>* reports_out, |
36 mojo::Array<ServiceReportPtr> report) { | 36 Array<ServiceReportPtr> report) { |
37 for (size_t i = 0; i < report.size(); i++) | 37 for (size_t i = 0; i < report.size(); i++) |
38 reports_out->push_back(*report[i]); | 38 reports_out->push_back(*report[i]); |
39 loop->QuitWhenIdle(); | 39 loop->QuitWhenIdle(); |
40 } | 40 } |
41 | 41 |
42 class ShellTestBaseTest : public ShellTestBase { | 42 class ShellTestBaseTest : public ShellTestBase { |
43 public: | 43 public: |
44 // Convenience helpers for use as callbacks in tests. | 44 // Convenience helpers for use as callbacks in tests. |
45 template <typename T> | 45 template <typename T> |
46 base::Callback<void()> SetAndQuit(T* val, T result) { | 46 base::Callback<void()> SetAndQuit(T* val, T result) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 message_loop()->Run(); | 237 message_loop()->Run(); |
238 | 238 |
239 EXPECT_EQ(time_message, party_time); | 239 EXPECT_EQ(time_message, party_time); |
240 } | 240 } |
241 | 241 |
242 // Tests that service A in App 1 can be a client of service B in App 2. | 242 // Tests that service A in App 1 can be a client of service B in App 2. |
243 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { | 243 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { |
244 TestServicePtr service; | 244 TestServicePtr service; |
245 ConnectToService(test_app_url(), &service); | 245 ConnectToService(test_app_url(), &service); |
246 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 246 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
247 service->Ping(mojo::Callback<void()>()); | 247 service->Ping(Callback<void()>()); |
248 message_loop()->Run(); | 248 message_loop()->Run(); |
249 | 249 |
250 for (int i = 0; i < 8; i++) | 250 for (int i = 0; i < 8; i++) |
251 service->Ping(mojo::Callback<void()>()); | 251 service->Ping(Callback<void()>()); |
252 service->Ping(message_loop()->QuitWhenIdleClosure()); | 252 service->Ping(message_loop()->QuitWhenIdleClosure()); |
253 message_loop()->Run(); | 253 message_loop()->Run(); |
254 | 254 |
255 // If everything worked properly, the tracking service should report | 255 // If everything worked properly, the tracking service should report |
256 // 10 pings to TestService. | 256 // 10 pings to TestService. |
257 std::vector<ServiceReport> reports; | 257 std::vector<ServiceReport> reports; |
258 GetReport(&reports); | 258 GetReport(&reports); |
259 ASSERT_EQ(1U, reports.size()); | 259 ASSERT_EQ(1U, reports.size()); |
260 EXPECT_EQ(TestService::Name_, reports[0].service_name); | 260 EXPECT_EQ(TestService::Name_, reports[0].service_name); |
261 EXPECT_EQ(10U, reports[0].total_requests); | 261 EXPECT_EQ(10U, reports[0].total_requests); |
262 } | 262 } |
263 | 263 |
264 // Connect several services together and use the tracking service to verify | 264 // Connect several services together and use the tracking service to verify |
265 // communication. | 265 // communication. |
266 TEST_F(ShellTestBaseTest, ConnectManyClientsAndServices) { | 266 TEST_F(ShellTestBaseTest, ConnectManyClientsAndServices) { |
267 TestServicePtr service; | 267 TestServicePtr service; |
268 TestTimeServicePtr time_service; | 268 TestTimeServicePtr time_service; |
269 | 269 |
270 // Make a request to the TestService and have it contact TimeService in the | 270 // Make a request to the TestService and have it contact TimeService in the |
271 // tracking app. Do all this with tracking enabled, meaning both services | 271 // tracking app. Do all this with tracking enabled, meaning both services |
272 // are connected as clients of the TrackedRequestService. | 272 // are connected as clients of the TrackedRequestService. |
273 ConnectToService(test_app_url(), &service); | 273 ConnectToService(test_app_url(), &service); |
274 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 274 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
275 message_loop()->Run(); | 275 message_loop()->Run(); |
276 for (int i = 0; i < 5; i++) | 276 for (int i = 0; i < 5; i++) |
277 service->Ping(mojo::Callback<void()>()); | 277 service->Ping(Callback<void()>()); |
278 int64 time_result; | 278 int64 time_result; |
279 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", | 279 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", |
280 SetAndQuit<int64>(&time_result)); | 280 SetAndQuit<int64>(&time_result)); |
281 message_loop()->Run(); | 281 message_loop()->Run(); |
282 | 282 |
283 // Also make a few requests to the TimeService in the test_app. | 283 // Also make a few requests to the TimeService in the test_app. |
284 ConnectToService(test_app_url(), &time_service); | 284 ConnectToService(test_app_url(), &time_service); |
285 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 285 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
286 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 286 time_service->GetPartyTime(Callback<void(uint64_t)>()); |
287 message_loop()->Run(); | 287 message_loop()->Run(); |
288 for (int i = 0; i < 18; i++) | 288 for (int i = 0; i < 18; i++) |
289 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 289 time_service->GetPartyTime(Callback<void(uint64_t)>()); |
290 // Flush the tasks with one more to quit. | 290 // Flush the tasks with one more to quit. |
291 int64 party_time = 0; | 291 int64 party_time = 0; |
292 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); | 292 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); |
293 message_loop()->Run(); | 293 message_loop()->Run(); |
294 | 294 |
295 std::vector<ServiceReport> reports; | 295 std::vector<ServiceReport> reports; |
296 GetReport(&reports); | 296 GetReport(&reports); |
297 ASSERT_EQ(3U, reports.size()); | 297 ASSERT_EQ(3U, reports.size()); |
298 EXPECT_EQ(TestService::Name_, reports[0].service_name); | 298 EXPECT_EQ(TestService::Name_, reports[0].service_name); |
299 EXPECT_EQ(6U, reports[0].total_requests); | 299 EXPECT_EQ(6U, reports[0].total_requests); |
300 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); | 300 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
301 EXPECT_EQ(1U, reports[1].total_requests); | 301 EXPECT_EQ(1U, reports[1].total_requests); |
302 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 302 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
303 EXPECT_EQ(20U, reports[2].total_requests); | 303 EXPECT_EQ(20U, reports[2].total_requests); |
304 } | 304 } |
305 | 305 |
306 } // namespace | 306 } // namespace |
307 } // namespace test | 307 } // namespace test |
308 } // namespace shell | 308 } // namespace shell |
309 } // namespace mojo | 309 } // namespace mojo |
OLD | NEW |