Skip to content

Commit

Permalink
24hour clock now using current active user's settings
Browse files Browse the repository at this point in the history
BUG=386949
TEST=SystemTrayDelegateChromeOSTest.TestMultiProfile24HourClock

Review URL: https://codereview.chromium.org/784903002

Cr-Commit-Position: refs/heads/master@{#309186}
  • Loading branch information
rsorokin authored and Commit bot committed Dec 19, 2014
1 parent 33cad73 commit c957804
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 1 deletion.
1 change: 1 addition & 0 deletions chrome/browser/chromeos/profiles/profile_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class ProfileHelper
friend class ProfileHelperTest;
friend class ProfileListChromeOSTest;
friend class SessionStateDelegateChromeOSTest;
friend class SystemTrayDelegateChromeOSTest;

// BrowsingDataRemover::Observer implementation:
void OnBrowsingDataRemoverDone() override;
Expand Down
26 changes: 25 additions & 1 deletion chrome/browser/ui/ash/system_tray_delegate_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ SystemTrayDelegateChromeOS::SystemTrayDelegateChromeOS()
registrar_->Add(this,
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
registrar_->Add(this, chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
content::NotificationService::AllSources());

AccessibilityManager* accessibility_manager = AccessibilityManager::Get();
CHECK(accessibility_manager);
Expand Down Expand Up @@ -835,6 +837,10 @@ void SystemTrayDelegateChromeOS::UserAddedToSession(
const user_manager::User* active_user) {
}

void SystemTrayDelegateChromeOS::ActiveUserChanged(
const user_manager::User* /* active_user */) {
}

void SystemTrayDelegateChromeOS::UserChangedChildStatus(
user_manager::User* user) {
Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(user);
Expand Down Expand Up @@ -911,7 +917,6 @@ void SystemTrayDelegateChromeOS::SetProfile(Profile* profile) {
base::Bind(&SystemTrayDelegateChromeOS::UpdatePerformanceTracing,
base::Unretained(this)));

UpdateClockType();
UpdateShowLogoutButtonInTray();
UpdateLogoutDialogDuration();
UpdatePerformanceTracing();
Expand Down Expand Up @@ -953,6 +958,16 @@ bool SystemTrayDelegateChromeOS::ShouldUse24HourClock() const {
? system_use_24_hour_clock
: (base::GetHourClockType() == base::k24HourClock));

user_manager::User* active_user =
user_manager::UserManager::Get()->GetActiveUser();
if (active_user) {
Profile* user_profile = ProfileHelper::Get()->GetProfileByUser(active_user);
if (user_profile) {
user_pref =
user_profile->GetPrefs()->FindPreference(prefs::kUse24HourClock);
}
}

bool use_24_hour_clock = true;
user_pref->GetValue()->GetAsBoolean(&use_24_hour_clock);
return use_24_hour_clock;
Expand Down Expand Up @@ -1095,6 +1110,10 @@ void SystemTrayDelegateChromeOS::Observe(
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED: {
UpdateClockType();
break;
}
case chrome::NOTIFICATION_UPGRADE_RECOMMENDED: {
ash::UpdateInfo info;
GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info);
Expand Down Expand Up @@ -1268,6 +1287,11 @@ void SystemTrayDelegateChromeOS::UserAddedToSession(
GetSystemTrayNotifier()->NotifyUserAddedToSession();
}

void SystemTrayDelegateChromeOS::ActiveUserChanged(
const std::string& /* user_id */) {
UpdateClockType();
}

// Overridden from chrome::BrowserListObserver.
void SystemTrayDelegateChromeOS::OnBrowserRemoved(Browser* browser) {
NotifyIfLastWindowClosed();
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/ui/ash/system_tray_delegate_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class SystemTrayDelegateChromeOS

// Overridden from user_manager::UserManager::UserSessionStateObserver:
void UserAddedToSession(const user_manager::User* active_user) override;
void ActiveUserChanged(const user_manager::User* active_user) override;

void UserChangedChildStatus(user_manager::User* user) override;

Expand Down Expand Up @@ -237,6 +238,7 @@ class SystemTrayDelegateChromeOS

// Overridden from ash::SessionStateObserver
void UserAddedToSession(const std::string& user_id) override;
void ActiveUserChanged(const std::string& user_id) override;

// Overridden from chrome::BrowserListObserver:
void OnBrowserRemoved(Browser* browser) override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2014 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 "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"

#include <string>
#include <vector>

#include "ash/shell.h"
#include "ash/system/date/date_default_view.h"
#include "ash/system/date/date_view.h"
#include "ash/system/date/tray_date.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/session/user_session_manager.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/common/pref_names.h"
#include "components/user_manager/user_manager.h"
#include "content/public/test/test_utils.h"

namespace chromeos {

namespace {

const char* kUser1 = "user1@test.com";
const char* kUser2 = "user2@test.com";

base::HourClockType GetHourType() {
const ash::TrayDate* tray_date = ash::Shell::GetInstance()
->GetPrimarySystemTray()
->GetTrayDateForTesting();
const ash::DateDefaultView* date_default_view =
tray_date->GetDefaultViewForTesting();

return date_default_view->GetDateView()->GetHourTypeForTesting();
}

void CreateDefaultView() {
ash::TrayDate* tray_date = ash::Shell::GetInstance()
->GetPrimarySystemTray()
->GetTrayDateForTesting();
tray_date->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE);
}

} // namespace

class SystemTrayDelegateChromeOSTest : public LoginManagerTest {
protected:
SystemTrayDelegateChromeOSTest()
: LoginManagerTest(false /* should_launch_browser */) {}

virtual ~SystemTrayDelegateChromeOSTest() {}

void SetupUserProfile(std::string user_name, bool use_24_hour_clock) {
const user_manager::User* user =
user_manager::UserManager::Get()->FindUser(user_name);
Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
profile->GetPrefs()->SetBoolean(prefs::kUse24HourClock, use_24_hour_clock);
}

private:
DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest);
};

IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
PRE_TestMultiProfile24HourClock) {
RegisterUser(kUser1);
RegisterUser(kUser2);
StartupUtils::MarkOobeCompleted();
}

// Test that clock type is taken from user profile for current active user.
IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
TestMultiProfile24HourClock) {
LoginUser(kUser1);
SetupUserProfile(kUser1, true /* use_24_hour_clock */);
CreateDefaultView();
EXPECT_EQ(base::k24HourClock, GetHourType());
UserAddingScreen::Get()->Start();
content::RunAllPendingInMessageLoop();
AddUser(kUser2);
SetupUserProfile(kUser2, false /* use_24_hour_clock */);
CreateDefaultView();
EXPECT_EQ(base::k12HourClock, GetHourType());
user_manager::UserManager::Get()->SwitchActiveUser(kUser1);
CreateDefaultView();
EXPECT_EQ(base::k24HourClock, GetHourType());
}

} // namespace chromeos
1 change: 1 addition & 0 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@
'browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc',
'browser/ui/ash/launcher/launcher_favicon_loader_browsertest.cc',
'browser/ui/ash/keyboard_controller_browsertest.cc',
'browser/ui/ash/system_tray_delegate_chromeos_browsertest_chromeos.cc',
'browser/ui/ash/shelf_browsertest.cc',
'browser/ui/ash/volume_controller_browsertest_chromeos.cc',
'browser/ui/autofill/autofill_dialog_controller_browsertest.cc',
Expand Down

0 comments on commit c957804

Please sign in to comment.