| 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 "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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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) { |
| 47 return base::Bind(&ShellTestBaseTest::SetAndQuitImpl<T>, | 47 return base::Bind(&ShellTestBaseTest::SetAndQuitImpl<T>, |
| 48 base::Unretained(this), val, result); | 48 base::Unretained(this), val, result); |
| 49 } | 49 } |
| 50 template <typename T> | 50 template <typename T> |
| 51 base::Callback<void(T result)> SetAndQuit(T* val) { | 51 base::Callback<void(T result)> SetAndQuit(T* val) { |
| 52 return base::Bind(&ShellTestBaseTest::SetAndQuitImpl<T>, | 52 return base::Bind(&ShellTestBaseTest::SetAndQuitImpl<T>, |
| 53 base::Unretained(this), val); | 53 base::Unretained(this), val); |
| 54 } | 54 } |
| 55 static GURL test_app_url() { | 55 static GURL test_app_url() { return GURL("mojo:test_app"); } |
| 56 return GURL("mojo:mojo_test_app"); | |
| 57 } | |
| 58 | 56 |
| 59 void GetReport(std::vector<ServiceReport>* report) { | 57 void GetReport(std::vector<ServiceReport>* report) { |
| 60 ConnectToService(GURL("mojo:mojo_test_request_tracker_app"), | 58 ConnectToService(GURL("mojo:test_request_tracker_app"), &request_tracking_); |
| 61 &request_tracking_); | |
| 62 request_tracking_->GetReport(base::Bind(&GetReportCallback, | 59 request_tracking_->GetReport(base::Bind(&GetReportCallback, |
| 63 base::Unretained(message_loop()), | 60 base::Unretained(message_loop()), |
| 64 base::Unretained(report))); | 61 base::Unretained(report))); |
| 65 message_loop()->Run(); | 62 message_loop()->Run(); |
| 66 } | 63 } |
| 67 | 64 |
| 68 private: | 65 private: |
| 69 template<typename T> | 66 template<typename T> |
| 70 void SetAndQuitImpl(T* val, T result) { | 67 void SetAndQuitImpl(T* val, T result) { |
| 71 *val = result; | 68 *val = result; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 217 |
| 221 EXPECT_EQ(time_message, party_time); | 218 EXPECT_EQ(time_message, party_time); |
| 222 } | 219 } |
| 223 | 220 |
| 224 // Tests that a service A in App 1 can talk to service B in App 2 and | 221 // Tests that a service A in App 1 can talk to service B in App 2 and |
| 225 // parameters are passed around properly. | 222 // parameters are passed around properly. |
| 226 TEST_F(ShellTestBaseTest, ConnectDifferentServicesInDifferentApps) { | 223 TEST_F(ShellTestBaseTest, ConnectDifferentServicesInDifferentApps) { |
| 227 int64 time_message; | 224 int64 time_message; |
| 228 TestServicePtr service; | 225 TestServicePtr service; |
| 229 ConnectToService(test_app_url(), &service); | 226 ConnectToService(test_app_url(), &service); |
| 230 service->ConnectToAppAndGetTime("mojo:mojo_test_request_tracker_app", | 227 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", |
| 231 SetAndQuit<int64>(&time_message)); | 228 SetAndQuit<int64>(&time_message)); |
| 232 message_loop()->Run(); | 229 message_loop()->Run(); |
| 233 | 230 |
| 234 // Verify by hitting the TimeService in the request tracker app directly. | 231 // Verify by hitting the TimeService in the request tracker app directly. |
| 235 TestTimeServicePtr time_service; | 232 TestTimeServicePtr time_service; |
| 236 ConnectToService(GURL("mojo:mojo_test_request_tracker_app"), &time_service); | 233 ConnectToService(GURL("mojo:test_request_tracker_app"), &time_service); |
| 237 int64 party_time; | 234 int64 party_time; |
| 238 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); | 235 time_service->GetPartyTime(SetAndQuit<int64>(&party_time)); |
| 239 message_loop()->Run(); | 236 message_loop()->Run(); |
| 240 | 237 |
| 241 EXPECT_EQ(time_message, party_time); | 238 EXPECT_EQ(time_message, party_time); |
| 242 } | 239 } |
| 243 | 240 |
| 244 // Tests that service A in App 1 can be a client of service B in App 2. | 241 // Tests that service A in App 1 can be a client of service B in App 2. |
| 245 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { | 242 TEST_F(ShellTestBaseTest, ConnectServiceAsClientOfSeparateApp) { |
| 246 TestServicePtr service; | 243 TestServicePtr service; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 271 | 268 |
| 272 // Make a request to the TestService and have it contact TimeService in the | 269 // Make a request to the TestService and have it contact TimeService in the |
| 273 // tracking app. Do all this with tracking enabled, meaning both services | 270 // tracking app. Do all this with tracking enabled, meaning both services |
| 274 // are connected as clients of the TrackedRequestService. | 271 // are connected as clients of the TrackedRequestService. |
| 275 ConnectToService(test_app_url(), &service); | 272 ConnectToService(test_app_url(), &service); |
| 276 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 273 service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
| 277 message_loop()->Run(); | 274 message_loop()->Run(); |
| 278 for (int i = 0; i < 5; i++) | 275 for (int i = 0; i < 5; i++) |
| 279 service->Ping(mojo::Callback<void()>()); | 276 service->Ping(mojo::Callback<void()>()); |
| 280 int64 time_result; | 277 int64 time_result; |
| 281 service->ConnectToAppAndGetTime("mojo:mojo_test_request_tracker_app", | 278 service->ConnectToAppAndGetTime("mojo:test_request_tracker_app", |
| 282 SetAndQuit<int64>(&time_result)); | 279 SetAndQuit<int64>(&time_result)); |
| 283 message_loop()->Run(); | 280 message_loop()->Run(); |
| 284 | 281 |
| 285 // Also make a few requests to the TimeService in the test_app. | 282 // Also make a few requests to the TimeService in the test_app. |
| 286 ConnectToService(test_app_url(), &time_service); | 283 ConnectToService(test_app_url(), &time_service); |
| 287 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); | 284 time_service->StartTrackingRequests(message_loop()->QuitWhenIdleClosure()); |
| 288 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 285 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); |
| 289 message_loop()->Run(); | 286 message_loop()->Run(); |
| 290 for (int i = 0; i < 18; i++) | 287 for (int i = 0; i < 18; i++) |
| 291 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); | 288 time_service->GetPartyTime(mojo::Callback<void(uint64_t)>()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); | 299 EXPECT_EQ(TestTimeService::Name_, reports[1].service_name); |
| 303 EXPECT_EQ(1U, reports[1].total_requests); | 300 EXPECT_EQ(1U, reports[1].total_requests); |
| 304 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); | 301 EXPECT_EQ(TestTimeService::Name_, reports[2].service_name); |
| 305 EXPECT_EQ(20U, reports[2].total_requests); | 302 EXPECT_EQ(20U, reports[2].total_requests); |
| 306 } | 303 } |
| 307 | 304 |
| 308 } // namespace | 305 } // namespace |
| 309 } // namespace test | 306 } // namespace test |
| 310 } // namespace shell | 307 } // namespace shell |
| 311 } // namespace mojo | 308 } // namespace mojo |
| OLD | NEW |