OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <string> |
| 6 |
| 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ash/test/display_manager_test_api.h" |
| 10 #include "ash/wm/window_positioner.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/values.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/chromeos/policy/login_policy_test_base.h" |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_list.h" |
| 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/host_desktop.h" |
| 23 #include "components/user_manager/user.h" |
| 24 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/test/test_utils.h" |
| 27 #include "policy/policy_constants.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 |
| 30 namespace policy { |
| 31 |
| 32 class ForceMaximizeOnFirstRunTest : public LoginPolicyTestBase { |
| 33 protected: |
| 34 ForceMaximizeOnFirstRunTest() : LoginPolicyTestBase() {} |
| 35 |
| 36 scoped_ptr<base::DictionaryValue> GetMandatoryPoliciesValue() const override { |
| 37 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 38 dict->SetBoolean(key::kForceMaximizeOnFirstRun, true); |
| 39 return dict; |
| 40 } |
| 41 |
| 42 void SetUpResolution() { |
| 43 // Set a screen resolution for which the first browser window will not be |
| 44 // maximized by default. |
| 45 const int width = |
| 46 ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100; |
| 47 // Set resolution to 1466x300. |
| 48 const std::string resolution = base::IntToString(width) + "x300"; |
| 49 ash::DisplayManager* const display_manager = |
| 50 ash::Shell::GetInstance()->display_manager(); |
| 51 ash::test::DisplayManagerTestApi display_manager_test_api(display_manager); |
| 52 display_manager_test_api.UpdateDisplay(resolution); |
| 53 } |
| 54 |
| 55 const Browser* OpenNewBrowserWindow() { |
| 56 const user_manager::User* const user = |
| 57 user_manager::UserManager::Get()->GetActiveUser(); |
| 58 Profile* const profile = |
| 59 chromeos::ProfileHelper::Get()->GetProfileByUser(user); |
| 60 return CreateBrowser(profile); |
| 61 } |
| 62 |
| 63 private: |
| 64 DISALLOW_COPY_AND_ASSIGN(ForceMaximizeOnFirstRunTest); |
| 65 }; |
| 66 |
| 67 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, PRE_TwoRuns) { |
| 68 SetUpResolution(); |
| 69 SkipToLoginScreen(); |
| 70 LogIn(kAccountId, kAccountPassword); |
| 71 |
| 72 // Check that the first browser window is maximized. |
| 73 const BrowserList* const browser_list = |
| 74 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 75 EXPECT_EQ(1U, browser_list->size()); |
| 76 const Browser* const browser = browser_list->get(0); |
| 77 ASSERT_TRUE(browser); |
| 78 EXPECT_TRUE(browser->window()->IsMaximized()); |
| 79 |
| 80 // Un-maximize the window as its state will be carried forward to the next |
| 81 // opened window. |
| 82 browser->window()->Restore(); |
| 83 EXPECT_FALSE(browser->window()->IsMaximized()); |
| 84 |
| 85 // Create a second window and check that it is not affected by the policy. |
| 86 const Browser* const browser1 = OpenNewBrowserWindow(); |
| 87 ASSERT_TRUE(browser1); |
| 88 EXPECT_FALSE(browser1->window()->IsMaximized()); |
| 89 } |
| 90 |
| 91 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, TwoRuns) { |
| 92 SetUpResolution(); |
| 93 content::WindowedNotificationObserver( |
| 94 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 95 content::NotificationService::AllSources()).Wait(); |
| 96 LogIn(kAccountId, kAccountPassword); |
| 97 |
| 98 const Browser* const browser = OpenNewBrowserWindow(); |
| 99 ASSERT_TRUE(browser); |
| 100 EXPECT_FALSE(browser->window()->IsMaximized()); |
| 101 } |
| 102 |
| 103 class ForceMaximizetPolicyFalseTest : public ForceMaximizeOnFirstRunTest { |
| 104 protected: |
| 105 ForceMaximizetPolicyFalseTest() : ForceMaximizeOnFirstRunTest() {} |
| 106 |
| 107 scoped_ptr<base::DictionaryValue> GetMandatoryPoliciesValue() const override { |
| 108 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 109 dict->SetBoolean(key::kForceMaximizeOnFirstRun, false); |
| 110 return dict; |
| 111 } |
| 112 |
| 113 private: |
| 114 DISALLOW_COPY_AND_ASSIGN(ForceMaximizetPolicyFalseTest); |
| 115 }; |
| 116 |
| 117 IN_PROC_BROWSER_TEST_F(ForceMaximizetPolicyFalseTest, GeneralFirstRun) { |
| 118 SetUpResolution(); |
| 119 SkipToLoginScreen(); |
| 120 LogIn(kAccountId, kAccountPassword); |
| 121 |
| 122 const BrowserList* const browser_list = |
| 123 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 124 EXPECT_EQ(1U, browser_list->size()); |
| 125 const Browser* const browser = browser_list->get(0); |
| 126 ASSERT_TRUE(browser); |
| 127 EXPECT_FALSE(browser->window()->IsMaximized()); |
| 128 } |
| 129 |
| 130 } // namespace policy |
OLD | NEW |