Fix the duplicatedly commited composition text when switching IME.
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / device_system_use_24hour_clock_browsertest.cc
blob8d7084082f0d6d26f4a42922f8f791e60315c4bc
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 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckUnset) {
109 bool system_use_24hour_clock;
110 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
111 &system_use_24hour_clock));
113 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
114 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
115 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
117 TestPrimarySystemTrayCreateDefaultView();
118 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
121 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckTrue) {
122 bool system_use_24hour_clock = true;
123 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
124 &system_use_24hour_clock));
125 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
127 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
128 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
129 TestPrimarySystemTrayCreateDefaultView();
130 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
132 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
133 proto.mutable_use_24hour_clock()->set_use_24hour_clock(true);
134 RefreshPolicyAndWaitDeviceSettingsUpdated();
136 system_use_24hour_clock = false;
137 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
138 &system_use_24hour_clock));
139 EXPECT_TRUE(system_use_24hour_clock);
140 EXPECT_TRUE(GetSystemTrayDelegateShouldUse24HourClock());
141 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayTimeHourType());
143 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
144 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayDateHourType());
147 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckFalse) {
148 bool system_use_24hour_clock = true;
149 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
150 &system_use_24hour_clock));
151 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView());
153 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
154 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
155 TestPrimarySystemTrayCreateDefaultView();
156 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
158 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
159 proto.mutable_use_24hour_clock()->set_use_24hour_clock(false);
160 RefreshPolicyAndWaitDeviceSettingsUpdated();
162 system_use_24hour_clock = true;
163 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock,
164 &system_use_24hour_clock));
165 EXPECT_FALSE(system_use_24hour_clock);
166 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock());
167 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType());
168 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView());
169 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType());
172 } // namespace chromeos