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 "chrome/browser/ui/webui/media_router/media_router_ui.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); | 148 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); |
149 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title))); | 149 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title))); |
150 std::unique_ptr<RouteRequestResult> result = | 150 std::unique_ptr<RouteRequestResult> result = |
151 RouteRequestResult::FromError("Timed out", RouteRequestResult::TIMED_OUT); | 151 RouteRequestResult::FromError("Timed out", RouteRequestResult::TIMED_OUT); |
152 for (const auto& callback : callbacks) | 152 for (const auto& callback : callbacks) |
153 callback.Run(*result); | 153 callback.Run(*result); |
154 } | 154 } |
155 | 155 |
156 TEST_F(MediaRouterUITest, RouteCreationTimeoutForPresentation) { | 156 TEST_F(MediaRouterUITest, RouteCreationTimeoutForPresentation) { |
157 CreateMediaRouterUI(&profile_); | 157 CreateMediaRouterUI(&profile_); |
158 PresentationRequest presentation_request(RenderFrameHostId(0, 0), | 158 PresentationRequest presentation_request( |
159 {"https://presentationurl.fakeurl"}, | 159 RenderFrameHostId(0, 0), {GURL("https://presentationurl.com")}, |
160 GURL("https://frameurl.fakeurl")); | 160 GURL("https://frameurl.fakeurl")); |
161 media_router_ui_->OnDefaultPresentationChanged(presentation_request); | 161 media_router_ui_->OnDefaultPresentationChanged(presentation_request); |
162 std::vector<MediaRouteResponseCallback> callbacks; | 162 std::vector<MediaRouteResponseCallback> callbacks; |
163 EXPECT_CALL( | 163 EXPECT_CALL( |
164 mock_router_, | 164 mock_router_, |
165 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), false)) | 165 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), false)) |
166 .WillOnce(SaveArg<4>(&callbacks)); | 166 .WillOnce(SaveArg<4>(&callbacks)); |
167 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), | 167 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), |
168 MediaCastMode::DEFAULT); | 168 MediaCastMode::DEFAULT); |
169 | 169 |
170 std::string expected_title = | 170 std::string expected_title = |
(...skipping 17 matching lines...) Expand all Loading... |
188 "domain", MediaCastMode::DEFAULT); | 188 "domain", MediaCastMode::DEFAULT); |
189 std::string expected_title = l10n_util::GetStringUTF8( | 189 std::string expected_title = l10n_util::GetStringUTF8( |
190 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 190 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
191 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title))); | 191 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title))); |
192 sink_callback.Run("foundSinkId"); | 192 sink_callback.Run("foundSinkId"); |
193 } | 193 } |
194 | 194 |
195 TEST_F(MediaRouterUITest, RouteRequestFromIncognito) { | 195 TEST_F(MediaRouterUITest, RouteRequestFromIncognito) { |
196 CreateMediaRouterUI(profile_.GetOffTheRecordProfile()); | 196 CreateMediaRouterUI(profile_.GetOffTheRecordProfile()); |
197 | 197 |
198 PresentationRequest presentation_request( | 198 PresentationRequest presentation_request(RenderFrameHostId(0, 0), |
199 RenderFrameHostId(0, 0), {"https://fooUrl"}, GURL("https://frameUrl")); | 199 {GURL("https://foo.url.com/")}, |
| 200 GURL("https://frameUrl")); |
200 media_router_ui_->OnDefaultPresentationChanged(presentation_request); | 201 media_router_ui_->OnDefaultPresentationChanged(presentation_request); |
201 | 202 |
202 EXPECT_CALL( | 203 EXPECT_CALL( |
203 mock_router_, | 204 mock_router_, |
204 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), true)); | 205 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), true)); |
205 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), | 206 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), |
206 MediaCastMode::DEFAULT); | 207 MediaCastMode::DEFAULT); |
207 } | 208 } |
208 | 209 |
209 TEST_F(MediaRouterUITest, SortedSinks) { | 210 TEST_F(MediaRouterUITest, SortedSinks) { |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 | 481 |
481 EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get())); | 482 EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get())); |
482 } | 483 } |
483 | 484 |
484 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { | 485 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { |
485 content::PresentationError expected_error( | 486 content::PresentationError expected_error( |
486 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 487 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |
487 "No screens found."); | 488 "No screens found."); |
488 PresentationRequestCallbacks request_callbacks(expected_error); | 489 PresentationRequestCallbacks request_callbacks(expected_error); |
489 create_session_request_.reset(new CreatePresentationConnectionRequest( | 490 create_session_request_.reset(new CreatePresentationConnectionRequest( |
490 RenderFrameHostId(0, 0), std::string("http://google.com/presentation"), | 491 RenderFrameHostId(0, 0), GURL("http://google.com/presentation"), |
491 GURL("http://google.com"), | 492 GURL("http://google.com"), |
492 base::Bind(&PresentationRequestCallbacks::Success, | 493 base::Bind(&PresentationRequestCallbacks::Success, |
493 base::Unretained(&request_callbacks)), | 494 base::Unretained(&request_callbacks)), |
494 base::Bind(&PresentationRequestCallbacks::Error, | 495 base::Bind(&PresentationRequestCallbacks::Error, |
495 base::Unretained(&request_callbacks)))); | 496 base::Unretained(&request_callbacks)))); |
496 CreateMediaRouterUI(&profile_); | 497 CreateMediaRouterUI(&profile_); |
497 // Destroying the UI should return the expected error from above to the error | 498 // Destroying the UI should return the expected error from above to the error |
498 // callback. | 499 // callback. |
499 media_router_ui_.reset(); | 500 media_router_ui_.reset(); |
500 } | 501 } |
501 | 502 |
502 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) { | 503 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) { |
503 content::PresentationError expected_error( | 504 content::PresentationError expected_error( |
504 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, | 505 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, |
505 "No screens found."); | 506 "No screens found."); |
506 PresentationRequestCallbacks request_callbacks(expected_error); | 507 PresentationRequestCallbacks request_callbacks(expected_error); |
507 std::string presentation_url("http://google.com/presentation"); | 508 GURL presentation_url("http://google.com/presentation"); |
508 create_session_request_.reset(new CreatePresentationConnectionRequest( | 509 create_session_request_.reset(new CreatePresentationConnectionRequest( |
509 RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), | 510 RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), |
510 base::Bind(&PresentationRequestCallbacks::Success, | 511 base::Bind(&PresentationRequestCallbacks::Success, |
511 base::Unretained(&request_callbacks)), | 512 base::Unretained(&request_callbacks)), |
512 base::Bind(&PresentationRequestCallbacks::Error, | 513 base::Bind(&PresentationRequestCallbacks::Error, |
513 base::Unretained(&request_callbacks)))); | 514 base::Unretained(&request_callbacks)))); |
514 CreateMediaRouterUI(&profile_); | 515 CreateMediaRouterUI(&profile_); |
515 | 516 |
516 // Send a sink to the UI that is compatible with sources other than the | 517 // Send a sink to the UI that is compatible with sources other than the |
517 // presentation url to cause a NotFoundError. | 518 // presentation url to cause a NotFoundError. |
518 std::vector<MediaSink> sinks; | 519 std::vector<MediaSink> sinks; |
519 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); | 520 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); |
520 std::vector<GURL> origins; | 521 std::vector<GURL> origins; |
521 for (auto* observer : media_sinks_observers_) { | 522 for (auto* observer : media_sinks_observers_) { |
522 if (observer->source().id() != presentation_url) { | 523 if (observer->source().id() != presentation_url.spec()) { |
523 observer->OnSinksUpdated(sinks, origins); | 524 observer->OnSinksUpdated(sinks, origins); |
524 } | 525 } |
525 } | 526 } |
526 // Destroying the UI should return the expected error from above to the error | 527 // Destroying the UI should return the expected error from above to the error |
527 // callback. | 528 // callback. |
528 media_router_ui_.reset(); | 529 media_router_ui_.reset(); |
529 } | 530 } |
530 | 531 |
531 TEST_F(MediaRouterUITest, AbortErrorOnClose) { | 532 TEST_F(MediaRouterUITest, AbortErrorOnClose) { |
532 content::PresentationError expected_error( | 533 content::PresentationError expected_error( |
533 content::PresentationErrorType:: | 534 content::PresentationErrorType:: |
534 PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 535 PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
535 "Dialog closed."); | 536 "Dialog closed."); |
536 PresentationRequestCallbacks request_callbacks(expected_error); | 537 PresentationRequestCallbacks request_callbacks(expected_error); |
537 std::string presentation_url("http://google.com/presentation"); | 538 GURL presentation_url("http://google.com/presentation"); |
538 create_session_request_.reset(new CreatePresentationConnectionRequest( | 539 create_session_request_.reset(new CreatePresentationConnectionRequest( |
539 RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), | 540 RenderFrameHostId(0, 0), presentation_url, GURL("http://google.com"), |
540 base::Bind(&PresentationRequestCallbacks::Success, | 541 base::Bind(&PresentationRequestCallbacks::Success, |
541 base::Unretained(&request_callbacks)), | 542 base::Unretained(&request_callbacks)), |
542 base::Bind(&PresentationRequestCallbacks::Error, | 543 base::Bind(&PresentationRequestCallbacks::Error, |
543 base::Unretained(&request_callbacks)))); | 544 base::Unretained(&request_callbacks)))); |
544 CreateMediaRouterUI(&profile_); | 545 CreateMediaRouterUI(&profile_); |
545 | 546 |
546 // Send a sink to the UI that is compatible with the presentation url to avoid | 547 // Send a sink to the UI that is compatible with the presentation url to avoid |
547 // a NotFoundError. | 548 // a NotFoundError. |
548 std::vector<MediaSink> sinks; | 549 std::vector<MediaSink> sinks; |
549 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); | 550 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); |
550 std::vector<GURL> origins; | 551 std::vector<GURL> origins; |
| 552 MediaSource::Id presentation_source_id = |
| 553 MediaSourceForPresentationUrl(presentation_url).id(); |
551 for (auto* observer : media_sinks_observers_) { | 554 for (auto* observer : media_sinks_observers_) { |
552 if (observer->source().id() == presentation_url) { | 555 if (observer->source().id() == presentation_source_id) { |
553 observer->OnSinksUpdated(sinks, origins); | 556 observer->OnSinksUpdated(sinks, origins); |
554 } | 557 } |
555 } | 558 } |
556 // Destroying the UI should return the expected error from above to the error | 559 // Destroying the UI should return the expected error from above to the error |
557 // callback. | 560 // callback. |
558 media_router_ui_.reset(); | 561 media_router_ui_.reset(); |
559 } | 562 } |
560 } // namespace media_router | 563 } // namespace media_router |
OLD | NEW |