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 // const char kTestUser1Hash[] = "test1@domain.com-hash"; | |
cschuet (SLOW)
2016/03/31 08:15:02
remove commented code.
Alexander Alekseev
2016/03/31 10:24:37
Done.
| |
4004 } // anonymous namespace | |
4005 | |
4006 class ChromeOSPolicyTest : public PolicyTest { | |
4007 public: | |
4008 ChromeOSPolicyTest() {} | |
4009 | |
4010 void SetUpCommandLine(base::CommandLine* command_line) override { | |
4011 PolicyTest::SetUpCommandLine(command_line); | |
4012 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, | |
4013 cryptohome_id1_.id()); | |
4014 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash"); | |
4015 command_line->AppendSwitch( | |
4016 chromeos::switches::kAllowFailedPolicyFetchForTest); | |
4017 | |
4018 command_line->AppendSwitch( | |
4019 chromeos::switches::kEnableSystemTimezoneAutomaticDetectionPolicy); | |
4020 } | |
4021 | |
4022 protected: | |
4023 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); | |
4024 const cryptohome::Identification cryptohome_id1_ = | |
4025 cryptohome::Identification(test_account_id1_); | |
4026 | |
4027 // Logs in |account_id|. | |
4028 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { | |
4029 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, | |
4030 false); | |
4031 base::RunLoop().RunUntilIdle(); | |
4032 } | |
4033 | |
4034 void NavigateToUrl(const GURL& url) { | |
4035 ui_test_utils::NavigateToURL(browser(), url); | |
4036 base::RunLoop().RunUntilIdle(); | |
4037 } | |
4038 | |
4039 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() { | |
4040 PrefService* local_state = g_browser_process->local_state(); | |
4041 EXPECT_FALSE(local_state->IsManagedPreference( | |
4042 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4043 EXPECT_EQ(0, local_state->GetInteger( | |
4044 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4045 } | |
4046 | |
4047 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) { | |
4048 PolicyMap policies; | |
4049 policies.Set(key::kSystemTimezoneAutomaticDetection, | |
4050 POLICY_LEVEL_MANDATORY, | |
4051 POLICY_SCOPE_MACHINE, | |
4052 POLICY_SOURCE_CLOUD, | |
4053 new base::FundamentalValue(policy_value), | |
4054 NULL); | |
4055 UpdateProviderPolicy(policies); | |
4056 | |
4057 PrefService* local_state = g_browser_process->local_state(); | |
4058 | |
4059 EXPECT_TRUE(local_state->IsManagedPreference( | |
4060 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4061 EXPECT_EQ(policy_value, | |
4062 local_state->GetInteger( | |
4063 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4064 } | |
4065 | |
4066 void SetEmptyPolicy() { UpdateProviderPolicy(PolicyMap()); } | |
4067 | |
4068 bool CheckResolveTimezoneByGeolocation(bool checked, bool disabled) { | |
4069 checker.set_web_contents( | |
4070 browser()->tab_strip_model()->GetActiveWebContents()); | |
4071 const std::string expression = base::StringPrintf( | |
4072 "(function () {\n" | |
4073 " var checkbox = " | |
4074 "document.getElementById('resolve-timezone-by-geolocation');\n" | |
4075 " if (!checkbox) {\n" | |
4076 " console.log('resolve-timezone-by-geolocation not found.');\n" | |
4077 " return false;\n" | |
4078 " }\n" | |
4079 " var expected_checked = %s;\n" | |
4080 " var expected_disabled = %s;\n" | |
4081 " var checked = checkbox.checked;\n" | |
4082 " var disabled = checkbox.disabled;\n" | |
4083 " if (checked != expected_checked)\n" | |
4084 " console.log('ERROR: expected_checked=' + expected_checked + ' != " | |
4085 "checked=' + checked);\n" | |
4086 "\n" | |
4087 " if (disabled != expected_disabled)\n" | |
4088 " console.log('ERROR: expected_disabled=' + expected_disabled + ' " | |
4089 "!= disabled=' + disabled);\n" | |
4090 "\n" | |
4091 " return (checked == expected_checked && disabled == " | |
4092 "expected_disabled);\n" | |
4093 "})()", | |
4094 checked ? "true" : "false", disabled ? "true" : "false"); | |
4095 return checker.GetBool(expression); | |
4096 } | |
4097 | |
4098 private: | |
4099 chromeos::test::JSChecker checker; | |
4100 | |
4101 DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicyTest); | |
4102 }; | |
4103 | |
4104 IN_PROC_BROWSER_TEST_F(ChromeOSPolicyTest, SystemTimezoneAutomaticDetection) { | |
4105 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings")); | |
4106 chromeos::system::TimeZoneResolverManager* manager = | |
4107 g_browser_process->platform_part()->GetTimezoneResolverManager(); | |
4108 | |
4109 // Policy not set. | |
4110 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | |
4111 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4112 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4113 | |
4114 int policy_value = 0 /* USERS_DECIDE */; | |
4115 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4116 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4117 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4118 | |
4119 policy_value = 1 /* DISABLED */; | |
4120 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4121 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); | |
4122 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4123 | |
4124 policy_value = 2 /* IP_ONLY */; | |
4125 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4126 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); | |
4127 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4128 | |
4129 policy_value = 3 /* SEND_WIFI_ACCESS_POINTS */; | |
4130 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4131 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); | |
4132 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4133 | |
4134 policy_value = 1 /* DISABLED */; | |
4135 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4136 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); | |
4137 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4138 | |
4139 SetEmptyPolicy(); | |
4140 // Policy not set. | |
4141 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | |
4142 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4143 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4144 } | |
3994 #endif // defined(OS_CHROMEOS) | 4145 #endif // defined(OS_CHROMEOS) |
3995 | 4146 |
3996 } // namespace policy | 4147 } // namespace policy |
OLD | NEW |