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 29 matching lines...) Expand all Loading... |
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 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { | 48 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { |
49 public: | 49 public: |
50 ResolutionNotificationControllerTest() | 50 ResolutionNotificationControllerTest() : accept_count_(0) {} |
51 : accept_count_(0) { | |
52 } | |
53 | 51 |
54 ~ResolutionNotificationControllerTest() override {} | 52 ~ResolutionNotificationControllerTest() override {} |
55 | 53 |
56 protected: | 54 protected: |
57 void SetUp() override { | 55 void SetUp() override { |
58 ash::test::AshTestBase::SetUp(); | 56 ash::test::AshTestBase::SetUp(); |
59 ResolutionNotificationController::SuppressTimerForTest(); | 57 ResolutionNotificationController::SuppressTimerForTest(); |
60 } | 58 } |
61 | 59 |
62 void SetDisplayResolutionAndNotifyWithResolution( | 60 void SetDisplayResolutionAndNotifyWithResolution( |
63 const display::Display& display, | 61 const display::Display& display, |
64 const gfx::Size& new_resolution, | 62 const gfx::Size& new_resolution, |
65 const gfx::Size& actual_new_resolution) { | 63 const gfx::Size& actual_new_resolution) { |
66 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 64 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
67 | 65 |
68 const DisplayInfo& info = display_manager->GetDisplayInfo(display.id()); | 66 const DisplayInfo& info = display_manager->GetDisplayInfo(display.id()); |
69 DisplayMode old_mode(info.size_in_pixel(), | 67 DisplayMode old_mode(info.size_in_pixel(), 60 /* refresh_rate */, |
70 60 /* refresh_rate */, | 68 false /* interlaced */, false /* native */); |
71 false /* interlaced */, | |
72 false /* native */); | |
73 DisplayMode new_mode = old_mode; | 69 DisplayMode new_mode = old_mode; |
74 new_mode.size = new_resolution; | 70 new_mode.size = new_resolution; |
75 | 71 |
76 if (display_manager->SetDisplayMode(display.id(), new_mode)) { | 72 if (display_manager->SetDisplayMode(display.id(), new_mode)) { |
77 controller()->PrepareNotification( | 73 controller()->PrepareNotification( |
78 display.id(), | 74 display.id(), old_mode, new_mode, |
79 old_mode, | |
80 new_mode, | |
81 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, | 75 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, |
82 base::Unretained(this))); | 76 base::Unretained(this))); |
83 } | 77 } |
84 | 78 |
85 // OnConfigurationChanged event won't be emitted in the test environment, | 79 // OnConfigurationChanged event won't be emitted in the test environment, |
86 // so invoke UpdateDisplay() to emit that event explicitly. | 80 // so invoke UpdateDisplay() to emit that event explicitly. |
87 std::vector<DisplayInfo> info_list; | 81 std::vector<DisplayInfo> info_list; |
88 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 82 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
89 int64_t id = display_manager->GetDisplayAt(i).id(); | 83 int64_t id = display_manager->GetDisplayAt(i).id(); |
90 DisplayInfo info = display_manager->GetDisplayInfo(id); | 84 DisplayInfo info = display_manager->GetDisplayInfo(id); |
91 if (display.id() == id) { | 85 if (display.id() == id) { |
92 gfx::Rect bounds = info.bounds_in_native(); | 86 gfx::Rect bounds = info.bounds_in_native(); |
93 bounds.set_size(actual_new_resolution); | 87 bounds.set_size(actual_new_resolution); |
94 info.SetBounds(bounds); | 88 info.SetBounds(bounds); |
95 } | 89 } |
96 info_list.push_back(info); | 90 info_list.push_back(info); |
97 } | 91 } |
98 display_manager->OnNativeDisplaysChanged(info_list); | 92 display_manager->OnNativeDisplaysChanged(info_list); |
99 RunAllPendingInMessageLoop(); | 93 RunAllPendingInMessageLoop(); |
100 } | 94 } |
101 | 95 |
102 void SetDisplayResolutionAndNotify(const display::Display& display, | 96 void SetDisplayResolutionAndNotify(const display::Display& display, |
103 const gfx::Size& new_resolution) { | 97 const gfx::Size& new_resolution) { |
104 SetDisplayResolutionAndNotifyWithResolution( | 98 SetDisplayResolutionAndNotifyWithResolution(display, new_resolution, |
105 display, new_resolution, new_resolution); | 99 new_resolution); |
106 } | 100 } |
107 | 101 |
108 static base::string16 GetNotificationMessage() { | 102 static base::string16 GetNotificationMessage() { |
109 const message_center::NotificationList::Notifications& notifications = | 103 const message_center::NotificationList::Notifications& notifications = |
110 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 104 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
111 for (message_center::NotificationList::Notifications::const_iterator iter = | 105 for (message_center::NotificationList::Notifications::const_iterator iter = |
112 notifications.begin(); iter != notifications.end(); ++iter) { | 106 notifications.begin(); |
| 107 iter != notifications.end(); ++iter) { |
113 if ((*iter)->id() == ResolutionNotificationController::kNotificationId) | 108 if ((*iter)->id() == ResolutionNotificationController::kNotificationId) |
114 return (*iter)->title(); | 109 return (*iter)->title(); |
115 } | 110 } |
116 | 111 |
117 return base::string16(); | 112 return base::string16(); |
118 } | 113 } |
119 | 114 |
120 static void ClickOnNotification() { | 115 static void ClickOnNotification() { |
121 message_center::MessageCenter::Get()->ClickOnNotification( | 116 message_center::MessageCenter::Get()->ClickOnNotification( |
122 ResolutionNotificationController::kNotificationId); | 117 ResolutionNotificationController::kNotificationId); |
123 } | 118 } |
124 | 119 |
125 static void ClickOnNotificationButton(int index) { | 120 static void ClickOnNotificationButton(int index) { |
126 message_center::MessageCenter::Get()->ClickOnNotificationButton( | 121 message_center::MessageCenter::Get()->ClickOnNotificationButton( |
127 ResolutionNotificationController::kNotificationId, index); | 122 ResolutionNotificationController::kNotificationId, index); |
128 } | 123 } |
129 | 124 |
130 static void CloseNotification() { | 125 static void CloseNotification() { |
131 message_center::MessageCenter::Get()->RemoveNotification( | 126 message_center::MessageCenter::Get()->RemoveNotification( |
132 ResolutionNotificationController::kNotificationId, true /* by_user */); | 127 ResolutionNotificationController::kNotificationId, true /* by_user */); |
133 } | 128 } |
134 | 129 |
135 static bool IsNotificationVisible() { | 130 static bool IsNotificationVisible() { |
136 return message_center::MessageCenter::Get()->FindVisibleNotificationById( | 131 return message_center::MessageCenter::Get()->FindVisibleNotificationById( |
137 ResolutionNotificationController::kNotificationId); | 132 ResolutionNotificationController::kNotificationId); |
138 } | 133 } |
139 | 134 |
140 static void TickTimer() { | 135 static void TickTimer() { controller()->OnTimerTick(); } |
141 controller()->OnTimerTick(); | |
142 } | |
143 | 136 |
144 static ResolutionNotificationController* controller() { | 137 static ResolutionNotificationController* controller() { |
145 return Shell::GetInstance()->resolution_notification_controller(); | 138 return Shell::GetInstance()->resolution_notification_controller(); |
146 } | 139 } |
147 | 140 |
148 int accept_count() const { | 141 int accept_count() const { return accept_count_; } |
149 return accept_count_; | |
150 } | |
151 | 142 |
152 private: | 143 private: |
153 void OnAccepted() { | 144 void OnAccepted() { |
154 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 145 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
155 accept_count_++; | 146 accept_count_++; |
156 } | 147 } |
157 | 148 |
158 int accept_count_; | 149 int accept_count_; |
159 | 150 |
160 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 151 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
161 }; | 152 }; |
162 | 153 |
163 // Basic behaviors and verifies it doesn't cause crashes. | 154 // Basic behaviors and verifies it doesn't cause crashes. |
164 TEST_F(ResolutionNotificationControllerTest, Basic) { | 155 TEST_F(ResolutionNotificationControllerTest, Basic) { |
165 if (!SupportsMultipleDisplays()) | 156 if (!SupportsMultipleDisplays()) |
166 return; | 157 return; |
167 | 158 |
168 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 159 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
169 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 160 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
170 ash::DisplayManager* display_manager = | 161 ash::DisplayManager* display_manager = |
171 ash::Shell::GetInstance()->display_manager(); | 162 ash::Shell::GetInstance()->display_manager(); |
172 ASSERT_EQ(0, accept_count()); | 163 ASSERT_EQ(0, accept_count()); |
173 EXPECT_FALSE(IsNotificationVisible()); | 164 EXPECT_FALSE(IsNotificationVisible()); |
174 | 165 |
175 // Changes the resolution and apply the result. | 166 // Changes the resolution and apply the result. |
176 SetDisplayResolutionAndNotify( | 167 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
177 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 168 gfx::Size(200, 200)); |
178 EXPECT_TRUE(IsNotificationVisible()); | 169 EXPECT_TRUE(IsNotificationVisible()); |
179 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 170 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
180 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), | 171 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), |
181 GetNotificationMessage()); | 172 GetNotificationMessage()); |
182 DisplayMode mode; | 173 DisplayMode mode; |
183 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 174 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
184 EXPECT_EQ("200x200", mode.size.ToString()); | 175 EXPECT_EQ("200x200", mode.size.ToString()); |
185 EXPECT_EQ(60.0, mode.refresh_rate); | 176 EXPECT_EQ(60.0, mode.refresh_rate); |
186 | 177 |
187 // Click the revert button, which reverts to the best resolution. | 178 // Click the revert button, which reverts to the best resolution. |
(...skipping 11 matching lines...) Expand all Loading... |
199 return; | 190 return; |
200 | 191 |
201 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 192 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
202 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 193 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
203 ash::DisplayManager* display_manager = | 194 ash::DisplayManager* display_manager = |
204 ash::Shell::GetInstance()->display_manager(); | 195 ash::Shell::GetInstance()->display_manager(); |
205 ASSERT_EQ(0, accept_count()); | 196 ASSERT_EQ(0, accept_count()); |
206 EXPECT_FALSE(IsNotificationVisible()); | 197 EXPECT_FALSE(IsNotificationVisible()); |
207 | 198 |
208 // Changes the resolution and apply the result. | 199 // Changes the resolution and apply the result. |
209 SetDisplayResolutionAndNotify( | 200 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
210 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 201 gfx::Size(200, 200)); |
211 EXPECT_TRUE(IsNotificationVisible()); | 202 EXPECT_TRUE(IsNotificationVisible()); |
212 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 203 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
213 DisplayMode mode; | 204 DisplayMode mode; |
214 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 205 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
215 EXPECT_EQ("200x200", mode.size.ToString()); | 206 EXPECT_EQ("200x200", mode.size.ToString()); |
216 EXPECT_EQ(60.0, mode.refresh_rate); | 207 EXPECT_EQ(60.0, mode.refresh_rate); |
217 | 208 |
218 // Click the revert button, which reverts the resolution. | 209 // Click the revert button, which reverts the resolution. |
219 ClickOnNotification(); | 210 ClickOnNotification(); |
220 RunAllPendingInMessageLoop(); | 211 RunAllPendingInMessageLoop(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 return; | 261 return; |
271 | 262 |
272 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 263 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
273 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 264 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
274 ash::DisplayManager* display_manager = | 265 ash::DisplayManager* display_manager = |
275 ash::Shell::GetInstance()->display_manager(); | 266 ash::Shell::GetInstance()->display_manager(); |
276 ASSERT_EQ(0, accept_count()); | 267 ASSERT_EQ(0, accept_count()); |
277 EXPECT_FALSE(IsNotificationVisible()); | 268 EXPECT_FALSE(IsNotificationVisible()); |
278 | 269 |
279 // Changes the resolution and apply the result. | 270 // Changes the resolution and apply the result. |
280 SetDisplayResolutionAndNotify( | 271 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
281 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 272 gfx::Size(200, 200)); |
282 EXPECT_TRUE(IsNotificationVisible()); | 273 EXPECT_TRUE(IsNotificationVisible()); |
283 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 274 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
284 DisplayMode mode; | 275 DisplayMode mode; |
285 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 276 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
286 EXPECT_EQ("200x200", mode.size.ToString()); | 277 EXPECT_EQ("200x200", mode.size.ToString()); |
287 EXPECT_EQ(60.0f, mode.refresh_rate); | 278 EXPECT_EQ(60.0f, mode.refresh_rate); |
288 | 279 |
289 // Close the notification (imitates clicking [x] button). Also verifies if | 280 // Close the notification (imitates clicking [x] button). Also verifies if |
290 // this does not cause a crash. See crbug.com/271784 | 281 // this does not cause a crash. See crbug.com/271784 |
291 CloseNotification(); | 282 CloseNotification(); |
292 RunAllPendingInMessageLoop(); | 283 RunAllPendingInMessageLoop(); |
293 EXPECT_FALSE(IsNotificationVisible()); | 284 EXPECT_FALSE(IsNotificationVisible()); |
294 EXPECT_EQ(1, accept_count()); | 285 EXPECT_EQ(1, accept_count()); |
295 } | 286 } |
296 | 287 |
297 TEST_F(ResolutionNotificationControllerTest, Timeout) { | 288 TEST_F(ResolutionNotificationControllerTest, Timeout) { |
298 if (!SupportsMultipleDisplays()) | 289 if (!SupportsMultipleDisplays()) |
299 return; | 290 return; |
300 | 291 |
301 UpdateDisplay("300x300#300x300%59|200x200%60"); | 292 UpdateDisplay("300x300#300x300%59|200x200%60"); |
302 const display::Display& display = | 293 const display::Display& display = |
303 display::Screen::GetScreen()->GetPrimaryDisplay(); | 294 display::Screen::GetScreen()->GetPrimaryDisplay(); |
304 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 295 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
305 | 296 |
306 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { | 297 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { |
307 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " | 298 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i |
308 << i << "-th timer tick"; | 299 << "-th timer tick"; |
309 TickTimer(); | 300 TickTimer(); |
310 RunAllPendingInMessageLoop(); | 301 RunAllPendingInMessageLoop(); |
311 } | 302 } |
312 EXPECT_FALSE(IsNotificationVisible()); | 303 EXPECT_FALSE(IsNotificationVisible()); |
313 EXPECT_EQ(0, accept_count()); | 304 EXPECT_EQ(0, accept_count()); |
314 ash::DisplayManager* display_manager = | 305 ash::DisplayManager* display_manager = |
315 ash::Shell::GetInstance()->display_manager(); | 306 ash::Shell::GetInstance()->display_manager(); |
316 DisplayMode mode; | 307 DisplayMode mode; |
317 EXPECT_TRUE( | 308 EXPECT_TRUE( |
318 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); | 309 display_manager->GetSelectedModeForDisplayId(display.id(), &mode)); |
319 EXPECT_EQ("300x300", mode.size.ToString()); | 310 EXPECT_EQ("300x300", mode.size.ToString()); |
320 EXPECT_EQ(59.0f, mode.refresh_rate); | 311 EXPECT_EQ(59.0f, mode.refresh_rate); |
321 } | 312 } |
322 | 313 |
323 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 314 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
324 if (!SupportsMultipleDisplays()) | 315 if (!SupportsMultipleDisplays()) |
325 return; | 316 return; |
326 | 317 |
327 UpdateDisplay("300x300#300x300%56|200x200%57," | 318 UpdateDisplay( |
328 "200x200#250x250%58|200x200%59|100x100%60"); | 319 "300x300#300x300%56|200x200%57," |
| 320 "200x200#250x250%58|200x200%59|100x100%60"); |
329 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 321 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
330 ash::DisplayManager* display_manager = | 322 ash::DisplayManager* display_manager = |
331 ash::Shell::GetInstance()->display_manager(); | 323 ash::Shell::GetInstance()->display_manager(); |
332 SetDisplayResolutionAndNotify( | 324 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
333 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); | 325 gfx::Size(100, 100)); |
334 ASSERT_TRUE(IsNotificationVisible()); | 326 ASSERT_TRUE(IsNotificationVisible()); |
335 | 327 |
336 // Disconnects the secondary display and verifies it doesn't cause crashes. | 328 // Disconnects the secondary display and verifies it doesn't cause crashes. |
337 UpdateDisplay("300x300#300x300%56|200x200%57"); | 329 UpdateDisplay("300x300#300x300%56|200x200%57"); |
338 RunAllPendingInMessageLoop(); | 330 RunAllPendingInMessageLoop(); |
339 EXPECT_FALSE(IsNotificationVisible()); | 331 EXPECT_FALSE(IsNotificationVisible()); |
340 EXPECT_EQ(0, accept_count()); | 332 EXPECT_EQ(0, accept_count()); |
341 DisplayMode mode; | 333 DisplayMode mode; |
342 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 334 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
343 gfx::Size resolution; | 335 gfx::Size resolution; |
344 EXPECT_EQ("200x200", mode.size.ToString()); | 336 EXPECT_EQ("200x200", mode.size.ToString()); |
345 EXPECT_EQ(59.0f, mode.refresh_rate); | 337 EXPECT_EQ(59.0f, mode.refresh_rate); |
346 } | 338 } |
347 | 339 |
348 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 340 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
349 if (!SupportsMultipleDisplays()) | 341 if (!SupportsMultipleDisplays()) |
350 return; | 342 return; |
351 | 343 |
352 UpdateDisplay("300x300#300x300%56|200x200%57," | 344 UpdateDisplay( |
353 "250x250#250x250%58|200x200%59"); | 345 "300x300#300x300%56|200x200%57," |
| 346 "250x250#250x250%58|200x200%59"); |
354 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 347 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
355 ash::DisplayManager* display_manager = | 348 ash::DisplayManager* display_manager = |
356 ash::Shell::GetInstance()->display_manager(); | 349 ash::Shell::GetInstance()->display_manager(); |
357 | 350 |
358 SetDisplayResolutionAndNotify( | 351 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
359 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); | 352 gfx::Size(200, 200)); |
360 EXPECT_TRUE(IsNotificationVisible()); | 353 EXPECT_TRUE(IsNotificationVisible()); |
361 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 354 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
362 DisplayMode mode; | 355 DisplayMode mode; |
363 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 356 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
364 EXPECT_EQ("200x200", mode.size.ToString()); | 357 EXPECT_EQ("200x200", mode.size.ToString()); |
365 EXPECT_EQ(59.0f, mode.refresh_rate); | 358 EXPECT_EQ(59.0f, mode.refresh_rate); |
366 | 359 |
367 // Invokes SetDisplayResolutionAndNotify during the previous notification is | 360 // Invokes SetDisplayResolutionAndNotify during the previous notification is |
368 // visible. | 361 // visible. |
369 SetDisplayResolutionAndNotify( | 362 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), |
370 ScreenUtil::GetSecondaryDisplay(), gfx::Size(250, 250)); | 363 gfx::Size(250, 250)); |
371 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 364 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
372 EXPECT_EQ("250x250", mode.size.ToString()); | 365 EXPECT_EQ("250x250", mode.size.ToString()); |
373 EXPECT_EQ(58.0f, mode.refresh_rate); | 366 EXPECT_EQ(58.0f, mode.refresh_rate); |
374 | 367 |
375 // Then, click the revert button. Although |old_resolution| for the second | 368 // Then, click the revert button. Although |old_resolution| for the second |
376 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original | 369 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original |
377 // size 250x250. | 370 // size 250x250. |
378 ClickOnNotificationButton(0); | 371 ClickOnNotificationButton(0); |
379 RunAllPendingInMessageLoop(); | 372 RunAllPendingInMessageLoop(); |
380 EXPECT_FALSE(IsNotificationVisible()); | 373 EXPECT_FALSE(IsNotificationVisible()); |
381 EXPECT_EQ(0, accept_count()); | 374 EXPECT_EQ(0, accept_count()); |
382 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 375 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
383 EXPECT_EQ("250x250", mode.size.ToString()); | 376 EXPECT_EQ("250x250", mode.size.ToString()); |
384 EXPECT_EQ(58.0f, mode.refresh_rate); | 377 EXPECT_EQ(58.0f, mode.refresh_rate); |
385 } | 378 } |
386 | 379 |
387 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 380 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
388 if (!SupportsMultipleDisplays()) | 381 if (!SupportsMultipleDisplays()) |
389 return; | 382 return; |
390 | 383 |
391 UpdateDisplay("300x300#300x300%56|200x200%57," | 384 UpdateDisplay( |
392 "250x250#250x250%58|220x220%59|200x200%60"); | 385 "300x300#300x300%56|200x200%57," |
| 386 "250x250#250x250%58|220x220%59|200x200%60"); |
393 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); | 387 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
394 ash::DisplayManager* display_manager = | 388 ash::DisplayManager* display_manager = |
395 ash::Shell::GetInstance()->display_manager(); | 389 ash::Shell::GetInstance()->display_manager(); |
396 ASSERT_EQ(0, accept_count()); | 390 ASSERT_EQ(0, accept_count()); |
397 EXPECT_FALSE(IsNotificationVisible()); | 391 EXPECT_FALSE(IsNotificationVisible()); |
398 | 392 |
399 // Changes the resolution and apply the result. | 393 // Changes the resolution and apply the result. |
400 SetDisplayResolutionAndNotifyWithResolution( | 394 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(), |
401 ScreenUtil::GetSecondaryDisplay(), | 395 gfx::Size(220, 220), |
402 gfx::Size(220, 220), | 396 gfx::Size(200, 200)); |
403 gfx::Size(200, 200)); | |
404 EXPECT_TRUE(IsNotificationVisible()); | 397 EXPECT_TRUE(IsNotificationVisible()); |
405 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 398 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
406 EXPECT_EQ( | 399 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), |
407 ExpectedFallbackNotificationMessage( | 400 gfx::Size(200, 200)), |
408 id2, gfx::Size(220, 220), gfx::Size(200, 200)), | 401 GetNotificationMessage()); |
409 GetNotificationMessage()); | |
410 DisplayMode mode; | 402 DisplayMode mode; |
411 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 403 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
412 EXPECT_EQ("200x200", mode.size.ToString()); | 404 EXPECT_EQ("200x200", mode.size.ToString()); |
413 EXPECT_EQ(60.0f, mode.refresh_rate); | 405 EXPECT_EQ(60.0f, mode.refresh_rate); |
414 | 406 |
415 // Click the revert button, which reverts to the best resolution. | 407 // Click the revert button, which reverts to the best resolution. |
416 ClickOnNotificationButton(0); | 408 ClickOnNotificationButton(0); |
417 RunAllPendingInMessageLoop(); | 409 RunAllPendingInMessageLoop(); |
418 EXPECT_FALSE(IsNotificationVisible()); | 410 EXPECT_FALSE(IsNotificationVisible()); |
419 EXPECT_EQ(0, accept_count()); | 411 EXPECT_EQ(0, accept_count()); |
420 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); | 412 EXPECT_TRUE(display_manager->GetSelectedModeForDisplayId(id2, &mode)); |
421 EXPECT_EQ("250x250", mode.size.ToString()); | 413 EXPECT_EQ("250x250", mode.size.ToString()); |
422 EXPECT_EQ(58.0f, mode.refresh_rate); | 414 EXPECT_EQ(58.0f, mode.refresh_rate); |
423 } | 415 } |
424 | 416 |
425 } // namespace ash | 417 } // namespace ash |
OLD | NEW |