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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc
diff --git a/chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc b/chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc
index 1396d79000130fe2d5aa9ed7575c5988c70fe747..609d120b588a941739930ebd3bc4f0061f6ff833 100644
--- a/chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc
+++ b/chrome/browser/ui/webui/media_router/media_router_ui_unittest.cc
@@ -49,10 +49,19 @@ class MockMediaRouterWebUIMessageHandler
~MockMediaRouterWebUIMessageHandler() override {}
MOCK_METHOD1(UpdateMediaRouteStatus, void(const MediaStatus& status));
+ MOCK_METHOD3(UpdateCastModes,
+ void(const CastModeSet& cast_modes,
+ const std::string& source_host,
+ base::Optional<MediaCastMode> forced_cast_mode));
};
class PresentationRequestCallbacks {
public:
+ PresentationRequestCallbacks()
+ : expected_error_(content::PresentationError(
+ content::PresentationErrorType::PRESENTATION_ERROR_UNKNOWN,
+ "")) {}
+
explicit PresentationRequestCallbacks(
const content::PresentationError& expected_error)
: expected_error_(expected_error) {}
@@ -503,8 +512,9 @@ TEST_F(MediaRouterUITest, NotFoundErrorOnCloseWithNoSinks) {
"No screens found.");
PresentationRequestCallbacks request_callbacks(expected_error);
create_session_request_.reset(new CreatePresentationConnectionRequest(
- RenderFrameHostId(0, 0), {GURL("http://google.com/presentation"),
- GURL("http://google.com/presentation2")},
+ RenderFrameHostId(0, 0),
+ {GURL("http://google.com/presentation"),
+ GURL("http://google.com/presentation2")},
url::Origin(GURL("http://google.com")),
base::Bind(&PresentationRequestCallbacks::Success,
base::Unretained(&request_callbacks)),
@@ -683,4 +693,56 @@ TEST_F(MediaRouterUITest, SendInitialMediaStatusUpdate) {
media_router_ui_->OnMediaControllerUIAvailable(route_id);
}
+TEST_F(MediaRouterUITest, SetsForcedCastModeWithPresentationURLs) {
+ content::PresentationError expected_error(
+ content::PresentationErrorType::PRESENTATION_ERROR_NO_AVAILABLE_SCREENS,
+ "No screens found.");
+ PresentationRequestCallbacks request_callbacks(expected_error);
+ create_session_request_.reset(new CreatePresentationConnectionRequest(
+ RenderFrameHostId(0, 0),
+ {GURL("http://google.com/presentation"),
+ GURL("http://google.com/presentation2")},
+ url::Origin(GURL("http://google.com")),
+ base::Bind(&PresentationRequestCallbacks::Success,
+ base::Unretained(&request_callbacks)),
+ base::Bind(&PresentationRequestCallbacks::Error,
+ base::Unretained(&request_callbacks))));
+
+ SessionTabHelper::CreateForWebContents(web_contents());
+ web_ui_contents_.reset(
+ WebContents::Create(WebContents::CreateParams(profile())));
+ web_ui_.set_web_contents(web_ui_contents_.get());
+ media_router_ui_ = base::MakeUnique<MediaRouterUI>(&web_ui_);
+ message_handler_ = base::MakeUnique<MockMediaRouterWebUIMessageHandler>(
+ media_router_ui_.get());
+ message_handler_->SetWebUIForTest(&web_ui_);
+ EXPECT_CALL(mock_router_, RegisterMediaSinksObserver(_))
+ .WillRepeatedly(Invoke([this](MediaSinksObserver* observer) {
+ this->media_sinks_observers_.push_back(observer);
+ return true;
+ }));
+ EXPECT_CALL(mock_router_, RegisterMediaRoutesObserver(_)).Times(AnyNumber());
+ // For some reason we push two sets of cast modes to the dialog, even when
+ // initializing the dialog with a presentation request. The WebUI can handle
+ // the forced mode that is not in the initial cast mode set, but is this a
+ // bug?
+ CastModeSet expected_modes(
+ {MediaCastMode::TAB_MIRROR, MediaCastMode::DESKTOP_MIRROR});
+ EXPECT_CALL(
+ *message_handler_,
+ UpdateCastModes(expected_modes, "",
+ base::Optional<MediaCastMode>(MediaCastMode::DEFAULT)));
+ expected_modes.insert(MediaCastMode::DEFAULT);
+ EXPECT_CALL(
+ *message_handler_,
+ UpdateCastModes(expected_modes, "google.com",
+ base::Optional<MediaCastMode>(MediaCastMode::DEFAULT)));
+ media_router_ui_->UIInitialized();
+ media_router_ui_->InitForTest(&mock_router_, web_contents(),
+ message_handler_.get(),
+ std::move(create_session_request_));
+ // |media_router_ui_| takes ownership of |request_callbacks|.
+ media_router_ui_.reset();
+}
+
} // namespace media_router

Powered by Google App Engine
This is Rietveld 408576698