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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 #include "ui/base/resource/resource_bundle.h" | 184 #include "ui/base/resource/resource_bundle.h" |
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/login/test/js_checker.h" |
| 195 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" |
194 #include "chrome/browser/profiles/profile_manager.h" | 196 #include "chrome/browser/profiles/profile_manager.h" |
195 #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" | 197 #include "chrome/browser/ui/ash/chrome_screenshot_grabber.h" |
196 #include "chromeos/audio/cras_audio_handler.h" | 198 #include "chromeos/audio/cras_audio_handler.h" |
| 199 #include "chromeos/chromeos_switches.h" |
| 200 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 201 #include "components/signin/core/account_id/account_id.h" |
| 202 #include "components/user_manager/user_manager.h" |
197 #include "ui/chromeos/accessibility_types.h" | 203 #include "ui/chromeos/accessibility_types.h" |
198 #include "ui/keyboard/keyboard_util.h" | 204 #include "ui/keyboard/keyboard_util.h" |
199 #include "ui/snapshot/screenshot_grabber.h" | 205 #include "ui/snapshot/screenshot_grabber.h" |
200 #endif | 206 #endif |
201 | 207 |
202 #if !defined(OS_MACOSX) | 208 #if !defined(OS_MACOSX) |
203 #include "base/compiler_specific.h" | 209 #include "base/compiler_specific.h" |
204 #include "chrome/browser/ui/extensions/app_launch_params.h" | 210 #include "chrome/browser/ui/extensions/app_launch_params.h" |
205 #include "chrome/browser/ui/extensions/application_launch.h" | 211 #include "chrome/browser/ui/extensions/application_launch.h" |
206 #include "extensions/browser/app_window/app_window.h" | 212 #include "extensions/browser/app_window/app_window.h" |
(...skipping 3777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3984 EXPECT_TRUE(display_manager->unified_desktop_enabled()); | 3990 EXPECT_TRUE(display_manager->unified_desktop_enabled()); |
3985 policies.Set(key::kUnifiedDesktopEnabledByDefault, | 3991 policies.Set(key::kUnifiedDesktopEnabledByDefault, |
3986 POLICY_LEVEL_MANDATORY, | 3992 POLICY_LEVEL_MANDATORY, |
3987 POLICY_SCOPE_USER, | 3993 POLICY_SCOPE_USER, |
3988 POLICY_SOURCE_CLOUD, | 3994 POLICY_SOURCE_CLOUD, |
3989 new base::FundamentalValue(false), | 3995 new base::FundamentalValue(false), |
3990 NULL); | 3996 NULL); |
3991 UpdateProviderPolicy(policies); | 3997 UpdateProviderPolicy(policies); |
3992 EXPECT_FALSE(display_manager->unified_desktop_enabled()); | 3998 EXPECT_FALSE(display_manager->unified_desktop_enabled()); |
3993 } | 3999 } |
| 4000 |
| 4001 namespace { |
| 4002 const char kTestUser1[] = "test1@domain.com"; |
| 4003 } // anonymous namespace |
| 4004 |
| 4005 class ChromeOSPolicyTest : public PolicyTest { |
| 4006 public: |
| 4007 ChromeOSPolicyTest() {} |
| 4008 |
| 4009 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 4010 PolicyTest::SetUpCommandLine(command_line); |
| 4011 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, |
| 4012 cryptohome_id1_.id()); |
| 4013 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash"); |
| 4014 command_line->AppendSwitch( |
| 4015 chromeos::switches::kAllowFailedPolicyFetchForTest); |
| 4016 |
| 4017 command_line->AppendSwitch( |
| 4018 chromeos::switches::kEnableSystemTimezoneAutomaticDetectionPolicy); |
| 4019 } |
| 4020 |
| 4021 protected: |
| 4022 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); |
| 4023 const cryptohome::Identification cryptohome_id1_ = |
| 4024 cryptohome::Identification(test_account_id1_); |
| 4025 |
| 4026 // Logs in |account_id|. |
| 4027 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { |
| 4028 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, |
| 4029 false); |
| 4030 base::RunLoop().RunUntilIdle(); |
| 4031 } |
| 4032 |
| 4033 void NavigateToUrl(const GURL& url) { |
| 4034 ui_test_utils::NavigateToURL(browser(), url); |
| 4035 base::RunLoop().RunUntilIdle(); |
| 4036 } |
| 4037 |
| 4038 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() { |
| 4039 PrefService* local_state = g_browser_process->local_state(); |
| 4040 EXPECT_FALSE(local_state->IsManagedPreference( |
| 4041 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4042 EXPECT_EQ(0, local_state->GetInteger( |
| 4043 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4044 } |
| 4045 |
| 4046 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) { |
| 4047 PolicyMap policies; |
| 4048 policies.Set(key::kSystemTimezoneAutomaticDetection, |
| 4049 POLICY_LEVEL_MANDATORY, |
| 4050 POLICY_SCOPE_MACHINE, |
| 4051 POLICY_SOURCE_CLOUD, |
| 4052 new base::FundamentalValue(policy_value), |
| 4053 NULL); |
| 4054 UpdateProviderPolicy(policies); |
| 4055 |
| 4056 PrefService* local_state = g_browser_process->local_state(); |
| 4057 |
| 4058 EXPECT_TRUE(local_state->IsManagedPreference( |
| 4059 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4060 EXPECT_EQ(policy_value, |
| 4061 local_state->GetInteger( |
| 4062 prefs::kSystemTimezoneAutomaticDetectionPolicy)); |
| 4063 } |
| 4064 |
| 4065 void SetEmptyPolicy() { UpdateProviderPolicy(PolicyMap()); } |
| 4066 |
| 4067 bool CheckResolveTimezoneByGeolocation(bool checked, bool disabled) { |
| 4068 checker.set_web_contents( |
| 4069 browser()->tab_strip_model()->GetActiveWebContents()); |
| 4070 const std::string expression = base::StringPrintf( |
| 4071 "(function () {\n" |
| 4072 " var checkbox = " |
| 4073 "document.getElementById('resolve-timezone-by-geolocation');\n" |
| 4074 " if (!checkbox) {\n" |
| 4075 " console.log('resolve-timezone-by-geolocation not found.');\n" |
| 4076 " return false;\n" |
| 4077 " }\n" |
| 4078 " var expected_checked = %s;\n" |
| 4079 " var expected_disabled = %s;\n" |
| 4080 " var checked = checkbox.checked;\n" |
| 4081 " var disabled = checkbox.disabled;\n" |
| 4082 " if (checked != expected_checked)\n" |
| 4083 " console.log('ERROR: expected_checked=' + expected_checked + ' != " |
| 4084 "checked=' + checked);\n" |
| 4085 "\n" |
| 4086 " if (disabled != expected_disabled)\n" |
| 4087 " console.log('ERROR: expected_disabled=' + expected_disabled + ' " |
| 4088 "!= disabled=' + disabled);\n" |
| 4089 "\n" |
| 4090 " return (checked == expected_checked && disabled == " |
| 4091 "expected_disabled);\n" |
| 4092 "})()", |
| 4093 checked ? "true" : "false", disabled ? "true" : "false"); |
| 4094 return checker.GetBool(expression); |
| 4095 } |
| 4096 |
| 4097 private: |
| 4098 chromeos::test::JSChecker checker; |
| 4099 |
| 4100 DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicyTest); |
| 4101 }; |
| 4102 |
| 4103 IN_PROC_BROWSER_TEST_F(ChromeOSPolicyTest, SystemTimezoneAutomaticDetection) { |
| 4104 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings")); |
| 4105 chromeos::system::TimeZoneResolverManager* manager = |
| 4106 g_browser_process->platform_part()->GetTimezoneResolverManager(); |
| 4107 |
| 4108 // Policy not set. |
| 4109 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
| 4110 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4111 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4112 |
| 4113 int policy_value = 0 /* USERS_DECIDE */; |
| 4114 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4115 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4116 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4117 |
| 4118 policy_value = 1 /* DISABLED */; |
| 4119 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4120 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); |
| 4121 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4122 |
| 4123 policy_value = 2 /* IP_ONLY */; |
| 4124 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4125 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); |
| 4126 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4127 |
| 4128 policy_value = 3 /* SEND_WIFI_ACCESS_POINTS */; |
| 4129 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4130 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); |
| 4131 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4132 |
| 4133 policy_value = 1 /* DISABLED */; |
| 4134 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); |
| 4135 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); |
| 4136 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4137 |
| 4138 SetEmptyPolicy(); |
| 4139 // Policy not set. |
| 4140 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
| 4141 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
| 4142 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
| 4143 } |
3994 #endif // defined(OS_CHROMEOS) | 4144 #endif // defined(OS_CHROMEOS) |
3995 | 4145 |
3996 } // namespace policy | 4146 } // namespace policy |
OLD | NEW |