Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc

Issue 2678123003: Revert of Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 .Times(AnyNumber()); 107 .Times(AnyNumber());
108 media_router_ui_->InitForTest(&mock_router_, web_contents(), 108 media_router_ui_->InitForTest(&mock_router_, web_contents(),
109 message_handler_.get(), 109 message_handler_.get(),
110 std::move(create_session_request_)); 110 std::move(create_session_request_));
111 message_handler_->SetWebUIForTest(&web_ui_); 111 message_handler_->SetWebUIForTest(&web_ui_);
112 } 112 }
113 113
114 MediaSink CreateSinkCompatibleWithAllSources() { 114 MediaSink CreateSinkCompatibleWithAllSources() {
115 MediaSink sink("sinkId", "sinkName", MediaSink::GENERIC); 115 MediaSink sink("sinkId", "sinkName", MediaSink::GENERIC);
116 for (auto* observer : media_sinks_observers_) 116 for (auto* observer : media_sinks_observers_)
117 observer->OnSinksUpdated({sink}, std::vector<url::Origin>()); 117 observer->OnSinksUpdated({sink}, std::vector<GURL>());
118 return sink; 118 return sink;
119 } 119 }
120 120
121 protected: 121 protected:
122 MockMediaRouter mock_router_; 122 MockMediaRouter mock_router_;
123 content::TestWebUI web_ui_; 123 content::TestWebUI web_ui_;
124 std::unique_ptr<WebContents> web_ui_contents_; 124 std::unique_ptr<WebContents> web_ui_contents_;
125 std::unique_ptr<CreatePresentationConnectionRequest> create_session_request_; 125 std::unique_ptr<CreatePresentationConnectionRequest> create_session_request_;
126 std::unique_ptr<MediaRouterUI> media_router_ui_; 126 std::unique_ptr<MediaRouterUI> media_router_ui_;
127 std::unique_ptr<MediaRouterWebUIMessageHandler> message_handler_; 127 std::unique_ptr<MediaRouterWebUIMessageHandler> message_handler_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 std::unique_ptr<RouteRequestResult> result = 163 std::unique_ptr<RouteRequestResult> result =
164 RouteRequestResult::FromError("Timed out", RouteRequestResult::TIMED_OUT); 164 RouteRequestResult::FromError("Timed out", RouteRequestResult::TIMED_OUT);
165 for (const auto& callback : callbacks) 165 for (const auto& callback : callbacks)
166 callback.Run(*result); 166 callback.Run(*result);
167 } 167 }
168 168
169 TEST_F(MediaRouterUITest, RouteCreationTimeoutForPresentation) { 169 TEST_F(MediaRouterUITest, RouteCreationTimeoutForPresentation) {
170 CreateMediaRouterUI(profile()); 170 CreateMediaRouterUI(profile());
171 PresentationRequest presentation_request( 171 PresentationRequest presentation_request(
172 RenderFrameHostId(0, 0), {GURL("https://presentationurl.com")}, 172 RenderFrameHostId(0, 0), {GURL("https://presentationurl.com")},
173 url::Origin(GURL("https://frameurl.fakeurl"))); 173 GURL("https://frameurl.fakeurl"));
174 media_router_ui_->OnDefaultPresentationChanged(presentation_request); 174 media_router_ui_->OnDefaultPresentationChanged(presentation_request);
175 std::vector<MediaRouteResponseCallback> callbacks; 175 std::vector<MediaRouteResponseCallback> callbacks;
176 EXPECT_CALL( 176 EXPECT_CALL(
177 mock_router_, 177 mock_router_,
178 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), false)) 178 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), false))
179 .WillOnce(SaveArg<4>(&callbacks)); 179 .WillOnce(SaveArg<4>(&callbacks));
180 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), 180 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(),
181 MediaCastMode::DEFAULT); 181 MediaCastMode::DEFAULT);
182 182
183 std::string expected_title = 183 std::string expected_title =
(...skipping 17 matching lines...) Expand all
201 "domain", MediaCastMode::DEFAULT); 201 "domain", MediaCastMode::DEFAULT);
202 std::string expected_title = l10n_util::GetStringUTF8( 202 std::string expected_title = l10n_util::GetStringUTF8(
203 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); 203 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB);
204 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title))); 204 EXPECT_CALL(mock_router_, AddIssue(IssueTitleEquals(expected_title)));
205 sink_callback.Run("foundSinkId"); 205 sink_callback.Run("foundSinkId");
206 } 206 }
207 207
208 TEST_F(MediaRouterUITest, RouteRequestFromIncognito) { 208 TEST_F(MediaRouterUITest, RouteRequestFromIncognito) {
209 CreateMediaRouterUI(profile()->GetOffTheRecordProfile()); 209 CreateMediaRouterUI(profile()->GetOffTheRecordProfile());
210 210
211 PresentationRequest presentation_request( 211 PresentationRequest presentation_request(RenderFrameHostId(0, 0),
212 RenderFrameHostId(0, 0), {GURL("https://foo.url.com/")}, 212 {GURL("https://foo.url.com/")},
213 url::Origin(GURL("https://frameUrl"))); 213 GURL("https://frameUrl"));
214 media_router_ui_->OnDefaultPresentationChanged(presentation_request); 214 media_router_ui_->OnDefaultPresentationChanged(presentation_request);
215 215
216 EXPECT_CALL( 216 EXPECT_CALL(
217 mock_router_, 217 mock_router_,
218 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), true)); 218 CreateRoute(_, _, _, _, _, base::TimeDelta::FromSeconds(20), true));
219 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(), 219 media_router_ui_->CreateRoute(CreateSinkCompatibleWithAllSources().id(),
220 MediaCastMode::DEFAULT); 220 MediaCastMode::DEFAULT);
221 } 221 }
222 222
223 TEST_F(MediaRouterUITest, SortedSinks) { 223 TEST_F(MediaRouterUITest, SortedSinks) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 } 470 }
471 471
472 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { 472 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) {
473 content::PresentationError expected_error( 473 content::PresentationError expected_error(
474 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, 474 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
475 "No screens found."); 475 "No screens found.");
476 PresentationRequestCallbacks request_callbacks(expected_error); 476 PresentationRequestCallbacks request_callbacks(expected_error);
477 create_session_request_.reset(new CreatePresentationConnectionRequest( 477 create_session_request_.reset(new CreatePresentationConnectionRequest(
478 RenderFrameHostId(0, 0), {GURL("http://google.com/presentation"), 478 RenderFrameHostId(0, 0), {GURL("http://google.com/presentation"),
479 GURL("http://google.com/presentation2")}, 479 GURL("http://google.com/presentation2")},
480 url::Origin(GURL("http://google.com")), 480 GURL("http://google.com"),
481 base::Bind(&PresentationRequestCallbacks::Success, 481 base::Bind(&PresentationRequestCallbacks::Success,
482 base::Unretained(&request_callbacks)), 482 base::Unretained(&request_callbacks)),
483 base::Bind(&PresentationRequestCallbacks::Error, 483 base::Bind(&PresentationRequestCallbacks::Error,
484 base::Unretained(&request_callbacks)))); 484 base::Unretained(&request_callbacks))));
485 CreateMediaRouterUI(profile()); 485 CreateMediaRouterUI(profile());
486 // Destroying the UI should return the expected error from above to the error 486 // Destroying the UI should return the expected error from above to the error
487 // callback. 487 // callback.
488 media_router_ui_.reset(); 488 media_router_ui_.reset();
489 } 489 }
490 490
491 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) { 491 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoCompatibleSinks) {
492 content::PresentationError expected_error( 492 content::PresentationError expected_error(
493 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, 493 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
494 "No screens found."); 494 "No screens found.");
495 PresentationRequestCallbacks request_callbacks(expected_error); 495 PresentationRequestCallbacks request_callbacks(expected_error);
496 GURL presentation_url("http://google.com/presentation"); 496 GURL presentation_url("http://google.com/presentation");
497 create_session_request_.reset(new CreatePresentationConnectionRequest( 497 create_session_request_.reset(new CreatePresentationConnectionRequest(
498 RenderFrameHostId(0, 0), {presentation_url}, 498 RenderFrameHostId(0, 0), {presentation_url}, GURL("http://google.com"),
499 url::Origin(GURL("http://google.com")),
500 base::Bind(&PresentationRequestCallbacks::Success, 499 base::Bind(&PresentationRequestCallbacks::Success,
501 base::Unretained(&request_callbacks)), 500 base::Unretained(&request_callbacks)),
502 base::Bind(&PresentationRequestCallbacks::Error, 501 base::Bind(&PresentationRequestCallbacks::Error,
503 base::Unretained(&request_callbacks)))); 502 base::Unretained(&request_callbacks))));
504 CreateMediaRouterUI(profile()); 503 CreateMediaRouterUI(profile());
505 504
506 // Send a sink to the UI that is compatible with sources other than the 505 // Send a sink to the UI that is compatible with sources other than the
507 // presentation url to cause a NotFoundError. 506 // presentation url to cause a NotFoundError.
508 std::vector<MediaSink> sinks; 507 std::vector<MediaSink> sinks;
509 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); 508 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC);
510 std::vector<url::Origin> origins; 509 std::vector<GURL> origins;
511 for (auto* observer : media_sinks_observers_) { 510 for (auto* observer : media_sinks_observers_) {
512 if (observer->source().id() != presentation_url.spec()) { 511 if (observer->source().id() != presentation_url.spec()) {
513 observer->OnSinksUpdated(sinks, origins); 512 observer->OnSinksUpdated(sinks, origins);
514 } 513 }
515 } 514 }
516 // Destroying the UI should return the expected error from above to the error 515 // Destroying the UI should return the expected error from above to the error
517 // callback. 516 // callback.
518 media_router_ui_.reset(); 517 media_router_ui_.reset();
519 } 518 }
520 519
521 TEST_F(MediaRouterUITest, AbortErrorOnClose) { 520 TEST_F(MediaRouterUITest, AbortErrorOnClose) {
522 content::PresentationError expected_error( 521 content::PresentationError expected_error(
523 content::PresentationErrorType:: 522 content::PresentationErrorType::
524 PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 523 PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
525 "Dialog closed."); 524 "Dialog closed.");
526 PresentationRequestCallbacks request_callbacks(expected_error); 525 PresentationRequestCallbacks request_callbacks(expected_error);
527 GURL presentation_url("http://google.com/presentation"); 526 GURL presentation_url("http://google.com/presentation");
528 create_session_request_.reset(new CreatePresentationConnectionRequest( 527 create_session_request_.reset(new CreatePresentationConnectionRequest(
529 RenderFrameHostId(0, 0), {presentation_url}, 528 RenderFrameHostId(0, 0), {presentation_url}, GURL("http://google.com"),
530 url::Origin(GURL("http://google.com")),
531 base::Bind(&PresentationRequestCallbacks::Success, 529 base::Bind(&PresentationRequestCallbacks::Success,
532 base::Unretained(&request_callbacks)), 530 base::Unretained(&request_callbacks)),
533 base::Bind(&PresentationRequestCallbacks::Error, 531 base::Bind(&PresentationRequestCallbacks::Error,
534 base::Unretained(&request_callbacks)))); 532 base::Unretained(&request_callbacks))));
535 CreateMediaRouterUI(profile()); 533 CreateMediaRouterUI(profile());
536 534
537 // Send a sink to the UI that is compatible with the presentation url to avoid 535 // Send a sink to the UI that is compatible with the presentation url to avoid
538 // a NotFoundError. 536 // a NotFoundError.
539 std::vector<MediaSink> sinks; 537 std::vector<MediaSink> sinks;
540 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC); 538 sinks.emplace_back("sink id", "sink name", MediaSink::GENERIC);
541 std::vector<url::Origin> origins; 539 std::vector<GURL> origins;
542 MediaSource::Id presentation_source_id = 540 MediaSource::Id presentation_source_id =
543 MediaSourceForPresentationUrl(presentation_url).id(); 541 MediaSourceForPresentationUrl(presentation_url).id();
544 for (auto* observer : media_sinks_observers_) { 542 for (auto* observer : media_sinks_observers_) {
545 if (observer->source().id() == presentation_source_id) { 543 if (observer->source().id() == presentation_source_id) {
546 observer->OnSinksUpdated(sinks, origins); 544 observer->OnSinksUpdated(sinks, origins);
547 } 545 }
548 } 546 }
549 // Destroying the UI should return the expected error from above to the error 547 // Destroying the UI should return the expected error from above to the error
550 // callback. 548 // callback.
551 media_router_ui_.reset(); 549 media_router_ui_.reset();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 EXPECT_FALSE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin()); 601 EXPECT_FALSE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin());
604 602
605 media_router_ui_->RecordCastModeSelection(MediaCastMode::TAB_MIRROR); 603 media_router_ui_->RecordCastModeSelection(MediaCastMode::TAB_MIRROR);
606 EXPECT_TRUE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin()); 604 EXPECT_TRUE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin());
607 media_router_ui_->RecordCastModeSelection(MediaCastMode::DESKTOP_MIRROR); 605 media_router_ui_->RecordCastModeSelection(MediaCastMode::DESKTOP_MIRROR);
608 // Selecting desktop mirroring should not change the recorded preferences. 606 // Selecting desktop mirroring should not change the recorded preferences.
609 EXPECT_TRUE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin()); 607 EXPECT_TRUE(media_router_ui_->UserSelectedTabMirroringForCurrentOrigin());
610 } 608 }
611 609
612 } // namespace media_router 610 } // namespace media_router
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/media_router/media_router_ui.cc ('k') | chrome/browser/ui/webui/media_router/query_result_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698