Commit 03aecfe9 authored by Takumi Fujimoto's avatar Takumi Fujimoto Committed by Commit Bot

[Local Screen Casting] Do not try to get the primary display when no displays

This CL makes WiredDisplayMediaRouteProvider not check for the primary display when there is 0 or 1 display.
This should fix the crash in which WDMRP attempts to get the primary display when the primary display ID is invalid.

Bug: 803881
Change-Id: I095ff7a69b1777c3466d2b6378fcd95e497c5641
Reviewed-on: https://chromium-review.googlesource.com/895389Reviewed-by: default avatarDerek Cheng <imcheng@chromium.org>
Commit-Queue: Takumi Fujimoto <takumif@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533760}
parent ca828d17
...@@ -331,6 +331,11 @@ std::vector<MediaSinkInternal> WiredDisplayMediaRouteProvider::GetSinks() ...@@ -331,6 +331,11 @@ std::vector<MediaSinkInternal> WiredDisplayMediaRouteProvider::GetSinks()
std::vector<Display> WiredDisplayMediaRouteProvider::GetAvailableDisplays() std::vector<Display> WiredDisplayMediaRouteProvider::GetAvailableDisplays()
const { const {
std::vector<Display> displays = GetAllDisplays(); std::vector<Display> displays = GetAllDisplays();
// If there is only one display, the user should not be able to present to it.
// If there are no displays, GetPrimaryDisplay() below fails.
if (displays.size() <= 1)
return std::vector<Display>();
const Display primary_display = GetPrimaryDisplay(); const Display primary_display = GetPrimaryDisplay();
std::sort( std::sort(
displays.begin(), displays.end(), displays.begin(), displays.end(),
...@@ -345,7 +350,8 @@ std::vector<Display> WiredDisplayMediaRouteProvider::GetAvailableDisplays() ...@@ -345,7 +350,8 @@ std::vector<Display> WiredDisplayMediaRouteProvider::GetAvailableDisplays()
return display.id() != primary_display.id() && return display.id() != primary_display.id() &&
display.bounds() == primary_display.bounds(); display.bounds() == primary_display.bounds();
}); });
// If there is only one display, the user should not be able to present to it. // If all the displays are mirrored, the user should not be able to present to
// them.
return displays.size() == 1 ? std::vector<Display>() : displays; return displays.size() == 1 ? std::vector<Display>() : displays;
} }
......
...@@ -128,6 +128,8 @@ class TestWiredDisplayMediaRouteProvider ...@@ -128,6 +128,8 @@ class TestWiredDisplayMediaRouteProvider
primary_display_ = std::move(primary_display); primary_display_ = std::move(primary_display);
} }
MOCK_CONST_METHOD0(GetPrimaryDisplayInternal, void());
protected: protected:
// In the actual class, this method returns display::Screen::GetAllDisplays(). // In the actual class, this method returns display::Screen::GetAllDisplays().
// TODO(takumif): Expand display::test::TestScreen to support multiple // TODO(takumif): Expand display::test::TestScreen to support multiple
...@@ -138,7 +140,10 @@ class TestWiredDisplayMediaRouteProvider ...@@ -138,7 +140,10 @@ class TestWiredDisplayMediaRouteProvider
// In the actual class, this method returns // In the actual class, this method returns
// display::Screen::GetPrimaryDisplay(). // display::Screen::GetPrimaryDisplay().
Display GetPrimaryDisplay() const override { return primary_display_; } Display GetPrimaryDisplay() const override {
GetPrimaryDisplayInternal();
return primary_display_;
}
private: private:
std::vector<Display> all_displays_; std::vector<Display> all_displays_;
...@@ -269,6 +274,20 @@ TEST_F(WiredDisplayMediaRouteProviderTest, NotifyOnDisplayChange) { ...@@ -269,6 +274,20 @@ TEST_F(WiredDisplayMediaRouteProviderTest, NotifyOnDisplayChange) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
TEST_F(WiredDisplayMediaRouteProviderTest, NoDisplay) {
provider_->StartObservingMediaSinks(kPresentationSource);
provider_->set_all_displays({primary_display_});
provider_->OnDisplayAdded(primary_display_);
base::RunLoop().RunUntilIdle();
// When the display list is empty, |provider_| should not try to get the
// primary display, as it would be invalid.
EXPECT_CALL(*provider_, GetPrimaryDisplayInternal()).Times(0);
provider_->set_all_displays({});
provider_->OnDisplayRemoved(primary_display_);
base::RunLoop().RunUntilIdle();
}
TEST_F(WiredDisplayMediaRouteProviderTest, NoSinksForNonPresentationSource) { TEST_F(WiredDisplayMediaRouteProviderTest, NoSinksForNonPresentationSource) {
EXPECT_CALL(router_, EXPECT_CALL(router_,
OnSinksReceived(kProviderId, kNonPresentationSource, _, _)) OnSinksReceived(kProviderId, kNonPresentationSource, _, _))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment