| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shell.h" | 5 #include "ash/shell.h" |
| 6 #include "ash/system/date/date_default_view.h" | 6 #include "ash/system/date/date_default_view.h" |
| 7 #include "ash/system/date/date_view.h" | 7 #include "ash/system/date/date_view.h" |
| 8 #include "ash/system/user/login_status.h" | 8 #include "ash/system/user/login_status.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| 11 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 12 #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/policy/proto/chrome_device_policy.pb.h" |
| 13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 #include "chrome/browser/lifetime/application_lifetime.h" |
| 14 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" | 16 #include "chrome/browser/ui/ash/system_tray_delegate_chromeos.h" |
| 15 #include "chromeos/chromeos_switches.h" | 17 #include "chromeos/chromeos_switches.h" |
| 18 #include "content/public/test/test_utils.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 20 |
| 18 namespace em = enterprise_management; | 21 namespace em = enterprise_management; |
| 19 | 22 |
| 20 namespace chromeos { | 23 namespace chromeos { |
| 21 | 24 |
| 22 class SystemUse24HourClockPolicyTest | 25 class SystemUse24HourClockPolicyTest |
| 23 : public policy::DevicePolicyCrosBrowserTest { | 26 : public policy::DevicePolicyCrosBrowserTest { |
| 24 public: | 27 public: |
| 25 SystemUse24HourClockPolicyTest() { | 28 SystemUse24HourClockPolicyTest() { |
| 26 } | 29 } |
| 27 | 30 |
| 28 void SetUpCommandLine(base::CommandLine* command_line) override { | 31 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 29 command_line->AppendSwitch(switches::kLoginManager); | 32 command_line->AppendSwitch(switches::kLoginManager); |
| 30 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); | 33 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests); |
| 31 } | 34 } |
| 32 | 35 |
| 33 void SetUpInProcessBrowserTestFixture() override { | 36 void SetUpInProcessBrowserTestFixture() override { |
| 34 InstallOwnerKey(); | 37 InstallOwnerKey(); |
| 35 MarkAsEnterpriseOwned(); | 38 MarkAsEnterpriseOwned(); |
| 36 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | 39 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 37 } | 40 } |
| 38 | 41 |
| 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(); |
| 48 } |
| 49 } |
| 50 |
| 39 protected: | 51 protected: |
| 40 void RefreshPolicyAndWaitDeviceSettingsUpdated() { | 52 void RefreshPolicyAndWaitDeviceSettingsUpdated() { |
| 41 scoped_ptr<CrosSettings::ObserverSubscription> observer = | 53 scoped_ptr<CrosSettings::ObserverSubscription> observer = |
| 42 CrosSettings::Get()->AddSettingsObserver( | 54 CrosSettings::Get()->AddSettingsObserver( |
| 43 kSystemUse24HourClock, | 55 kSystemUse24HourClock, |
| 44 base::MessageLoop::current()->QuitWhenIdleClosure()); | 56 base::MessageLoop::current()->QuitWhenIdleClosure()); |
| 45 | 57 |
| 46 RefreshDevicePolicy(); | 58 RefreshDevicePolicy(); |
| 47 base::MessageLoop::current()->Run(); | 59 base::MessageLoop::current()->Run(); |
| 48 } | 60 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 tray_date->GetDefaultViewForTesting(); | 99 tray_date->GetDefaultViewForTesting(); |
| 88 | 100 |
| 89 return date_default_view->GetDateView()->GetHourTypeForTesting(); | 101 return date_default_view->GetDateView()->GetHourTypeForTesting(); |
| 90 } | 102 } |
| 91 | 103 |
| 92 private: | 104 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(SystemUse24HourClockPolicyTest); | 105 DISALLOW_COPY_AND_ASSIGN(SystemUse24HourClockPolicyTest); |
| 94 }; | 106 }; |
| 95 | 107 |
| 96 // Disabled due to flakiness - http://crbug.com/450651. | 108 // Disabled due to flakiness - http://crbug.com/450651. |
| 97 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, DISABLED_CheckUnset) { | 109 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckUnset) { |
| 98 bool system_use_24hour_clock; | 110 bool system_use_24hour_clock; |
| 99 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, | 111 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, |
| 100 &system_use_24hour_clock)); | 112 &system_use_24hour_clock)); |
| 101 | 113 |
| 102 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); | 114 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); |
| 103 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); | 115 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); |
| 104 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); | 116 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); |
| 105 | 117 |
| 106 TestPrimarySystemTrayCreateDefaultView(); | 118 TestPrimarySystemTrayCreateDefaultView(); |
| 107 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); | 119 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); |
| 108 } | 120 } |
| 109 | 121 |
| 110 // Disabled due to flakiness - http://crbug.com/450651. | 122 // Disabled due to flakiness - http://crbug.com/450651. |
| 111 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, DISABLED_CheckTrue) { | 123 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckTrue) { |
| 112 bool system_use_24hour_clock = true; | 124 bool system_use_24hour_clock = true; |
| 113 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, | 125 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, |
| 114 &system_use_24hour_clock)); | 126 &system_use_24hour_clock)); |
| 115 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); | 127 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); |
| 116 | 128 |
| 117 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); | 129 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); |
| 118 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); | 130 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); |
| 119 TestPrimarySystemTrayCreateDefaultView(); | 131 TestPrimarySystemTrayCreateDefaultView(); |
| 120 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); | 132 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); |
| 121 | 133 |
| 122 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 134 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 123 proto.mutable_use_24hour_clock()->set_use_24hour_clock(true); | 135 proto.mutable_use_24hour_clock()->set_use_24hour_clock(true); |
| 124 RefreshPolicyAndWaitDeviceSettingsUpdated(); | 136 RefreshPolicyAndWaitDeviceSettingsUpdated(); |
| 125 | 137 |
| 126 system_use_24hour_clock = false; | 138 system_use_24hour_clock = false; |
| 127 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, | 139 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, |
| 128 &system_use_24hour_clock)); | 140 &system_use_24hour_clock)); |
| 129 EXPECT_TRUE(system_use_24hour_clock); | 141 EXPECT_TRUE(system_use_24hour_clock); |
| 130 EXPECT_TRUE(GetSystemTrayDelegateShouldUse24HourClock()); | 142 EXPECT_TRUE(GetSystemTrayDelegateShouldUse24HourClock()); |
| 131 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayTimeHourType()); | 143 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayTimeHourType()); |
| 132 | 144 |
| 133 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView()); | 145 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView()); |
| 134 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayDateHourType()); | 146 EXPECT_EQ(base::k24HourClock, TestGetPrimarySystemTrayDateHourType()); |
| 135 } | 147 } |
| 136 | 148 |
| 137 // Disabled due to flakiness - http://crbug.com/450651. | 149 // Disabled due to flakiness - http://crbug.com/450651. |
| 138 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, DISABLED_CheckFalse) { | 150 IN_PROC_BROWSER_TEST_F(SystemUse24HourClockPolicyTest, CheckFalse) { |
| 139 bool system_use_24hour_clock = true; | 151 bool system_use_24hour_clock = true; |
| 140 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, | 152 EXPECT_FALSE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, |
| 141 &system_use_24hour_clock)); | 153 &system_use_24hour_clock)); |
| 142 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); | 154 EXPECT_FALSE(TestPrimarySystemTrayHasDateDefaultView()); |
| 143 | 155 |
| 144 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); | 156 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); |
| 145 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); | 157 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); |
| 146 TestPrimarySystemTrayCreateDefaultView(); | 158 TestPrimarySystemTrayCreateDefaultView(); |
| 147 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); | 159 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); |
| 148 | 160 |
| 149 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 161 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 150 proto.mutable_use_24hour_clock()->set_use_24hour_clock(false); | 162 proto.mutable_use_24hour_clock()->set_use_24hour_clock(false); |
| 151 RefreshPolicyAndWaitDeviceSettingsUpdated(); | 163 RefreshPolicyAndWaitDeviceSettingsUpdated(); |
| 152 | 164 |
| 153 system_use_24hour_clock = true; | 165 system_use_24hour_clock = true; |
| 154 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, | 166 EXPECT_TRUE(CrosSettings::Get()->GetBoolean(kSystemUse24HourClock, |
| 155 &system_use_24hour_clock)); | 167 &system_use_24hour_clock)); |
| 156 EXPECT_FALSE(system_use_24hour_clock); | 168 EXPECT_FALSE(system_use_24hour_clock); |
| 157 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); | 169 EXPECT_FALSE(GetSystemTrayDelegateShouldUse24HourClock()); |
| 158 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); | 170 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayTimeHourType()); |
| 159 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView()); | 171 EXPECT_TRUE(TestPrimarySystemTrayHasDateDefaultView()); |
| 160 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); | 172 EXPECT_EQ(base::k12HourClock, TestGetPrimarySystemTrayDateHourType()); |
| 161 } | 173 } |
| 162 | 174 |
| 163 } // namespace chromeos | 175 } // namespace chromeos |
| OLD | NEW |