| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "ash/common/ash_switches.h" | 17 #include "ash/common/ash_switches.h" |
| 18 #include "ash/common/shelf/shelf_item_delegate_manager.h" | 18 #include "ash/common/shelf/shelf_item_delegate_manager.h" |
| 19 #include "ash/common/shelf/shelf_model.h" | 19 #include "ash/common/shelf/shelf_model.h" |
| 20 #include "ash/common/shelf/shelf_model_observer.h" | 20 #include "ash/common/shelf/shelf_model_observer.h" |
| 21 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 21 #include "ash/common/wm_shell.h" | 22 #include "ash/common/wm_shell.h" |
| 23 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 22 #include "ash/shell.h" | 24 #include "ash/shell.h" |
| 23 #include "ash/test/ash_test_helper.h" | 25 #include "ash/test/ash_test_helper.h" |
| 24 #include "ash/test/shelf_item_delegate_manager_test_api.h" | 26 #include "ash/test/shelf_item_delegate_manager_test_api.h" |
| 25 #include "ash/test/test_session_state_delegate.h" | 27 #include "ash/test/test_session_state_delegate.h" |
| 26 #include "ash/test/test_shell_delegate.h" | 28 #include "ash/test/test_shell_delegate.h" |
| 29 #include "ash/wm/window_util.h" |
| 27 #include "base/command_line.h" | 30 #include "base/command_line.h" |
| 28 #include "base/compiler_specific.h" | 31 #include "base/compiler_specific.h" |
| 29 #include "base/files/file_path.h" | 32 #include "base/files/file_path.h" |
| 30 #include "base/location.h" | 33 #include "base/location.h" |
| 31 #include "base/macros.h" | 34 #include "base/macros.h" |
| 32 #include "base/memory/ptr_util.h" | 35 #include "base/memory/ptr_util.h" |
| 33 #include "base/message_loop/message_loop.h" | 36 #include "base/message_loop/message_loop.h" |
| 34 #include "base/single_thread_task_runner.h" | 37 #include "base/single_thread_task_runner.h" |
| 35 #include "base/strings/utf_string_conversions.h" | 38 #include "base/strings/utf_string_conversions.h" |
| 36 #include "base/threading/thread_task_runner_handle.h" | 39 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #include "extensions/browser/app_window/native_app_window.h" | 94 #include "extensions/browser/app_window/native_app_window.h" |
| 92 #include "extensions/common/extension.h" | 95 #include "extensions/common/extension.h" |
| 93 #include "extensions/common/manifest_constants.h" | 96 #include "extensions/common/manifest_constants.h" |
| 94 #include "sync/api/fake_sync_change_processor.h" | 97 #include "sync/api/fake_sync_change_processor.h" |
| 95 #include "sync/api/sync_error_factory_mock.h" | 98 #include "sync/api/sync_error_factory_mock.h" |
| 96 #include "sync/protocol/sync.pb.h" | 99 #include "sync/protocol/sync.pb.h" |
| 97 #include "testing/gtest/include/gtest/gtest.h" | 100 #include "testing/gtest/include/gtest/gtest.h" |
| 98 #include "ui/aura/client/window_tree_client.h" | 101 #include "ui/aura/client/window_tree_client.h" |
| 99 #include "ui/aura/window.h" | 102 #include "ui/aura/window.h" |
| 100 #include "ui/base/models/menu_model.h" | 103 #include "ui/base/models/menu_model.h" |
| 104 #include "ui/display/display.h" |
| 105 #include "ui/display/screen.h" |
| 101 #include "ui/views/widget/widget.h" | 106 #include "ui/views/widget/widget.h" |
| 102 | 107 |
| 103 using base::ASCIIToUTF16; | 108 using base::ASCIIToUTF16; |
| 104 using extensions::Extension; | 109 using extensions::Extension; |
| 105 using extensions::Manifest; | 110 using extensions::Manifest; |
| 106 using extensions::UnloadedExtensionInfo; | 111 using extensions::UnloadedExtensionInfo; |
| 112 using arc::mojom::OrientationLock; |
| 107 | 113 |
| 108 namespace { | 114 namespace { |
| 109 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; | 115 const char* offline_gmail_url = "https://mail.google.com/mail/mu/u"; |
| 110 const char* gmail_url = "https://mail.google.com/mail/u"; | 116 const char* gmail_url = "https://mail.google.com/mail/u"; |
| 111 const char* kGmailLaunchURL = "https://mail.google.com/mail/ca"; | 117 const char* kGmailLaunchURL = "https://mail.google.com/mail/ca"; |
| 112 | 118 |
| 113 // An extension prefix. | 119 // An extension prefix. |
| 114 const char kCrxAppPrefix[] = "_crx_"; | 120 const char kCrxAppPrefix[] = "_crx_"; |
| 115 | 121 |
| 116 // Dummy app id is used to put at least one pin record to prevent initializing | 122 // Dummy app id is used to put at least one pin record to prevent initializing |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { | 305 class ChromeLauncherControllerImplTest : public BrowserWithTestWindowTest { |
| 300 protected: | 306 protected: |
| 301 ChromeLauncherControllerImplTest() | 307 ChromeLauncherControllerImplTest() |
| 302 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false), | 308 : BrowserWithTestWindowTest(Browser::TYPE_TABBED, false), |
| 303 test_controller_(NULL), | 309 test_controller_(NULL), |
| 304 extension_service_(NULL) {} | 310 extension_service_(NULL) {} |
| 305 | 311 |
| 306 ~ChromeLauncherControllerImplTest() override {} | 312 ~ChromeLauncherControllerImplTest() override {} |
| 307 | 313 |
| 308 void SetUp() override { | 314 void SetUp() override { |
| 315 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 316 command_line->AppendSwitch(ash::switches::kAshUseFirstDisplayAsInternal); |
| 317 command_line->AppendSwitch(ash::switches::kAshEnableTouchViewTesting); |
| 318 |
| 309 app_list::AppListSyncableServiceFactory::SetUseInTesting(); | 319 app_list::AppListSyncableServiceFactory::SetUseInTesting(); |
| 310 | 320 |
| 311 BrowserWithTestWindowTest::SetUp(); | 321 BrowserWithTestWindowTest::SetUp(); |
| 312 | 322 |
| 313 if (!profile_manager_) { | 323 if (!profile_manager_) { |
| 314 profile_manager_.reset( | 324 profile_manager_.reset( |
| 315 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 325 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 316 ASSERT_TRUE(profile_manager_->SetUp()); | 326 ASSERT_TRUE(profile_manager_->SetUp()); |
| 317 } | 327 } |
| 318 | 328 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 825 } | 835 } |
| 826 | 836 |
| 827 void EnableArc(bool enable) { | 837 void EnableArc(bool enable) { |
| 828 enable ? arc_test_.arc_auth_service()->EnableArc() | 838 enable ? arc_test_.arc_auth_service()->EnableArc() |
| 829 : arc_test_.arc_auth_service()->DisableArc(); | 839 : arc_test_.arc_auth_service()->DisableArc(); |
| 830 arc_test_.arc_auth_service()->OnSyncedPrefChanged(prefs::kArcEnabled, | 840 arc_test_.arc_auth_service()->OnSyncedPrefChanged(prefs::kArcEnabled, |
| 831 false); | 841 false); |
| 832 base::RunLoop().RunUntilIdle(); | 842 base::RunLoop().RunUntilIdle(); |
| 833 } | 843 } |
| 834 | 844 |
| 845 void EnableTabletMode(bool enable) { |
| 846 ash::MaximizeModeController* controller = |
| 847 ash::WmShell::Get()->maximize_mode_controller(); |
| 848 controller->EnableMaximizeModeWindowManager(enable); |
| 849 } |
| 850 |
| 835 void ValidateArcState(bool arc_enabled, | 851 void ValidateArcState(bool arc_enabled, |
| 836 bool arc_managed, | 852 bool arc_managed, |
| 837 arc::ArcAuthService::State state, | 853 arc::ArcAuthService::State state, |
| 838 const std::string& pin_status) { | 854 const std::string& pin_status) { |
| 839 EXPECT_EQ(arc_managed, arc_test_.arc_auth_service()->IsArcManaged()); | 855 EXPECT_EQ(arc_managed, arc_test_.arc_auth_service()->IsArcManaged()); |
| 840 EXPECT_EQ(arc_enabled, arc_test_.arc_auth_service()->IsArcEnabled()); | 856 EXPECT_EQ(arc_enabled, arc_test_.arc_auth_service()->IsArcEnabled()); |
| 841 EXPECT_EQ(state, arc_test_.arc_auth_service()->state()); | 857 EXPECT_EQ(state, arc_test_.arc_auth_service()->state()); |
| 842 EXPECT_EQ(pin_status, GetPinnedAppStatus()); | 858 EXPECT_EQ(pin_status, GetPinnedAppStatus()); |
| 843 } | 859 } |
| 844 | 860 |
| 845 // Creates app window and set optional Arc application id. | 861 // Creates app window and set optional Arc application id. |
| 846 views::Widget* CreateAppWindow(std::string* window_app_id) { | 862 views::Widget* CreateArcWindow(std::string& window_app_id) { |
| 847 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 863 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 848 params.bounds = gfx::Rect(5, 5, 20, 20); | 864 params.bounds = gfx::Rect(5, 5, 20, 20); |
| 865 params.context = GetContext(); |
| 849 views::Widget* widget = new views::Widget(); | 866 views::Widget* widget = new views::Widget(); |
| 850 widget->Init(params); | 867 widget->Init(params); |
| 851 widget->Show(); | 868 widget->Show(); |
| 852 widget->Activate(); | 869 widget->Activate(); |
| 853 if (window_app_id) { | 870 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), |
| 854 exo::ShellSurface::SetApplicationId(widget->GetNativeWindow(), | 871 &window_app_id); |
| 855 window_app_id); | |
| 856 } | |
| 857 return widget; | 872 return widget; |
| 858 } | 873 } |
| 859 | 874 |
| 875 arc::mojom::AppInfo CreateAppInfo(const std::string& name, |
| 876 const std::string& activity, |
| 877 const std::string& package_name, |
| 878 OrientationLock lock) { |
| 879 arc::mojom::AppInfo appinfo; |
| 880 appinfo.name = name; |
| 881 appinfo.package_name = package_name; |
| 882 appinfo.activity = activity; |
| 883 appinfo.orientation_lock = lock; |
| 884 return appinfo; |
| 885 } |
| 886 |
| 887 std::string AddArcAppAndShortcut(const arc::mojom::AppInfo& app_info) { |
| 888 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); |
| 889 // Adding app to the prefs, and check that the app is accessible by id. |
| 890 prefs->AddAppAndShortcut( |
| 891 app_info.name, app_info.package_name, app_info.activity, |
| 892 std::string() /* intent_uri */, std::string() /* icon_resource_id */, |
| 893 false /* sticky */, true /* notifications_enabled */, |
| 894 false /* shortcut */, app_info.orientation_lock); |
| 895 const std::string app_id = |
| 896 ArcAppListPrefs::GetAppId(app_info.package_name, app_info.activity); |
| 897 EXPECT_TRUE(prefs->GetApp(app_id)); |
| 898 return app_id; |
| 899 } |
| 900 |
| 901 void NotifyOnTaskCreated(const arc::mojom::AppInfo& appinfo, |
| 902 int32_t task_id) { |
| 903 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); |
| 904 prefs->OnTaskCreated(task_id, appinfo.package_name, appinfo.activity); |
| 905 } |
| 906 |
| 907 void NotifyOnTaskOrientationLockRequested(int32_t task_id, |
| 908 OrientationLock lock) { |
| 909 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); |
| 910 prefs->OnTaskOrientationLockRequested(task_id, lock); |
| 911 } |
| 912 |
| 860 // Needed for extension service & friends to work. | 913 // Needed for extension service & friends to work. |
| 861 scoped_refptr<Extension> extension1_; | 914 scoped_refptr<Extension> extension1_; |
| 862 scoped_refptr<Extension> extension2_; | 915 scoped_refptr<Extension> extension2_; |
| 863 scoped_refptr<Extension> extension3_; | 916 scoped_refptr<Extension> extension3_; |
| 864 scoped_refptr<Extension> extension4_; | 917 scoped_refptr<Extension> extension4_; |
| 865 scoped_refptr<Extension> extension5_; | 918 scoped_refptr<Extension> extension5_; |
| 866 scoped_refptr<Extension> extension6_; | 919 scoped_refptr<Extension> extension6_; |
| 867 scoped_refptr<Extension> extension7_; | 920 scoped_refptr<Extension> extension7_; |
| 868 scoped_refptr<Extension> extension8_; | 921 scoped_refptr<Extension> extension8_; |
| 869 scoped_refptr<Extension> arc_support_host_; | 922 scoped_refptr<Extension> arc_support_host_; |
| (...skipping 2468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3338 launcher_controller_->CloseLauncherItem(shelfId3); | 3391 launcher_controller_->CloseLauncherItem(shelfId3); |
| 3339 EXPECT_EQ(1, app_icon_loader1->fetch_count()); | 3392 EXPECT_EQ(1, app_icon_loader1->fetch_count()); |
| 3340 EXPECT_EQ(1, app_icon_loader1->clear_count()); | 3393 EXPECT_EQ(1, app_icon_loader1->clear_count()); |
| 3341 EXPECT_EQ(1, app_icon_loader2->fetch_count()); | 3394 EXPECT_EQ(1, app_icon_loader2->fetch_count()); |
| 3342 EXPECT_EQ(1, app_icon_loader2->clear_count()); | 3395 EXPECT_EQ(1, app_icon_loader2->clear_count()); |
| 3343 } | 3396 } |
| 3344 | 3397 |
| 3345 TEST_F(ChromeLauncherControllerImplTest, ArcAppPinPolicy) { | 3398 TEST_F(ChromeLauncherControllerImplTest, ArcAppPinPolicy) { |
| 3346 arc_test_.SetUp(profile()); | 3399 arc_test_.SetUp(profile()); |
| 3347 InitLauncherControllerWithBrowser(); | 3400 InitLauncherControllerWithBrowser(); |
| 3348 | 3401 arc::mojom::AppInfo appinfo = CreateAppInfo( |
| 3349 arc::mojom::AppInfo appinfo; | 3402 "Some App", "SomeActivity", "com.example.app", OrientationLock::NONE); |
| 3350 appinfo.name = "Some App"; | 3403 const std::string app_id = AddArcAppAndShortcut(appinfo); |
| 3351 appinfo.activity = "SomeActivity"; | |
| 3352 appinfo.package_name = "com.example.app"; | |
| 3353 | |
| 3354 ArcAppListPrefs* const prefs = arc_test_.arc_app_list_prefs(); | |
| 3355 ASSERT_TRUE(prefs); | |
| 3356 | |
| 3357 // Adding app to the prefs, and check that the app is accessible by id. | |
| 3358 prefs->AddAppAndShortcut(appinfo.name, appinfo.package_name, appinfo.activity, | |
| 3359 std::string() /* intent_uri */, | |
| 3360 std::string() /* icon_resource_id */, | |
| 3361 false /* sticky */, true /* notifications_enabled */, | |
| 3362 false /* shortcut */); | |
| 3363 const std::string app_id = | |
| 3364 ArcAppListPrefs::GetAppId(appinfo.package_name, appinfo.activity); | |
| 3365 EXPECT_TRUE(prefs->GetApp(app_id)); | |
| 3366 | 3404 |
| 3367 // Set policy, that makes pins ARC app. Unlike native extension, for ARC app | 3405 // Set policy, that makes pins ARC app. Unlike native extension, for ARC app |
| 3368 // package_name (not hash) specified as id. In this test we check that | 3406 // package_name (not hash) specified as id. In this test we check that |
| 3369 // by hash we can determine that appropriate package was set by policy. | 3407 // by hash we can determine that appropriate package was set by policy. |
| 3370 base::ListValue policy_value; | 3408 base::ListValue policy_value; |
| 3371 InsertPrefValue(&policy_value, 0, appinfo.package_name); | 3409 InsertPrefValue(&policy_value, 0, appinfo.package_name); |
| 3372 profile()->GetTestingPrefService()->SetManagedPref( | 3410 profile()->GetTestingPrefService()->SetManagedPref( |
| 3373 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); | 3411 prefs::kPolicyPinnedLauncherApps, policy_value.DeepCopy()); |
| 3374 | 3412 |
| 3375 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); | 3413 EXPECT_TRUE(launcher_controller_->IsAppPinned(app_id)); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3420 // be automatically removed. | 3458 // be automatically removed. |
| 3421 EnableArc(false); | 3459 EnableArc(false); |
| 3422 ValidateArcState(false, false, arc::ArcAuthService::State::STOPPED, | 3460 ValidateArcState(false, false, arc::ArcAuthService::State::STOPPED, |
| 3423 "AppList, Chrome"); | 3461 "AppList, Chrome"); |
| 3424 | 3462 |
| 3425 // 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. |
| 3426 EnableArc(true); | 3464 EnableArc(true); |
| 3427 ValidateArcState(true, false, arc::ArcAuthService::State::FETCHING_CODE, | 3465 ValidateArcState(true, false, arc::ArcAuthService::State::FETCHING_CODE, |
| 3428 "AppList, Chrome"); | 3466 "AppList, Chrome"); |
| 3429 } | 3467 } |
| 3468 |
| 3469 TEST_F(ChromeLauncherControllerImplTest, ArcOrientationLock) { |
| 3470 DCHECK(display::Display::HasInternalDisplay()); |
| 3471 |
| 3472 extension_service_->AddExtension(arc_support_host_.get()); |
| 3473 arc_test_.SetUp(profile()); |
| 3474 EnableArc(true); |
| 3475 EnableTabletMode(true); |
| 3476 |
| 3477 InitLauncherController(); |
| 3478 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 |
| 3486 const std::string app_id_none = AddArcAppAndShortcut(appinfo_none); |
| 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 = |
| 3501 ash::Shell::GetInstance()->screen_orientation_controller(); |
| 3502 |
| 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. |
| 3525 window_none->Activate(); |
| 3526 EXPECT_FALSE(controller->rotation_locked()); |
| 3527 EXPECT_EQ(display::Display::ROTATE_0, |
| 3528 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3529 |
| 3530 // Activating a window with PORTRAIT orientation locks the screen to 90. |
| 3531 window_portrait->Activate(); |
| 3532 EXPECT_TRUE(controller->rotation_locked()); |
| 3533 EXPECT_EQ(display::Display::ROTATE_90, |
| 3534 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3535 |
| 3536 // Disable Tablet mode, and make sure the screen is unlocked. |
| 3537 EnableTabletMode(false); |
| 3538 EXPECT_FALSE(controller->rotation_locked()); |
| 3539 EXPECT_EQ(display::Display::ROTATE_0, |
| 3540 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3541 |
| 3542 // Re-enable Tablet mode, and make sure the screen is locked to 90. |
| 3543 EnableTabletMode(true); |
| 3544 EXPECT_TRUE(controller->rotation_locked()); |
| 3545 EXPECT_EQ(display::Display::ROTATE_90, |
| 3546 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3547 |
| 3548 window_portrait->Activate(); |
| 3549 EXPECT_TRUE(controller->rotation_locked()); |
| 3550 EXPECT_EQ(display::Display::ROTATE_90, |
| 3551 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3552 |
| 3553 window_landscape->Activate(); |
| 3554 EXPECT_TRUE(controller->rotation_locked()); |
| 3555 EXPECT_EQ(display::Display::ROTATE_0, |
| 3556 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3557 |
| 3558 // OnTaskOrientationLockRequested can overwrite the current lock. |
| 3559 NotifyOnTaskOrientationLockRequested(task_id_landscape, |
| 3560 OrientationLock::NONE); |
| 3561 EXPECT_FALSE(controller->rotation_locked()); |
| 3562 EXPECT_EQ(display::Display::ROTATE_0, |
| 3563 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3564 |
| 3565 NotifyOnTaskOrientationLockRequested(task_id_landscape, |
| 3566 OrientationLock::PORTRAIT); |
| 3567 EXPECT_TRUE(controller->rotation_locked()); |
| 3568 EXPECT_EQ(display::Display::ROTATE_90, |
| 3569 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3570 |
| 3571 // Non active window won't change the lock. |
| 3572 NotifyOnTaskOrientationLockRequested(task_id_none, |
| 3573 OrientationLock::LANDSCAPE); |
| 3574 EXPECT_TRUE(controller->rotation_locked()); |
| 3575 EXPECT_EQ(display::Display::ROTATE_90, |
| 3576 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3577 |
| 3578 // But activating it will change the locked orinetation. |
| 3579 window_none->Activate(); |
| 3580 EXPECT_TRUE(controller->rotation_locked()); |
| 3581 EXPECT_EQ(display::Display::ROTATE_0, |
| 3582 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3583 |
| 3584 // OnTaskOrientationLockRequested will not lock the screen in non Tablet mode. |
| 3585 EnableTabletMode(false); |
| 3586 EXPECT_FALSE(controller->rotation_locked()); |
| 3587 EXPECT_EQ(display::Display::ROTATE_0, |
| 3588 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3589 |
| 3590 NotifyOnTaskOrientationLockRequested(task_id_none, OrientationLock::PORTRAIT); |
| 3591 EXPECT_FALSE(controller->rotation_locked()); |
| 3592 EXPECT_EQ(display::Display::ROTATE_0, |
| 3593 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3594 |
| 3595 // But it remembers the orientation lock and use it when Tablet mode is |
| 3596 // enabled. |
| 3597 EnableTabletMode(true); |
| 3598 EXPECT_TRUE(controller->rotation_locked()); |
| 3599 EXPECT_EQ(display::Display::ROTATE_90, |
| 3600 display::Screen::GetScreen()->GetPrimaryDisplay().rotation()); |
| 3601 } |
| OLD | NEW |