OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 #include "url/gurl.h" | 185 #include "url/gurl.h" |
186 #include "url/origin.h" | 186 #include "url/origin.h" |
187 | 187 |
188 #if defined(OS_CHROMEOS) | 188 #if defined(OS_CHROMEOS) |
189 #include "ash/accelerators/accelerator_controller.h" | 189 #include "ash/accelerators/accelerator_controller.h" |
190 #include "ash/accelerators/accelerator_table.h" | 190 #include "ash/accelerators/accelerator_table.h" |
191 #include "ash/shell.h" | 191 #include "ash/shell.h" |
192 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 192 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
193 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" | 193 #include "chrome/browser/chromeos/accessibility/magnification_manager.h" |
194 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 194 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 195 #include "chrome/browser/chromeos/login/test/js_checker.h" |
| 196 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" |
195 #include "chrome/browser/profiles/profile_manager.h" | 197 #include "chrome/browser/profiles/profile_manager.h" |
196 #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" | 198 #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" |
197 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 199 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
198 #include "chromeos/audio/cras_audio_handler.h" | 200 #include "chromeos/audio/cras_audio_handler.h" |
| 201 #include "chromeos/chromeos_switches.h" |
| 202 #include "chromeos/cryptohome/cryptohome_parameters.h" |
199 #include "chromeos/dbus/dbus_thread_manager.h" | 203 #include "chromeos/dbus/dbus_thread_manager.h" |
200 #include "chromeos/dbus/fake_session_manager_client.h" | 204 #include "chromeos/dbus/fake_session_manager_client.h" |
201 #include "chromeos/dbus/session_manager_client.h" | 205 #include "chromeos/dbus/session_manager_client.h" |
202 #include "components/arc/arc_bridge_service.h" | 206 #include "components/arc/arc_bridge_service.h" |
203 #include "components/arc/arc_bridge_service_impl.h" | 207 #include "components/arc/arc_bridge_service_impl.h" |
204 #include "components/arc/arc_service_manager.h" | 208 #include "components/arc/arc_service_manager.h" |
205 #include "components/arc/test/fake_arc_bridge_bootstrap.h" | 209 #include "components/arc/test/fake_arc_bridge_bootstrap.h" |
206 #include "components/arc/test/fake_arc_bridge_instance.h" | 210 #include "components/arc/test/fake_arc_bridge_instance.h" |
| 211 #include "components/signin/core/account_id/account_id.h" |
| 212 #include "components/user_manager/user_manager.h" |
207 #include "ui/chromeos/accessibility_types.h" | 213 #include "ui/chromeos/accessibility_types.h" |
208 #include "ui/keyboard/keyboard_util.h" | 214 #include "ui/keyboard/keyboard_util.h" |
209 #include "ui/snapshot/screenshot_grabber.h" | 215 #include "ui/snapshot/screenshot_grabber.h" |
210 #endif | 216 #endif |
211 | 217 |
212 #if !defined(OS_MACOSX) | 218 #if !defined(OS_MACOSX) |
213 #include "base/compiler_specific.h" | 219 #include "base/compiler_specific.h" |
214 #include "chrome/browser/ui/extensions/app_launch_params.h" | 220 #include "chrome/browser/ui/extensions/app_launch_params.h" |
215 #include "chrome/browser/ui/extensions/application_launch.h" | 221 #include "chrome/browser/ui/extensions/application_launch.h" |
216 #include "extensions/browser/app_window/app_window.h" | 222 #include "extensions/browser/app_window/app_window.h" |
(...skipping 3857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4074 POLICY_SCOPE_USER, | 4080 POLICY_SCOPE_USER, |
4075 POLICY_SOURCE_CLOUD, | 4081 POLICY_SOURCE_CLOUD, |
4076 new base::FundamentalValue(false), | 4082 new base::FundamentalValue(false), |
4077 nullptr); | 4083 nullptr); |
4078 UpdateProviderPolicy(policies); | 4084 UpdateProviderPolicy(policies); |
4079 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); | 4085 EXPECT_FALSE(pref->GetBoolean(prefs::kArcEnabled)); |
4080 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); | 4086 EXPECT_EQ(arc::ArcBridgeService::State::STOPPED, arc_bridge_service->state()); |
4081 | 4087 |
4082 TearDownTest(); | 4088 TearDownTest(); |
4083 } | 4089 } |
| 4090 |
| 4091 namespace { |
| 4092 const char kTestUser1[] = "test1@domain.com"; |
| 4093 } // anonymous namespace |
| 4094 |
| 4095 class ChromeOSPolicyTest : public PolicyTest { |
| 4096 public: |
| 4097 ChromeOSPolicyTest() {} |
| 4098 |
| 4099 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 4100 PolicyTest::SetUpCommandLine(command_line); |
| 4101 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, |
| 4102 cryptohome_id1_.id()); |
| 4103 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash"); |
| 4104 command_line->AppendSwitch( |
| 4105 chromeos::switches::kAllowFailedPolicyFetchForTest); |
| 4106 |
| 4107 command_line->AppendSwitch( |
| 4108 chromeos::switches::kEnableSystemTimezoneAutomaticDetectionPolicy); |
| 4109 } |
| 4110 |
| 4111 protected: |
| 4112 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); |
| 4113 const cryptohome::Identification cryptohome_id1_ = |
| 4114 cryptohome::Identification(test_account_id1_); |
| 4115 |
| 4116 // Logs in |account_id|. |
| 4117 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { |
| 4118 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, |
| 4119 false); |
| 4120 base::RunLoop().RunUntilIdle(); |
| 4121 } |
| 4122 |
| 4123 void NavigateToUrl(const GURL& url) { |
| 4124 ui_test_utils::NavigateToURL(browser(), url); |
| 4125 base::RunLoop().RunUntilIdle(); |
| 4126 } |
| 4127 |
| 4128 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() { |
| 4129 PrefService* local_state = g_browser_process->local_state(); |
| 4130 EXPECT_FALSE(local_state->IsManagedPreference( |
| 4131 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4132 EXPECT_EQ(0, local_state->GetInteger( |
| 4133 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4134 } |
| 4135 |
| 4136 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) { |
| 4137 PolicyMap policies; |
| 4138 policies.Set(key::kSystemTimezoneAutomaticDetection, |
| 4139 POLICY_LEVEL_MANDATORY, |
| 4140 POLICY_SCOPE_MACHINE, |
| 4141 POLICY_SOURCE_CLOUD, |
| 4142 new base::FundamentalValue(policy_value), |
| 4143 NULL); |
| 4144 UpdateProviderPolicy(policies); |
| 4145 |
| 4146 PrefService* local_state = g_browser_process->local_state(); |
| 4147 |
| 4148 EXPECT_TRUE(local_state->IsManagedPreference( |
| 4149 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4150 EXPECT_EQ(policy_value, |
| 4151 local_state->GetInteger( |
| 4152 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4153 } |
| 4154 |
| 4155 void SetEmptyPolicy() { UpdateProviderPolicy(PolicyMap()); } |
| 4156 |
| 4157 bool CheckResolveTimezoneByGeolocation(bool checked, bool disabled) { |
| 4158 checker.set_web_contents( |
| 4159 browser()->tab_strip_model()->GetActiveWebContents()); |
| 4160 const std::string expression = base::StringPrintf( |
| 4161 "(function () {\n" |
| 4162 " var checkbox = " |
| 4163 "document.getElementById('resolve-timezone-by-geolocation');\n" |
| 4164 " if (!checkbox) {\n" |
| 4165 " console.log('resolve-timezone-by-geolocation not found.');\n" |
| 4166 " return false;\n" |
| 4167 " }\n" |
| 4168 " var expected_checked = %s;\n" |
| 4169 " var expected_disabled = %s;\n" |
| 4170 " var checked = checkbox.checked;\n" |
| 4171 " var disabled = checkbox.disabled;\n" |
| 4172 " if (checked != expected_checked)\n" |
| 4173 " console.log('ERROR: expected_checked=' + expected_checked + ' != " |
| 4174 "checked=' + checked);\n" |
| 4175 "\n" |
| 4176 " if (disabled != expected_disabled)\n" |
| 4177 " console.log('ERROR: expected_disabled=' + expected_disabled + ' " |
| 4178 "!= disabled=' + disabled);\n" |
| 4179 "\n" |
| 4180 " return (checked == expected_checked && disabled == " |
| 4181 "expected_disabled);\n" |
| 4182 "})()", |
| 4183 checked ? "true" : "false", disabled ? "true" : "false"); |
| 4184 return checker.GetBool(expression); |
| 4185 } |
| 4186 |
| 4187 private: |
| 4188 chromeos::test::JSChecker checker; |
| 4189 |
| 4190 DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicyTest); |
| 4191 }; |
| 4192 |
| 4193 IN_PROC_BROWSER_TEST_F(ChromeOSPolicyTest, SystemTimezoneAutomaticDetection) { |
| 4194 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings")); |
| 4195 chromeos::system::TimeZoneResolverManager* manager = |
| 4196 g_browser_process->platform_part()->GetTimezoneResolverManager(); |
| 4197 |
| 4198 // Policy not set. |
| 4199 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
| 4200 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4201 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4202 |
| 4203 int policy_value = 0 /* USERS_DECIDE */; |
| 4204 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4205 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4206 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4207 |
| 4208 policy_value = 1 /* DISABLED */; |
| 4209 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4210 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); |
| 4211 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4212 |
| 4213 policy_value = 2 /* IP_ONLY */; |
| 4214 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4215 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); |
| 4216 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4217 |
| 4218 policy_value = 3 /* SEND_WIFI_ACCESS_POINTS */; |
| 4219 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4220 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); |
| 4221 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4222 |
| 4223 policy_value = 1 /* DISABLED */; |
| 4224 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4225 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); |
| 4226 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4227 |
| 4228 SetEmptyPolicy(); |
| 4229 // Policy not set. |
| 4230 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
| 4231 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4232 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4233 } |
4084 #endif // defined(OS_CHROMEOS) | 4234 #endif // defined(OS_CHROMEOS) |
4085 | 4235 |
4086 } // namespace policy | 4236 } // namespace policy |
OLD | NEW |