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"
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"
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
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
);
62 class DisplayNotificationsTest
: public InProcessBrowserTest
{
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()
75 return message_center::MessageCenter::Get()->GetVisibleNotifications();
79 class SystemTrayDelegateChromeOSTest
: public LoginManagerTest
{
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
);
94 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest
);
97 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest
,
98 PRE_TestMultiProfile24HourClock
) {
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
) {
108 SetupUserProfile(kUser1
, true /* Use_24_hour_clock. */);
110 EXPECT_EQ(base::k24HourClock
, GetHourType());
111 UserAddingScreen::Get()->Start();
112 content::RunAllPendingInMessageLoop();
114 SetupUserProfile(kUser2
, false /* Use_24_hour_clock. */);
116 EXPECT_EQ(base::k12HourClock
, GetHourType());
117 user_manager::UserManager::Get()->SwitchActiveUser(kUser1
);
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