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

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: Added JSONWriter and removed depricated function. 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/strings/string_number_conversions.h"
13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/policy/login_policy_test_base.h"
15 #include "chrome/browser/chromeos/profiles/profile_helper.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/host_desktop.h"
20 #include "components/user_manager/user.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_utils.h"
23 #include "policy/policy_constants.h"
24 #include "testing/gtest/include/gtest/gtest.h"
25
26 namespace policy {
27
28 class ForceMaximizeOnFirstRunTest : public LoginPolicyTestBase {
29 protected:
30 ForceMaximizeOnFirstRunTest() : LoginPolicyTestBase() {}
31
32 base::DictionaryValue* GetMandatoryPoliciesValue() const override {
33 base::DictionaryValue* const dict = new base::DictionaryValue;
bartfab (slow) 2015/04/02 13:29:31 Nit 1: #include "base/values.h" Nit 2: Use a scope
34 dict->SetBoolean(key::kForceMaximizeOnFirstRun, true);
35 return dict;
36 }
37
38 void SetUpResolution() {
39 // Set a screen resolution for which the first browser window will not be
40 // maximized by default.
41 const int width =
42 ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
43 // Set resolution to 1466x300.
44 const std::string resolution = base::IntToString(width) + "x300";
45 ash::DisplayManager* const display_manager =
46 ash::Shell::GetInstance()->display_manager();
47 ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
48 display_manager_test_api.UpdateDisplay(resolution);
49 }
50
51 private:
52 DISALLOW_COPY_AND_ASSIGN(ForceMaximizeOnFirstRunTest);
53 };
54
55 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, PRE_TwoRuns) {
56 SetUpResolution();
57 SkipToLoginScreen();
58 LogIn(kAccountId, kAccountPassword);
59
60 // Check that the first browser window is maximized.
61 const BrowserList* const browser_list =
62 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
63 EXPECT_EQ(1U, browser_list->size());
64 const Browser* const browser = browser_list->get(0);
65 ASSERT_TRUE(browser);
66 EXPECT_TRUE(browser->window()->IsMaximized());
67
68 // Un-maximize the window as its state will be carried forward to the next
69 // opened window.
70 browser->window()->Restore();
71 EXPECT_FALSE(browser->window()->IsMaximized());
72
73 // Create a second window and check that it is not affected by the policy.
74 const user_manager::User* const user =
bartfab (slow) 2015/04/02 13:29:31 The code is fine as it is but if you want to make
peletskyi 2015/04/02 15:24:50 I'd prefer helper :)
75 user_manager::UserManager::Get()->GetActiveUser();
bartfab (slow) 2015/04/02 13:29:31 Nit: #include "components/user_manager/user.h"
peletskyi 2015/04/02 15:24:50 Already here
bartfab (slow) 2015/04/07 11:37:16 Sorry, I meant "components/user_manager/user_manag
peletskyi 2015/04/07 13:14:29 Done.
76 Profile* const profile =
bartfab (slow) 2015/04/02 13:29:31 Nit: #include "chrome/browser/profiles/profile.h"
peletskyi 2015/04/02 15:24:50 Done.
77 chromeos::ProfileHelper::Get()->GetProfileByUser(user);
78 const Browser* const browser1 = CreateBrowser(profile);
79 ASSERT_TRUE(browser1);
80 EXPECT_FALSE(browser1->window()->IsMaximized());
81 }
82
83 IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, TwoRuns) {
84 SetUpResolution();
85 content::WindowedNotificationObserver(
86 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
87 content::NotificationService::AllSources()).Wait();
88 LogIn(kAccountId, kAccountPassword);
89
90 const user_manager::User* const user =
91 user_manager::UserManager::Get()->GetActiveUser();
92 Profile* const profile =
93 chromeos::ProfileHelper::Get()->GetProfileByUser(user);
94 const Browser* const browser = CreateBrowser(profile);
95 ASSERT_TRUE(browser);
96 EXPECT_FALSE(browser->window()->IsMaximized());
97 }
98
99 class ForceMaximizetPolicyFalseTest : public ForceMaximizeOnFirstRunTest {
100 protected:
101 ForceMaximizetPolicyFalseTest() : ForceMaximizeOnFirstRunTest() {}
102
103 base::DictionaryValue* GetMandatoryPoliciesValue() const override {
104 base::DictionaryValue* const dict = new base::DictionaryValue;
bartfab (slow) 2015/04/02 13:29:31 Nit: Use a scoped_ptr.
peletskyi 2015/04/02 15:24:50 Done.
105 dict->SetBoolean(key::kForceMaximizeOnFirstRun, false);
106 return dict;
107 }
108
109 private:
110 DISALLOW_COPY_AND_ASSIGN(ForceMaximizetPolicyFalseTest);
111 };
112
113 IN_PROC_BROWSER_TEST_F(ForceMaximizetPolicyFalseTest, GeneralFirstRun) {
114 SetUpResolution();
115 SkipToLoginScreen();
116 LogIn(kAccountId, kAccountPassword);
117
118 const BrowserList* const browser_list =
119 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
120 EXPECT_EQ(1U, browser_list->size());
121 const Browser* const browser = browser_list->get(0);
122 ASSERT_TRUE(browser);
123 EXPECT_FALSE(browser->window()->IsMaximized());
124 }
125
126 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698