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

Unified Diff: ash/display/resolution_notification_controller_unittest.cc

Issue 2196923002: Make ash::DisplayMode more like ui::DisplayMode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 4 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: ash/display/resolution_notification_controller_unittest.cc
diff --git a/ash/display/resolution_notification_controller_unittest.cc b/ash/display/resolution_notification_controller_unittest.cc
index 5bf87a80b6623de871077f734698295851f66615..addaaceb2e30f63604cc205e41baaec72a52afca 100644
--- a/ash/display/resolution_notification_controller_unittest.cc
+++ b/ash/display/resolution_notification_controller_unittest.cc
@@ -64,10 +64,13 @@ class ResolutionNotificationControllerTest : public ash::test::AshTestBase {
DisplayManager* display_manager = Shell::GetInstance()->display_manager();
const DisplayInfo& info = display_manager->GetDisplayInfo(display.id());
- DisplayMode old_mode(info.size_in_pixel(), 60 /* refresh_rate */,
- false /* interlaced */, false /* native */);
- DisplayMode new_mode = old_mode;
- new_mode.size = new_resolution;
+ scoped_refptr<DisplayMode> old_mode(
+ new DisplayMode(info.size_in_pixel(), 60 /* refresh_rate */,
+ false /* interlaced */, false /* native */));
+ scoped_refptr<DisplayMode> new_mode(
+ new DisplayMode(new_resolution, old_mode->refresh_rate(),
+ old_mode->is_interlaced(), old_mode->native(),
+ old_mode->ui_scale(), old_mode->device_scale_factor()));
if (display_manager->SetDisplayMode(display.id(), new_mode)) {
controller()->PrepareNotification(
@@ -170,19 +173,21 @@ TEST_F(ResolutionNotificationControllerTest, Basic) {
EXPECT_FALSE(controller()->DoesNotificationTimeout());
EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)),
GetNotificationMessage());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0, mode->refresh_rate());
// Click the revert button, which reverts to the best resolution.
ClickOnNotificationButton(0);
RunAllPendingInMessageLoop();
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(0, accept_count());
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("250x250", mode.size.ToString());
- EXPECT_EQ(59.0, mode.refresh_rate);
+ mode = display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("250x250", mode->size().ToString());
+ EXPECT_EQ(59.0, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) {
@@ -201,19 +206,21 @@ TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) {
gfx::Size(200, 200));
EXPECT_TRUE(IsNotificationVisible());
EXPECT_FALSE(controller()->DoesNotificationTimeout());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0, mode->refresh_rate());
// Click the revert button, which reverts the resolution.
ClickOnNotification();
RunAllPendingInMessageLoop();
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(1, accept_count());
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0, mode.refresh_rate);
+ mode = display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, AcceptButton) {
@@ -235,11 +242,13 @@ TEST_F(ResolutionNotificationControllerTest, AcceptButton) {
ClickOnNotificationButton(0);
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(1, accept_count());
- DisplayMode mode;
- EXPECT_TRUE(
- display_manager->GetSelectedModeForDisplayId(display.id(), &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0f, mode.refresh_rate);
+
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(display.id());
+ EXPECT_TRUE(!!mode);
+
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0f, mode->refresh_rate());
// In that case the second button is revert.
UpdateDisplay("300x300#300x300%59|200x200%60");
@@ -250,10 +259,11 @@ TEST_F(ResolutionNotificationControllerTest, AcceptButton) {
ClickOnNotificationButton(1);
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(1, accept_count());
- EXPECT_TRUE(
- display_manager->GetSelectedModeForDisplayId(display.id(), &mode));
- EXPECT_EQ("300x300", mode.size.ToString());
- EXPECT_EQ(59.0f, mode.refresh_rate);
+ mode = display_manager->GetSelectedModeForDisplayId(display.id());
+ EXPECT_TRUE(!!mode);
+
+ EXPECT_EQ("300x300", mode->size().ToString());
+ EXPECT_EQ(59.0f, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, Close) {
@@ -272,10 +282,11 @@ TEST_F(ResolutionNotificationControllerTest, Close) {
gfx::Size(200, 200));
EXPECT_TRUE(IsNotificationVisible());
EXPECT_FALSE(controller()->DoesNotificationTimeout());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0f, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0f, mode->refresh_rate());
// Close the notification (imitates clicking [x] button). Also verifies if
// this does not cause a crash. See crbug.com/271784
@@ -304,11 +315,11 @@ TEST_F(ResolutionNotificationControllerTest, Timeout) {
EXPECT_EQ(0, accept_count());
ash::DisplayManager* display_manager =
ash::Shell::GetInstance()->display_manager();
- DisplayMode mode;
- EXPECT_TRUE(
- display_manager->GetSelectedModeForDisplayId(display.id(), &mode));
- EXPECT_EQ("300x300", mode.size.ToString());
- EXPECT_EQ(59.0f, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(display.id());
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("300x300", mode->size().ToString());
+ EXPECT_EQ(59.0f, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) {
@@ -330,11 +341,12 @@ TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) {
RunAllPendingInMessageLoop();
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(0, accept_count());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
gfx::Size resolution;
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(59.0f, mode.refresh_rate);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(59.0f, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) {
@@ -352,18 +364,20 @@ TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) {
gfx::Size(200, 200));
EXPECT_TRUE(IsNotificationVisible());
EXPECT_FALSE(controller()->DoesNotificationTimeout());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(59.0f, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(59.0f, mode->refresh_rate());
// Invokes SetDisplayResolutionAndNotify during the previous notification is
// visible.
SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
gfx::Size(250, 250));
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("250x250", mode.size.ToString());
- EXPECT_EQ(58.0f, mode.refresh_rate);
+ mode = display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("250x250", mode->size().ToString());
+ EXPECT_EQ(58.0f, mode->refresh_rate());
// Then, click the revert button. Although |old_resolution| for the second
// SetDisplayResolutionAndNotify is 200x200, it should revert to the original
@@ -372,9 +386,10 @@ TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) {
RunAllPendingInMessageLoop();
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(0, accept_count());
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("250x250", mode.size.ToString());
- EXPECT_EQ(58.0f, mode.refresh_rate);
+ mode = display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("250x250", mode->size().ToString());
+ EXPECT_EQ(58.0f, mode->refresh_rate());
}
TEST_F(ResolutionNotificationControllerTest, Fallback) {
@@ -399,19 +414,22 @@ TEST_F(ResolutionNotificationControllerTest, Fallback) {
EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220),
gfx::Size(200, 200)),
GetNotificationMessage());
- DisplayMode mode;
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("200x200", mode.size.ToString());
- EXPECT_EQ(60.0f, mode.refresh_rate);
+ scoped_refptr<DisplayMode> mode =
+ display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("200x200", mode->size().ToString());
+ EXPECT_EQ(60.0f, mode->refresh_rate());
// Click the revert button, which reverts to the best resolution.
ClickOnNotificationButton(0);
RunAllPendingInMessageLoop();
EXPECT_FALSE(IsNotificationVisible());
EXPECT_EQ(0, accept_count());
- EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode));
- EXPECT_EQ("250x250", mode.size.ToString());
- EXPECT_EQ(58.0f, mode.refresh_rate);
+
+ mode = display_manager->GetSelectedModeForDisplayId(id2);
+ EXPECT_TRUE(!!mode);
+ EXPECT_EQ("250x250", mode->size().ToString());
+ EXPECT_EQ(58.0f, mode->refresh_rate());
}
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698