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_ash.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 "ui/gfx/size.h" | 12 #include "ui/gfx/size.h" |
13 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
14 | 14 |
15 namespace ash { | 15 namespace ash { |
16 namespace internal { | 16 namespace internal { |
17 | 17 |
18 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { | 18 class ResolutionNotificationControllerTest : public ash::test::AshTestBase { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 101 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
102 }; | 102 }; |
103 | 103 |
104 // Basic behaviors and verifies it doesn't cause crashes. | 104 // Basic behaviors and verifies it doesn't cause crashes. |
105 TEST_F(ResolutionNotificationControllerTest, Basic) { | 105 TEST_F(ResolutionNotificationControllerTest, Basic) { |
106 if (!SupportsMultipleDisplays()) | 106 if (!SupportsMultipleDisplays()) |
107 return; | 107 return; |
108 | 108 |
109 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); | 109 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); |
110 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 110 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
111 ash::internal::DisplayManager* display_manager = | 111 ash::internal::DisplayManager* display_manager = |
112 ash::Shell::GetInstance()->display_manager(); | 112 ash::Shell::GetInstance()->display_manager(); |
113 ASSERT_EQ(0, accept_count()); | 113 ASSERT_EQ(0, accept_count()); |
114 EXPECT_FALSE(IsNotificationVisible()); | 114 EXPECT_FALSE(IsNotificationVisible()); |
115 | 115 |
116 // Changes the resolution and apply the result. | 116 // Changes the resolution and apply the result. |
117 SetDisplayResolutionAndNotify( | 117 SetDisplayResolutionAndNotify( |
118 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); | 118 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
119 EXPECT_TRUE(IsNotificationVisible()); | 119 EXPECT_TRUE(IsNotificationVisible()); |
120 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 120 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
121 gfx::Size resolution; | 121 gfx::Size resolution; |
122 EXPECT_TRUE( | 122 EXPECT_TRUE( |
123 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 123 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
124 EXPECT_EQ("200x200", resolution.ToString()); | 124 EXPECT_EQ("200x200", resolution.ToString()); |
125 | 125 |
126 // Click the revert button, which reverts to the best resolution. | 126 // Click the revert button, which reverts to the best resolution. |
127 ClickOnNotificationButton(0); | 127 ClickOnNotificationButton(0); |
128 RunAllPendingInMessageLoop(); | 128 RunAllPendingInMessageLoop(); |
129 EXPECT_FALSE(IsNotificationVisible()); | 129 EXPECT_FALSE(IsNotificationVisible()); |
130 EXPECT_EQ(0, accept_count()); | 130 EXPECT_EQ(0, accept_count()); |
131 EXPECT_FALSE( | 131 EXPECT_FALSE( |
132 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 132 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
133 } | 133 } |
134 | 134 |
135 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 135 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
136 if (!SupportsMultipleDisplays()) | 136 if (!SupportsMultipleDisplays()) |
137 return; | 137 return; |
138 | 138 |
139 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); | 139 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); |
140 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 140 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
141 ash::internal::DisplayManager* display_manager = | 141 ash::internal::DisplayManager* display_manager = |
142 ash::Shell::GetInstance()->display_manager(); | 142 ash::Shell::GetInstance()->display_manager(); |
143 ASSERT_EQ(0, accept_count()); | 143 ASSERT_EQ(0, accept_count()); |
144 EXPECT_FALSE(IsNotificationVisible()); | 144 EXPECT_FALSE(IsNotificationVisible()); |
145 | 145 |
146 // Changes the resolution and apply the result. | 146 // Changes the resolution and apply the result. |
147 SetDisplayResolutionAndNotify( | 147 SetDisplayResolutionAndNotify( |
148 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); | 148 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
149 EXPECT_TRUE(IsNotificationVisible()); | 149 EXPECT_TRUE(IsNotificationVisible()); |
150 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 150 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
151 gfx::Size resolution; | 151 gfx::Size resolution; |
152 EXPECT_TRUE( | 152 EXPECT_TRUE( |
153 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 153 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
154 EXPECT_EQ("200x200", resolution.ToString()); | 154 EXPECT_EQ("200x200", resolution.ToString()); |
155 | 155 |
156 // Click the revert button, which reverts the resolution. | 156 // Click the revert button, which reverts the resolution. |
157 ClickOnNotification(); | 157 ClickOnNotification(); |
158 RunAllPendingInMessageLoop(); | 158 RunAllPendingInMessageLoop(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_EQ(1, accept_count()); | 197 EXPECT_EQ(1, accept_count()); |
198 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId( | 198 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId( |
199 display.id(), &resolution)); | 199 display.id(), &resolution)); |
200 } | 200 } |
201 | 201 |
202 TEST_F(ResolutionNotificationControllerTest, Close) { | 202 TEST_F(ResolutionNotificationControllerTest, Close) { |
203 if (!SupportsMultipleDisplays()) | 203 if (!SupportsMultipleDisplays()) |
204 return; | 204 return; |
205 | 205 |
206 UpdateDisplay("100x100,150x150#150x150|200x200"); | 206 UpdateDisplay("100x100,150x150#150x150|200x200"); |
207 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 207 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
208 ash::internal::DisplayManager* display_manager = | 208 ash::internal::DisplayManager* display_manager = |
209 ash::Shell::GetInstance()->display_manager(); | 209 ash::Shell::GetInstance()->display_manager(); |
210 ASSERT_EQ(0, accept_count()); | 210 ASSERT_EQ(0, accept_count()); |
211 EXPECT_FALSE(IsNotificationVisible()); | 211 EXPECT_FALSE(IsNotificationVisible()); |
212 | 212 |
213 // Changes the resolution and apply the result. | 213 // Changes the resolution and apply the result. |
214 SetDisplayResolutionAndNotify( | 214 SetDisplayResolutionAndNotify( |
215 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); | 215 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
216 EXPECT_TRUE(IsNotificationVisible()); | 216 EXPECT_TRUE(IsNotificationVisible()); |
217 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 217 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
218 gfx::Size resolution; | 218 gfx::Size resolution; |
219 EXPECT_TRUE( | 219 EXPECT_TRUE( |
220 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 220 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
221 EXPECT_EQ("200x200", resolution.ToString()); | 221 EXPECT_EQ("200x200", resolution.ToString()); |
222 | 222 |
223 // Close the notification (imitates clicking [x] button). Also verifies if | 223 // Close the notification (imitates clicking [x] button). Also verifies if |
224 // this does not cause a crash. See crbug.com/271784 | 224 // this does not cause a crash. See crbug.com/271784 |
225 CloseNotification(); | 225 CloseNotification(); |
(...skipping 23 matching lines...) Expand all Loading... |
249 ash::Shell::GetInstance()->display_manager(); | 249 ash::Shell::GetInstance()->display_manager(); |
250 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId( | 250 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId( |
251 display.id(), &resolution)); | 251 display.id(), &resolution)); |
252 } | 252 } |
253 | 253 |
254 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 254 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
255 if (!SupportsMultipleDisplays()) | 255 if (!SupportsMultipleDisplays()) |
256 return; | 256 return; |
257 | 257 |
258 UpdateDisplay("300x300#300x300|200x200,200x200#250x250|200x200|100x100"); | 258 UpdateDisplay("300x300#300x300|200x200,200x200#250x250|200x200|100x100"); |
259 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 259 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
260 ash::internal::DisplayManager* display_manager = | 260 ash::internal::DisplayManager* display_manager = |
261 ash::Shell::GetInstance()->display_manager(); | 261 ash::Shell::GetInstance()->display_manager(); |
262 SetDisplayResolutionAndNotify( | 262 SetDisplayResolutionAndNotify( |
263 ScreenAsh::GetSecondaryDisplay(), gfx::Size(100, 100)); | 263 ScreenUtil::GetSecondaryDisplay(), gfx::Size(100, 100)); |
264 ASSERT_TRUE(IsNotificationVisible()); | 264 ASSERT_TRUE(IsNotificationVisible()); |
265 | 265 |
266 // Disconnects the secondary display and verifies it doesn't cause crashes. | 266 // Disconnects the secondary display and verifies it doesn't cause crashes. |
267 UpdateDisplay("300x300#300x300|200x200"); | 267 UpdateDisplay("300x300#300x300|200x200"); |
268 RunAllPendingInMessageLoop(); | 268 RunAllPendingInMessageLoop(); |
269 EXPECT_FALSE(IsNotificationVisible()); | 269 EXPECT_FALSE(IsNotificationVisible()); |
270 EXPECT_EQ(0, accept_count()); | 270 EXPECT_EQ(0, accept_count()); |
271 gfx::Size resolution; | 271 gfx::Size resolution; |
272 EXPECT_TRUE( | 272 EXPECT_TRUE( |
273 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 273 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
274 EXPECT_EQ("200x200", resolution.ToString()); | 274 EXPECT_EQ("200x200", resolution.ToString()); |
275 } | 275 } |
276 | 276 |
277 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 277 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
278 if (!SupportsMultipleDisplays()) | 278 if (!SupportsMultipleDisplays()) |
279 return; | 279 return; |
280 | 280 |
281 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); | 281 UpdateDisplay("300x300#300x300|200x200,250x250#250x250|200x200"); |
282 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id(); | 282 int64 id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); |
283 ash::internal::DisplayManager* display_manager = | 283 ash::internal::DisplayManager* display_manager = |
284 ash::Shell::GetInstance()->display_manager(); | 284 ash::Shell::GetInstance()->display_manager(); |
285 | 285 |
286 SetDisplayResolutionAndNotify( | 286 SetDisplayResolutionAndNotify( |
287 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200)); | 287 ScreenUtil::GetSecondaryDisplay(), gfx::Size(200, 200)); |
288 EXPECT_TRUE(IsNotificationVisible()); | 288 EXPECT_TRUE(IsNotificationVisible()); |
289 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 289 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
290 gfx::Size resolution; | 290 gfx::Size resolution; |
291 EXPECT_TRUE( | 291 EXPECT_TRUE( |
292 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 292 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
293 EXPECT_EQ("200x200", resolution.ToString()); | 293 EXPECT_EQ("200x200", resolution.ToString()); |
294 | 294 |
295 // Invokes SetDisplayResolutionAndNotify during the previous notification is | 295 // Invokes SetDisplayResolutionAndNotify during the previous notification is |
296 // visible. | 296 // visible. |
297 SetDisplayResolutionAndNotify( | 297 SetDisplayResolutionAndNotify( |
298 ScreenAsh::GetSecondaryDisplay(), gfx::Size(250, 250)); | 298 ScreenUtil::GetSecondaryDisplay(), gfx::Size(250, 250)); |
299 EXPECT_FALSE( | 299 EXPECT_FALSE( |
300 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 300 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
301 | 301 |
302 // Then, click the revert button. Although |old_resolution| for the second | 302 // Then, click the revert button. Although |old_resolution| for the second |
303 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original | 303 // SetDisplayResolutionAndNotify is 200x200, it should revert to the original |
304 // size 150x150. | 304 // size 150x150. |
305 ClickOnNotificationButton(0); | 305 ClickOnNotificationButton(0); |
306 RunAllPendingInMessageLoop(); | 306 RunAllPendingInMessageLoop(); |
307 EXPECT_FALSE(IsNotificationVisible()); | 307 EXPECT_FALSE(IsNotificationVisible()); |
308 EXPECT_EQ(0, accept_count()); | 308 EXPECT_EQ(0, accept_count()); |
309 EXPECT_FALSE( | 309 EXPECT_FALSE( |
310 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); | 310 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); |
311 } | 311 } |
312 | 312 |
313 } // namespace internal | 313 } // namespace internal |
314 } // namespace ash | 314 } // namespace ash |
OLD | NEW |