| 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" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "mojo/public/cpp/bindings/error_handler.h" | 12 #include "mojo/public/cpp/bindings/error_handler.h" |
| 13 #include "mojo/public/cpp/bindings/interface_ptr.h" | 13 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 14 #include "mojo/public/cpp/system/core.h" | 14 #include "mojo/public/cpp/system/core.h" |
| 15 #include "services/test_service/test_request_tracker.mojom.h" | 15 #include "services/test_service/test_request_tracker.mojom.h" |
| 16 #include "services/test_service/test_service.mojom.h" | 16 #include "services/test_service/test_service.mojom.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 | 19 |
| 20 using mojo::Callback; |
| 20 using mojo::test::ServiceReport; | 21 using mojo::test::ServiceReport; |
| 21 using mojo::test::ServiceReportPtr; | 22 using mojo::test::ServiceReportPtr; |
| 22 using mojo::test::TestService; | 23 using mojo::test::TestService; |
| 23 using mojo::test::TestTimeService; | 24 using mojo::test::TestTimeService; |
| 24 using mojo::test::TestServicePtr; | 25 using mojo::test::TestServicePtr; |
| 25 using mojo::test::TestTimeServicePtr; | 26 using mojo::test::TestTimeServicePtr; |
| 26 using mojo::test::TestTrackedRequestService; | 27 using mojo::test::TestTrackedRequestService; |
| 27 using mojo::test::TestTrackedRequestServicePtr; | 28 using mojo::test::TestTrackedRequestServicePtr; |
| 28 | 29 |
| 29 namespace shell { | 30 namespace shell { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 message_loop()->Run(); | 237 message_loop()->Run(); |
| 237 | 238 |
| 238 EXPECT_EQ(time_message, party_time); | 239 EXPECT_EQ(time_message, party_time); |
| 239 } | 240 } |
| 240 | 241 |
| 241 // 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. |
| 242 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { | 243 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { |
| 243 TestServicePtr service; | 244 TestServicePtr service; |
| 244 ConnectToService(test_app_url(), &service); | 245 ConnectToService(test_app_url(), &service); |
| 245 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 246 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
| 246 service->Ping(mojo::Callback<void()>()); | 247 service->Ping(Callback<void()>()); |
| 247 message_loop()->Run(); | 248 message_loop()->Run(); |
| 248 | 249 |
| 249 for (int i = 0; i < 8; i++) | 250 for (int i = 0; i < 8; i++) |
| 250 service->Ping(mojo::Callback<void()>()); | 251 service->Ping(Callback<void()>()); |
| 251 service->Ping(message_loop()->QuitWhenIdleClosure()); | 252 service->Ping(message_loop()->QuitWhenIdleClosure()); |
| 252 message_loop()->Run(); | 253 message_loop()->Run(); |
| 253 | 254 |
| 254 // If everything worked properly, the tracking service should report | 255 // If everything worked properly, the tracking service should report |
| 255 // 10 pings to TestService. | 256 // 10 pings to TestService. |
| 256 std::vector<ServiceReport> reports; | 257 std::vector<ServiceReport> reports; |
| 257 GetReport(&reports); | 258 GetReport(&reports); |
| 258 ASSERT_EQ(1U, reports.size()); | 259 ASSERT_EQ(1U, reports.size()); |
| 259 EXPECT_EQ(TestService::Name_, reports[0].service_name); | 260 EXPECT_EQ(TestService::Name_, reports[0].service_name); |
| 260 EXPECT_EQ(10U, reports[0].total_requests); | 261 EXPECT_EQ(10U, reports[0].total_requests); |
| 261 } | 262 } |
| 262 | 263 |
| 263 // Connect several services together and use the tracking service to verify | 264 // Connect several services together and use the tracking service to verify |
| 264 // communication. | 265 // communication. |
| 265 TEST_F(ShellTestBaseTest, ConnectManyClientsAndServices) { | 266 TEST_F(ShellTestBaseTest, ConnectManyClientsAndServices) { |
| 266 TestServicePtr service; | 267 TestServicePtr service; |
| 267 TestTimeServicePtr time_service; | 268 TestTimeServicePtr time_service; |
| 268 | 269 |
| 269 // 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 |
| 270 // tracking app. Do all this with tracking enabled, meaning both services | 271 // tracking app. Do all this with tracking enabled, meaning both services |
| 271 // are connected as clients of the TrackedRequestService. | 272 // are connected as clients of the TrackedRequestService. |
| 272 ConnectToService(test_app_url(), &service); | 273 ConnectToService(test_app_url(), &service); |
| 273 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 274 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
| 274 message_loop()->Run(); | 275 message_loop()->Run(); |
| 275 for (int i = 0; i < 5; i++) | 276 for (int i = 0; i < 5; i++) |
| 276 service->Ping(mojo::Callback<void()>()); | 277 service->Ping(Callback<void()>()); |
| 277 int64 time_result; | 278 int64 time_result; |
| 278 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", | 279 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", |
| 279 SetAndQuit<int64>(&time_result)); | 280 SetAndQuit<int64>(&time_result)); |
| 280 message_loop()->Run(); | 281 message_loop()->Run(); |
| 281 | 282 |
| 282 // 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. |
| 283 ConnectToService(test_app_url(), &time_service); | 284 ConnectToService(test_app_url(), &time_service); |
| 284 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 285 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
| 285 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 286 time_service->GetPartyTime(Callback<void(uint64_t)>()); |
| 286 message_loop()->Run(); | 287 message_loop()->Run(); |
| 287 for (int i = 0; i < 18; i++) | 288 for (int i = 0; i < 18; i++) |
| 288 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 289 time_service->GetPartyTime(Callback<void(uint64_t)>()); |
| 289 // Flush the tasks with one more to quit. | 290 // Flush the tasks with one more to quit. |
| 290 int64 party_time = 0; | 291 int64 party_time = 0; |
| 291 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); | 292 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); |
| 292 message_loop()->Run(); | 293 message_loop()->Run(); |
| 293 | 294 |
| 294 std::vector<ServiceReport> reports; | 295 std::vector<ServiceReport> reports; |
| 295 GetReport(&reports); | 296 GetReport(&reports); |
| 296 ASSERT_EQ(3U, reports.size()); | 297 ASSERT_EQ(3U, reports.size()); |
| 297 EXPECT_EQ(TestService::Name_, reports[0].service_name); | 298 EXPECT_EQ(TestService::Name_, reports[0].service_name); |
| 298 EXPECT_EQ(6U, reports[0].total_requests); | 299 EXPECT_EQ(6U, reports[0].total_requests); |
| 299 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); | 300 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
| 300 EXPECT_EQ(1U, reports[1].total_requests); | 301 EXPECT_EQ(1U, reports[1].total_requests); |
| 301 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 302 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
| 302 EXPECT_EQ(20U, reports[2].total_requests); | 303 EXPECT_EQ(20U, reports[2].total_requests); |
| 303 } | 304 } |
| 304 | 305 |
| 305 } // namespace | 306 } // namespace |
| 306 } // namespace test | 307 } // namespace test |
| 307 } // namespace shell | 308 } // namespace shell |
| OLD | NEW |