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

Unified 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, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
diff --git a/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc b/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d3b899d01ebd9e7eed93a1ac408db08742bba419
--- /dev/null
+++ b/chrome/browser/chromeos/policy/force_maximize_on_first_run_chromeos_browsertest.cc
@@ -0,0 +1,126 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <string>
+
+#include "ash/display/display_manager.h"
+#include "ash/shell.h"
+#include "ash/test/display_manager_test_api.h"
+#include "ash/wm/window_positioner.h"
+#include "base/macros.h"
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/chromeos/policy/login_policy_test_base.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/host_desktop.h"
+#include "components/user_manager/user.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_utils.h"
+#include "policy/policy_constants.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace policy {
+
+class ForceMaximizeOnFirstRunTest : public LoginPolicyTestBase {
+ protected:
+ ForceMaximizeOnFirstRunTest() : LoginPolicyTestBase() {}
+
+ base::DictionaryValue* GetMandatoryPoliciesValue() const override {
+ 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
+ dict->SetBoolean(key::kForceMaximizeOnFirstRun, true);
+ return dict;
+ }
+
+ void SetUpResolution() {
+ // Set a screen resolution for which the first browser window will not be
+ // maximized by default.
+ const int width =
+ ash::WindowPositioner::GetForceMaximizedWidthLimit() + 100;
+ // Set resolution to 1466x300.
+ const std::string resolution = base::IntToString(width) + "x300";
+ ash::DisplayManager* const display_manager =
+ ash::Shell::GetInstance()->display_manager();
+ ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
+ display_manager_test_api.UpdateDisplay(resolution);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ForceMaximizeOnFirstRunTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, PRE_TwoRuns) {
+ SetUpResolution();
+ SkipToLoginScreen();
+ LogIn(kAccountId, kAccountPassword);
+
+ // Check that the first browser window is maximized.
+ const BrowserList* const browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+ EXPECT_EQ(1U, browser_list->size());
+ const Browser* const browser = browser_list->get(0);
+ ASSERT_TRUE(browser);
+ EXPECT_TRUE(browser->window()->IsMaximized());
+
+ // Un-maximize the window as its state will be carried forward to the next
+ // opened window.
+ browser->window()->Restore();
+ EXPECT_FALSE(browser->window()->IsMaximized());
+
+ // Create a second window and check that it is not affected by the policy.
+ 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 :)
+ 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.
+ 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.
+ chromeos::ProfileHelper::Get()->GetProfileByUser(user);
+ const Browser* const browser1 = CreateBrowser(profile);
+ ASSERT_TRUE(browser1);
+ EXPECT_FALSE(browser1->window()->IsMaximized());
+}
+
+IN_PROC_BROWSER_TEST_F(ForceMaximizeOnFirstRunTest, TwoRuns) {
+ SetUpResolution();
+ content::WindowedNotificationObserver(
+ chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE,
+ content::NotificationService::AllSources()).Wait();
+ LogIn(kAccountId, kAccountPassword);
+
+ const user_manager::User* const user =
+ user_manager::UserManager::Get()->GetActiveUser();
+ Profile* const profile =
+ chromeos::ProfileHelper::Get()->GetProfileByUser(user);
+ const Browser* const browser = CreateBrowser(profile);
+ ASSERT_TRUE(browser);
+ EXPECT_FALSE(browser->window()->IsMaximized());
+}
+
+class ForceMaximizetPolicyFalseTest : public ForceMaximizeOnFirstRunTest {
+ protected:
+ ForceMaximizetPolicyFalseTest() : ForceMaximizeOnFirstRunTest() {}
+
+ base::DictionaryValue* GetMandatoryPoliciesValue() const override {
+ 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.
+ dict->SetBoolean(key::kForceMaximizeOnFirstRun, false);
+ return dict;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ForceMaximizetPolicyFalseTest);
+};
+
+IN_PROC_BROWSER_TEST_F(ForceMaximizetPolicyFalseTest, GeneralFirstRun) {
+ SetUpResolution();
+ SkipToLoginScreen();
+ LogIn(kAccountId, kAccountPassword);
+
+ const BrowserList* const browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
+ EXPECT_EQ(1U, browser_list->size());
+ const Browser* const browser = browser_list->get(0);
+ ASSERT_TRUE(browser);
+ EXPECT_FALSE(browser->window()->IsMaximized());
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698