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" | |
8 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
11 #include "base/bind.h" | 10 #include "base/bind.h" |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "grit/ash_strings.h" | 12 #include "grit/ash_strings.h" |
14 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/display/manager/display_manager.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 | 21 |
22 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { | 22 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { |
23 public: | 23 public: |
24 ResolutionNotificationControllerTest() : accept_count_(0) {} | 24 ResolutionNotificationControllerTest() : accept_count_(0) {} |
(...skipping 22 matching lines...) Expand all Loading... |
47 protected: | 47 protected: |
48 void SetUp() override { | 48 void SetUp() override { |
49 ash::test::AshTestBase::SetUp(); | 49 ash::test::AshTestBase::SetUp(); |
50 ResolutionNotificationController::SuppressTimerForTest(); | 50 ResolutionNotificationController::SuppressTimerForTest(); |
51 } | 51 } |
52 | 52 |
53 void SetDisplayResolutionAndNotifyWithResolution( | 53 void SetDisplayResolutionAndNotifyWithResolution( |
54 const display::Display& display, | 54 const display::Display& display, |
55 const gfx::Size& new_resolution, | 55 const gfx::Size& new_resolution, |
56 const gfx::Size& actual_new_resolution) { | 56 const gfx::Size& actual_new_resolution) { |
57 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
58 | |
59 const display::ManagedDisplayInfo& info = | 57 const display::ManagedDisplayInfo& info = |
60 display_manager->GetDisplayInfo(display.id()); | 58 display_manager()->GetDisplayInfo(display.id()); |
61 scoped_refptr<display::ManagedDisplayMode> old_mode( | 59 scoped_refptr<display::ManagedDisplayMode> old_mode( |
62 new display::ManagedDisplayMode( | 60 new display::ManagedDisplayMode( |
63 info.size_in_pixel(), 60 /* refresh_rate */, false /* interlaced */, | 61 info.size_in_pixel(), 60 /* refresh_rate */, false /* interlaced */, |
64 false /* native */)); | 62 false /* native */)); |
65 scoped_refptr<display::ManagedDisplayMode> new_mode( | 63 scoped_refptr<display::ManagedDisplayMode> new_mode( |
66 new display::ManagedDisplayMode( | 64 new display::ManagedDisplayMode( |
67 new_resolution, old_mode->refresh_rate(), old_mode->is_interlaced(), | 65 new_resolution, old_mode->refresh_rate(), old_mode->is_interlaced(), |
68 old_mode->native(), old_mode->ui_scale(), | 66 old_mode->native(), old_mode->ui_scale(), |
69 old_mode->device_scale_factor())); | 67 old_mode->device_scale_factor())); |
70 | 68 |
71 if (display_manager->SetDisplayMode(display.id(), new_mode)) { | 69 if (display_manager()->SetDisplayMode(display.id(), new_mode)) { |
72 controller()->PrepareNotification( | 70 controller()->PrepareNotification( |
73 display.id(), old_mode, new_mode, | 71 display.id(), old_mode, new_mode, |
74 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, | 72 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, |
75 base::Unretained(this))); | 73 base::Unretained(this))); |
76 } | 74 } |
77 | 75 |
78 // OnConfigurationChanged event won't be emitted in the test environment, | 76 // OnConfigurationChanged event won't be emitted in the test environment, |
79 // so invoke UpdateDisplay() to emit that event explicitly. | 77 // so invoke UpdateDisplay() to emit that event explicitly. |
80 std::vector<display::ManagedDisplayInfo> info_list; | 78 std::vector<display::ManagedDisplayInfo> info_list; |
81 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 79 for (size_t i = 0; i < display_manager()->GetNumDisplays(); ++i) { |
82 int64_t id = display_manager->GetDisplayAt(i).id(); | 80 int64_t id = display_manager()->GetDisplayAt(i).id(); |
83 display::ManagedDisplayInfo info = display_manager->GetDisplayInfo(id); | 81 display::ManagedDisplayInfo info = display_manager()->GetDisplayInfo(id); |
84 if (display.id() == id) { | 82 if (display.id() == id) { |
85 gfx::Rect bounds = info.bounds_in_native(); | 83 gfx::Rect bounds = info.bounds_in_native(); |
86 bounds.set_size(actual_new_resolution); | 84 bounds.set_size(actual_new_resolution); |
87 info.SetBounds(bounds); | 85 info.SetBounds(bounds); |
88 } | 86 } |
89 info_list.push_back(info); | 87 info_list.push_back(info); |
90 } | 88 } |
91 display_manager->OnNativeDisplaysChanged(info_list); | 89 display_manager()->OnNativeDisplaysChanged(info_list); |
92 RunAllPendingInMessageLoop(); | 90 RunAllPendingInMessageLoop(); |
93 } | 91 } |
94 | 92 |
95 void SetDisplayResolutionAndNotify(const display::Display& display, | 93 void SetDisplayResolutionAndNotify(const display::Display& display, |
96 const gfx::Size& new_resolution) { | 94 const gfx::Size& new_resolution) { |
97 SetDisplayResolutionAndNotifyWithResolution(display, new_resolution, | 95 SetDisplayResolutionAndNotifyWithResolution(display, new_resolution, |
98 new_resolution); | 96 new_resolution); |
99 } | 97 } |
100 | 98 |
101 static base::string16 GetNotificationMessage() { | 99 static base::string16 GetNotificationMessage() { |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 291 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
294 | 292 |
295 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { | 293 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { |
296 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i | 294 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i |
297 << "-th timer tick"; | 295 << "-th timer tick"; |
298 TickTimer(); | 296 TickTimer(); |
299 RunAllPendingInMessageLoop(); | 297 RunAllPendingInMessageLoop(); |
300 } | 298 } |
301 EXPECT_FALSE(IsNotificationVisible()); | 299 EXPECT_FALSE(IsNotificationVisible()); |
302 EXPECT_EQ(0, accept_count()); | 300 EXPECT_EQ(0, accept_count()); |
303 ash::DisplayManager* display_manager = | |
304 ash::Shell::GetInstance()->display_manager(); | |
305 scoped_refptr<display::ManagedDisplayMode> mode = | 301 scoped_refptr<display::ManagedDisplayMode> mode = |
306 display_manager->GetSelectedModeForDisplayId(display.id()); | 302 display_manager()->GetSelectedModeForDisplayId(display.id()); |
307 EXPECT_TRUE(!!mode); | 303 EXPECT_TRUE(!!mode); |
308 EXPECT_EQ("300x300", mode->size().ToString()); | 304 EXPECT_EQ("300x300", mode->size().ToString()); |
309 EXPECT_EQ(59.0f, mode->refresh_rate()); | 305 EXPECT_EQ(59.0f, mode->refresh_rate()); |
310 } | 306 } |
311 | 307 |
312 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 308 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
313 if (!SupportsMultipleDisplays()) | 309 if (!SupportsMultipleDisplays()) |
314 return; | 310 return; |
315 | 311 |
316 UpdateDisplay( | 312 UpdateDisplay( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 EXPECT_FALSE(IsNotificationVisible()); | 403 EXPECT_FALSE(IsNotificationVisible()); |
408 EXPECT_EQ(0, accept_count()); | 404 EXPECT_EQ(0, accept_count()); |
409 | 405 |
410 mode = display_manager()->GetSelectedModeForDisplayId(id2); | 406 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
411 EXPECT_TRUE(!!mode); | 407 EXPECT_TRUE(!!mode); |
412 EXPECT_EQ("250x250", mode->size().ToString()); | 408 EXPECT_EQ("250x250", mode->size().ToString()); |
413 EXPECT_EQ(58.0f, mode->refresh_rate()); | 409 EXPECT_EQ(58.0f, mode->refresh_rate()); |
414 } | 410 } |
415 | 411 |
416 } // namespace ash | 412 } // namespace ash |
OLD | NEW |