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 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 4341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4352 test_default_geo_policy_value.GetInt() == 2); | 4352 test_default_geo_policy_value.GetInt() == 2); |
4353 EXPECT_EQ(expected_pref_managed, | 4353 EXPECT_EQ(expected_pref_managed, |
4354 pref->IsManagedPreference(prefs::kArcLocationServiceEnabled)) | 4354 pref->IsManagedPreference(prefs::kArcLocationServiceEnabled)) |
4355 << "ArcLocationServiceEnabled policy is set to " << test_policy_value | 4355 << "ArcLocationServiceEnabled policy is set to " << test_policy_value |
4356 << "DefaultGeolocationSetting policy is set to " | 4356 << "DefaultGeolocationSetting policy is set to " |
4357 << test_default_geo_policy_value; | 4357 << test_default_geo_policy_value; |
4358 } | 4358 } |
4359 } | 4359 } |
4360 } | 4360 } |
4361 | 4361 |
4362 namespace { | |
4363 const char kTestUser1[] = "test1@domain.com"; | |
4364 } // anonymous namespace | |
4365 | |
4366 class ChromeOSPolicyTest : public PolicyTest { | |
4367 public: | |
4368 ChromeOSPolicyTest() {} | |
4369 | |
4370 void SetUpCommandLine(base::CommandLine* command_line) override { | |
4371 PolicyTest::SetUpCommandLine(command_line); | |
4372 command_line->AppendSwitchASCII(chromeos::switches::kLoginUser, | |
4373 cryptohome_id1_.id()); | |
4374 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, "hash"); | |
4375 command_line->AppendSwitch( | |
4376 chromeos::switches::kAllowFailedPolicyFetchForTest); | |
4377 } | |
4378 | |
4379 protected: | |
4380 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); | |
4381 const cryptohome::Identification cryptohome_id1_ = | |
4382 cryptohome::Identification(test_account_id1_); | |
4383 | |
4384 // Logs in |account_id|. | |
4385 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { | |
4386 user_manager::UserManager::Get()->UserLoggedIn(account_id, user_id_hash, | |
4387 false); | |
4388 base::RunLoop().RunUntilIdle(); | |
4389 } | |
4390 | |
4391 void NavigateToUrl(const GURL& url) { | |
4392 ui_test_utils::NavigateToURL(browser(), url); | |
4393 base::RunLoop().RunUntilIdle(); | |
4394 } | |
4395 | |
4396 void CheckSystemTimezoneAutomaticDetectionPolicyUnset() { | |
4397 PrefService* local_state = g_browser_process->local_state(); | |
4398 EXPECT_FALSE(local_state->IsManagedPreference( | |
4399 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4400 EXPECT_EQ(0, local_state->GetInteger( | |
4401 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4402 } | |
4403 | |
4404 void SetAndTestSystemTimezoneAutomaticDetectionPolicy(int policy_value) { | |
4405 PolicyMap policies; | |
4406 policies.Set(key::kSystemTimezoneAutomaticDetection, POLICY_LEVEL_MANDATORY, | |
4407 POLICY_SCOPE_MACHINE, POLICY_SOURCE_CLOUD, | |
4408 base::MakeUnique<base::Value>(policy_value), nullptr); | |
4409 UpdateProviderPolicy(policies); | |
4410 | |
4411 PrefService* local_state = g_browser_process->local_state(); | |
4412 | |
4413 EXPECT_TRUE(local_state->IsManagedPreference( | |
4414 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4415 EXPECT_EQ(policy_value, | |
4416 local_state->GetInteger( | |
4417 prefs::kSystemTimezoneAutomaticDetectionPolicy)); | |
4418 } | |
4419 | |
4420 void SetEmptyPolicy() { UpdateProviderPolicy(PolicyMap()); } | |
4421 | |
4422 bool CheckResolveTimezoneByGeolocation(bool checked, bool disabled) { | |
4423 checker.set_web_contents( | |
4424 browser()->tab_strip_model()->GetActiveWebContents()); | |
4425 const std::string expression = base::StringPrintf( | |
4426 "(function () {\n" | |
4427 " var checkbox = " | |
4428 "document.getElementById('resolve-timezone-by-geolocation');\n" | |
4429 " if (!checkbox) {\n" | |
4430 " console.log('resolve-timezone-by-geolocation not found.');\n" | |
4431 " return false;\n" | |
4432 " }\n" | |
4433 " var expected_checked = %s;\n" | |
4434 " var expected_disabled = %s;\n" | |
4435 " var checked = checkbox.checked;\n" | |
4436 " var disabled = checkbox.disabled;\n" | |
4437 " if (checked != expected_checked)\n" | |
4438 " console.log('ERROR: expected_checked=' + expected_checked + ' != " | |
4439 "checked=' + checked);\n" | |
4440 "\n" | |
4441 " if (disabled != expected_disabled)\n" | |
4442 " console.log('ERROR: expected_disabled=' + expected_disabled + ' " | |
4443 "!= disabled=' + disabled);\n" | |
4444 "\n" | |
4445 " return (checked == expected_checked && disabled == " | |
4446 "expected_disabled);\n" | |
4447 "})()", | |
4448 checked ? "true" : "false", disabled ? "true" : "false"); | |
4449 return checker.GetBool(expression); | |
4450 } | |
4451 | |
4452 private: | |
4453 chromeos::test::JSChecker checker; | |
4454 | |
4455 DISALLOW_COPY_AND_ASSIGN(ChromeOSPolicyTest); | |
4456 }; | |
4457 | |
4458 IN_PROC_BROWSER_TEST_F(ChromeOSPolicyTest, SystemTimezoneAutomaticDetection) { | |
4459 base::test::ScopedFeatureList disable_md_settings; | |
4460 disable_md_settings.InitAndDisableFeature(features::kMaterialDesignSettings); | |
4461 | |
4462 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings")); | |
4463 chromeos::system::TimeZoneResolverManager* manager = | |
4464 g_browser_process->platform_part()->GetTimezoneResolverManager(); | |
4465 | |
4466 // Policy not set. | |
4467 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | |
4468 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4469 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4470 | |
4471 int policy_value = 0 /* USERS_DECIDE */; | |
4472 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4473 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4474 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4475 | |
4476 policy_value = 1 /* DISABLED */; | |
4477 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4478 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); | |
4479 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4480 | |
4481 policy_value = 2 /* IP_ONLY */; | |
4482 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4483 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); | |
4484 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4485 | |
4486 policy_value = 3 /* SEND_WIFI_ACCESS_POINTS */; | |
4487 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4488 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); | |
4489 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4490 | |
4491 policy_value = 4 /* SEND_ALL_LOCATION_INFO */; | |
4492 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4493 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, true)); | |
4494 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4495 | |
4496 policy_value = 1 /* DISABLED */; | |
4497 SetAndTestSystemTimezoneAutomaticDetectionPolicy(policy_value); | |
4498 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(false, true)); | |
4499 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4500 | |
4501 SetEmptyPolicy(); | |
4502 // Policy not set. | |
4503 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | |
4504 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | |
4505 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | |
4506 } | |
4507 #endif // defined(OS_CHROMEOS) | 4362 #endif // defined(OS_CHROMEOS) |
4508 | 4363 |
4509 class NetworkTimePolicyTest : public PolicyTest { | 4364 class NetworkTimePolicyTest : public PolicyTest { |
4510 public: | 4365 public: |
4511 void SetUpCommandLine(base::CommandLine* command_line) override { | 4366 void SetUpCommandLine(base::CommandLine* command_line) override { |
4512 command_line->AppendSwitchASCII( | 4367 command_line->AppendSwitchASCII( |
4513 switches::kEnableFeatures, | 4368 switches::kEnableFeatures, |
4514 std::string(network_time::kNetworkTimeServiceQuerying.name) + | 4369 std::string(network_time::kNetworkTimeServiceQuerying.name) + |
4515 "<SSLNetworkTimeBrowserTestFieldTrial"); | 4370 "<SSLNetworkTimeBrowserTestFieldTrial"); |
4516 command_line->AppendSwitchASCII( | 4371 command_line->AppendSwitchASCII( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4577 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 4432 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
4578 base::MakeUnique<base::Value>(true), nullptr); | 4433 base::MakeUnique<base::Value>(true), nullptr); |
4579 UpdateProviderPolicy(policies); | 4434 UpdateProviderPolicy(policies); |
4580 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | 4435 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); |
4581 interstitial_page = tab->GetInterstitialPage(); | 4436 interstitial_page = tab->GetInterstitialPage(); |
4582 ASSERT_TRUE(interstitial_page); | 4437 ASSERT_TRUE(interstitial_page); |
4583 EXPECT_EQ(1u, num_requests()); | 4438 EXPECT_EQ(1u, num_requests()); |
4584 } | 4439 } |
4585 | 4440 |
4586 } // namespace policy | 4441 } // namespace policy |
OLD | NEW |