| 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" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
| 17 #include "ui/message_center/notification.h" | 17 #include "ui/message_center/notification.h" |
| 18 #include "ui/message_center/notification_list.h" | 18 #include "ui/message_center/notification_list.h" |
| 19 | 19 |
| 20 namespace ash { | 20 namespace ash { |
| 21 namespace { | |
| 22 | |
| 23 base::string16 ExpectedNotificationMessage(int64_t display_id, | |
| 24 const gfx::Size& new_resolution) { | |
| 25 return l10n_util::GetStringFUTF16( | |
| 26 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | |
| 27 base::UTF8ToUTF16( | |
| 28 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | |
| 29 display_id)), | |
| 30 base::UTF8ToUTF16(new_resolution.ToString())); | |
| 31 } | |
| 32 | |
| 33 base::string16 ExpectedFallbackNotificationMessage( | |
| 34 int64_t display_id, | |
| 35 const gfx::Size& specified_resolution, | |
| 36 const gfx::Size& fallback_resolution) { | |
| 37 return l10n_util::GetStringFUTF16( | |
| 38 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, | |
| 39 base::UTF8ToUTF16( | |
| 40 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | |
| 41 display_id)), | |
| 42 base::UTF8ToUTF16(specified_resolution.ToString()), | |
| 43 base::UTF8ToUTF16(fallback_resolution.ToString())); | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | 21 |
| 48 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { | 22 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { |
| 49 public: | 23 public: |
| 50 ResolutionNotificationControllerTest() : accept_count_(0) {} | 24 ResolutionNotificationControllerTest() : accept_count_(0) {} |
| 51 | 25 |
| 52 ~ResolutionNotificationControllerTest() override {} | 26 ~ResolutionNotificationControllerTest() override {} |
| 53 | 27 |
| 28 base::string16 ExpectedNotificationMessage(int64_t display_id, |
| 29 const gfx::Size& new_resolution) { |
| 30 return l10n_util::GetStringFUTF16( |
| 31 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 32 base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(display_id)), |
| 33 base::UTF8ToUTF16(new_resolution.ToString())); |
| 34 } |
| 35 |
| 36 base::string16 ExpectedFallbackNotificationMessage( |
| 37 int64_t display_id, |
| 38 const gfx::Size& specified_resolution, |
| 39 const gfx::Size& fallback_resolution) { |
| 40 return l10n_util::GetStringFUTF16( |
| 41 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, |
| 42 base::UTF8ToUTF16(display_manager()->GetDisplayNameForId(display_id)), |
| 43 base::UTF8ToUTF16(specified_resolution.ToString()), |
| 44 base::UTF8ToUTF16(fallback_resolution.ToString())); |
| 45 } |
| 46 |
| 54 protected: | 47 protected: |
| 55 void SetUp() override { | 48 void SetUp() override { |
| 56 ash::test::AshTestBase::SetUp(); | 49 ash::test::AshTestBase::SetUp(); |
| 57 ResolutionNotificationController::SuppressTimerForTest(); | 50 ResolutionNotificationController::SuppressTimerForTest(); |
| 58 } | 51 } |
| 59 | 52 |
| 60 void SetDisplayResolutionAndNotifyWithResolution( | 53 void SetDisplayResolutionAndNotifyWithResolution( |
| 61 const display::Display& display, | 54 const display::Display& display, |
| 62 const gfx::Size& new_resolution, | 55 const gfx::Size& new_resolution, |
| 63 const gfx::Size& actual_new_resolution) { | 56 const gfx::Size& actual_new_resolution) { |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 149 |
| 157 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 150 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
| 158 }; | 151 }; |
| 159 | 152 |
| 160 // Basic behaviors and verifies it doesn't cause crashes. | 153 // Basic behaviors and verifies it doesn't cause crashes. |
| 161 TEST_F(ResolutionNotificationControllerTest, Basic) { | 154 TEST_F(ResolutionNotificationControllerTest, Basic) { |
| 162 if (!SupportsMultipleDisplays()) | 155 if (!SupportsMultipleDisplays()) |
| 163 return; | 156 return; |
| 164 | 157 |
| 165 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 158 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 166 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 159 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 167 ash::DisplayManager* display_manager = | |
| 168 ash::Shell::GetInstance()->display_manager(); | |
| 169 ASSERT_EQ(0, accept_count()); | 160 ASSERT_EQ(0, accept_count()); |
| 170 EXPECT_FALSE(IsNotificationVisible()); | 161 EXPECT_FALSE(IsNotificationVisible()); |
| 171 | 162 |
| 172 // Changes the resolution and apply the result. | 163 // Changes the resolution and apply the result. |
| 173 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 164 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 174 gfx::Size(200, 200)); | 165 gfx::Size(200, 200)); |
| 175 EXPECT_TRUE(IsNotificationVisible()); | 166 EXPECT_TRUE(IsNotificationVisible()); |
| 176 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 167 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 177 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), | 168 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), |
| 178 GetNotificationMessage()); | 169 GetNotificationMessage()); |
| 179 scoped_refptr<display::ManagedDisplayMode> mode = | 170 scoped_refptr<display::ManagedDisplayMode> mode = |
| 180 display_manager->GetSelectedModeForDisplayId(id2); | 171 display_manager()->GetSelectedModeForDisplayId(id2); |
| 181 EXPECT_TRUE(!!mode); | 172 EXPECT_TRUE(!!mode); |
| 182 EXPECT_EQ("200x200", mode->size().ToString()); | 173 EXPECT_EQ("200x200", mode->size().ToString()); |
| 183 EXPECT_EQ(60.0, mode->refresh_rate()); | 174 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 184 | 175 |
| 185 // Click the revert button, which reverts to the best resolution. | 176 // Click the revert button, which reverts to the best resolution. |
| 186 ClickOnNotificationButton(0); | 177 ClickOnNotificationButton(0); |
| 187 RunAllPendingInMessageLoop(); | 178 RunAllPendingInMessageLoop(); |
| 188 EXPECT_FALSE(IsNotificationVisible()); | 179 EXPECT_FALSE(IsNotificationVisible()); |
| 189 EXPECT_EQ(0, accept_count()); | 180 EXPECT_EQ(0, accept_count()); |
| 190 mode = display_manager->GetSelectedModeForDisplayId(id2); | 181 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 191 EXPECT_TRUE(!!mode); | 182 EXPECT_TRUE(!!mode); |
| 192 EXPECT_EQ("250x250", mode->size().ToString()); | 183 EXPECT_EQ("250x250", mode->size().ToString()); |
| 193 EXPECT_EQ(59.0, mode->refresh_rate()); | 184 EXPECT_EQ(59.0, mode->refresh_rate()); |
| 194 } | 185 } |
| 195 | 186 |
| 196 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 187 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
| 197 if (!SupportsMultipleDisplays()) | 188 if (!SupportsMultipleDisplays()) |
| 198 return; | 189 return; |
| 199 | 190 |
| 200 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 191 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 201 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 192 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 202 ash::DisplayManager* display_manager = | |
| 203 ash::Shell::GetInstance()->display_manager(); | |
| 204 ASSERT_EQ(0, accept_count()); | 193 ASSERT_EQ(0, accept_count()); |
| 205 EXPECT_FALSE(IsNotificationVisible()); | 194 EXPECT_FALSE(IsNotificationVisible()); |
| 206 | 195 |
| 207 // Changes the resolution and apply the result. | 196 // Changes the resolution and apply the result. |
| 208 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 197 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 209 gfx::Size(200, 200)); | 198 gfx::Size(200, 200)); |
| 210 EXPECT_TRUE(IsNotificationVisible()); | 199 EXPECT_TRUE(IsNotificationVisible()); |
| 211 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 200 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 212 scoped_refptr<display::ManagedDisplayMode> mode = | 201 scoped_refptr<display::ManagedDisplayMode> mode = |
| 213 display_manager->GetSelectedModeForDisplayId(id2); | 202 display_manager()->GetSelectedModeForDisplayId(id2); |
| 214 EXPECT_TRUE(!!mode); | 203 EXPECT_TRUE(!!mode); |
| 215 EXPECT_EQ("200x200", mode->size().ToString()); | 204 EXPECT_EQ("200x200", mode->size().ToString()); |
| 216 EXPECT_EQ(60.0, mode->refresh_rate()); | 205 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 217 | 206 |
| 218 // Click the revert button, which reverts the resolution. | 207 // Click the revert button, which reverts the resolution. |
| 219 ClickOnNotification(); | 208 ClickOnNotification(); |
| 220 RunAllPendingInMessageLoop(); | 209 RunAllPendingInMessageLoop(); |
| 221 EXPECT_FALSE(IsNotificationVisible()); | 210 EXPECT_FALSE(IsNotificationVisible()); |
| 222 EXPECT_EQ(1, accept_count()); | 211 EXPECT_EQ(1, accept_count()); |
| 223 mode = display_manager->GetSelectedModeForDisplayId(id2); | 212 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 224 EXPECT_TRUE(!!mode); | 213 EXPECT_TRUE(!!mode); |
| 225 EXPECT_EQ("200x200", mode->size().ToString()); | 214 EXPECT_EQ("200x200", mode->size().ToString()); |
| 226 EXPECT_EQ(60.0, mode->refresh_rate()); | 215 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 227 } | 216 } |
| 228 | 217 |
| 229 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { | 218 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { |
| 230 if (!SupportsMultipleDisplays()) | 219 if (!SupportsMultipleDisplays()) |
| 231 return; | 220 return; |
| 232 | 221 |
| 233 ash::DisplayManager* display_manager = | |
| 234 ash::Shell::GetInstance()->display_manager(); | |
| 235 | |
| 236 UpdateDisplay("300x300#300x300%59|200x200%60"); | 222 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 237 const display::Display& display = | 223 const display::Display& display = |
| 238 display::Screen::GetScreen()->GetPrimaryDisplay(); | 224 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 239 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 225 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 240 EXPECT_TRUE(IsNotificationVisible()); | 226 EXPECT_TRUE(IsNotificationVisible()); |
| 241 | 227 |
| 242 // If there's a single display only, it will have timeout and the first button | 228 // If there's a single display only, it will have timeout and the first button |
| 243 // becomes accept. | 229 // becomes accept. |
| 244 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 230 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
| 245 ClickOnNotificationButton(0); | 231 ClickOnNotificationButton(0); |
| 246 EXPECT_FALSE(IsNotificationVisible()); | 232 EXPECT_FALSE(IsNotificationVisible()); |
| 247 EXPECT_EQ(1, accept_count()); | 233 EXPECT_EQ(1, accept_count()); |
| 248 | 234 |
| 249 scoped_refptr<display::ManagedDisplayMode> mode = | 235 scoped_refptr<display::ManagedDisplayMode> mode = |
| 250 display_manager->GetSelectedModeForDisplayId(display.id()); | 236 display_manager()->GetSelectedModeForDisplayId(display.id()); |
| 251 EXPECT_TRUE(!!mode); | 237 EXPECT_TRUE(!!mode); |
| 252 | 238 |
| 253 EXPECT_EQ("200x200", mode->size().ToString()); | 239 EXPECT_EQ("200x200", mode->size().ToString()); |
| 254 EXPECT_EQ(60.0f, mode->refresh_rate()); | 240 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 255 | 241 |
| 256 // In that case the second button is revert. | 242 // In that case the second button is revert. |
| 257 UpdateDisplay("300x300#300x300%59|200x200%60"); | 243 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 258 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 244 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 259 EXPECT_TRUE(IsNotificationVisible()); | 245 EXPECT_TRUE(IsNotificationVisible()); |
| 260 | 246 |
| 261 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 247 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
| 262 ClickOnNotificationButton(1); | 248 ClickOnNotificationButton(1); |
| 263 EXPECT_FALSE(IsNotificationVisible()); | 249 EXPECT_FALSE(IsNotificationVisible()); |
| 264 EXPECT_EQ(1, accept_count()); | 250 EXPECT_EQ(1, accept_count()); |
| 265 mode = display_manager->GetSelectedModeForDisplayId(display.id()); | 251 mode = display_manager()->GetSelectedModeForDisplayId(display.id()); |
| 266 EXPECT_TRUE(!!mode); | 252 EXPECT_TRUE(!!mode); |
| 267 | 253 |
| 268 EXPECT_EQ("300x300", mode->size().ToString()); | 254 EXPECT_EQ("300x300", mode->size().ToString()); |
| 269 EXPECT_EQ(59.0f, mode->refresh_rate()); | 255 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 270 } | 256 } |
| 271 | 257 |
| 272 TEST_F(ResolutionNotificationControllerTest, Close) { | 258 TEST_F(ResolutionNotificationControllerTest, Close) { |
| 273 if (!SupportsMultipleDisplays()) | 259 if (!SupportsMultipleDisplays()) |
| 274 return; | 260 return; |
| 275 | 261 |
| 276 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 262 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
| 277 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 263 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 278 ash::DisplayManager* display_manager = | |
| 279 ash::Shell::GetInstance()->display_manager(); | |
| 280 ASSERT_EQ(0, accept_count()); | 264 ASSERT_EQ(0, accept_count()); |
| 281 EXPECT_FALSE(IsNotificationVisible()); | 265 EXPECT_FALSE(IsNotificationVisible()); |
| 282 | 266 |
| 283 // Changes the resolution and apply the result. | 267 // Changes the resolution and apply the result. |
| 284 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 268 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 285 gfx::Size(200, 200)); | 269 gfx::Size(200, 200)); |
| 286 EXPECT_TRUE(IsNotificationVisible()); | 270 EXPECT_TRUE(IsNotificationVisible()); |
| 287 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 271 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 288 scoped_refptr<display::ManagedDisplayMode> mode = | 272 scoped_refptr<display::ManagedDisplayMode> mode = |
| 289 display_manager->GetSelectedModeForDisplayId(id2); | 273 display_manager()->GetSelectedModeForDisplayId(id2); |
| 290 EXPECT_TRUE(!!mode); | 274 EXPECT_TRUE(!!mode); |
| 291 EXPECT_EQ("200x200", mode->size().ToString()); | 275 EXPECT_EQ("200x200", mode->size().ToString()); |
| 292 EXPECT_EQ(60.0f, mode->refresh_rate()); | 276 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 293 | 277 |
| 294 // Close the notification (imitates clicking [x] button). Also verifies if | 278 // Close the notification (imitates clicking [x] button). Also verifies if |
| 295 // this does not cause a crash. See crbug.com/271784 | 279 // this does not cause a crash. See crbug.com/271784 |
| 296 CloseNotification(); | 280 CloseNotification(); |
| 297 RunAllPendingInMessageLoop(); | 281 RunAllPendingInMessageLoop(); |
| 298 EXPECT_FALSE(IsNotificationVisible()); | 282 EXPECT_FALSE(IsNotificationVisible()); |
| 299 EXPECT_EQ(1, accept_count()); | 283 EXPECT_EQ(1, accept_count()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 325 EXPECT_EQ(59.0f, mode->refresh_rate()); | 309 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 326 } | 310 } |
| 327 | 311 |
| 328 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 312 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
| 329 if (!SupportsMultipleDisplays()) | 313 if (!SupportsMultipleDisplays()) |
| 330 return; | 314 return; |
| 331 | 315 |
| 332 UpdateDisplay( | 316 UpdateDisplay( |
| 333 "300x300#300x300%56|200x200%57," | 317 "300x300#300x300%56|200x200%57," |
| 334 "200x200#250x250%58|200x200%59|100x100%60"); | 318 "200x200#250x250%58|200x200%59|100x100%60"); |
| 335 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 319 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 336 ash::DisplayManager* display_manager = | 320 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 337 ash::Shell::GetInstance()->display_manager(); | |
| 338 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | |
| 339 gfx::Size(100, 100)); | 321 gfx::Size(100, 100)); |
| 340 ASSERT_TRUE(IsNotificationVisible()); | 322 ASSERT_TRUE(IsNotificationVisible()); |
| 341 | 323 |
| 342 // Disconnects the secondary display and verifies it doesn't cause crashes. | 324 // Disconnects the secondary display and verifies it doesn't cause crashes. |
| 343 UpdateDisplay("300x300#300x300%56|200x200%57"); | 325 UpdateDisplay("300x300#300x300%56|200x200%57"); |
| 344 RunAllPendingInMessageLoop(); | 326 RunAllPendingInMessageLoop(); |
| 345 EXPECT_FALSE(IsNotificationVisible()); | 327 EXPECT_FALSE(IsNotificationVisible()); |
| 346 EXPECT_EQ(0, accept_count()); | 328 EXPECT_EQ(0, accept_count()); |
| 347 scoped_refptr<display::ManagedDisplayMode> mode = | 329 scoped_refptr<display::ManagedDisplayMode> mode = |
| 348 display_manager->GetSelectedModeForDisplayId(id2); | 330 display_manager()->GetSelectedModeForDisplayId(id2); |
| 349 EXPECT_TRUE(!!mode); | 331 EXPECT_TRUE(!!mode); |
| 350 gfx::Size resolution; | 332 gfx::Size resolution; |
| 351 EXPECT_EQ("200x200", mode->size().ToString()); | 333 EXPECT_EQ("200x200", mode->size().ToString()); |
| 352 EXPECT_EQ(59.0f, mode->refresh_rate()); | 334 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 353 } | 335 } |
| 354 | 336 |
| 355 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 337 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
| 356 if (!SupportsMultipleDisplays()) | 338 if (!SupportsMultipleDisplays()) |
| 357 return; | 339 return; |
| 358 | 340 |
| 359 UpdateDisplay( | 341 UpdateDisplay( |
| 360 "300x300#300x300%56|200x200%57," | 342 "300x300#300x300%56|200x200%57," |
| 361 "250x250#250x250%58|200x200%59"); | 343 "250x250#250x250%58|200x200%59"); |
| 362 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 344 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 363 ash::DisplayManager* display_manager = | |
| 364 ash::Shell::GetInstance()->display_manager(); | |
| 365 | 345 |
| 366 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 346 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 367 gfx::Size(200, 200)); | 347 gfx::Size(200, 200)); |
| 368 EXPECT_TRUE(IsNotificationVisible()); | 348 EXPECT_TRUE(IsNotificationVisible()); |
| 369 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 349 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 370 scoped_refptr<display::ManagedDisplayMode> mode = | 350 scoped_refptr<display::ManagedDisplayMode> mode = |
| 371 display_manager->GetSelectedModeForDisplayId(id2); | 351 display_manager()->GetSelectedModeForDisplayId(id2); |
| 372 EXPECT_TRUE(!!mode); | 352 EXPECT_TRUE(!!mode); |
| 373 EXPECT_EQ("200x200", mode->size().ToString()); | 353 EXPECT_EQ("200x200", mode->size().ToString()); |
| 374 EXPECT_EQ(59.0f, mode->refresh_rate()); | 354 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 375 | 355 |
| 376 // Invokes SetDisplayResolutionAndNotify during the previous notification is | 356 // Invokes SetDisplayResolutionAndNotify during the previous notification is |
| 377 // visible. | 357 // visible. |
| 378 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), | 358 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 379 gfx::Size(250, 250)); | 359 gfx::Size(250, 250)); |
| 380 mode = display_manager->GetSelectedModeForDisplayId(id2); | 360 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 381 EXPECT_TRUE(!!mode); | 361 EXPECT_TRUE(!!mode); |
| 382 EXPECT_EQ("250x250", mode->size().ToString()); | 362 EXPECT_EQ("250x250", mode->size().ToString()); |
| 383 EXPECT_EQ(58.0f, mode->refresh_rate()); | 363 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 384 | 364 |
| 385 // Then, click the revert button. Although |old_resolution| for the second | 365 // Then, click the revert button. Although |old_resolution| for the second |
| 386 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original | 366 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original |
| 387 // size 250x250. | 367 // size 250x250. |
| 388 ClickOnNotificationButton(0); | 368 ClickOnNotificationButton(0); |
| 389 RunAllPendingInMessageLoop(); | 369 RunAllPendingInMessageLoop(); |
| 390 EXPECT_FALSE(IsNotificationVisible()); | 370 EXPECT_FALSE(IsNotificationVisible()); |
| 391 EXPECT_EQ(0, accept_count()); | 371 EXPECT_EQ(0, accept_count()); |
| 392 mode = display_manager->GetSelectedModeForDisplayId(id2); | 372 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 393 EXPECT_TRUE(!!mode); | 373 EXPECT_TRUE(!!mode); |
| 394 EXPECT_EQ("250x250", mode->size().ToString()); | 374 EXPECT_EQ("250x250", mode->size().ToString()); |
| 395 EXPECT_EQ(58.0f, mode->refresh_rate()); | 375 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 396 } | 376 } |
| 397 | 377 |
| 398 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 378 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
| 399 if (!SupportsMultipleDisplays()) | 379 if (!SupportsMultipleDisplays()) |
| 400 return; | 380 return; |
| 401 | 381 |
| 402 UpdateDisplay( | 382 UpdateDisplay( |
| 403 "300x300#300x300%56|200x200%57," | 383 "300x300#300x300%56|200x200%57," |
| 404 "250x250#250x250%58|220x220%59|200x200%60"); | 384 "250x250#250x250%58|220x220%59|200x200%60"); |
| 405 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 385 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 406 ash::DisplayManager* display_manager = | |
| 407 ash::Shell::GetInstance()->display_manager(); | |
| 408 ASSERT_EQ(0, accept_count()); | 386 ASSERT_EQ(0, accept_count()); |
| 409 EXPECT_FALSE(IsNotificationVisible()); | 387 EXPECT_FALSE(IsNotificationVisible()); |
| 410 | 388 |
| 411 // Changes the resolution and apply the result. | 389 // Changes the resolution and apply the result. |
| 412 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(), | 390 SetDisplayResolutionAndNotifyWithResolution( |
| 413 gfx::Size(220, 220), | 391 display_manager()->GetSecondaryDisplay(), gfx::Size(220, 220), |
| 414 gfx::Size(200, 200)); | 392 gfx::Size(200, 200)); |
| 415 EXPECT_TRUE(IsNotificationVisible()); | 393 EXPECT_TRUE(IsNotificationVisible()); |
| 416 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 394 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 417 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), | 395 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), |
| 418 gfx::Size(200, 200)), | 396 gfx::Size(200, 200)), |
| 419 GetNotificationMessage()); | 397 GetNotificationMessage()); |
| 420 scoped_refptr<display::ManagedDisplayMode> mode = | 398 scoped_refptr<display::ManagedDisplayMode> mode = |
| 421 display_manager->GetSelectedModeForDisplayId(id2); | 399 display_manager()->GetSelectedModeForDisplayId(id2); |
| 422 EXPECT_TRUE(!!mode); | 400 EXPECT_TRUE(!!mode); |
| 423 EXPECT_EQ("200x200", mode->size().ToString()); | 401 EXPECT_EQ("200x200", mode->size().ToString()); |
| 424 EXPECT_EQ(60.0f, mode->refresh_rate()); | 402 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 425 | 403 |
| 426 // Click the revert button, which reverts to the best resolution. | 404 // Click the revert button, which reverts to the best resolution. |
| 427 ClickOnNotificationButton(0); | 405 ClickOnNotificationButton(0); |
| 428 RunAllPendingInMessageLoop(); | 406 RunAllPendingInMessageLoop(); |
| 429 EXPECT_FALSE(IsNotificationVisible()); | 407 EXPECT_FALSE(IsNotificationVisible()); |
| 430 EXPECT_EQ(0, accept_count()); | 408 EXPECT_EQ(0, accept_count()); |
| 431 | 409 |
| 432 mode = display_manager->GetSelectedModeForDisplayId(id2); | 410 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 433 EXPECT_TRUE(!!mode); | 411 EXPECT_TRUE(!!mode); |
| 434 EXPECT_EQ("250x250", mode->size().ToString()); | 412 EXPECT_EQ("250x250", mode->size().ToString()); |
| 435 EXPECT_EQ(58.0f, mode->refresh_rate()); | 413 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 436 } | 414 } |
| 437 | 415 |
| 438 } // namespace ash | 416 } // namespace ash |
| OLD | NEW |