Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / ui / ash / system_tray_delegate_chromeos_browsertest_chromeos.cc
blob098238d8f5a465caa6df2c40c9954f04954b601c
1 // Copyright 2014 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.
5 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
7 #include <string>
9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "ash/system/date/date_default_view.h"
12 #include "ash/system/date/date_view.h"
13 #include "ash/system/date/tray_date.h"
14 #include "ash/test/display_manager_test_api.h"
15 #include "base/prefs/pref_service.h"
16 #include "chrome/browser/chromeos/login/login_manager_test.h"
17 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
18 #include "chrome/browser/chromeos/login/startup_utils.h"
19 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/chrome_pages.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/user_manager/user_manager.h"
29 #include "content/public/test/test_utils.h"
30 #include "ui/message_center/message_center.h"
31 #include "ui/message_center/notification_list.h"
33 namespace chromeos {
35 namespace {
37 // Because policy is not needed this test it is better to use e-mails that
38 // are definitely not enterprise. This lets us to avoid faking of policy fetch
39 // procedure.
40 const char kUser1[] = "user1@gmail.com";
41 const char kUser2[] = "user2@gmail.com";
43 base::HourClockType GetHourType() {
44 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
45 ->GetPrimarySystemTray()
46 ->GetTrayDateForTesting();
47 const ash::DateDefaultView* date_default_view =
48 tray_date->GetDefaultViewForTesting();
50 return date_default_view->GetDateView()->GetHourTypeForTesting();
53 void CreateDefaultView() {
54 ash::TrayDate* tray_date = ash::Shell::GetInstance()
55 ->GetPrimarySystemTray()
56 ->GetTrayDateForTesting();
57 tray_date->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE);
60 } // namespace
62 class DisplayNotificationsTest : public InProcessBrowserTest {
63 public:
64 DisplayNotificationsTest() {}
65 ~DisplayNotificationsTest() override {}
67 void SetUp() override { InProcessBrowserTest::SetUp(); }
69 void UpdateDisplay(const std::string& display_specs) {
70 ash::test::DisplayManagerTestApi().UpdateDisplay(display_specs);
73 message_center::NotificationList::Notifications GetVisibleNotifications()
74 const {
75 return message_center::MessageCenter::Get()->GetVisibleNotifications();
79 class SystemTrayDelegateChromeOSTest : public LoginManagerTest {
80 protected:
81 SystemTrayDelegateChromeOSTest()
82 : LoginManagerTest(false /* should_launch_browser */) {}
84 ~SystemTrayDelegateChromeOSTest() override {}
86 void SetupUserProfile(std::string user_name, bool use_24_hour_clock) {
87 const user_manager::User* user =
88 user_manager::UserManager::Get()->FindUser(user_name);
89 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
90 profile->GetPrefs()->SetBoolean(prefs::kUse24HourClock, use_24_hour_clock);
93 private:
94 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest);
97 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
98 PRE_TestMultiProfile24HourClock) {
99 RegisterUser(kUser1);
100 RegisterUser(kUser2);
101 StartupUtils::MarkOobeCompleted();
104 // Test that clock type is taken from user profile for current active user.
105 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
106 TestMultiProfile24HourClock) {
107 LoginUser(kUser1);
108 SetupUserProfile(kUser1, true /* Use_24_hour_clock. */);
109 CreateDefaultView();
110 EXPECT_EQ(base::k24HourClock, GetHourType());
111 UserAddingScreen::Get()->Start();
112 content::RunAllPendingInMessageLoop();
113 AddUser(kUser2);
114 SetupUserProfile(kUser2, false /* Use_24_hour_clock. */);
115 CreateDefaultView();
116 EXPECT_EQ(base::k12HourClock, GetHourType());
117 user_manager::UserManager::Get()->SwitchActiveUser(kUser1);
118 CreateDefaultView();
119 EXPECT_EQ(base::k24HourClock, GetHourType());
122 // Makes sure that no notifications are shown when rotating the
123 // display on display settings URLs.
124 IN_PROC_BROWSER_TEST_F(DisplayNotificationsTest,
125 TestDisplayOrientationChangeNotification) {
126 // Open the display settings page.
127 ui_test_utils::NavigateToURL(browser(),
128 GURL("chrome://settings-frame/display"));
129 // Rotate the display 90 degrees.
130 UpdateDisplay("400x400/r");
131 // Ensure that no notification was displayed.
132 EXPECT_TRUE(GetVisibleNotifications().empty());
134 // Reset the display.
135 UpdateDisplay("400x400");
137 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings/display"));
138 UpdateDisplay("400x400/r");
139 EXPECT_TRUE(GetVisibleNotifications().empty());
141 UpdateDisplay("400x400");
143 ui_test_utils::NavigateToURL(browser(),
144 GURL("chrome://settings/displayOverscan"));
145 UpdateDisplay("400x400/r");
146 EXPECT_TRUE(GetVisibleNotifications().empty());
148 UpdateDisplay("400x400");
150 ui_test_utils::NavigateToURL(browser(), GURL("chrome://version"));
151 UpdateDisplay("400x400/r");
152 // Ensure that there is a notification that is shown.
153 EXPECT_FALSE(GetVisibleNotifications().empty());
156 } // namespace chromeos