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

Side by Side Diff: chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc

Issue 964503002: Implemented ForceMaximizeBrowserWindowOnFirstRun policy, added unit test and browser test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Now we use scoped_ptr Created 5 years, 8 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
(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 "content/public/browser/notification_service.h"
25 #include "content/public/test/test_utils.h"
26 #include "policy/policy_constants.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28
29 namespace policy {
30
31 class ForceMaximizeOnFirstRunTest : public LoginPolicyTestBase {
32 protected:
33 ForceMaximizeOnFirstRunTest() : LoginPolicyTestBase() {}
34
35 scoped_ptr<base::DictionaryValue> GetMandatoryPoliciesValue() const override {
36 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
37 dict->SetBoolean(key::kForceMaximizeOnFirstRun, true);
38 return dict;
39 }
40
41 void SetUpResolution() {
42 // Set a screen resolution for which the first browser window will not be
43 // maximized by default.
44 const int width =
45 ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
46 // Set resolution to 1466x300.
47 const std::string resolution = base::IntToString(width) + "x300";
48 ash::DisplayManager* const display_manager =
49 ash::Shell::GetInstance()->display_manager();
50 ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
51 display_manager_test_api.UpdateDisplay(resolution);
52 }
53
54 const Browser* OpenNewBrowserWindow() {
bartfab (slow) 2015/04/07 11:37:17 Nit: There is no need for this to be a member of F
peletskyi 2015/04/07 13:14:29 We refer to CreateBrowser()
bartfab (slow) 2015/04/07 13:27:06 Acknowledged.
55 const user_manager::User* const user =
56 user_manager::UserManager::Get()->GetActiveUser();
57 Profile* const profile =
58 chromeos::ProfileHelper::Get()->GetProfileByUser(user);
59 return CreateBrowser(profile);
60 }
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(ForceMaximizeOnFirstRunTest);
64 };
65
66 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, PRE_TwoRuns) {
67 SetUpResolution();
68 SkipToLoginScreen();
69 LogIn(kAccountId, kAccountPassword);
70
71 // Check that the first browser window is maximized.
72 const BrowserList* const browser_list =
73 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
74 EXPECT_EQ(1U, browser_list->size());
75 const Browser* const browser = browser_list->get(0);
76 ASSERT_TRUE(browser);
77 EXPECT_TRUE(browser->window()->IsMaximized());
78
79 // Un-maximize the window as its state will be carried forward to the next
80 // opened window.
81 browser->window()->Restore();
82 EXPECT_FALSE(browser->window()->IsMaximized());
83
84 // Create a second window and check that it is not affected by the policy.
85 const Browser* const browser1 = OpenNewBrowserWindow();
86 ASSERT_TRUE(browser1);
87 EXPECT_FALSE(browser1->window()->IsMaximized());
88 }
89
90 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, TwoRuns) {
91 SetUpResolution();
92 content::WindowedNotificationObserver(
93 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
94 content::NotificationService::AllSources()).Wait();
95 LogIn(kAccountId, kAccountPassword);
96
97 const Browser* const browser = OpenNewBrowserWindow();
98 ASSERT_TRUE(browser);
99 EXPECT_FALSE(browser->window()->IsMaximized());
100 }
101
102 class ForceMaximizetPolicyFalseTest : public ForceMaximizeOnFirstRunTest {
103 protected:
104 ForceMaximizetPolicyFalseTest() : ForceMaximizeOnFirstRunTest() {}
105
106 scoped_ptr<base::DictionaryValue> GetMandatoryPoliciesValue() const override {
107 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
108 dict->SetBoolean(key::kForceMaximizeOnFirstRun, false);
109 return dict;
110 }
111
112 private:
113 DISALLOW_COPY_AND_ASSIGN(ForceMaximizetPolicyFalseTest);
114 };
115
116 IN_PROC_BROWSER_TEST_F(ForceMaximizetPolicyFalseTest, GeneralFirstRun) {
117 SetUpResolution();
118 SkipToLoginScreen();
119 LogIn(kAccountId, kAccountPassword);
120
121 const BrowserList* const browser_list =
122 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
123 EXPECT_EQ(1U, browser_list->size());
124 const Browser* const browser = browser_list->get(0);
125 ASSERT_TRUE(browser);
126 EXPECT_FALSE(browser->window()->IsMaximized());
127 }
128
129 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698