1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/display/screen_orientation_controller.h"
#include <memory>
#include <vector>
#include "ash/accelerometer/accelerometer_reader.h"
#include "ash/accelerometer/accelerometer_types.h"
#include "ash/constants/app_types.h"
#include "ash/constants/ash_switches.h"
#include "ash/display/screen_orientation_controller_test_api.h"
#include "ash/shell.h"
#include "ash/system/screen_layout_observer.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "ash/test_shell_delegate.h"
#include "ash/wm/splitview/split_view_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/tablet_mode/tablet_mode_controller_test_api.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "base/command_line.h"
#include "base/numerics/math_constants.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_type.h"
#include "ui/display/display.h"
#include "ui/display/display_switches.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/manager/managed_display_info.h"
#include "ui/display/test/display_manager_test_api.h"
#include "ui/events/event_constants.h"
#include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_client.h"
namespace ash {
namespace {
using base::kMeanGravityFloat;
const float kDegreesToRadians = 3.1415926f / 180.0f;
void EnableTabletMode(bool enable) {
Shell::Get()->tablet_mode_controller()->ForceUiTabletModeState(enable);
}
bool RotationLocked() {
return Shell::Get()->screen_orientation_controller()->rotation_locked();
}
bool UserRotationLocked() {
return Shell::Get()->screen_orientation_controller()->user_rotation_locked();
}
void SetDisplayRotationById(int64_t display_id,
display::Display::Rotation rotation) {
Shell::Get()->display_manager()->SetDisplayRotation(
display_id, rotation, display::Display::RotationSource::USER);
}
void SetInternalDisplayRotation(display::Display::Rotation rotation) {
SetDisplayRotationById(display::Display::InternalDisplayId(), rotation);
}
void TriggerLidUpdate(const gfx::Vector3dF& lid) {
AccelerometerUpdate update;
update.Set(ACCELEROMETER_SOURCE_SCREEN, lid.x(), lid.y(), lid.z());
Shell::Get()->screen_orientation_controller()->OnAccelerometerUpdated(update);
}
// Shows |child| and adds |child| to |parent|.
void AddWindowAndShow(aura::Window* child, aura::Window* parent) {
child->Show();
parent->AddChild(child);
}
// Adds |child| to |parent| and activates |parent|.
void AddWindowAndActivateParent(aura::Window* child, aura::Window* parent) {
AddWindowAndShow(child, parent);
Shell::Get()->activation_client()->ActivateWindow(parent);
}
void Lock(aura::Window* window, chromeos::OrientationType orientation_lock) {
Shell::Get()->screen_orientation_controller()->LockOrientationForWindow(
window, orientation_lock);
}
void Unlock(aura::Window* window) {
Shell::Get()->screen_orientation_controller()->UnlockOrientationForWindow(
window);
}
// Creates a window of type WINDOW_TYPE_CONTROL.
std::unique_ptr<aura::Window> CreateControlWindow() {
std::unique_ptr<aura::Window> window = std::make_unique<aura::Window>(
nullptr, aura::client::WindowType::WINDOW_TYPE_CONTROL);
window->Init(ui::LAYER_NOT_DRAWN);
window->set_owned_by_parent(false);
return window;
}
} // namespace
class ScreenOrientationControllerTest : public AshTestBase {
public:
ScreenOrientationControllerTest() = default;
ScreenOrientationControllerTest(const ScreenOrientationControllerTest&) =
delete;
ScreenOrientationControllerTest& operator=(
const ScreenOrientationControllerTest&) = delete;
~ScreenOrientationControllerTest() override = default;
// AshTestBase:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
::switches::kUseFirstDisplayAsInternal);
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletMode);
AshTestBase::SetUp();
}
protected:
aura::Window* CreateAppWindowInShellWithId(int id) {
aura::Window* window = CreateTestWindowInShellWithId(id);
window->SetProperty(aura::client::kAppType,
static_cast<int>(AppType::CHROME_APP));
return window;
}
void SetSystemRotationLocked(bool rotation_locked) {
ScreenOrientationControllerTestApi(
Shell::Get()->screen_orientation_controller())
.SetRotationLocked(rotation_locked);
}
void SetUserRotationLocked(bool rotation_locked) {
if (Shell::Get()->screen_orientation_controller()->user_rotation_locked() !=
rotation_locked) {
Shell::Get()->screen_orientation_controller()->ToggleUserRotationLock();
}
}
chromeos::OrientationType UserLockedOrientation() const {
ScreenOrientationControllerTestApi test_api(
Shell::Get()->screen_orientation_controller());
return test_api.UserLockedOrientation();
}
SplitViewController* split_view_controller() {
return SplitViewController::Get(Shell::GetPrimaryRootWindow());
}
};
// Tests that a Window can lock rotation.
TEST_F(ScreenOrientationControllerTest, LockOrientation) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked());
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
auto modal = CreateTestWindow(gfx::Rect(0, 0, 400, 400));
modal->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
}
// Tests that a Window can unlock rotation.
TEST_F(ScreenOrientationControllerTest, Unlock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked());
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
Unlock(child_window.get());
EXPECT_FALSE(RotationLocked());
}
// Tests that a Window is able to change the orientation of the display after
// having locked rotation.
TEST_F(ScreenOrientationControllerTest, OrientationChanges) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked());
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that orientation can only be set by the first Window that has set a
// rotation lock.
TEST_F(ScreenOrientationControllerTest, SecondContentCannotChangeOrientation) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window1 = CreateControlWindow();
std::unique_ptr<aura::Window> child_window2 = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window1.get(), focus_window1.get());
AddWindowAndShow(child_window2.get(), focus_window2.get());
Lock(child_window1.get(), chromeos::OrientationType::kLandscape);
Lock(child_window2.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that only the Window that set a rotation lock can perform an unlock.
TEST_F(ScreenOrientationControllerTest, SecondContentCannotUnlock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window1 = CreateControlWindow();
std::unique_ptr<aura::Window> child_window2 = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window1.get(), focus_window1.get());
AddWindowAndShow(child_window2.get(), focus_window2.get());
Lock(child_window1.get(), chromeos::OrientationType::kLandscape);
Unlock(child_window2.get());
EXPECT_TRUE(RotationLocked());
}
// Tests that a rotation lock is applied only while the Window are a part of the
// active window.
TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window.get(), focus_window1.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
ASSERT_TRUE(RotationLocked());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
activation_client->ActivateWindow(focus_window2.get());
EXPECT_FALSE(RotationLocked());
activation_client->ActivateWindow(focus_window1.get());
EXPECT_TRUE(RotationLocked());
}
// Tests that switching between windows with different orientation locks change
// the orientation.
TEST_F(ScreenOrientationControllerTest, ActiveWindowChangesUpdateOrientation) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window1 = CreateControlWindow();
std::unique_ptr<aura::Window> child_window2 = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window1.get(), focus_window1.get());
AddWindowAndShow(child_window2.get(), focus_window2.get());
Lock(child_window1.get(), chromeos::OrientationType::kLandscape);
Lock(child_window2.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
activation_client->ActivateWindow(focus_window2.get());
EXPECT_TRUE(RotationLocked());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
activation_client->ActivateWindow(focus_window1.get());
EXPECT_TRUE(RotationLocked());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that a rotation lock is removed when the setting window is hidden, and
// that it is reapplied when the window becomes visible.
TEST_F(ScreenOrientationControllerTest, VisibilityChangesLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
EXPECT_TRUE(RotationLocked());
child_window->Hide();
EXPECT_FALSE(RotationLocked());
child_window->Show();
EXPECT_TRUE(RotationLocked());
}
// Tests that when a window is destroyed that its rotation lock is removed, and
// window activations no longer change the lock
TEST_F(ScreenOrientationControllerTest, WindowDestructionRemovesLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window.get(), focus_window1.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
ASSERT_TRUE(RotationLocked());
focus_window1->RemoveChild(child_window.get());
child_window.reset();
EXPECT_FALSE(RotationLocked());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
activation_client->ActivateWindow(focus_window2.get());
EXPECT_FALSE(RotationLocked());
activation_client->ActivateWindow(focus_window1.get());
EXPECT_FALSE(RotationLocked());
}
TEST_F(ScreenOrientationControllerTest, SplitViewPreventsLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window1 = CreateControlWindow();
std::unique_ptr<aura::Window> child_window2 = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window1.get(), focus_window1.get());
AddWindowAndShow(child_window2.get(), focus_window2.get());
Lock(child_window1.get(), chromeos::OrientationType::kLandscape);
Lock(child_window2.get(), chromeos::OrientationType::kPortrait);
ASSERT_TRUE(RotationLocked());
split_view_controller()->SnapWindow(
focus_window1.get(), SplitViewController::SnapPosition::kPrimary);
split_view_controller()->SnapWindow(
focus_window1.get(), SplitViewController::SnapPosition::kSecondary);
EXPECT_FALSE(RotationLocked());
split_view_controller()->EndSplitView();
EXPECT_TRUE(RotationLocked());
}
// Tests that accelerometer readings in each of the screen angles will trigger a
// rotation of the internal display.
TEST_F(ScreenOrientationControllerTest, DisplayRotation) {
EnableTabletMode(true);
// Now test rotating in all directions.
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(-kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that low angles are ignored by the accelerometer (i.e. when the device
// is almost laying flat).
TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) {
EnableTabletMode(true);
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, kMeanGravityFloat));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, kMeanGravityFloat));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, kMeanGravityFloat));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, kMeanGravityFloat));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, kMeanGravityFloat));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that the display will stick to the current orientation beyond the
// halfway point, preventing frequent updates back and forth.
TEST_F(ScreenOrientationControllerTest, RotationSticky) {
EnableTabletMode(true);
gfx::Vector3dF gravity(0.0f, kMeanGravityFloat, 0.0f);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
// Turn past half-way point to next direction and rotation should remain
// the same.
float degrees = 50.0;
gravity.set_x(-sin(degrees * kDegreesToRadians) * -kMeanGravityFloat);
gravity.set_y(-cos(degrees * kDegreesToRadians) * -kMeanGravityFloat);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
// Turn more and the screen should rotate.
degrees = 70.0;
gravity.set_x(-sin(degrees * kDegreesToRadians) * -kMeanGravityFloat);
gravity.set_y(-cos(degrees * kDegreesToRadians) * -kMeanGravityFloat);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
// Turn back just beyond the half-way point and the new rotation should
// still be in effect.
degrees = 40.0;
gravity.set_x(-sin(degrees * kDegreesToRadians) * -kMeanGravityFloat);
gravity.set_y(-cos(degrees * kDegreesToRadians) * -kMeanGravityFloat);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
}
// Tests that the display will stick to its current orientation when the
// rotation lock has been set.
TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) {
EnableTabletMode(true);
SetUserRotationLocked(true);
// Turn past the threshold for rotation.
float degrees = 90.0;
gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * -kMeanGravityFloat,
-cos(degrees * kDegreesToRadians) * -kMeanGravityFloat,
0.0f);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
SetUserRotationLocked(false);
TriggerLidUpdate(gravity);
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
}
// Tests that if a user has set a display rotation that it is restored upon
// exiting tablet mode.
TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
display::test::DisplayManagerTestApi(display_manager())
.SetFirstDisplayAsInternalDisplay();
SetInternalDisplayRotation(display::Display::ROTATE_90);
EnableTabletMode(true);
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
EnableTabletMode(false);
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
}
// Tests that if a user changes the display rotation, while rotation is locked,
// that the updates are recorded. Upon exiting tablet mode the latest user
// rotation should be applied.
TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
EnableTabletMode(true);
SetInternalDisplayRotation(display::Display::ROTATE_270);
// User sets rotation to the same rotation that the display was at when
// tablet mode was activated.
SetInternalDisplayRotation(display::Display::ROTATE_0);
EnableTabletMode(false);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Tests that when the orientation lock is set to Landscape, that rotation can
// be done between the two angles of the orientation.
TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true);
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
// Inverse of orientation is allowed
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
// Display rotations between are not allowed
TriggerLidUpdate(gfx::Vector3dF(-kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
}
// Tests that when the orientation lock is set to Portrait, that rotation can be
// done between the two angles of the orientation.
TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true);
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
// Inverse of orientation is allowed
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
// Display rotations between are not allowed
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
}
// Tests that for an orientation lock which does not allow rotation, that the
// display rotation remains constant.
TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true);
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kPortraitPrimary);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_TRUE(RotationLocked());
// Rotation does not change.
TriggerLidUpdate(gfx::Vector3dF(-kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
}
// Tests that after a Window has applied an orientation lock which supports
// rotation, that a user rotation lock does not allow rotation.
TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
EnableTabletMode(true);
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kLandscape);
Unlock(child_window.get());
SetUserRotationLocked(true);
EXPECT_TRUE(RotationLocked());
EXPECT_TRUE(UserRotationLocked());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
// Verifies rotating an inactive Display is successful.
TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) {
const int64_t kInternalDisplayId = 9;
const int64_t kExternalDisplayId = 10;
const display::Display::Rotation kNewRotation = display::Display::ROTATE_180;
const display::ManagedDisplayInfo internal_display_info =
display::CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 600, 500));
const display::ManagedDisplayInfo external_display_info =
display::CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 600, 500));
std::vector<display::ManagedDisplayInfo> display_info_list_two_active;
display_info_list_two_active.push_back(internal_display_info);
display_info_list_two_active.push_back(external_display_info);
std::vector<display::ManagedDisplayInfo> display_info_list_one_active;
display_info_list_one_active.push_back(external_display_info);
// The display::ManagedDisplayInfo list with two active displays needs to be
// added first so that the DisplayManager can track the
// |internal_display_info| as inactive instead of non-existent.
display_manager()->OnNativeDisplaysChanged(display_info_list_two_active);
display_manager()->OnNativeDisplaysChanged(display_info_list_one_active);
display::test::ScopedSetInternalDisplayId set_internal(display_manager(),
kInternalDisplayId);
ASSERT_NE(kNewRotation, display_manager()
->GetDisplayInfo(kInternalDisplayId)
.GetActiveRotation());
ScreenOrientationControllerTestApi(
Shell::Get()->screen_orientation_controller())
.SetDisplayRotation(kNewRotation,
display::Display::RotationSource::ACTIVE);
EXPECT_EQ(kNewRotation, display_manager()
->GetDisplayInfo(kInternalDisplayId)
.GetActiveRotation());
}
TEST_F(ScreenOrientationControllerTest, UserRotationLockedOrientation) {
ScreenOrientationController* orientation_controller =
Shell::Get()->screen_orientation_controller();
orientation_controller->ToggleUserRotationLock();
EXPECT_TRUE(orientation_controller->user_rotation_locked());
EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_270);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_180);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kLandscapeSecondary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_90);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kPortraitSecondary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_270);
UpdateDisplay("800x1280");
orientation_controller->ToggleUserRotationLock();
EXPECT_TRUE(orientation_controller->user_rotation_locked());
EXPECT_EQ(chromeos::OrientationType::kPortraitPrimary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_90);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_180);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kPortraitSecondary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
SetInternalDisplayRotation(display::Display::ROTATE_270);
orientation_controller->ToggleUserRotationLock();
EXPECT_EQ(chromeos::OrientationType::kLandscapeSecondary,
UserLockedOrientation());
orientation_controller->ToggleUserRotationLock();
}
TEST_F(ScreenOrientationControllerTest, UserRotationLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window1 = CreateControlWindow();
std::unique_ptr<aura::Window> child_window2 = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window1(CreateAppWindowInShellWithId(0));
std::unique_ptr<aura::Window> focus_window2(CreateAppWindowInShellWithId(1));
AddWindowAndActivateParent(child_window2.get(), focus_window2.get());
AddWindowAndActivateParent(child_window1.get(), focus_window1.get());
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked());
ASSERT_FALSE(UserRotationLocked());
ScreenOrientationController* orientation_controller =
Shell::Get()->screen_orientation_controller();
ASSERT_FALSE(orientation_controller->user_rotation_locked());
orientation_controller->ToggleUserRotationLock();
ASSERT_TRUE(orientation_controller->user_rotation_locked());
Lock(child_window1.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
::wm::ActivationClient* activation_client = Shell::Get()->activation_client();
// Activating any will switch to the natural orientation.
activation_client->ActivateWindow(focus_window2.get());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
// Activating the portrait window will rotate to the portrait.
activation_client->ActivateWindow(focus_window1.get());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
// User locked to the 90 dig.
orientation_controller->ToggleUserRotationLock();
orientation_controller->ToggleUserRotationLock();
// Switching to Any orientation will stay to the user locked orientation.
activation_client->ActivateWindow(focus_window2.get());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
// Application forced to be landscape.
Lock(child_window2.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
Lock(child_window1.get(), chromeos::OrientationType::kAny);
activation_client->ActivateWindow(focus_window1.get());
// Switching back to any will rotate to user rotation.
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
}
TEST_F(ScreenOrientationControllerTest, ClamshellPhysicalTabletState) {
// Auto-rotation is disabled while the device is not physically used as a
// tablet.
TabletModeControllerTestApi tablet_mode_controller_test_api;
EXPECT_FALSE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
// Once the device goes into tablet mode, it becomes possible to auto-rotate.
tablet_mode_controller_test_api.OpenLidToAngle(270);
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
// Hooking an external pointing device will exits tablet UI mode, but the
// device is still in a physical tablet state, which means auto-rotation is
// still possible.
tablet_mode_controller_test_api.AttachExternalMouse();
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_FALSE(tablet_mode_controller_test_api.IsTabletModeStarted());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
}
TEST_F(ScreenOrientationControllerTest,
ApplyAppsRequestedLocksOnlyInUITabletMode) {
std::unique_ptr<aura::Window> window(CreateAppWindowInShellWithId(0));
TabletModeControllerTestApi tablet_mode_controller_test_api;
// Unit tests are supposed to be in reference to a hypothetical computer, but
// they can detect a mouse connected to the actual computer on which they are
// run. That is relevant here because external pointing devices prevent tablet
// mode. Detach all mice, so that this unit test will produce the same results
// whether the host machine has a mouse or not.
tablet_mode_controller_test_api.DetachAllMice();
tablet_mode_controller_test_api.OpenLidToAngle(270);
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ScreenOrientationController* orientation_controller =
Shell::Get()->screen_orientation_controller();
orientation_controller->ToggleUserRotationLock();
EXPECT_TRUE(orientation_controller->user_rotation_locked());
EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
UserLockedOrientation());
// Apps' requested orientation locks are only applied in UI tablet mode.
Lock(window.get(), chromeos::OrientationType::kPortrait);
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
// Exiting to clamshell mode while the device is still physically a tablet
// should restore the user rotation lock, and ignore the app-requested one.
tablet_mode_controller_test_api.AttachExternalMouse();
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_FALSE(tablet_mode_controller_test_api.IsTabletModeStarted());
EXPECT_TRUE(orientation_controller->user_rotation_locked());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
UserLockedOrientation());
// Further requested orientation locks by apps will remain ignored.
Lock(window.get(), chromeos::OrientationType::kPortraitSecondary);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kLandscapePrimary,
UserLockedOrientation());
// When UI tablet mode triggers again, the most recent app requested
// orientation lock for the active window will be applied.
tablet_mode_controller_test_api.DetachAllMice();
EXPECT_TRUE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_TRUE(tablet_mode_controller_test_api.IsTabletModeStarted());
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
// Orientation should be restored once the device exits the physical tablet
// state.
tablet_mode_controller_test_api.OpenLidToAngle(90);
EXPECT_FALSE(tablet_mode_controller_test_api.IsInPhysicalTabletState());
EXPECT_FALSE(tablet_mode_controller_test_api.IsTabletModeStarted());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
TEST_F(ScreenOrientationControllerTest, GetCurrentAppRequestedOrientationLock) {
UpdateDisplay("0+0-400x300,+400+0-500x400");
auto win0 = CreateAppWindow(gfx::Rect{100, 200});
auto win1 = CreateAppWindow(gfx::Rect{460, 10, 100, 200});
auto roots = Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
EXPECT_EQ(win0->GetRootWindow(), roots[0]);
EXPECT_EQ(win1->GetRootWindow(), roots[1]);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
auto* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
screen_orientation_controller->LockOrientationForWindow(
win0.get(), chromeos::OrientationType::kPortraitPrimary);
screen_orientation_controller->LockOrientationForWindow(
win1.get(), chromeos::OrientationType::kLandscape);
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
EXPECT_EQ(
chromeos::OrientationType::kAny,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
// Enter tablet mode and expect nothing will change until we activate win0.
TabletModeControllerTestApi().DetachAllMice();
EnableTabletMode(true);
// Run a loop for mirror mode to kick in which is triggered asynchronously.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
EXPECT_EQ(chromeos::OrientationType::kLandscape,
screen_orientation_controller->natural_orientation());
EXPECT_EQ(win1.get(), window_util::GetActiveWindow());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
wm::ActivateWindow(win0.get());
EXPECT_EQ(
chromeos::OrientationType::kPortraitPrimary,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_EQ(win0.get(), window_util::GetActiveWindow());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
base::RunLoop().RunUntilIdle();
roots = Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
EXPECT_EQ(win0->GetRootWindow(), roots[0]);
EXPECT_EQ(win1->GetRootWindow(), roots[1]);
// `win1` belongs to the external display, so it is not allowed to lock the
// rotation.
EXPECT_EQ(win0.get(), window_util::GetActiveWindow());
EXPECT_EQ(
chromeos::OrientationType::kPortraitPrimary,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
// Even if you activate `win1`, internal display is not affected and remain
// locked to the rotation requested by `win0`.
wm::ActivateWindow(win1.get());
EXPECT_EQ(
chromeos::OrientationType::kPortraitPrimary,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_TRUE(screen_orientation_controller->rotation_locked());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
// Once `win0` is snapped in splitview, it can no longer lock the rotation.
SplitViewController::Get(win0->GetRootWindow())
->SnapWindow(win0.get(), SplitViewController::SnapPosition::kSecondary);
EXPECT_EQ(
chromeos::OrientationType::kAny,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
}
TEST_F(ScreenOrientationControllerTest,
MoveWindowWithOrientationLockBetweenDisplays) {
UpdateDisplay("400x300,500x400");
// Enter tablet mode and expect nothing will change until we activate win0.
TabletModeControllerTestApi().DetachAllMice();
EnableTabletMode(true);
// Run a loop for mirror mode to kick in which is triggered asynchronously.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(display_manager()->IsInSoftwareMirrorMode());
// Now switch mirror mode off so that we can have two displays in tablet mode.
display_manager()->SetMirrorMode(display::MirrorMode::kOff, absl::nullopt);
base::RunLoop().RunUntilIdle();
auto roots = Shell::GetAllRootWindows();
ASSERT_EQ(2u, roots.size());
// Create a window that locks the orientation to portriat-primary.
auto win0 = CreateAppWindow(gfx::Rect{100, 200});
EXPECT_EQ(win0->GetRootWindow(), roots[0]);
EXPECT_EQ(win0.get(), window_util::GetActiveWindow());
auto* screen_orientation_controller =
Shell::Get()->screen_orientation_controller();
EXPECT_EQ(chromeos::OrientationType::kLandscape,
screen_orientation_controller->natural_orientation());
screen_orientation_controller->LockOrientationForWindow(
win0.get(), chromeos::OrientationType::kPortraitPrimary);
// Even with an accelerometer update that would trigger a 0 degree rotation,
// the rotation of the internal display is locked to 270.
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(
chromeos::OrientationType::kPortraitPrimary,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
// Triggers the move-active-window-between-displays shortcut.
auto* event_generator = GetEventGenerator();
auto trigger_shortcut = [event_generator]() {
constexpr int kFlags = ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN;
event_generator->PressKey(ui::VKEY_M, kFlags);
event_generator->ReleaseKey(ui::VKEY_M, kFlags);
};
// Move the window to the external display, and expect that the internal
// display's orientation is no longer locked.
trigger_shortcut();
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(win0->GetRootWindow(), roots[1]);
EXPECT_EQ(
chromeos::OrientationType::kAny,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
// Move the window back to the internal display, and expect that its
// orientation is locked again by that window.
trigger_shortcut();
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(win0->GetRootWindow(), roots[0]);
EXPECT_EQ(
chromeos::OrientationType::kPortraitPrimary,
screen_orientation_controller->GetCurrentAppRequestedOrientationLock());
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
EXPECT_EQ(chromeos::OrientationType::kAny, UserLockedOrientation());
}
// Tests that the controller ignores the app-requested orientation of floated
// windows.
TEST_F(ScreenOrientationControllerTest, IgnoreFloatWindowOrientationLock) {
EnableTabletMode(true);
std::unique_ptr<aura::Window> child_window = CreateControlWindow();
std::unique_ptr<aura::Window> focus_window(CreateAppWindow());
ASSERT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
ASSERT_FALSE(RotationLocked());
AddWindowAndActivateParent(child_window.get(), focus_window.get());
Lock(child_window.get(), chromeos::OrientationType::kPortrait);
EXPECT_TRUE(RotationLocked());
// Float `focus_window`.
const WindowFloatWMEvent float_event(
chromeos::FloatStartLocation::kBottomRight);
WindowState::Get(focus_window.get())->OnWMEvent(&float_event);
EXPECT_FALSE(RotationLocked());
}
class SupportsClamshellAutoRotation : public ScreenOrientationControllerTest {
public:
SupportsClamshellAutoRotation() = default;
SupportsClamshellAutoRotation(const SupportsClamshellAutoRotation&) = delete;
SupportsClamshellAutoRotation& operator=(
const SupportsClamshellAutoRotation&) = delete;
~SupportsClamshellAutoRotation() override = default;
// ScreenOrientationControllerTest:
void SetUp() override {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kSupportsClamshellAutoRotation);
ScreenOrientationControllerTest::SetUp();
}
};
// Tests that auto rotation is supported even in clamshell when
// kSupportsClamshellAutoRotation is set.
TEST_F(SupportsClamshellAutoRotation, ScreenRotation) {
TabletModeControllerTestApi tablet_mode_controller_test_api;
ASSERT_FALSE(tablet_mode_controller_test_api.IsTabletModeStarted());
// Test rotating in all directions are supported.
TriggerLidUpdate(gfx::Vector3dF(kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(-kMeanGravityFloat, 0.0f, 0.0f));
EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravityFloat, 0.0f));
EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
}
} // namespace ash
|