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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl_unittest.cc

Issue 2139893002: Add CURRENT lock orientation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add CURRENT lock orientation. Created 4 years, 5 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 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 "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h" 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 3448 matching lines...) Expand 10 before | Expand all | Expand 10 after
3459 EnableArc(false); 3459 EnableArc(false);
3460 ValidateArcState(false, false, arc::ArcAuthService::State::STOPPED, 3460 ValidateArcState(false, false, arc::ArcAuthService::State::STOPPED,
3461 "AppList, Chrome"); 3461 "AppList, Chrome");
3462 3462
3463 // Even if re-enable it again, Play Store pin does not appear automatically. 3463 // Even if re-enable it again, Play Store pin does not appear automatically.
3464 EnableArc(true); 3464 EnableArc(true);
3465 ValidateArcState(true, false, arc::ArcAuthService::State::FETCHING_CODE, 3465 ValidateArcState(true, false, arc::ArcAuthService::State::FETCHING_CODE,
3466 "AppList, Chrome"); 3466 "AppList, Chrome");
3467 } 3467 }
3468 3468
3469 TEST_F(ChromeLauncherControllerImplTest, ArcOrientationLock) { 3469 namespace {
3470 DCHECK(display::Display::HasInternalDisplay()); 3470
3471 class ChromeLauncherControllerOrientationTest
3472 : public ChromeLauncherControllerImplTest {
3473 public:
3474 ChromeLauncherControllerOrientationTest() {}
3475 ~ChromeLauncherControllerOrientationTest() override {}
3476
3477 protected:
3478 void InitApps() {
3479 appinfo_none_ =
3480 CreateAppInfo("None", "None", "com.example.app", OrientationLock::NONE);
3481 appinfo_landscape_ =
3482 CreateAppInfo("Landscape", "Landscape", "com.example.app",
3483 OrientationLock::LANDSCAPE);
3484 appinfo_portrait_ = CreateAppInfo("Portrait", "Portrait", "com.example.app",
3485 OrientationLock::PORTRAIT);
3486 appinfo_current_ = CreateAppInfo(
3487 "LockCurrent", "current", "com.example.app", OrientationLock::CURRENT);
3488
3489 AddArcAppAndShortcut(appinfo_none_);
3490 AddArcAppAndShortcut(appinfo_landscape_);
3491 AddArcAppAndShortcut(appinfo_portrait_);
3492 AddArcAppAndShortcut(appinfo_current_);
3493
3494 ash::ScreenOrientationController* controller =
3495 ash::Shell::GetInstance()->screen_orientation_controller();
3496
3497 // Creating a window with NONE orientation will not lock the screen.
3498 window_none_ = CreateArcWindow(window_app_id_none_);
3499 NotifyOnTaskCreated(appinfo_none_, task_id_none_);
3500 EXPECT_FALSE(controller->rotation_locked());
3501 EXPECT_EQ(display::Display::ROTATE_0,
3502 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3503
3504 // Create a arc window with PORTRAIT orientation locks the screen to 90.
3505 window_portrait_ = CreateArcWindow(window_app_id_portrait_);
3506 NotifyOnTaskCreated(appinfo_portrait_, task_id_portrait_);
3507 EXPECT_TRUE(controller->rotation_locked());
3508 EXPECT_EQ(display::Display::ROTATE_90,
3509 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3510
3511 // Create a arc window with LANDSCAPE orientation locks the screen to 0.
3512 window_landscape_ = CreateArcWindow(window_app_id_landscape_);
3513 NotifyOnTaskCreated(appinfo_landscape_, task_id_landscape_);
3514 EXPECT_TRUE(controller->rotation_locked());
3515 EXPECT_EQ(display::Display::ROTATE_0,
3516 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3517 }
3518
3519 int32_t task_id_none_ = 1;
3520 int32_t task_id_landscape_ = 2;
3521 int32_t task_id_portrait_ = 3;
3522 int32_t task_id_current_ = 4;
3523
3524 // This needs to be kept on the instance because window's property has
3525 // refeference to this.
3526 std::string window_app_id_none_ = {"org.chromium.arc.1"};
3527 std::string window_app_id_landscape_ = {"org.chromium.arc.2"};
3528 std::string window_app_id_portrait_ = {"org.chromium.arc.3"};
3529 std::string window_app_id_current_ = {"org.chromium.arc.4"};
3530
3531 arc::mojom::AppInfo appinfo_none_;
3532 arc::mojom::AppInfo appinfo_landscape_;
3533 arc::mojom::AppInfo appinfo_portrait_;
3534 arc::mojom::AppInfo appinfo_current_;
3535
3536 views::Widget* window_none_ = nullptr;
3537 views::Widget* window_landscape_ = nullptr;
3538 views::Widget* window_portrait_ = nullptr;
3539 views::Widget* window_current_ = nullptr;
3540
3541 private:
3542 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerOrientationTest);
3543 };
3544
3545 } // namespace
3546
3547 TEST_F(ChromeLauncherControllerOrientationTest, ArcOrientationLock) {
3548 ASSERT_TRUE(display::Display::HasInternalDisplay());
3471 3549
3472 extension_service_->AddExtension(arc_support_host_.get()); 3550 extension_service_->AddExtension(arc_support_host_.get());
3473 arc_test_.SetUp(profile()); 3551 arc_test_.SetUp(profile());
3474 EnableArc(true); 3552 EnableArc(true);
3475 EnableTabletMode(true); 3553 EnableTabletMode(true);
3476 3554
3477 InitLauncherController(); 3555 InitLauncherController();
3478 arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get()); 3556 arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get());
3479 arc::mojom::AppInfo appinfo_none =
3480 CreateAppInfo("None", "None", "com.example.app", OrientationLock::NONE);
3481 arc::mojom::AppInfo appinfo_landscape = CreateAppInfo(
3482 "Landscape", "Landscape", "com.example.app", OrientationLock::LANDSCAPE);
3483 arc::mojom::AppInfo appinfo_portrait = CreateAppInfo(
3484 "Portrait", "Portrait", "com.example.app", OrientationLock::PORTRAIT);
3485 3557
3486 const std::string app_id_none = AddArcAppAndShortcut(appinfo_none); 3558 InitApps();
3487 const std::string app_id_landscape = AddArcAppAndShortcut(appinfo_landscape);
3488 const std::string app_id_portrait = AddArcAppAndShortcut(appinfo_portrait);
3489
3490 int32_t task_id_none = 1;
3491 int32_t task_id_landscape = 2;
3492 int32_t task_id_portrait = 3;
3493
3494 // This needs to be kept on stack because window's property has
3495 // refeference to this.
3496 std::string window_app_id_none("org.chromium.arc.1");
3497 std::string window_app_id_landscape("org.chromium.arc.2");
3498 std::string window_app_id_portrait("org.chromium.arc.3");
3499
3500 ash::ScreenOrientationController* controller = 3559 ash::ScreenOrientationController* controller =
3501 ash::Shell::GetInstance()->screen_orientation_controller(); 3560 ash::Shell::GetInstance()->screen_orientation_controller();
3502 3561
3503 // Creating a window with NONE orientation will not lock the screen.
3504 views::Widget* window_none = CreateArcWindow(window_app_id_none);
3505 NotifyOnTaskCreated(appinfo_none, task_id_none);
3506 EXPECT_FALSE(controller->rotation_locked());
3507 EXPECT_EQ(display::Display::ROTATE_0,
3508 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3509
3510 // Create a arc window with PORTRAIT orientation locks the screen to 90.
3511 views::Widget* window_portrait = CreateArcWindow(window_app_id_portrait);
3512 NotifyOnTaskCreated(appinfo_portrait, task_id_portrait);
3513 EXPECT_TRUE(controller->rotation_locked());
3514 EXPECT_EQ(display::Display::ROTATE_90,
3515 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3516
3517 // Create a arc window with LANDSCAPE orientation locks the screen to 0.
3518 views::Widget* window_landscape = CreateArcWindow(window_app_id_landscape);
3519 NotifyOnTaskCreated(appinfo_landscape, task_id_landscape);
3520 EXPECT_TRUE(controller->rotation_locked());
3521 EXPECT_EQ(display::Display::ROTATE_0,
3522 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3523
3524 // Activating a window with NON orientation unlocks the screen. 3562 // Activating a window with NON orientation unlocks the screen.
3525 window_none->Activate(); 3563 window_none_->Activate();
3526 EXPECT_FALSE(controller->rotation_locked()); 3564 EXPECT_FALSE(controller->rotation_locked());
3527 EXPECT_EQ(display::Display::ROTATE_0, 3565 EXPECT_EQ(display::Display::ROTATE_0,
3528 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3566 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3529 3567
3530 // Activating a window with PORTRAIT orientation locks the screen to 90. 3568 // Activating a window with PORTRAIT orientation locks the screen to 90.
3531 window_portrait->Activate(); 3569 window_portrait_->Activate();
3532 EXPECT_TRUE(controller->rotation_locked()); 3570 EXPECT_TRUE(controller->rotation_locked());
3533 EXPECT_EQ(display::Display::ROTATE_90, 3571 EXPECT_EQ(display::Display::ROTATE_90,
3534 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3572 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3535 3573
3536 // Disable Tablet mode, and make sure the screen is unlocked. 3574 // Disable Tablet mode, and make sure the screen is unlocked.
3537 EnableTabletMode(false); 3575 EnableTabletMode(false);
3538 EXPECT_FALSE(controller->rotation_locked()); 3576 EXPECT_FALSE(controller->rotation_locked());
3539 EXPECT_EQ(display::Display::ROTATE_0, 3577 EXPECT_EQ(display::Display::ROTATE_0,
3540 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3578 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3541 3579
3542 // Re-enable Tablet mode, and make sure the screen is locked to 90. 3580 // Re-enable Tablet mode, and make sure the screen is locked to 90.
3543 EnableTabletMode(true); 3581 EnableTabletMode(true);
3544 EXPECT_TRUE(controller->rotation_locked()); 3582 EXPECT_TRUE(controller->rotation_locked());
3545 EXPECT_EQ(display::Display::ROTATE_90, 3583 EXPECT_EQ(display::Display::ROTATE_90,
3546 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3584 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3547 3585
3548 window_portrait->Activate(); 3586 window_portrait_->Activate();
3549 EXPECT_TRUE(controller->rotation_locked()); 3587 EXPECT_TRUE(controller->rotation_locked());
3550 EXPECT_EQ(display::Display::ROTATE_90, 3588 EXPECT_EQ(display::Display::ROTATE_90,
3551 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3589 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3552 3590
3553 window_landscape->Activate(); 3591 window_landscape_->Activate();
3554 EXPECT_TRUE(controller->rotation_locked()); 3592 EXPECT_TRUE(controller->rotation_locked());
3555 EXPECT_EQ(display::Display::ROTATE_0, 3593 EXPECT_EQ(display::Display::ROTATE_0,
3556 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3594 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3557 3595
3558 // OnTaskOrientationLockRequested can overwrite the current lock. 3596 // OnTaskOrientationLockRequested can overwrite the current lock.
3559 NotifyOnTaskOrientationLockRequested(task_id_landscape, 3597 NotifyOnTaskOrientationLockRequested(task_id_landscape_,
3560 OrientationLock::NONE); 3598 OrientationLock::NONE);
3561 EXPECT_FALSE(controller->rotation_locked()); 3599 EXPECT_FALSE(controller->rotation_locked());
3562 EXPECT_EQ(display::Display::ROTATE_0, 3600 EXPECT_EQ(display::Display::ROTATE_0,
3563 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3601 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3564 3602
3565 NotifyOnTaskOrientationLockRequested(task_id_landscape, 3603 NotifyOnTaskOrientationLockRequested(task_id_landscape_,
3566 OrientationLock::PORTRAIT); 3604 OrientationLock::PORTRAIT);
3567 EXPECT_TRUE(controller->rotation_locked()); 3605 EXPECT_TRUE(controller->rotation_locked());
3568 EXPECT_EQ(display::Display::ROTATE_90, 3606 EXPECT_EQ(display::Display::ROTATE_90,
3569 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3607 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3570 3608
3571 // Non active window won't change the lock. 3609 // Non active window won't change the lock.
3572 NotifyOnTaskOrientationLockRequested(task_id_none, 3610 NotifyOnTaskOrientationLockRequested(task_id_none_,
3573 OrientationLock::LANDSCAPE); 3611 OrientationLock::LANDSCAPE);
3574 EXPECT_TRUE(controller->rotation_locked()); 3612 EXPECT_TRUE(controller->rotation_locked());
3575 EXPECT_EQ(display::Display::ROTATE_90, 3613 EXPECT_EQ(display::Display::ROTATE_90,
3576 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3614 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3577 3615
3578 // But activating it will change the locked orinetation. 3616 // But activating it will change the locked orinetation.
3579 window_none->Activate(); 3617 window_none_->Activate();
3580 EXPECT_TRUE(controller->rotation_locked()); 3618 EXPECT_TRUE(controller->rotation_locked());
3581 EXPECT_EQ(display::Display::ROTATE_0, 3619 EXPECT_EQ(display::Display::ROTATE_0,
3582 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3620 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3583 3621
3584 // OnTaskOrientationLockRequested will not lock the screen in non Tablet mode. 3622 // OnTaskOrientationLockRequested will not lock the screen in non Tablet mode.
3585 EnableTabletMode(false); 3623 EnableTabletMode(false);
3586 EXPECT_FALSE(controller->rotation_locked()); 3624 EXPECT_FALSE(controller->rotation_locked());
3587 EXPECT_EQ(display::Display::ROTATE_0, 3625 EXPECT_EQ(display::Display::ROTATE_0,
3588 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3626 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3589 3627
3590 NotifyOnTaskOrientationLockRequested(task_id_none, OrientationLock::PORTRAIT); 3628 NotifyOnTaskOrientationLockRequested(task_id_none_,
3629 OrientationLock::PORTRAIT);
3591 EXPECT_FALSE(controller->rotation_locked()); 3630 EXPECT_FALSE(controller->rotation_locked());
3592 EXPECT_EQ(display::Display::ROTATE_0, 3631 EXPECT_EQ(display::Display::ROTATE_0,
3593 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3632 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3594 3633
3595 // But it remembers the orientation lock and use it when Tablet mode is 3634 // But it remembers the orientation lock and use it when Tablet mode is
3596 // enabled. 3635 // enabled.
3597 EnableTabletMode(true); 3636 EnableTabletMode(true);
3598 EXPECT_TRUE(controller->rotation_locked()); 3637 EXPECT_TRUE(controller->rotation_locked());
3599 EXPECT_EQ(display::Display::ROTATE_90, 3638 EXPECT_EQ(display::Display::ROTATE_90,
3600 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); 3639 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3640
3641 // Manually unlock first.
3642 NotifyOnTaskOrientationLockRequested(task_id_none_, OrientationLock::NONE);
3643 EXPECT_FALSE(controller->rotation_locked());
3601 } 3644 }
3645
3646 TEST_F(ChromeLauncherControllerOrientationTest, CurrentWithLandscapeDisplay) {
3647 ASSERT_TRUE(display::Display::HasInternalDisplay());
3648
3649 extension_service_->AddExtension(arc_support_host_.get());
3650 arc_test_.SetUp(profile());
3651 EnableArc(true);
3652 EnableTabletMode(true);
3653
3654 InitLauncherController();
3655 arc::ArcAuthService::SetShelfDelegateForTesting(launcher_controller_.get());
3656
3657 InitApps();
3658 ash::ScreenOrientationController* controller =
3659 ash::Shell::GetInstance()->screen_orientation_controller();
3660
3661 // Start with portrait.
3662 window_portrait_->Activate();
3663
3664 // Create a arc window to lock the CURRENT orientation.
3665 views::Widget* window_current = CreateArcWindow(window_app_id_current_);
3666 NotifyOnTaskCreated(appinfo_current_, task_id_current_);
3667 EXPECT_TRUE(controller->rotation_locked());
3668 EXPECT_EQ(display::Display::ROTATE_90,
3669 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3670
3671 // Re-activating changes the orientation to previously locked orientation.
3672 window_landscape_->Activate();
3673 EXPECT_TRUE(controller->rotation_locked());
3674 EXPECT_EQ(display::Display::ROTATE_0,
3675 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3676 window_current->Activate();
3677 EXPECT_TRUE(controller->rotation_locked());
3678 EXPECT_EQ(display::Display::ROTATE_90,
3679 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3680
3681 // Exitting and re-entering tablet mode re-locks the orientation.
3682 EnableTabletMode(false);
3683 EXPECT_FALSE(controller->rotation_locked());
3684 EXPECT_EQ(display::Display::ROTATE_0,
3685 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3686
3687 EnableTabletMode(true);
3688 EXPECT_TRUE(window_current->IsActive());
3689 EXPECT_TRUE(controller->rotation_locked());
3690 EXPECT_EQ(display::Display::ROTATE_90,
3691 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3692
3693 // Manually unlock, and lock again at landscape.
3694 NotifyOnTaskOrientationLockRequested(task_id_current_, OrientationLock::NONE);
3695 window_landscape_->Activate();
3696 EXPECT_TRUE(controller->rotation_locked());
3697 window_current->Activate();
3698 EXPECT_FALSE(controller->rotation_locked());
3699 EXPECT_EQ(display::Display::ROTATE_0,
3700 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3701
3702 NotifyOnTaskOrientationLockRequested(task_id_current_,
3703 OrientationLock::CURRENT);
3704 EXPECT_TRUE(controller->rotation_locked());
3705 EXPECT_EQ(display::Display::ROTATE_0,
3706 display::Screen::GetScreen()->GetPrimaryDisplay().rotation());
3707 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698