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"
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 "base/prefs/pref_service.h"
15 #include "chrome/browser/chromeos/login/login_manager_test.h"
16 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
17 #include "chrome/browser/chromeos/login/startup_utils.h"
18 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
20 #include "chrome/common/pref_names.h"
21 #include "components/user_manager/user_manager.h"
22 #include "content/public/test/test_utils.h"
28 const char* kUser1
= "user1@test.com";
29 const char* kUser2
= "user2@test.com";
31 base::HourClockType
GetHourType() {
32 const ash::TrayDate
* tray_date
= ash::Shell::GetInstance()
33 ->GetPrimarySystemTray()
34 ->GetTrayDateForTesting();
35 const ash::DateDefaultView
* date_default_view
=
36 tray_date
->GetDefaultViewForTesting();
38 return date_default_view
->GetDateView()->GetHourTypeForTesting();
41 void CreateDefaultView() {
42 ash::TrayDate
* tray_date
= ash::Shell::GetInstance()
43 ->GetPrimarySystemTray()
44 ->GetTrayDateForTesting();
45 tray_date
->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE
);
50 class SystemTrayDelegateChromeOSTest
: public LoginManagerTest
{
52 SystemTrayDelegateChromeOSTest()
53 : LoginManagerTest(false /* should_launch_browser */) {}
55 ~SystemTrayDelegateChromeOSTest() override
{}
57 void SetupUserProfile(std::string user_name
, bool use_24_hour_clock
) {
58 const user_manager::User
* user
=
59 user_manager::UserManager::Get()->FindUser(user_name
);
60 Profile
* profile
= ProfileHelper::Get()->GetProfileByUser(user
);
61 profile
->GetPrefs()->SetBoolean(prefs::kUse24HourClock
, use_24_hour_clock
);
65 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest
);
68 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest
,
69 PRE_TestMultiProfile24HourClock
) {
72 StartupUtils::MarkOobeCompleted();
75 // Test that clock type is taken from user profile for current active user.
76 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest
,
77 TestMultiProfile24HourClock
) {
79 SetupUserProfile(kUser1
, true /* use_24_hour_clock */);
81 EXPECT_EQ(base::k24HourClock
, GetHourType());
82 UserAddingScreen::Get()->Start();
83 content::RunAllPendingInMessageLoop();
85 SetupUserProfile(kUser2
, false /* use_24_hour_clock */);
87 EXPECT_EQ(base::k12HourClock
, GetHourType());
88 user_manager::UserManager::Get()->SwitchActiveUser(kUser1
);
90 EXPECT_EQ(base::k24HourClock
, GetHourType());
93 } // namespace chromeos