| 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/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 accept_count_++; | 143 accept_count_++; |
| 144 } | 144 } |
| 145 | 145 |
| 146 int accept_count_; | 146 int accept_count_; |
| 147 | 147 |
| 148 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); | 148 DISALLOW_COPY_AND_ASSIGN(ResolutionNotificationControllerTest); |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 // Basic behaviors and verifies it doesn't cause crashes. | 151 // Basic behaviors and verifies it doesn't cause crashes. |
| 152 TEST_F(ResolutionNotificationControllerTest, Basic) { | 152 TEST_F(ResolutionNotificationControllerTest, Basic) { |
| 153 if (!SupportsMultipleDisplays()) | |
| 154 return; | |
| 155 | |
| 156 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 153 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 157 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 154 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 158 ASSERT_EQ(0, accept_count()); | 155 ASSERT_EQ(0, accept_count()); |
| 159 EXPECT_FALSE(IsNotificationVisible()); | 156 EXPECT_FALSE(IsNotificationVisible()); |
| 160 | 157 |
| 161 // Changes the resolution and apply the result. | 158 // Changes the resolution and apply the result. |
| 162 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), | 159 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 163 gfx::Size(200, 200)); | 160 gfx::Size(200, 200)); |
| 164 EXPECT_TRUE(IsNotificationVisible()); | 161 EXPECT_TRUE(IsNotificationVisible()); |
| 165 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 162 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 176 RunAllPendingInMessageLoop(); | 173 RunAllPendingInMessageLoop(); |
| 177 EXPECT_FALSE(IsNotificationVisible()); | 174 EXPECT_FALSE(IsNotificationVisible()); |
| 178 EXPECT_EQ(0, accept_count()); | 175 EXPECT_EQ(0, accept_count()); |
| 179 mode = display_manager()->GetSelectedModeForDisplayId(id2); | 176 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 180 EXPECT_TRUE(!!mode); | 177 EXPECT_TRUE(!!mode); |
| 181 EXPECT_EQ("250x250", mode->size().ToString()); | 178 EXPECT_EQ("250x250", mode->size().ToString()); |
| 182 EXPECT_EQ(59.0, mode->refresh_rate()); | 179 EXPECT_EQ(59.0, mode->refresh_rate()); |
| 183 } | 180 } |
| 184 | 181 |
| 185 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { | 182 TEST_F(ResolutionNotificationControllerTest, ClickMeansAccept) { |
| 186 if (!SupportsMultipleDisplays()) | |
| 187 return; | |
| 188 | |
| 189 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); | 183 UpdateDisplay("300x300#300x300%57|200x200%58,250x250#250x250%59|200x200%60"); |
| 190 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 184 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 191 ASSERT_EQ(0, accept_count()); | 185 ASSERT_EQ(0, accept_count()); |
| 192 EXPECT_FALSE(IsNotificationVisible()); | 186 EXPECT_FALSE(IsNotificationVisible()); |
| 193 | 187 |
| 194 // Changes the resolution and apply the result. | 188 // Changes the resolution and apply the result. |
| 195 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), | 189 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 196 gfx::Size(200, 200)); | 190 gfx::Size(200, 200)); |
| 197 EXPECT_TRUE(IsNotificationVisible()); | 191 EXPECT_TRUE(IsNotificationVisible()); |
| 198 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 192 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 199 scoped_refptr<display::ManagedDisplayMode> mode = | 193 scoped_refptr<display::ManagedDisplayMode> mode = |
| 200 display_manager()->GetSelectedModeForDisplayId(id2); | 194 display_manager()->GetSelectedModeForDisplayId(id2); |
| 201 EXPECT_TRUE(!!mode); | 195 EXPECT_TRUE(!!mode); |
| 202 EXPECT_EQ("200x200", mode->size().ToString()); | 196 EXPECT_EQ("200x200", mode->size().ToString()); |
| 203 EXPECT_EQ(60.0, mode->refresh_rate()); | 197 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 204 | 198 |
| 205 // Click the revert button, which reverts the resolution. | 199 // Click the revert button, which reverts the resolution. |
| 206 ClickOnNotification(); | 200 ClickOnNotification(); |
| 207 RunAllPendingInMessageLoop(); | 201 RunAllPendingInMessageLoop(); |
| 208 EXPECT_FALSE(IsNotificationVisible()); | 202 EXPECT_FALSE(IsNotificationVisible()); |
| 209 EXPECT_EQ(1, accept_count()); | 203 EXPECT_EQ(1, accept_count()); |
| 210 mode = display_manager()->GetSelectedModeForDisplayId(id2); | 204 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 211 EXPECT_TRUE(!!mode); | 205 EXPECT_TRUE(!!mode); |
| 212 EXPECT_EQ("200x200", mode->size().ToString()); | 206 EXPECT_EQ("200x200", mode->size().ToString()); |
| 213 EXPECT_EQ(60.0, mode->refresh_rate()); | 207 EXPECT_EQ(60.0, mode->refresh_rate()); |
| 214 } | 208 } |
| 215 | 209 |
| 216 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { | 210 TEST_F(ResolutionNotificationControllerTest, AcceptButton) { |
| 217 if (!SupportsMultipleDisplays()) | |
| 218 return; | |
| 219 | |
| 220 UpdateDisplay("300x300#300x300%59|200x200%60"); | 211 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 221 const display::Display& display = | 212 const display::Display& display = |
| 222 display::Screen::GetScreen()->GetPrimaryDisplay(); | 213 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 223 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 214 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 224 EXPECT_TRUE(IsNotificationVisible()); | 215 EXPECT_TRUE(IsNotificationVisible()); |
| 225 | 216 |
| 226 // If there's a single display only, it will have timeout and the first button | 217 // If there's a single display only, it will have timeout and the first button |
| 227 // becomes accept. | 218 // becomes accept. |
| 228 EXPECT_TRUE(controller()->DoesNotificationTimeout()); | 219 EXPECT_TRUE(controller()->DoesNotificationTimeout()); |
| 229 ClickOnNotificationButton(0); | 220 ClickOnNotificationButton(0); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 247 EXPECT_FALSE(IsNotificationVisible()); | 238 EXPECT_FALSE(IsNotificationVisible()); |
| 248 EXPECT_EQ(1, accept_count()); | 239 EXPECT_EQ(1, accept_count()); |
| 249 mode = display_manager()->GetSelectedModeForDisplayId(display.id()); | 240 mode = display_manager()->GetSelectedModeForDisplayId(display.id()); |
| 250 EXPECT_TRUE(!!mode); | 241 EXPECT_TRUE(!!mode); |
| 251 | 242 |
| 252 EXPECT_EQ("300x300", mode->size().ToString()); | 243 EXPECT_EQ("300x300", mode->size().ToString()); |
| 253 EXPECT_EQ(59.0f, mode->refresh_rate()); | 244 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 254 } | 245 } |
| 255 | 246 |
| 256 TEST_F(ResolutionNotificationControllerTest, Close) { | 247 TEST_F(ResolutionNotificationControllerTest, Close) { |
| 257 if (!SupportsMultipleDisplays()) | |
| 258 return; | |
| 259 | |
| 260 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); | 248 UpdateDisplay("100x100,150x150#150x150%59|200x200%60"); |
| 261 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 249 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 262 ASSERT_EQ(0, accept_count()); | 250 ASSERT_EQ(0, accept_count()); |
| 263 EXPECT_FALSE(IsNotificationVisible()); | 251 EXPECT_FALSE(IsNotificationVisible()); |
| 264 | 252 |
| 265 // Changes the resolution and apply the result. | 253 // Changes the resolution and apply the result. |
| 266 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), | 254 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 267 gfx::Size(200, 200)); | 255 gfx::Size(200, 200)); |
| 268 EXPECT_TRUE(IsNotificationVisible()); | 256 EXPECT_TRUE(IsNotificationVisible()); |
| 269 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 257 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 270 scoped_refptr<display::ManagedDisplayMode> mode = | 258 scoped_refptr<display::ManagedDisplayMode> mode = |
| 271 display_manager()->GetSelectedModeForDisplayId(id2); | 259 display_manager()->GetSelectedModeForDisplayId(id2); |
| 272 EXPECT_TRUE(!!mode); | 260 EXPECT_TRUE(!!mode); |
| 273 EXPECT_EQ("200x200", mode->size().ToString()); | 261 EXPECT_EQ("200x200", mode->size().ToString()); |
| 274 EXPECT_EQ(60.0f, mode->refresh_rate()); | 262 EXPECT_EQ(60.0f, mode->refresh_rate()); |
| 275 | 263 |
| 276 // Close the notification (imitates clicking [x] button). Also verifies if | 264 // Close the notification (imitates clicking [x] button). Also verifies if |
| 277 // this does not cause a crash. See crbug.com/271784 | 265 // this does not cause a crash. See crbug.com/271784 |
| 278 CloseNotification(); | 266 CloseNotification(); |
| 279 RunAllPendingInMessageLoop(); | 267 RunAllPendingInMessageLoop(); |
| 280 EXPECT_FALSE(IsNotificationVisible()); | 268 EXPECT_FALSE(IsNotificationVisible()); |
| 281 EXPECT_EQ(1, accept_count()); | 269 EXPECT_EQ(1, accept_count()); |
| 282 } | 270 } |
| 283 | 271 |
| 284 TEST_F(ResolutionNotificationControllerTest, Timeout) { | 272 TEST_F(ResolutionNotificationControllerTest, Timeout) { |
| 285 if (!SupportsMultipleDisplays()) | |
| 286 return; | |
| 287 | |
| 288 UpdateDisplay("300x300#300x300%59|200x200%60"); | 273 UpdateDisplay("300x300#300x300%59|200x200%60"); |
| 289 const display::Display& display = | 274 const display::Display& display = |
| 290 display::Screen::GetScreen()->GetPrimaryDisplay(); | 275 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 291 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); | 276 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); |
| 292 | 277 |
| 293 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { | 278 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { |
| 294 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i | 279 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i |
| 295 << "-th timer tick"; | 280 << "-th timer tick"; |
| 296 TickTimer(); | 281 TickTimer(); |
| 297 RunAllPendingInMessageLoop(); | 282 RunAllPendingInMessageLoop(); |
| 298 } | 283 } |
| 299 EXPECT_FALSE(IsNotificationVisible()); | 284 EXPECT_FALSE(IsNotificationVisible()); |
| 300 EXPECT_EQ(0, accept_count()); | 285 EXPECT_EQ(0, accept_count()); |
| 301 scoped_refptr<display::ManagedDisplayMode> mode = | 286 scoped_refptr<display::ManagedDisplayMode> mode = |
| 302 display_manager()->GetSelectedModeForDisplayId(display.id()); | 287 display_manager()->GetSelectedModeForDisplayId(display.id()); |
| 303 EXPECT_TRUE(!!mode); | 288 EXPECT_TRUE(!!mode); |
| 304 EXPECT_EQ("300x300", mode->size().ToString()); | 289 EXPECT_EQ("300x300", mode->size().ToString()); |
| 305 EXPECT_EQ(59.0f, mode->refresh_rate()); | 290 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 306 } | 291 } |
| 307 | 292 |
| 308 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { | 293 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { |
| 309 if (!SupportsMultipleDisplays()) | |
| 310 return; | |
| 311 | |
| 312 UpdateDisplay( | 294 UpdateDisplay( |
| 313 "300x300#300x300%56|200x200%57," | 295 "300x300#300x300%56|200x200%57," |
| 314 "200x200#250x250%58|200x200%59|100x100%60"); | 296 "200x200#250x250%58|200x200%59|100x100%60"); |
| 315 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 297 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 316 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), | 298 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 317 gfx::Size(100, 100)); | 299 gfx::Size(100, 100)); |
| 318 ASSERT_TRUE(IsNotificationVisible()); | 300 ASSERT_TRUE(IsNotificationVisible()); |
| 319 | 301 |
| 320 // Disconnects the secondary display and verifies it doesn't cause crashes. | 302 // Disconnects the secondary display and verifies it doesn't cause crashes. |
| 321 UpdateDisplay("300x300#300x300%56|200x200%57"); | 303 UpdateDisplay("300x300#300x300%56|200x200%57"); |
| 322 RunAllPendingInMessageLoop(); | 304 RunAllPendingInMessageLoop(); |
| 323 EXPECT_FALSE(IsNotificationVisible()); | 305 EXPECT_FALSE(IsNotificationVisible()); |
| 324 EXPECT_EQ(0, accept_count()); | 306 EXPECT_EQ(0, accept_count()); |
| 325 scoped_refptr<display::ManagedDisplayMode> mode = | 307 scoped_refptr<display::ManagedDisplayMode> mode = |
| 326 display_manager()->GetSelectedModeForDisplayId(id2); | 308 display_manager()->GetSelectedModeForDisplayId(id2); |
| 327 EXPECT_TRUE(!!mode); | 309 EXPECT_TRUE(!!mode); |
| 328 gfx::Size resolution; | 310 gfx::Size resolution; |
| 329 EXPECT_EQ("200x200", mode->size().ToString()); | 311 EXPECT_EQ("200x200", mode->size().ToString()); |
| 330 EXPECT_EQ(59.0f, mode->refresh_rate()); | 312 EXPECT_EQ(59.0f, mode->refresh_rate()); |
| 331 } | 313 } |
| 332 | 314 |
| 333 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { | 315 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { |
| 334 if (!SupportsMultipleDisplays()) | |
| 335 return; | |
| 336 | |
| 337 UpdateDisplay( | 316 UpdateDisplay( |
| 338 "300x300#300x300%56|200x200%57," | 317 "300x300#300x300%56|200x200%57," |
| 339 "250x250#250x250%58|200x200%59"); | 318 "250x250#250x250%58|200x200%59"); |
| 340 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 319 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 341 | 320 |
| 342 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), | 321 SetDisplayResolutionAndNotify(display_manager()->GetSecondaryDisplay(), |
| 343 gfx::Size(200, 200)); | 322 gfx::Size(200, 200)); |
| 344 EXPECT_TRUE(IsNotificationVisible()); | 323 EXPECT_TRUE(IsNotificationVisible()); |
| 345 EXPECT_FALSE(controller()->DoesNotificationTimeout()); | 324 EXPECT_FALSE(controller()->DoesNotificationTimeout()); |
| 346 scoped_refptr<display::ManagedDisplayMode> mode = | 325 scoped_refptr<display::ManagedDisplayMode> mode = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 365 RunAllPendingInMessageLoop(); | 344 RunAllPendingInMessageLoop(); |
| 366 EXPECT_FALSE(IsNotificationVisible()); | 345 EXPECT_FALSE(IsNotificationVisible()); |
| 367 EXPECT_EQ(0, accept_count()); | 346 EXPECT_EQ(0, accept_count()); |
| 368 mode = display_manager()->GetSelectedModeForDisplayId(id2); | 347 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 369 EXPECT_TRUE(!!mode); | 348 EXPECT_TRUE(!!mode); |
| 370 EXPECT_EQ("250x250", mode->size().ToString()); | 349 EXPECT_EQ("250x250", mode->size().ToString()); |
| 371 EXPECT_EQ(58.0f, mode->refresh_rate()); | 350 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 372 } | 351 } |
| 373 | 352 |
| 374 TEST_F(ResolutionNotificationControllerTest, Fallback) { | 353 TEST_F(ResolutionNotificationControllerTest, Fallback) { |
| 375 if (!SupportsMultipleDisplays()) | |
| 376 return; | |
| 377 | |
| 378 UpdateDisplay( | 354 UpdateDisplay( |
| 379 "300x300#300x300%56|200x200%57," | 355 "300x300#300x300%56|200x200%57," |
| 380 "250x250#250x250%58|220x220%59|200x200%60"); | 356 "250x250#250x250%58|220x220%59|200x200%60"); |
| 381 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); | 357 int64_t id2 = display_manager()->GetSecondaryDisplay().id(); |
| 382 ASSERT_EQ(0, accept_count()); | 358 ASSERT_EQ(0, accept_count()); |
| 383 EXPECT_FALSE(IsNotificationVisible()); | 359 EXPECT_FALSE(IsNotificationVisible()); |
| 384 | 360 |
| 385 // Changes the resolution and apply the result. | 361 // Changes the resolution and apply the result. |
| 386 SetDisplayResolutionAndNotifyWithResolution( | 362 SetDisplayResolutionAndNotifyWithResolution( |
| 387 display_manager()->GetSecondaryDisplay(), gfx::Size(220, 220), | 363 display_manager()->GetSecondaryDisplay(), gfx::Size(220, 220), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 403 EXPECT_FALSE(IsNotificationVisible()); | 379 EXPECT_FALSE(IsNotificationVisible()); |
| 404 EXPECT_EQ(0, accept_count()); | 380 EXPECT_EQ(0, accept_count()); |
| 405 | 381 |
| 406 mode = display_manager()->GetSelectedModeForDisplayId(id2); | 382 mode = display_manager()->GetSelectedModeForDisplayId(id2); |
| 407 EXPECT_TRUE(!!mode); | 383 EXPECT_TRUE(!!mode); |
| 408 EXPECT_EQ("250x250", mode->size().ToString()); | 384 EXPECT_EQ("250x250", mode->size().ToString()); |
| 409 EXPECT_EQ(58.0f, mode->refresh_rate()); | 385 EXPECT_EQ(58.0f, mode->refresh_rate()); |
| 410 } | 386 } |
| 411 | 387 |
| 412 } // namespace ash | 388 } // namespace ash |
| OLD | NEW |