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

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

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

Powered by Google App Engine
This is Rietveld 408576698