| 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 { | 21 namespace { |
| 22 | 22 |
| 23 base::string16 ExpectedNotificationMessage(int64 display_id, | 23 base::string16 ExpectedNotificationMessage(int64_t display_id, |
| 24 const gfx::Size& new_resolution) { | 24 const gfx::Size& new_resolution) { |
| 25 return l10n_util::GetStringFUTF16( | 25 return l10n_util::GetStringFUTF16( |
| 26 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 26 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 27 base::UTF8ToUTF16( | 27 base::UTF8ToUTF16( |
| 28 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 28 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
| 29 display_id)), | 29 display_id)), |
| 30 base::UTF8ToUTF16(new_resolution.ToString())); | 30 base::UTF8ToUTF16(new_resolution.ToString())); |
| 31 } | 31 } |
| 32 | 32 |
| 33 base::string16 ExpectedFallbackNotificationMessage( | 33 base::string16 ExpectedFallbackNotificationMessage( |
| 34 int64 display_id, | 34 int64_t display_id, |
| 35 const gfx::Size& specified_resolution, | 35 const gfx::Size& specified_resolution, |
| 36 const gfx::Size& fallback_resolution) { | 36 const gfx::Size& fallback_resolution) { |
| 37 return l10n_util::GetStringFUTF16( | 37 return l10n_util::GetStringFUTF16( |
| 38 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, | 38 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED_TO_UNSUPPORTED, |
| 39 base::UTF8ToUTF16( | 39 base::UTF8ToUTF16( |
| 40 Shell::GetInstance()->display_manager()->GetDisplayNameForId( | 40 Shell::GetInstance()->display_manager()->GetDisplayNameForId( |
| 41 display_id)), | 41 display_id)), |
| 42 base::UTF8ToUTF16(specified_resolution.ToString()), | 42 base::UTF8ToUTF16(specified_resolution.ToString()), |
| 43 base::UTF8ToUTF16(fallback_resolution.ToString())); | 43 base::UTF8ToUTF16(fallback_resolution.ToString())); |
| 44 } | 44 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 old_mode, | 79 old_mode, |
| 80 new_mode, | 80 new_mode, |
| 81 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, | 81 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, |
| 82 base::Unretained(this))); | 82 base::Unretained(this))); |
| 83 } | 83 } |
| 84 | 84 |
| 85 // OnConfigurationChanged event won't be emitted in the test environment, | 85 // OnConfigurationChanged event won't be emitted in the test environment, |
| 86 // so invoke UpdateDisplay() to emit that event explicitly. | 86 // so invoke UpdateDisplay() to emit that event explicitly. |
| 87 std::vector<DisplayInfo> info_list; | 87 std::vector<DisplayInfo> info_list; |
| 88 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 88 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 89 int64 id = display_manager->GetDisplayAt(i).id(); | 89 int64_t id = display_manager->GetDisplayAt(i).id(); |
| 90 DisplayInfo info = display_manager->GetDisplayInfo(id); | 90 DisplayInfo info = display_manager->GetDisplayInfo(id); |
| 91 if (display.id() == id) { | 91 if (display.id() == id) { |
| 92 gfx::Rect bounds = info.bounds_in_native(); | 92 gfx::Rect bounds = info.bounds_in_native(); |
| 93 bounds.set_size(actual_new_resolution); | 93 bounds.set_size(actual_new_resolution); |
| 94 info.SetBounds(bounds); | 94 info.SetBounds(bounds); |
| 95 } | 95 } |
| 96 info_list.push_back(info); | 96 info_list.push_back(info); |
| 97 } | 97 } |
| 98 display_manager->OnNativeDisplaysChanged(info_list); | 98 display_manager->OnNativeDisplaysChanged(info_list); |
| 99 RunAllPendingInMessageLoop(); | 99 RunAllPendingInMessageLoop(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 160 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
| 161 }; | 161 }; |
| 162 | 162 |
| 163 // Basic behaviors and verifies it doesn't cause crashes. | 163 // Basic behaviors and verifies it doesn't cause crashes. |
| 164 TEST_F(ResolutionNotificationControllerTest, Basic) { | 164 TEST_F(ResolutionNotificationControllerTest, Basic) { |
| 165 if (!SupportsMultipleDisplays()) | 165 if (!SupportsMultipleDisplays()) |
| 166 return; | 166 return; |
| 167 | 167 |
| 168 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 168 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 169 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 169 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 170 ash::DisplayManager* display_manager = | 170 ash::DisplayManager* display_manager = |
| 171 ash::Shell::GetInstance()->display_manager(); | 171 ash::Shell::GetInstance()->display_manager(); |
| 172 ASSERT_EQ(0, accept_count()); | 172 ASSERT_EQ(0, accept_count()); |
| 173 EXPECT_FALSE(IsNotificationVisible()); | 173 EXPECT_FALSE(IsNotificationVisible()); |
| 174 | 174 |
| 175 // Changes the resolution and apply the result. | 175 // Changes the resolution and apply the result. |
| 176 SetDisplayResolutionAndNotify( | 176 SetDisplayResolutionAndNotify( |
| 177 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 177 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
| 178 EXPECT_TRUE(IsNotificationVisible()); | 178 EXPECT_TRUE(IsNotificationVisible()); |
| 179 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 179 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 192 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 192 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
| 193 EXPECT_EQ("250x250", mode.size.ToString()); | 193 EXPECT_EQ("250x250", mode.size.ToString()); |
| 194 EXPECT_EQ(59.0, mode.refresh_rate); | 194 EXPECT_EQ(59.0, mode.refresh_rate); |
| 195 } | 195 } |
| 196 | 196 |
| 197 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 197 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
| 198 if (!SupportsMultipleDisplays()) | 198 if (!SupportsMultipleDisplays()) |
| 199 return; | 199 return; |
| 200 | 200 |
| 201 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 201 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 202 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 202 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 203 ash::DisplayManager* display_manager = | 203 ash::DisplayManager* display_manager = |
| 204 ash::Shell::GetInstance()->display_manager(); | 204 ash::Shell::GetInstance()->display_manager(); |
| 205 ASSERT_EQ(0, accept_count()); | 205 ASSERT_EQ(0, accept_count()); |
| 206 EXPECT_FALSE(IsNotificationVisible()); | 206 EXPECT_FALSE(IsNotificationVisible()); |
| 207 | 207 |
| 208 // Changes the resolution and apply the result. | 208 // Changes the resolution and apply the result. |
| 209 SetDisplayResolutionAndNotify( | 209 SetDisplayResolutionAndNotify( |
| 210 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 210 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
| 211 EXPECT_TRUE(IsNotificationVisible()); | 211 EXPECT_TRUE(IsNotificationVisible()); |
| 212 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 212 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 262 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); |
| 263 EXPECT_EQ("300x300", mode.size.ToString()); | 263 EXPECT_EQ("300x300", mode.size.ToString()); |
| 264 EXPECT_EQ(59.0f, mode.refresh_rate); | 264 EXPECT_EQ(59.0f, mode.refresh_rate); |
| 265 } | 265 } |
| 266 | 266 |
| 267 TEST_F(ResolutionNotificationControllerTest, Close) { | 267 TEST_F(ResolutionNotificationControllerTest, Close) { |
| 268 if (!SupportsMultipleDisplays()) | 268 if (!SupportsMultipleDisplays()) |
| 269 return; | 269 return; |
| 270 | 270 |
| 271 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 271 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
| 272 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 272 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 273 ash::DisplayManager* display_manager = | 273 ash::DisplayManager* display_manager = |
| 274 ash::Shell::GetInstance()->display_manager(); | 274 ash::Shell::GetInstance()->display_manager(); |
| 275 ASSERT_EQ(0, accept_count()); | 275 ASSERT_EQ(0, accept_count()); |
| 276 EXPECT_FALSE(IsNotificationVisible()); | 276 EXPECT_FALSE(IsNotificationVisible()); |
| 277 | 277 |
| 278 // Changes the resolution and apply the result. | 278 // Changes the resolution and apply the result. |
| 279 SetDisplayResolutionAndNotify( | 279 SetDisplayResolutionAndNotify( |
| 280 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 280 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
| 281 EXPECT_TRUE(IsNotificationVisible()); | 281 EXPECT_TRUE(IsNotificationVisible()); |
| 282 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 282 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 EXPECT_EQ("300x300", mode.size.ToString()); | 317 EXPECT_EQ("300x300", mode.size.ToString()); |
| 318 EXPECT_EQ(59.0f, mode.refresh_rate); | 318 EXPECT_EQ(59.0f, mode.refresh_rate); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 321 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
| 322 if (!SupportsMultipleDisplays()) | 322 if (!SupportsMultipleDisplays()) |
| 323 return; | 323 return; |
| 324 | 324 |
| 325 UpdateDisplay("300x300#300x300%56|200x200%57," | 325 UpdateDisplay("300x300#300x300%56|200x200%57," |
| 326 "200x200#250x250%58|200x200%59|100x100%60"); | 326 "200x200#250x250%58|200x200%59|100x100%60"); |
| 327 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 327 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 328 ash::DisplayManager* display_manager = | 328 ash::DisplayManager* display_manager = |
| 329 ash::Shell::GetInstance()->display_manager(); | 329 ash::Shell::GetInstance()->display_manager(); |
| 330 SetDisplayResolutionAndNotify( | 330 SetDisplayResolutionAndNotify( |
| 331 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); | 331 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); |
| 332 ASSERT_TRUE(IsNotificationVisible()); | 332 ASSERT_TRUE(IsNotificationVisible()); |
| 333 | 333 |
| 334 // Disconnects the secondary display and verifies it doesn't cause crashes. | 334 // Disconnects the secondary display and verifies it doesn't cause crashes. |
| 335 UpdateDisplay("300x300#300x300%56|200x200%57"); | 335 UpdateDisplay("300x300#300x300%56|200x200%57"); |
| 336 RunAllPendingInMessageLoop(); | 336 RunAllPendingInMessageLoop(); |
| 337 EXPECT_FALSE(IsNotificationVisible()); | 337 EXPECT_FALSE(IsNotificationVisible()); |
| 338 EXPECT_EQ(0, accept_count()); | 338 EXPECT_EQ(0, accept_count()); |
| 339 DisplayMode mode; | 339 DisplayMode mode; |
| 340 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 340 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
| 341 gfx::Size resolution; | 341 gfx::Size resolution; |
| 342 EXPECT_EQ("200x200", mode.size.ToString()); | 342 EXPECT_EQ("200x200", mode.size.ToString()); |
| 343 EXPECT_EQ(59.0f, mode.refresh_rate); | 343 EXPECT_EQ(59.0f, mode.refresh_rate); |
| 344 } | 344 } |
| 345 | 345 |
| 346 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 346 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
| 347 if (!SupportsMultipleDisplays()) | 347 if (!SupportsMultipleDisplays()) |
| 348 return; | 348 return; |
| 349 | 349 |
| 350 UpdateDisplay("300x300#300x300%56|200x200%57," | 350 UpdateDisplay("300x300#300x300%56|200x200%57," |
| 351 "250x250#250x250%58|200x200%59"); | 351 "250x250#250x250%58|200x200%59"); |
| 352 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 352 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 353 ash::DisplayManager* display_manager = | 353 ash::DisplayManager* display_manager = |
| 354 ash::Shell::GetInstance()->display_manager(); | 354 ash::Shell::GetInstance()->display_manager(); |
| 355 | 355 |
| 356 SetDisplayResolutionAndNotify( | 356 SetDisplayResolutionAndNotify( |
| 357 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 357 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
| 358 EXPECT_TRUE(IsNotificationVisible()); | 358 EXPECT_TRUE(IsNotificationVisible()); |
| 359 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 359 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 360 DisplayMode mode; | 360 DisplayMode mode; |
| 361 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 361 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
| 362 EXPECT_EQ("200x200", mode.size.ToString()); | 362 EXPECT_EQ("200x200", mode.size.ToString()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 381 EXPECT_EQ("250x250", mode.size.ToString()); | 381 EXPECT_EQ("250x250", mode.size.ToString()); |
| 382 EXPECT_EQ(58.0f, mode.refresh_rate); | 382 EXPECT_EQ(58.0f, mode.refresh_rate); |
| 383 } | 383 } |
| 384 | 384 |
| 385 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 385 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
| 386 if (!SupportsMultipleDisplays()) | 386 if (!SupportsMultipleDisplays()) |
| 387 return; | 387 return; |
| 388 | 388 |
| 389 UpdateDisplay("300x300#300x300%56|200x200%57," | 389 UpdateDisplay("300x300#300x300%56|200x200%57," |
| 390 "250x250#250x250%58|220x220%59|200x200%60"); | 390 "250x250#250x250%58|220x220%59|200x200%60"); |
| 391 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 391 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
| 392 ash::DisplayManager* display_manager = | 392 ash::DisplayManager* display_manager = |
| 393 ash::Shell::GetInstance()->display_manager(); | 393 ash::Shell::GetInstance()->display_manager(); |
| 394 ASSERT_EQ(0, accept_count()); | 394 ASSERT_EQ(0, accept_count()); |
| 395 EXPECT_FALSE(IsNotificationVisible()); | 395 EXPECT_FALSE(IsNotificationVisible()); |
| 396 | 396 |
| 397 // Changes the resolution and apply the result. | 397 // Changes the resolution and apply the result. |
| 398 SetDisplayResolutionAndNotifyWithResolution( | 398 SetDisplayResolutionAndNotifyWithResolution( |
| 399 ScreenUtil::GetSecondaryDisplay(), | 399 ScreenUtil::GetSecondaryDisplay(), |
| 400 gfx::Size(220, 220), | 400 gfx::Size(220, 220), |
| 401 gfx::Size(200, 200)); | 401 gfx::Size(200, 200)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 414 ClickOnNotificationButton(0); | 414 ClickOnNotificationButton(0); |
| 415 RunAllPendingInMessageLoop(); | 415 RunAllPendingInMessageLoop(); |
| 416 EXPECT_FALSE(IsNotificationVisible()); | 416 EXPECT_FALSE(IsNotificationVisible()); |
| 417 EXPECT_EQ(0, accept_count()); | 417 EXPECT_EQ(0, accept_count()); |
| 418 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 418 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
| 419 EXPECT_EQ("250x250", mode.size.ToString()); | 419 EXPECT_EQ("250x250", mode.size.ToString()); |
| 420 EXPECT_EQ(58.0f, mode.refresh_rate); | 420 EXPECT_EQ(58.0f, mode.refresh_rate); |
| 421 } | 421 } |
| 422 | 422 |
| 423 } // namespace ash | 423 } // namespace ash |
| OLD | NEW |