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

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

Issue 2862393002: [Media Router] Force DEFAULT cast mode when starting presentations from content. (Closed)
Patch Set: Fix bug found by closure compiler Created 3 years, 7 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace media_router { 42 namespace media_router {
43 43
44 class MockMediaRouterWebUIMessageHandler 44 class MockMediaRouterWebUIMessageHandler
45 : public MediaRouterWebUIMessageHandler { 45 : public MediaRouterWebUIMessageHandler {
46 public: 46 public:
47 explicit MockMediaRouterWebUIMessageHandler(MediaRouterUI* media_router_ui) 47 explicit MockMediaRouterWebUIMessageHandler(MediaRouterUI* media_router_ui)
48 : MediaRouterWebUIMessageHandler(media_router_ui) {} 48 : MediaRouterWebUIMessageHandler(media_router_ui) {}
49 ~MockMediaRouterWebUIMessageHandler() override {} 49 ~MockMediaRouterWebUIMessageHandler() override {}
50 50
51 MOCK_METHOD1(UpdateMediaRouteStatus, void(const MediaStatus& status)); 51 MOCK_METHOD1(UpdateMediaRouteStatus, void(const MediaStatus& status));
52 MOCK_METHOD3(UpdateCastModes,
53 void(const CastModeSet& cast_modes,
54 const std::string& source_host,
55 base::Optional<MediaCastMode> forced_cast_mode));
52 }; 56 };
53 57
54 class PresentationRequestCallbacks { 58 class PresentationRequestCallbacks {
55 public: 59 public:
60 PresentationRequestCallbacks()
61 : expected_error_(content::PresentationError(
62 content::PresentationErrorType::PRESENTATION_ERROR_UNKNOWN,
63 "")) {}
64
56 explicit PresentationRequestCallbacks( 65 explicit PresentationRequestCallbacks(
57 const content::PresentationError& expected_error) 66 const content::PresentationError& expected_error)
58 : expected_error_(expected_error) {} 67 : expected_error_(expected_error) {}
59 68
60 void Success(const content::PresentationInfo&, const MediaRoute&) {} 69 void Success(const content::PresentationInfo&, const MediaRoute&) {}
61 70
62 void Error(const content::PresentationError& error) { 71 void Error(const content::PresentationError& error) {
63 EXPECT_EQ(expected_error_.error_type, error.error_type); 72 EXPECT_EQ(expected_error_.error_type, error.error_type);
64 EXPECT_EQ(expected_error_.message, error.message); 73 EXPECT_EQ(expected_error_.message, error.message);
65 } 74 }
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 505
497 EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get())); 506 EXPECT_EQ("", MediaRouterUI::GetExtensionName(url, registry.get()));
498 } 507 }
499 508
500 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) { 509 TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) {
501 content::PresentationError expected_error( 510 content::PresentationError expected_error(
502 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS, 511 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
503 "No screens found."); 512 "No screens found.");
504 PresentationRequestCallbacks request_callbacks(expected_error); 513 PresentationRequestCallbacks request_callbacks(expected_error);
505 create_session_request_.reset(new CreatePresentationConnectionRequest( 514 create_session_request_.reset(new CreatePresentationConnectionRequest(
506 RenderFrameHostId(0, 0), {GURL("http://google.com/presentation"), 515 RenderFrameHostId(0, 0),
507 GURL("http://google.com/presentation2")}, 516 {GURL("http://google.com/presentation"),
517 GURL("http://google.com/presentation2")},
508 url::Origin(GURL("http://google.com")), 518 url::Origin(GURL("http://google.com")),
509 base::Bind(&PresentationRequestCallbacks::Success, 519 base::Bind(&PresentationRequestCallbacks::Success,
510 base::Unretained(&request_callbacks)), 520 base::Unretained(&request_callbacks)),
511 base::Bind(&PresentationRequestCallbacks::Error, 521 base::Bind(&PresentationRequestCallbacks::Error,
512 base::Unretained(&request_callbacks)))); 522 base::Unretained(&request_callbacks))));
513 CreateMediaRouterUI(profile()); 523 CreateMediaRouterUI(profile());
514 // Destroying the UI should return the expected error from above to the error 524 // Destroying the UI should return the expected error from above to the error
515 // callback. 525 // callback.
516 media_router_ui_.reset(); 526 media_router_ui_.reset();
517 } 527 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 media_router_ui_->OnRoutesUpdated({route}, std::vector<MediaRoute::Id>()); 686 media_router_ui_->OnRoutesUpdated({route}, std::vector<MediaRoute::Id>());
677 687
678 // If the controller has already received a media status update, MediaRouterUI 688 // If the controller has already received a media status update, MediaRouterUI
679 // should be notified with it when it starts observing the controller. 689 // should be notified with it when it starts observing the controller.
680 EXPECT_CALL(mock_router_, GetRouteController(route_id)) 690 EXPECT_CALL(mock_router_, GetRouteController(route_id))
681 .WillOnce(Return(controller)); 691 .WillOnce(Return(controller));
682 EXPECT_CALL(*message_handler_, UpdateMediaRouteStatus(status)); 692 EXPECT_CALL(*message_handler_, UpdateMediaRouteStatus(status));
683 media_router_ui_->OnMediaControllerUIAvailable(route_id); 693 media_router_ui_->OnMediaControllerUIAvailable(route_id);
684 } 694 }
685 695
696 TEST_F(MediaRouterUITest, SetsForcedCastModeWithPresentationURLs) {
697 content::PresentationError expected_error(
698 content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
699 "No screens found.");
700 PresentationRequestCallbacks request_callbacks(expected_error);
701 create_session_request_.reset(new CreatePresentationConnectionRequest(
702 RenderFrameHostId(0, 0),
703 {GURL("http://google.com/presentation"),
704 GURL("http://google.com/presentation2")},
705 url::Origin(GURL("http://google.com")),
706 base::Bind(&PresentationRequestCallbacks::Success,
707 base::Unretained(&request_callbacks)),
708 base::Bind(&PresentationRequestCallbacks::Error,
709 base::Unretained(&request_callbacks))));
710
711 SessionTabHelper::CreateForWebContents(web_contents());
712 web_ui_contents_.reset(
713 WebContents::Create(WebContents::CreateParams(profile())));
714 web_ui_.set_web_contents(web_ui_contents_.get());
715 media_router_ui_ = base::MakeUnique<MediaRouterUI>(&web_ui_);
716 message_handler_ = base::MakeUnique<MockMediaRouterWebUIMessageHandler>(
717 media_router_ui_.get());
718 message_handler_->SetWebUIForTest(&web_ui_);
719 EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_))
720 .WillRepeatedly(Invoke([this](MediaSinksObserver* observer) {
721 this->media_sinks_observers_.push_back(observer);
722 return true;
723 }));
724 EXPECT_CALL(mock_router_, RegisterMediaRoutesObserver(_)).Times(AnyNumber());
725 // For some reason we push two sets of cast modes to the dialog, even when
726 // initializing the dialog with a presentation request. The WebUI can handle
727 // the forced mode that is not in the initial cast mode set, but is this a
728 // bug?
729 CastModeSet expected_modes(
730 {MediaCastMode::TAB_MIRROR, MediaCastMode::DESKTOP_MIRROR});
731 EXPECT_CALL(
732 *message_handler_,
733 UpdateCastModes(expected_modes, "",
734 base::Optional<MediaCastMode>(MediaCastMode::DEFAULT)));
735 expected_modes.insert(MediaCastMode::DEFAULT);
736 EXPECT_CALL(
737 *message_handler_,
738 UpdateCastModes(expected_modes, "google.com",
739 base::Optional<MediaCastMode>(MediaCastMode::DEFAULT)));
740 media_router_ui_->UIInitialized();
741 media_router_ui_->InitForTest(&mock_router_, web_contents(),
742 message_handler_.get(),
743 std::move(create_session_request_));
744 // |media_router_ui_| takes ownership of |request_callbacks|.
745 media_router_ui_.reset();
746 }
747
686 } // namespace media_router 748 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698