Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_system_use_24hour_clock_browsertest.cc
blob8ff431db7424a90a1be8b5475c6cea3c968f1413
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/login/ui/login_display_host_impl.h"
12 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
13 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
14 #include "chrome/browser/chromeos/settings/cros_settings.h"
15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
17 #include "chromeos/chromeos_switches.h"
18 #include "content/public/test/test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h"
21 namespace em = enterprise_management;
23 namespace chromeos {
25 class SystemUse24HourClockPolicyTest
26 : public policy::DevicePolicyCrosBrowserTest {
27 public:
28 SystemUse24HourClockPolicyTest() {
31 void SetUpCommandLine(base::CommandLine* command_line) override {
32 command_line->AppendSwitch(switches::kLoginManager);
33 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
36 void SetUpInProcessBrowserTestFixture() override {
37 InstallOwnerKey();
38 MarkAsEnterpriseOwned();
39 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
42 void TearDownOnMainThread() override {
43 // If the login display is still showing, exit gracefully.
44 if (LoginDisplayHostImpl::default_host()) {
45 base::MessageLoop::current()->PostTask(FROM_HERE,
46 base::Bind(&chrome::AttemptExit));
47 content::RunMessageLoop();
51 protected:
52 void RefreshPolicyAndWaitDeviceSettingsUpdated() {
53 scoped_ptr<CrosSettings::ObserverSubscription> observer =
54 CrosSettings::Get()->AddSettingsObserver(
55 kSystemUse24HourClock,
56 base::MessageLoop::current()->QuitWhenIdleClosure());
58 RefreshDevicePolicy();
59 base::MessageLoop::current()->Run();
62 static bool GetSystemTrayDelegateShouldUse24HourClock() {
63 chromeos::SystemTrayDelegateChromeOS* tray_delegate =
64 static_cast<chromeos::SystemTrayDelegateChromeOS*>(
65 ash::Shell::GetInstance()->system_tray_delegate());
66 return tray_delegate->GetShouldUse24HourClockForTesting();
69 static base::HourClockType TestGetPrimarySystemTrayTimeHourType() {
70 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
71 ->GetPrimarySystemTray()
72 ->GetTrayDateForTesting();
73 const ash::tray::TimeView* time_tray = tray_date->GetTimeTrayForTesting();
75 return time_tray->GetHourTypeForTesting();
78 static bool TestPrimarySystemTrayHasDateDefaultView() {
79 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
80 ->GetPrimarySystemTray()
81 ->GetTrayDateForTesting();
82 const ash::DateDefaultView* date_default_view =
83 tray_date->GetDefaultViewForTesting();
84 return (date_default_view != NULL);
87 static void TestPrimarySystemTrayCreateDefaultView() {
88 ash::TrayDate* tray_date = ash::Shell::GetInstance()
89 ->GetPrimarySystemTray()
90 ->GetTrayDateForTesting();
91 tray_date->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE);
94 static base::HourClockType TestGetPrimarySystemTrayDateHourType() {
95 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
96 ->GetPrimarySystemTray()
97 ->GetTrayDateForTesting();
98 const ash::DateDefaultView* date_default_view =
99 tray_date->GetDefaultViewForTesting();
101 return date_default_view->GetDateView()->GetHourTypeForTesting();
104 private:
105 DISALLOW_COPY_AND_ASSIGN(SystemUse24HourClockPolicyTest);
108 // Disabled due to flakiness - http://crbug.com/450651.
109 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckUnset) {
110 bool system_use_24hour_clock;
111 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
112 &system_use_24hour_clock));
114 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
115 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
116 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
118 TestPrimarySystemTrayCreateDefaultView();
119 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
122 // Disabled due to flakiness - http://crbug.com/450651.
123 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckTrue) {
124 bool system_use_24hour_clock = true;
125 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
126 &system_use_24hour_clock));
127 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
129 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
130 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
131 TestPrimarySystemTrayCreateDefaultView();
132 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
134 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
135 proto.mutable_use_24hour_clock()->set_use_24hour_clock(true);
136 RefreshPolicyAndWaitDeviceSettingsUpdated();
138 system_use_24hour_clock = false;
139 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
140 &system_use_24hour_clock));
141 EXPECT_TRUE(system_use_24hour_clock);
142 EXPECT_TRUE(GetSystemTrayDelegateShouldUse24HourClock());
143 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayTimeHourType());
145 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
146 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayDateHourType());
149 // Disabled due to flakiness - http://crbug.com/450651.
150 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckFalse) {
151 bool system_use_24hour_clock = true;
152 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
153 &system_use_24hour_clock));
154 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
156 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
157 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
158 TestPrimarySystemTrayCreateDefaultView();
159 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
161 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
162 proto.mutable_use_24hour_clock()->set_use_24hour_clock(false);
163 RefreshPolicyAndWaitDeviceSettingsUpdated();
165 system_use_24hour_clock = true;
166 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
167 &system_use_24hour_clock));
168 EXPECT_FALSE(system_use_24hour_clock);
169 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
170 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
171 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
172 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
175 } // namespace chromeos