Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_controller_unittest.cc

Issue 289583002: Lock rotation when screen is manually rotated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Define sources for rotation Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/maximize_mode/maximize_mode_controller.h" 5 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
6 6
7 #include "ash/accelerometer/accelerometer_controller.h" 7 #include "ash/accelerometer/accelerometer_controller.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/system_tray_delegate.h" 10 #include "ash/system/tray/system_tray_delegate.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 EXPECT_TRUE(IsMaximizeModeStarted()); 145 EXPECT_TRUE(IsMaximizeModeStarted());
146 146
147 // Open 90 degrees. 147 // Open 90 degrees.
148 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 148 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
149 EXPECT_FALSE(IsMaximizeModeStarted()); 149 EXPECT_FALSE(IsMaximizeModeStarted());
150 } 150 }
151 151
152 // Tests that when the hinge is nearly vertically aligned, the current state 152 // Tests that when the hinge is nearly vertically aligned, the current state
153 // persists as the computed angle is highly inaccurate in this orientation. 153 // persists as the computed angle is highly inaccurate in this orientation.
154 TEST_F(MaximizeModeControllerTest, HingeAligned) { 154 TEST_F(MaximizeModeControllerTest, HingeAligned) {
155 // Laptop in normal orientation lid open 90 degrees. 155 // Laptop in normal orientation lid open 90 degrees.
156 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 156 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
157 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 157 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
158 EXPECT_FALSE(IsMaximizeModeStarted()); 158 EXPECT_FALSE(IsMaximizeModeStarted());
159 159
160 // Completely vertical. 160 // Completely vertical.
161 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f), 161 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, -1.0f, 0.0f),
162 gfx::Vector3dF(0.0f, -1.0f, 0.0f)); 162 gfx::Vector3dF(0.0f, -1.0f, 0.0f));
163 EXPECT_FALSE(IsMaximizeModeStarted()); 163 EXPECT_FALSE(IsMaximizeModeStarted());
164 164
165 // Close to vertical but with hinge appearing to be open 270 degrees. 165 // Close to vertical but with hinge appearing to be open 270 degrees.
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // Open up 270 degrees. 306 // Open up 270 degrees.
307 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 307 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
308 gfx::Vector3dF(1.0f, 0.0f, 0.0f)); 308 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
309 ASSERT_TRUE(IsMaximizeModeStarted()); 309 ASSERT_TRUE(IsMaximizeModeStarted());
310 310
311 event_generator.PressKey(ui::VKEY_ESCAPE, 0); 311 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
312 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0); 312 event_generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
313 EXPECT_EQ(0u, counter.event_count()); 313 EXPECT_EQ(0u, counter.event_count());
314 counter.reset(); 314 counter.reset();
315 315
316 // Touch should not be blocked. 316 // Touch should not be blocked.
317 event_generator.PressTouch(); 317 event_generator.PressTouch();
318 event_generator.ReleaseTouch(); 318 event_generator.ReleaseTouch();
319 EXPECT_GT(counter.event_count(), 0u); 319 EXPECT_GT(counter.event_count(), 0u);
320 counter.reset(); 320 counter.reset();
321 321
322 gfx::Vector3dF base; 322 gfx::Vector3dF base;
323 323
324 // Lid open 90 degrees. 324 // Lid open 90 degrees.
325 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f), 325 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
326 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 326 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 ASSERT_EQ(0, volume_delegate->handle_volume_up_count()); 386 ASSERT_EQ(0, volume_delegate->handle_volume_up_count());
387 event_generator.PressKey(ui::VKEY_VOLUME_UP, 0); 387 event_generator.PressKey(ui::VKEY_VOLUME_UP, 0);
388 event_generator.ReleaseKey(ui::VKEY_VOLUME_UP, 0); 388 event_generator.ReleaseKey(ui::VKEY_VOLUME_UP, 0);
389 EXPECT_EQ(1, volume_delegate->handle_volume_up_count()); 389 EXPECT_EQ(1, volume_delegate->handle_volume_up_count());
390 } 390 }
391 391
392 TEST_F(MaximizeModeControllerTest, LaptopTest) { 392 TEST_F(MaximizeModeControllerTest, LaptopTest) {
393 // Feeds in sample accelerometer data and verifies that there are no 393 // Feeds in sample accelerometer data and verifies that there are no
394 // transitions into touchview / maximize mode while shaking the device around 394 // transitions into touchview / maximize mode while shaking the device around
395 // with the hinge at less than 180 degrees. 395 // with the hinge at less than 180 degrees.
396 ASSERT_TRUE(kAccelerometerLaptopModeTestDataLength % 6 == 0); 396 ASSERT_EQ(0u, kAccelerometerLaptopModeTestDataLength % 6);
397 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) { 397 for (size_t i = 0; i < kAccelerometerLaptopModeTestDataLength / 6; ++i) {
398 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6], 398 gfx::Vector3dF base(kAccelerometerLaptopModeTestData[i * 6],
399 kAccelerometerLaptopModeTestData[i * 6 + 1], 399 kAccelerometerLaptopModeTestData[i * 6 + 1],
400 kAccelerometerLaptopModeTestData[i * 6 + 2]); 400 kAccelerometerLaptopModeTestData[i * 6 + 2]);
401 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3], 401 gfx::Vector3dF lid(kAccelerometerLaptopModeTestData[i * 6 + 3],
402 kAccelerometerLaptopModeTestData[i * 6 + 4], 402 kAccelerometerLaptopModeTestData[i * 6 + 4],
403 kAccelerometerLaptopModeTestData[i * 6 + 5]); 403 kAccelerometerLaptopModeTestData[i * 6 + 5]);
404 TriggerAccelerometerUpdate(base, lid); 404 TriggerAccelerometerUpdate(base, lid);
405 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 405 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
406 // one failure rather than potentially hundreds. 406 // one failure rather than potentially hundreds.
407 ASSERT_FALSE(IsMaximizeModeStarted()); 407 ASSERT_FALSE(IsMaximizeModeStarted());
408 } 408 }
409 } 409 }
410 410
411 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) { 411 TEST_F(MaximizeModeControllerTest, MaximizeModeTest) {
412 // Trigger maximize mode by opening to 270 to begin the test in maximize mode. 412 // Trigger maximize mode by opening to 270 to begin the test in maximize mode.
413 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 413 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
414 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 414 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
415 ASSERT_TRUE(IsMaximizeModeStarted()); 415 ASSERT_TRUE(IsMaximizeModeStarted());
416 416
417 // Feeds in sample accelerometer data and verifies that there are no 417 // Feeds in sample accelerometer data and verifies that there are no
418 // transitions out of touchview / maximize mode while shaking the device 418 // transitions out of touchview / maximize mode while shaking the device
419 // around. 419 // around.
420 ASSERT_TRUE(kAccelerometerFullyOpenTestDataLength % 6 == 0); 420 ASSERT_EQ(0u, kAccelerometerFullyOpenTestDataLength % 6);
421 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) { 421 for (size_t i = 0; i < kAccelerometerFullyOpenTestDataLength / 6; ++i) {
422 gfx::Vector3dF base(kAccelerometerFullyOpenTestData[i * 6], 422 gfx::Vector3dF base(kAccelerometerFullyOpenTestData[i * 6],
423 kAccelerometerFullyOpenTestData[i * 6 + 1], 423 kAccelerometerFullyOpenTestData[i * 6 + 1],
424 kAccelerometerFullyOpenTestData[i * 6 + 2]); 424 kAccelerometerFullyOpenTestData[i * 6 + 2]);
425 gfx::Vector3dF lid(kAccelerometerFullyOpenTestData[i * 6 + 3], 425 gfx::Vector3dF lid(kAccelerometerFullyOpenTestData[i * 6 + 3],
426 kAccelerometerFullyOpenTestData[i * 6 + 4], 426 kAccelerometerFullyOpenTestData[i * 6 + 4],
427 kAccelerometerFullyOpenTestData[i * 6 + 5]); 427 kAccelerometerFullyOpenTestData[i * 6 + 5]);
428 TriggerAccelerometerUpdate(base, lid); 428 TriggerAccelerometerUpdate(base, lid);
429 // There are a lot of samples, so ASSERT rather than EXPECT to only generate 429 // There are a lot of samples, so ASSERT rather than EXPECT to only generate
430 // one failure rather than potentially hundreds. 430 // one failure rather than potentially hundreds.
(...skipping 18 matching lines...) Expand all
449 gravity.set_x(-cos(degrees * kDegreesToRadians)); 449 gravity.set_x(-cos(degrees * kDegreesToRadians));
450 gravity.set_y(sin(degrees * kDegreesToRadians)); 450 gravity.set_y(sin(degrees * kDegreesToRadians));
451 TriggerAccelerometerUpdate(gravity, gravity); 451 TriggerAccelerometerUpdate(gravity, gravity);
452 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation()); 452 EXPECT_EQ(gfx::Display::ROTATE_0, GetInternalDisplayRotation());
453 453
454 maximize_mode_controller()->set_rotation_locked(false); 454 maximize_mode_controller()->set_rotation_locked(false);
455 TriggerAccelerometerUpdate(gravity, gravity); 455 TriggerAccelerometerUpdate(gravity, gravity);
456 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation()); 456 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
457 } 457 }
458 458
459 // Tests that when MaximizeModeController turns off MaximizeMode that on the 459 // Tests that if the display was rotated before entering maximize mode that
460 // next accelerometer update the rotation lock is cleared. 460 // rotation becomes locked.
461 TEST_F(MaximizeModeControllerTest, ExitingMaximizeModeClearRotationLock) { 461 TEST_F(MaximizeModeControllerTest,
462 // The base remains steady. 462 RotatedDisplayLocksRotationUponEnteringMaximizeMode) {
463 gfx::Vector3dF base(0.0f, 0.0f, 1.0f); 463 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
464 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId(),
465 gfx::Display::ROTATE_90, ui::USER);
466
467 // Trigger a non-maximize mode accelerometer update. Ensure that the display
468 // does not rotate.
469 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
470 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
471 EXPECT_FALSE(IsMaximizeModeStarted());
472 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
464 473
465 // Trigger maximize mode by opening to 270. 474 // Trigger maximize mode by opening to 270.
466 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f), 475 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
467 gfx::Vector3dF(-1.0f, 0.0f, 0.0f)); 476 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
468 ASSERT_TRUE(IsMaximizeModeStarted()); 477 ASSERT_TRUE(IsMaximizeModeStarted());
469 478 EXPECT_TRUE(maximize_mode_controller()->rotation_locked());
470 maximize_mode_controller()->set_rotation_locked(true); 479 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
471
472 // Open 90 degrees.
473 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
474 EXPECT_FALSE(IsMaximizeModeStarted());
475
476 // Send an update that would not relaunch MaximizeMode. 90 degrees.
477 TriggerAccelerometerUpdate(base, gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
478 EXPECT_FALSE(maximize_mode_controller()->rotation_locked());
479 } 480 }
480 481
482 // Tests that if a user has set a display rotation that it is restored upon
483 // exiting maximize mode.
484 TEST_F(MaximizeModeControllerTest, ResetUserRotationUponExit) {
485 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
486 display_manager->SetDisplayRotation(gfx::Display::InternalDisplayId (),
flackr 2014/05/16 16:00:22 s/ ()/()
jonross 2014/05/20 15:24:30 Done.
487 gfx::Display::ROTATE_90, ui::USER);
488
489 // Trigger maximize mode
490 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, -1.0f),
491 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
492 ASSERT_TRUE(IsMaximizeModeStarted());
493 ASSERT_TRUE(maximize_mode_controller()->rotation_locked());
494
495 maximize_mode_controller()->set_rotation_locked(false);
496
497 TriggerAccelerometerUpdate(gfx::Vector3dF(1.0f, 0.0f, 0.0f),
498 gfx::Vector3dF(1.0f, 0.0f, 0.0f));
499 EXPECT_EQ(gfx::Display::ROTATE_180, GetInternalDisplayRotation());;
flackr 2014/05/16 16:00:22 s/;;/;
jonross 2014/05/20 15:24:30 Done.
500
501 // Exit maximize mode
502 TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
503 gfx::Vector3dF(-1.0f, 0.0f, 0.0f));
504 EXPECT_FALSE(IsMaximizeModeStarted());
505 EXPECT_EQ(gfx::Display::ROTATE_90, GetInternalDisplayRotation());
506 }
flackr 2014/05/16 16:00:22 nit: blank line before closing namespace.
jonross 2014/05/20 15:24:30 Done.
481 } // namespace ash 507 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698