Update {virtual,override,final} to follow C++11 style in chrome/browser/chromeos...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_system_use_24hour_clock_browsertest.cc
blob92215c49ffb94bf29794a86472e7ae4659006b5d
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 "ash/shell.h"
6 #include "ash/system/date/date_default_view.h"
7 #include "ash/system/date/date_view.h"
8 #include "ash/system/user/login_status.h"
9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h"
11 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
15 #include "chromeos/chromeos_switches.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace em = enterprise_management;
20 namespace chromeos {
22 class SystemUse24HourClockPolicyTest
23 : public policy::DevicePolicyCrosBrowserTest {
24 public:
25 SystemUse24HourClockPolicyTest() {
28 void SetUpCommandLine(base::CommandLine* command_line) override {
29 command_line->AppendSwitch(switches::kLoginManager);
30 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
33 void SetUpInProcessBrowserTestFixture() override {
34 InstallOwnerKey();
35 MarkAsEnterpriseOwned();
36 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
39 protected:
40 void RefreshPolicyAndWaitDeviceSettingsUpdated() {
41 scoped_ptr<CrosSettings::ObserverSubscription> observer =
42 CrosSettings::Get()->AddSettingsObserver(
43 kSystemUse24HourClock,
44 base::MessageLoop::current()->QuitWhenIdleClosure());
46 RefreshDevicePolicy();
47 base::MessageLoop::current()->Run();
50 static bool GetSystemTrayDelegateShouldUse24HourClock() {
51 chromeos::SystemTrayDelegateChromeOS* tray_delegate =
52 static_cast<chromeos::SystemTrayDelegateChromeOS*>(
53 ash::Shell::GetInstance()->system_tray_delegate());
54 return tray_delegate->GetShouldUse24HourClockForTesting();
57 static base::HourClockType TestGetPrimarySystemTrayTimeHourType() {
58 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
59 ->GetPrimarySystemTray()
60 ->GetTrayDateForTesting();
61 const ash::tray::TimeView* time_tray = tray_date->GetTimeTrayForTesting();
63 return time_tray->GetHourTypeForTesting();
66 static bool TestPrimarySystemTrayHasDateDefaultView() {
67 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
68 ->GetPrimarySystemTray()
69 ->GetTrayDateForTesting();
70 const ash::DateDefaultView* date_default_view =
71 tray_date->GetDefaultViewForTesting();
72 return (date_default_view != NULL);
75 static void TestPrimarySystemTrayCreateDefaultView() {
76 ash::TrayDate* tray_date = ash::Shell::GetInstance()
77 ->GetPrimarySystemTray()
78 ->GetTrayDateForTesting();
79 tray_date->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE);
82 static base::HourClockType TestGetPrimarySystemTrayDateHourType() {
83 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
84 ->GetPrimarySystemTray()
85 ->GetTrayDateForTesting();
86 const ash::DateDefaultView* date_default_view =
87 tray_date->GetDefaultViewForTesting();
89 return date_default_view->GetDateView()->GetHourTypeForTesting();
92 private:
93 DISALLOW_COPY_AND_ASSIGN(SystemUse24HourClockPolicyTest);
96 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckUnset) {
97 bool system_use_24hour_clock;
98 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
99 &system_use_24hour_clock));
101 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
102 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
103 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
105 TestPrimarySystemTrayCreateDefaultView();
106 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
109 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckTrue) {
110 bool system_use_24hour_clock = true;
111 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
112 &system_use_24hour_clock));
113 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
115 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
116 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
117 TestPrimarySystemTrayCreateDefaultView();
118 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
120 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
121 proto.mutable_use_24hour_clock()->set_use_24hour_clock(true);
122 RefreshPolicyAndWaitDeviceSettingsUpdated();
124 system_use_24hour_clock = false;
125 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
126 &system_use_24hour_clock));
127 EXPECT_TRUE(system_use_24hour_clock);
128 EXPECT_TRUE(GetSystemTrayDelegateShouldUse24HourClock());
129 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayTimeHourType());
131 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
132 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayDateHourType());
135 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckFalse) {
136 bool system_use_24hour_clock = true;
137 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
138 &system_use_24hour_clock));
139 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
141 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
142 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
143 TestPrimarySystemTrayCreateDefaultView();
144 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
146 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
147 proto.mutable_use_24hour_clock()->set_use_24hour_clock(false);
148 RefreshPolicyAndWaitDeviceSettingsUpdated();
150 system_use_24hour_clock = true;
151 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
152 &system_use_24hour_clock));
153 EXPECT_FALSE(system_use_24hour_clock);
154 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
155 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
156 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
157 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
160 } // namespace chromeos