Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "chrome/browser/media/router/issue.h" | |
| 12 #include "chrome/browser/media/router/media_route.h" | 13 #include "chrome/browser/media/router/media_route.h" |
| 13 #include "chrome/browser/media/router/media_router_mojo_test.h" | 14 #include "chrome/browser/media/router/media_router_mojo_test.h" |
| 15 #include "chrome/browser/media/router/media_router_type_converters.h" | |
| 14 #include "chrome/browser/media/router/mock_media_router.h" | 16 #include "chrome/browser/media/router/mock_media_router.h" |
| 15 #include "chrome/browser/media/router/test_helper.h" | 17 #include "chrome/browser/media/router/test_helper.h" |
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 18 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 18 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
| 19 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
| 20 #include "extensions/browser/process_manager_factory.h" | 22 #include "extensions/browser/process_manager_factory.h" |
| 21 #include "media/base/gmock_callback_support.h" | 23 #include "media/base/gmock_callback_support.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 25 using testing::_; | 27 using testing::_; |
| 26 using testing::Eq; | 28 using testing::Eq; |
| 27 using testing::Invoke; | 29 using testing::Invoke; |
| 30 using testing::Mock; | |
| 28 using testing::Pointee; | 31 using testing::Pointee; |
| 29 using testing::Return; | 32 using testing::Return; |
| 30 using testing::ReturnRef; | 33 using testing::ReturnRef; |
| 31 using testing::SaveArg; | 34 using testing::SaveArg; |
| 32 | 35 |
| 33 namespace media_router { | 36 namespace media_router { |
| 34 | 37 |
| 35 namespace { | 38 namespace { |
| 36 | 39 |
| 37 const char kDescription[] = "description"; | 40 const char kDescription[] = "description"; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 54 const content::PresentationSessionMessage* actual) { | 57 const content::PresentationSessionMessage* actual) { |
| 55 if (expected->presentation_url != actual->presentation_url || | 58 if (expected->presentation_url != actual->presentation_url || |
| 56 expected->presentation_id != actual->presentation_id || | 59 expected->presentation_id != actual->presentation_id || |
| 57 expected->type != actual->type) { | 60 expected->type != actual->type) { |
| 58 return false; | 61 return false; |
| 59 } | 62 } |
| 60 return expected->is_binary() ? *(expected->data) == *(actual->data) | 63 return expected->is_binary() ? *(expected->data) == *(actual->data) |
| 61 : *(expected->message) == *(actual->message); | 64 : *(expected->message) == *(actual->message); |
| 62 } | 65 } |
| 63 | 66 |
| 67 interfaces::IssuePtr CreateMojoIssue() { | |
| 68 interfaces::IssuePtr mojoIssue; | |
| 69 mojoIssue = interfaces::Issue::New(); | |
|
imcheng
2015/07/29 01:49:38
nit: combine with line above
haibinlu
2015/07/29 17:24:15
Done.
| |
| 70 mojoIssue->title = "title"; | |
| 71 mojoIssue->message = "msg"; | |
| 72 mojoIssue->route_id = ""; | |
| 73 mojoIssue->default_action = interfaces::Issue::ActionType::ACTION_TYPE_OK; | |
| 74 mojoIssue->secondary_actions = | |
| 75 mojo::Array<interfaces::Issue::ActionType>::New(0); | |
| 76 mojoIssue->severity = interfaces::Issue::Severity::SEVERITY_WARNING; | |
| 77 mojoIssue->is_blocking = false; | |
| 78 mojoIssue->help_url = ""; | |
| 79 return mojoIssue.Pass(); | |
| 80 } | |
| 81 | |
| 64 } // namespace | 82 } // namespace |
| 65 | 83 |
| 66 class RouteResponseCallbackHandler { | 84 class RouteResponseCallbackHandler { |
| 67 public: | 85 public: |
| 68 MOCK_METHOD2(Invoke, | 86 MOCK_METHOD2(Invoke, |
| 69 void(const MediaRoute* route, const std::string& error_text)); | 87 void(const MediaRoute* route, const std::string& error_text)); |
| 70 }; | 88 }; |
| 71 | 89 |
| 72 class SendMessageCallbackHandler { | 90 class SendMessageCallbackHandler { |
| 73 public: | 91 public: |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 route_response_callbacks); | 269 route_response_callbacks); |
| 252 ProcessEventLoop(); | 270 ProcessEventLoop(); |
| 253 } | 271 } |
| 254 | 272 |
| 255 TEST_F(MediaRouterMojoImplTest, CloseRoute) { | 273 TEST_F(MediaRouterMojoImplTest, CloseRoute) { |
| 256 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId))); | 274 EXPECT_CALL(mock_media_route_provider_, CloseRoute(mojo::String(kRouteId))); |
| 257 router()->CloseRoute(kRouteId); | 275 router()->CloseRoute(kRouteId); |
| 258 ProcessEventLoop(); | 276 ProcessEventLoop(); |
| 259 } | 277 } |
| 260 | 278 |
| 279 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterIssuesObserver) { | |
| 280 MockIssuesObserver issue_observer1(router()); | |
| 281 MockIssuesObserver issue_observer2(router()); | |
| 282 const Issue* issue; | |
| 283 EXPECT_CALL(issue_observer1, OnIssueUpdated(_)) | |
| 284 .WillRepeatedly(SaveArg<0>(&issue)); | |
| 285 EXPECT_CALL(issue_observer2, OnIssueUpdated(_)); | |
| 286 media_router_proxy_->OnIssue(CreateMojoIssue().Pass()); | |
| 287 ProcessEventLoop(); | |
| 288 | |
| 289 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer1)); | |
| 290 EXPECT_TRUE(Mock::VerifyAndClearExpectations(&issue_observer2)); | |
| 291 | |
| 292 router()->ClearIssue(issue->id()); | |
| 293 router()->UnregisterIssuesObserver(&issue_observer1); | |
| 294 EXPECT_CALL(issue_observer2, OnIssueUpdated(_)); | |
| 295 media_router_proxy_->OnIssue(CreateMojoIssue().Pass()); | |
| 296 ProcessEventLoop(); | |
| 297 } | |
| 298 | |
| 261 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { | 299 TEST_F(MediaRouterMojoImplTest, RegisterAndUnregisterMediaSinksObserver) { |
| 262 MediaSource media_source(kSource); | 300 MediaSource media_source(kSource); |
| 263 | 301 |
| 264 MockMediaRouter mock_router; | 302 MockMediaRouter mock_router; |
| 265 EXPECT_CALL(mock_media_route_provider_, | 303 EXPECT_CALL(mock_media_route_provider_, |
| 266 StartObservingMediaSinks(mojo::String(kSource))).Times(2); | 304 StartObservingMediaSinks(mojo::String(kSource))).Times(2); |
| 267 EXPECT_CALL(mock_media_route_provider_, | 305 EXPECT_CALL(mock_media_route_provider_, |
| 268 StartObservingMediaSinks(mojo::String(kSource2))); | 306 StartObservingMediaSinks(mojo::String(kSource2))); |
| 269 | 307 |
| 270 MediaSinksObserver* captured_observer; | 308 MediaSinksObserver* captured_observer; |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 binding.reset(new mojo::Binding<interfaces::MediaRouteProvider>( | 555 binding.reset(new mojo::Binding<interfaces::MediaRouteProvider>( |
| 518 &mock_media_route_provider, mojo::GetProxy(&media_route_provider_proxy))); | 556 &mock_media_route_provider, mojo::GetProxy(&media_route_provider_proxy))); |
| 519 media_router_proxy->RegisterMediaRouteProvider( | 557 media_router_proxy->RegisterMediaRouteProvider( |
| 520 media_route_provider_proxy.Pass(), | 558 media_route_provider_proxy.Pass(), |
| 521 base::Bind(&RegisterMediaRouteProviderHandler::Invoke, | 559 base::Bind(&RegisterMediaRouteProviderHandler::Invoke, |
| 522 base::Unretained(&provide_handler))); | 560 base::Unretained(&provide_handler))); |
| 523 message_loop.RunUntilIdle(); | 561 message_loop.RunUntilIdle(); |
| 524 } | 562 } |
| 525 | 563 |
| 526 } // namespace media_router | 564 } // namespace media_router |
| OLD | NEW |