| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ash/display/resolution_notification_controller.h" | 5 #include "ash/display/resolution_notification_controller.h" |
| 6 | 6 |
| 7 #include "ash/display/display_manager.h" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 ResolutionNotificationController::SuppressTimerForTest(); | 57 ResolutionNotificationController::SuppressTimerForTest(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void SetDisplayResolutionAndNotifyWithResolution( | 60 void SetDisplayResolutionAndNotifyWithResolution( |
| 61 const display::Display& display, | 61 const display::Display& display, |
| 62 const gfx::Size& new_resolution, | 62 const gfx::Size& new_resolution, |
| 63 const gfx::Size& actual_new_resolution) { | 63 const gfx::Size& actual_new_resolution) { |
| 64 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 64 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 65 | 65 |
| 66 const DisplayInfo& info = display_manager->GetDisplayInfo(display.id()); | 66 const DisplayInfo& info = display_manager->GetDisplayInfo(display.id()); |
| 67 DisplayMode old_mode(info.size_in_pixel(), 60 /* refresh_rate */, | 67 scoped_refptr<DisplayMode> old_mode( |
| 68 false /* interlaced */, false /* native */); | 68 new DisplayMode(info.size_in_pixel(), 60 /* refresh_rate */, |
| 69 DisplayMode new_mode = old_mode; | 69 false /* interlaced */, false /* native */)); |
| 70 new_mode.size = new_resolution; | 70 scoped_refptr<DisplayMode> new_mode( |
| 71 new DisplayMode(new_resolution, old_mode->refresh_rate(), |
| 72 old_mode->is_interlaced(), old_mode->native(), |
| 73 old_mode->ui_scale(), old_mode->device_scale_factor())); |
| 71 | 74 |
| 72 if (display_manager->SetDisplayMode(display.id(), new_mode)) { | 75 if (display_manager->SetDisplayMode(display.id(), new_mode)) { |
| 73 controller()->PrepareNotification( | 76 controller()->PrepareNotification( |
| 74 display.id(), old_mode, new_mode, | 77 display.id(), old_mode, new_mode, |
| 75 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, | 78 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, |
| 76 base::Unretained(this))); | 79 base::Unretained(this))); |
| 77 } | 80 } |
| 78 | 81 |
| 79 // OnConfigurationChanged event won't be emitted in the test environment, | 82 // OnConfigurationChanged event won't be emitted in the test environment, |
| 80 // so invoke UpdateDisplay() to emit that event explicitly. | 83 // so invoke UpdateDisplay() to emit that event explicitly. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 ASSERT_EQ(0, accept_count()); | 166 ASSERT_EQ(0, accept_count()); |
| 164 EXPECT_FALSE(IsNotificationVisible()); | 167 EXPECT_FALSE(IsNotificationVisible()); |
| 165 | 168 |
| 166 // Changes the resolution and apply the result. | 169 // Changes the resolution and apply the result. |
| 167 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 170 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 168 gfx::Size(200, 200)); | 171 gfx::Size(200, 200)); |
| 169 EXPECT_TRUE(IsNotificationVisible()); | 172 EXPECT_TRUE(IsNotificationVisible()); |
| 170 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 173 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 171 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), | 174 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), |
| 172 GetNotificationMessage()); | 175 GetNotificationMessage()); |
| 173 DisplayMode mode; | 176 scoped_refptr<DisplayMode> mode = |
| 174 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 177 display_manager->GetSelectedModeForDisplayId(id2); |
| 175 EXPECT_EQ("200x200", mode.size.ToString()); | 178 EXPECT_TRUE(!!mode); |
| 176 EXPECT_EQ(60.0, mode.refresh_rate); | 179 EXPECT_EQ("200x200", mode->size().ToString()); |
| 180 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 177 | 181 |
| 178 // Click the revert button, which reverts to the best resolution. | 182 // Click the revert button, which reverts to the best resolution. |
| 179 ClickOnNotificationButton(0); | 183 ClickOnNotificationButton(0); |
| 180 RunAllPendingInMessageLoop(); | 184 RunAllPendingInMessageLoop(); |
| 181 EXPECT_FALSE(IsNotificationVisible()); | 185 EXPECT_FALSE(IsNotificationVisible()); |
| 182 EXPECT_EQ(0, accept_count()); | 186 EXPECT_EQ(0, accept_count()); |
| 183 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 187 mode = display_manager->GetSelectedModeForDisplayId(id2); |
| 184 EXPECT_EQ("250x250", mode.size.ToString()); | 188 EXPECT_TRUE(!!mode); |
| 185 EXPECT_EQ(59.0, mode.refresh_rate); | 189 EXPECT_EQ("250x250", mode->size().ToString()); |
| 190 EXPECT_EQ(59.0, mode->refresh_rate()); |
| 186 } | 191 } |
| 187 | 192 |
| 188 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 193 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
| 189 if (!SupportsMultipleDisplays()) | 194 if (!SupportsMultipleDisplays()) |
| 190 return; | 195 return; |
| 191 | 196 |
| 192 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 197 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 193 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 198 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 194 ash::DisplayManager* display_manager = | 199 ash::DisplayManager* display_manager = |
| 195 ash::Shell::GetInstance()->display_manager(); | 200 ash::Shell::GetInstance()->display_manager(); |
| 196 ASSERT_EQ(0, accept_count()); | 201 ASSERT_EQ(0, accept_count()); |
| 197 EXPECT_FALSE(IsNotificationVisible()); | 202 EXPECT_FALSE(IsNotificationVisible()); |
| 198 | 203 |
| 199 // Changes the resolution and apply the result. | 204 // Changes the resolution and apply the result. |
| 200 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 205 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 201 gfx::Size(200, 200)); | 206 gfx::Size(200, 200)); |
| 202 EXPECT_TRUE(IsNotificationVisible()); | 207 EXPECT_TRUE(IsNotificationVisible()); |
| 203 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 208 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 204 DisplayMode mode; | 209 scoped_refptr<DisplayMode> mode = |
| 205 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 210 display_manager->GetSelectedModeForDisplayId(id2); |
| 206 EXPECT_EQ("200x200", mode.size.ToString()); | 211 EXPECT_TRUE(!!mode); |
| 207 EXPECT_EQ(60.0, mode.refresh_rate); | 212 EXPECT_EQ("200x200", mode->size().ToString()); |
| 213 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 208 | 214 |
| 209 // Click the revert button, which reverts the resolution. | 215 // Click the revert button, which reverts the resolution. |
| 210 ClickOnNotification(); | 216 ClickOnNotification(); |
| 211 RunAllPendingInMessageLoop(); | 217 RunAllPendingInMessageLoop(); |
| 212 EXPECT_FALSE(IsNotificationVisible()); | 218 EXPECT_FALSE(IsNotificationVisible()); |
| 213 EXPECT_EQ(1, accept_count()); | 219 EXPECT_EQ(1, accept_count()); |
| 214 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 220 mode = display_manager->GetSelectedModeForDisplayId(id2); |
| 215 EXPECT_EQ("200x200", mode.size.ToString()); | 221 EXPECT_TRUE(!!mode); |
| 216 EXPECT_EQ(60.0, mode.refresh_rate); | 222 EXPECT_EQ("200x200", mode->size().ToString()); |
| 223 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 217 } | 224 } |
| 218 | 225 |
| 219 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { | 226 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { |
| 220 if (!SupportsMultipleDisplays()) | 227 if (!SupportsMultipleDisplays()) |
| 221 return; | 228 return; |
| 222 | 229 |
| 223 ash::DisplayManager* display_manager = | 230 ash::DisplayManager* display_manager = |
| 224 ash::Shell::GetInstance()->display_manager(); | 231 ash::Shell::GetInstance()->display_manager(); |
| 225 | 232 |
| 226 UpdateDisplay("300x300#300x300%59|200x200%60"); | 233 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 227 const display::Display& display = | 234 const display::Display& display = |
| 228 display::Screen::GetScreen()->GetPrimaryDisplay(); | 235 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 229 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 236 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 230 EXPECT_TRUE(IsNotificationVisible()); | 237 EXPECT_TRUE(IsNotificationVisible()); |
| 231 | 238 |
| 232 // If there's a single display only, it will have timeout and the first button | 239 // If there's a single display only, it will have timeout and the first button |
| 233 // becomes accept. | 240 // becomes accept. |
| 234 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 241 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
| 235 ClickOnNotificationButton(0); | 242 ClickOnNotificationButton(0); |
| 236 EXPECT_FALSE(IsNotificationVisible()); | 243 EXPECT_FALSE(IsNotificationVisible()); |
| 237 EXPECT_EQ(1, accept_count()); | 244 EXPECT_EQ(1, accept_count()); |
| 238 DisplayMode mode; | 245 |
| 239 EXPECT_TRUE( | 246 scoped_refptr<DisplayMode> mode = |
| 240 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 247 display_manager->GetSelectedModeForDisplayId(display.id()); |
| 241 EXPECT_EQ("200x200", mode.size.ToString()); | 248 EXPECT_TRUE(!!mode); |
| 242 EXPECT_EQ(60.0f, mode.refresh_rate); | 249 |
| 250 EXPECT_EQ("200x200", mode->size().ToString()); |
| 251 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 243 | 252 |
| 244 // In that case the second button is revert. | 253 // In that case the second button is revert. |
| 245 UpdateDisplay("300x300#300x300%59|200x200%60"); | 254 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 246 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 255 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 247 EXPECT_TRUE(IsNotificationVisible()); | 256 EXPECT_TRUE(IsNotificationVisible()); |
| 248 | 257 |
| 249 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 258 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
| 250 ClickOnNotificationButton(1); | 259 ClickOnNotificationButton(1); |
| 251 EXPECT_FALSE(IsNotificationVisible()); | 260 EXPECT_FALSE(IsNotificationVisible()); |
| 252 EXPECT_EQ(1, accept_count()); | 261 EXPECT_EQ(1, accept_count()); |
| 253 EXPECT_TRUE( | 262 mode = display_manager->GetSelectedModeForDisplayId(display.id()); |
| 254 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 263 EXPECT_TRUE(!!mode); |
| 255 EXPECT_EQ("300x300", mode.size.ToString()); | 264 |
| 256 EXPECT_EQ(59.0f, mode.refresh_rate); | 265 EXPECT_EQ("300x300", mode->size().ToString()); |
| 266 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 257 } | 267 } |
| 258 | 268 |
| 259 TEST_F(ResolutionNotificationControllerTest, Close) { | 269 TEST_F(ResolutionNotificationControllerTest, Close) { |
| 260 if (!SupportsMultipleDisplays()) | 270 if (!SupportsMultipleDisplays()) |
| 261 return; | 271 return; |
| 262 | 272 |
| 263 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 273 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
| 264 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 274 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 265 ash::DisplayManager* display_manager = | 275 ash::DisplayManager* display_manager = |
| 266 ash::Shell::GetInstance()->display_manager(); | 276 ash::Shell::GetInstance()->display_manager(); |
| 267 ASSERT_EQ(0, accept_count()); | 277 ASSERT_EQ(0, accept_count()); |
| 268 EXPECT_FALSE(IsNotificationVisible()); | 278 EXPECT_FALSE(IsNotificationVisible()); |
| 269 | 279 |
| 270 // Changes the resolution and apply the result. | 280 // Changes the resolution and apply the result. |
| 271 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 281 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 272 gfx::Size(200, 200)); | 282 gfx::Size(200, 200)); |
| 273 EXPECT_TRUE(IsNotificationVisible()); | 283 EXPECT_TRUE(IsNotificationVisible()); |
| 274 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 284 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 275 DisplayMode mode; | 285 scoped_refptr<DisplayMode> mode = |
| 276 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 286 display_manager->GetSelectedModeForDisplayId(id2); |
| 277 EXPECT_EQ("200x200", mode.size.ToString()); | 287 EXPECT_TRUE(!!mode); |
| 278 EXPECT_EQ(60.0f, mode.refresh_rate); | 288 EXPECT_EQ("200x200", mode->size().ToString()); |
| 289 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 279 | 290 |
| 280 // Close the notification (imitates clicking [x] button). Also verifies if | 291 // Close the notification (imitates clicking [x] button). Also verifies if |
| 281 // this does not cause a crash. See crbug.com/271784 | 292 // this does not cause a crash. See crbug.com/271784 |
| 282 CloseNotification(); | 293 CloseNotification(); |
| 283 RunAllPendingInMessageLoop(); | 294 RunAllPendingInMessageLoop(); |
| 284 EXPECT_FALSE(IsNotificationVisible()); | 295 EXPECT_FALSE(IsNotificationVisible()); |
| 285 EXPECT_EQ(1, accept_count()); | 296 EXPECT_EQ(1, accept_count()); |
| 286 } | 297 } |
| 287 | 298 |
| 288 TEST_F(ResolutionNotificationControllerTest, Timeout) { | 299 TEST_F(ResolutionNotificationControllerTest, Timeout) { |
| 289 if (!SupportsMultipleDisplays()) | 300 if (!SupportsMultipleDisplays()) |
| 290 return; | 301 return; |
| 291 | 302 |
| 292 UpdateDisplay("300x300#300x300%59|200x200%60"); | 303 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 293 const display::Display& display = | 304 const display::Display& display = |
| 294 display::Screen::GetScreen()->GetPrimaryDisplay(); | 305 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 295 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 306 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 296 | 307 |
| 297 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { | 308 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { |
| 298 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i | 309 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i |
| 299 << "-th timer tick"; | 310 << "-th timer tick"; |
| 300 TickTimer(); | 311 TickTimer(); |
| 301 RunAllPendingInMessageLoop(); | 312 RunAllPendingInMessageLoop(); |
| 302 } | 313 } |
| 303 EXPECT_FALSE(IsNotificationVisible()); | 314 EXPECT_FALSE(IsNotificationVisible()); |
| 304 EXPECT_EQ(0, accept_count()); | 315 EXPECT_EQ(0, accept_count()); |
| 305 ash::DisplayManager* display_manager = | 316 ash::DisplayManager* display_manager = |
| 306 ash::Shell::GetInstance()->display_manager(); | 317 ash::Shell::GetInstance()->display_manager(); |
| 307 DisplayMode mode; | 318 scoped_refptr<DisplayMode> mode = |
| 308 EXPECT_TRUE( | 319 display_manager->GetSelectedModeForDisplayId(display.id()); |
| 309 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 320 EXPECT_TRUE(!!mode); |
| 310 EXPECT_EQ("300x300", mode.size.ToString()); | 321 EXPECT_EQ("300x300", mode->size().ToString()); |
| 311 EXPECT_EQ(59.0f, mode.refresh_rate); | 322 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 312 } | 323 } |
| 313 | 324 |
| 314 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 325 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
| 315 if (!SupportsMultipleDisplays()) | 326 if (!SupportsMultipleDisplays()) |
| 316 return; | 327 return; |
| 317 | 328 |
| 318 UpdateDisplay( | 329 UpdateDisplay( |
| 319 "300x300#300x300%56|200x200%57," | 330 "300x300#300x300%56|200x200%57," |
| 320 "200x200#250x250%58|200x200%59|100x100%60"); | 331 "200x200#250x250%58|200x200%59|100x100%60"); |
| 321 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 332 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 322 ash::DisplayManager* display_manager = | 333 ash::DisplayManager* display_manager = |
| 323 ash::Shell::GetInstance()->display_manager(); | 334 ash::Shell::GetInstance()->display_manager(); |
| 324 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 335 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 325 gfx::Size(100, 100)); | 336 gfx::Size(100, 100)); |
| 326 ASSERT_TRUE(IsNotificationVisible()); | 337 ASSERT_TRUE(IsNotificationVisible()); |
| 327 | 338 |
| 328 // Disconnects the secondary display and verifies it doesn't cause crashes. | 339 // Disconnects the secondary display and verifies it doesn't cause crashes. |
| 329 UpdateDisplay("300x300#300x300%56|200x200%57"); | 340 UpdateDisplay("300x300#300x300%56|200x200%57"); |
| 330 RunAllPendingInMessageLoop(); | 341 RunAllPendingInMessageLoop(); |
| 331 EXPECT_FALSE(IsNotificationVisible()); | 342 EXPECT_FALSE(IsNotificationVisible()); |
| 332 EXPECT_EQ(0, accept_count()); | 343 EXPECT_EQ(0, accept_count()); |
| 333 DisplayMode mode; | 344 scoped_refptr<DisplayMode> mode = |
| 334 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 345 display_manager->GetSelectedModeForDisplayId(id2); |
| 346 EXPECT_TRUE(!!mode); |
| 335 gfx::Size resolution; | 347 gfx::Size resolution; |
| 336 EXPECT_EQ("200x200", mode.size.ToString()); | 348 EXPECT_EQ("200x200", mode->size().ToString()); |
| 337 EXPECT_EQ(59.0f, mode.refresh_rate); | 349 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 338 } | 350 } |
| 339 | 351 |
| 340 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 352 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
| 341 if (!SupportsMultipleDisplays()) | 353 if (!SupportsMultipleDisplays()) |
| 342 return; | 354 return; |
| 343 | 355 |
| 344 UpdateDisplay( | 356 UpdateDisplay( |
| 345 "300x300#300x300%56|200x200%57," | 357 "300x300#300x300%56|200x200%57," |
| 346 "250x250#250x250%58|200x200%59"); | 358 "250x250#250x250%58|200x200%59"); |
| 347 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 359 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 348 ash::DisplayManager* display_manager = | 360 ash::DisplayManager* display_manager = |
| 349 ash::Shell::GetInstance()->display_manager(); | 361 ash::Shell::GetInstance()->display_manager(); |
| 350 | 362 |
| 351 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 363 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 352 gfx::Size(200, 200)); | 364 gfx::Size(200, 200)); |
| 353 EXPECT_TRUE(IsNotificationVisible()); | 365 EXPECT_TRUE(IsNotificationVisible()); |
| 354 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 366 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 355 DisplayMode mode; | 367 scoped_refptr<DisplayMode> mode = |
| 356 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 368 display_manager->GetSelectedModeForDisplayId(id2); |
| 357 EXPECT_EQ("200x200", mode.size.ToString()); | 369 EXPECT_TRUE(!!mode); |
| 358 EXPECT_EQ(59.0f, mode.refresh_rate); | 370 EXPECT_EQ("200x200", mode->size().ToString()); |
| 371 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 359 | 372 |
| 360 // Invokes SetDisplayResolutionAndNotify during the previous notification is | 373 // Invokes SetDisplayResolutionAndNotify during the previous notification is |
| 361 // visible. | 374 // visible. |
| 362 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 375 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
| 363 gfx::Size(250, 250)); | 376 gfx::Size(250, 250)); |
| 364 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 377 mode = display_manager->GetSelectedModeForDisplayId(id2); |
| 365 EXPECT_EQ("250x250", mode.size.ToString()); | 378 EXPECT_TRUE(!!mode); |
| 366 EXPECT_EQ(58.0f, mode.refresh_rate); | 379 EXPECT_EQ("250x250", mode->size().ToString()); |
| 380 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 367 | 381 |
| 368 // Then, click the revert button. Although |old_resolution| for the second | 382 // Then, click the revert button. Although |old_resolution| for the second |
| 369 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original | 383 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original |
| 370 // size 250x250. | 384 // size 250x250. |
| 371 ClickOnNotificationButton(0); | 385 ClickOnNotificationButton(0); |
| 372 RunAllPendingInMessageLoop(); | 386 RunAllPendingInMessageLoop(); |
| 373 EXPECT_FALSE(IsNotificationVisible()); | 387 EXPECT_FALSE(IsNotificationVisible()); |
| 374 EXPECT_EQ(0, accept_count()); | 388 EXPECT_EQ(0, accept_count()); |
| 375 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 389 mode = display_manager->GetSelectedModeForDisplayId(id2); |
| 376 EXPECT_EQ("250x250", mode.size.ToString()); | 390 EXPECT_TRUE(!!mode); |
| 377 EXPECT_EQ(58.0f, mode.refresh_rate); | 391 EXPECT_EQ("250x250", mode->size().ToString()); |
| 392 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 378 } | 393 } |
| 379 | 394 |
| 380 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 395 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
| 381 if (!SupportsMultipleDisplays()) | 396 if (!SupportsMultipleDisplays()) |
| 382 return; | 397 return; |
| 383 | 398 |
| 384 UpdateDisplay( | 399 UpdateDisplay( |
| 385 "300x300#300x300%56|200x200%57," | 400 "300x300#300x300%56|200x200%57," |
| 386 "250x250#250x250%58|220x220%59|200x200%60"); | 401 "250x250#250x250%58|220x220%59|200x200%60"); |
| 387 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 402 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 388 ash::DisplayManager* display_manager = | 403 ash::DisplayManager* display_manager = |
| 389 ash::Shell::GetInstance()->display_manager(); | 404 ash::Shell::GetInstance()->display_manager(); |
| 390 ASSERT_EQ(0, accept_count()); | 405 ASSERT_EQ(0, accept_count()); |
| 391 EXPECT_FALSE(IsNotificationVisible()); | 406 EXPECT_FALSE(IsNotificationVisible()); |
| 392 | 407 |
| 393 // Changes the resolution and apply the result. | 408 // Changes the resolution and apply the result. |
| 394 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(), | 409 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(), |
| 395 gfx::Size(220, 220), | 410 gfx::Size(220, 220), |
| 396 gfx::Size(200, 200)); | 411 gfx::Size(200, 200)); |
| 397 EXPECT_TRUE(IsNotificationVisible()); | 412 EXPECT_TRUE(IsNotificationVisible()); |
| 398 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 413 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 399 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), | 414 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), |
| 400 gfx::Size(200, 200)), | 415 gfx::Size(200, 200)), |
| 401 GetNotificationMessage()); | 416 GetNotificationMessage()); |
| 402 DisplayMode mode; | 417 scoped_refptr<DisplayMode> mode = |
| 403 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 418 display_manager->GetSelectedModeForDisplayId(id2); |
| 404 EXPECT_EQ("200x200", mode.size.ToString()); | 419 EXPECT_TRUE(!!mode); |
| 405 EXPECT_EQ(60.0f, mode.refresh_rate); | 420 EXPECT_EQ("200x200", mode->size().ToString()); |
| 421 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 406 | 422 |
| 407 // Click the revert button, which reverts to the best resolution. | 423 // Click the revert button, which reverts to the best resolution. |
| 408 ClickOnNotificationButton(0); | 424 ClickOnNotificationButton(0); |
| 409 RunAllPendingInMessageLoop(); | 425 RunAllPendingInMessageLoop(); |
| 410 EXPECT_FALSE(IsNotificationVisible()); | 426 EXPECT_FALSE(IsNotificationVisible()); |
| 411 EXPECT_EQ(0, accept_count()); | 427 EXPECT_EQ(0, accept_count()); |
| 412 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 428 |
| 413 EXPECT_EQ("250x250", mode.size.ToString()); | 429 mode = display_manager->GetSelectedModeForDisplayId(id2); |
| 414 EXPECT_EQ(58.0f, mode.refresh_rate); | 430 EXPECT_TRUE(!!mode); |
| 431 EXPECT_EQ("250x250", mode->size().ToString()); |
| 432 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 415 } | 433 } |
| 416 | 434 |
| 417 } // namespace ash | 435 } // namespace ash |
| OLD | NEW |