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 15 matching lines...) Expand all Loading... |
26 #include "base/memory/ptr_util.h" | 26 #include "base/memory/ptr_util.h" |
27 #include "base/memory/ref_counted.h" | 27 #include "base/memory/ref_counted.h" |
28 #include "base/message_loop/message_loop.h" | 28 #include "base/message_loop/message_loop.h" |
29 #include "base/path_service.h" | 29 #include "base/path_service.h" |
30 #include "base/run_loop.h" | 30 #include "base/run_loop.h" |
31 #include "base/strings/string16.h" | 31 #include "base/strings/string16.h" |
32 #include "base/strings/string_number_conversions.h" | 32 #include "base/strings/string_number_conversions.h" |
33 #include "base/strings/string_util.h" | 33 #include "base/strings/string_util.h" |
34 #include "base/strings/stringprintf.h" | 34 #include "base/strings/stringprintf.h" |
35 #include "base/strings/utf_string_conversions.h" | 35 #include "base/strings/utf_string_conversions.h" |
36 #include "base/test/scoped_feature_list.h" | |
37 #include "base/test/test_file_util.h" | 36 #include "base/test/test_file_util.h" |
38 #include "base/threading/sequenced_worker_pool.h" | 37 #include "base/threading/sequenced_worker_pool.h" |
39 #include "base/threading/thread_restrictions.h" | 38 #include "base/threading/thread_restrictions.h" |
40 #include "base/time/time.h" | 39 #include "base/time/time.h" |
41 #include "base/values.h" | 40 #include "base/values.h" |
42 #include "build/build_config.h" | 41 #include "build/build_config.h" |
43 #include "chrome/app/chrome_command_ids.h" | 42 #include "chrome/app/chrome_command_ids.h" |
44 #include "chrome/browser/background/background_contents_service.h" | 43 #include "chrome/browser/background/background_contents_service.h" |
45 #include "chrome/browser/browser_process.h" | 44 #include "chrome/browser/browser_process.h" |
46 #include "chrome/browser/chrome_notification_types.h" | 45 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 #include "chrome/browser/translate/chrome_translate_client.h" | 81 #include "chrome/browser/translate/chrome_translate_client.h" |
83 #include "chrome/browser/translate/translate_service.h" | 82 #include "chrome/browser/translate/translate_service.h" |
84 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" | 83 #include "chrome/browser/ui/bookmarks/bookmark_bar.h" |
85 #include "chrome/browser/ui/browser.h" | 84 #include "chrome/browser/ui/browser.h" |
86 #include "chrome/browser/ui/browser_commands.h" | 85 #include "chrome/browser/ui/browser_commands.h" |
87 #include "chrome/browser/ui/browser_list.h" | 86 #include "chrome/browser/ui/browser_list.h" |
88 #include "chrome/browser/ui/browser_tabstrip.h" | 87 #include "chrome/browser/ui/browser_tabstrip.h" |
89 #include "chrome/browser/ui/browser_window.h" | 88 #include "chrome/browser/ui/browser_window.h" |
90 #include "chrome/browser/ui/location_bar/location_bar.h" | 89 #include "chrome/browser/ui/location_bar/location_bar.h" |
91 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 90 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
92 #include "chrome/common/chrome_features.h" | |
93 #include "chrome/common/chrome_paths.h" | 91 #include "chrome/common/chrome_paths.h" |
94 #include "chrome/common/chrome_switches.h" | 92 #include "chrome/common/chrome_switches.h" |
95 #include "chrome/common/extensions/extension_constants.h" | 93 #include "chrome/common/extensions/extension_constants.h" |
96 #include "chrome/common/pref_names.h" | 94 #include "chrome/common/pref_names.h" |
97 #include "chrome/common/url_constants.h" | 95 #include "chrome/common/url_constants.h" |
98 #include "chrome/grit/generated_resources.h" | 96 #include "chrome/grit/generated_resources.h" |
99 #include "chrome/test/base/in_process_browser_test.h" | 97 #include "chrome/test/base/in_process_browser_test.h" |
100 #include "chrome/test/base/search_test_utils.h" | 98 #include "chrome/test/base/search_test_utils.h" |
101 #include "chrome/test/base/ui_test_utils.h" | 99 #include "chrome/test/base/ui_test_utils.h" |
102 #include "components/bookmarks/common/bookmark_pref_names.h" | 100 #include "components/bookmarks/common/bookmark_pref_names.h" |
(...skipping 4249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4352 test_default_geo_policy_value.GetInt() == 2); | 4350 test_default_geo_policy_value.GetInt() == 2); |
4353 EXPECT_EQ(expected_pref_managed, | 4351 EXPECT_EQ(expected_pref_managed, |
4354 pref->IsManagedPreference(prefs::kArcLocationServiceEnabled)) | 4352 pref->IsManagedPreference(prefs::kArcLocationServiceEnabled)) |
4355 << "ArcLocationServiceEnabled policy is set to " << test_policy_value | 4353 << "ArcLocationServiceEnabled policy is set to " << test_policy_value |
4356 << "DefaultGeolocationSetting policy is set to " | 4354 << "DefaultGeolocationSetting policy is set to " |
4357 << test_default_geo_policy_value; | 4355 << test_default_geo_policy_value; |
4358 } | 4356 } |
4359 } | 4357 } |
4360 } | 4358 } |
4361 | 4359 |
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) | 4360 #endif // defined(OS_CHROMEOS) |
4508 | 4361 |
4509 class NetworkTimePolicyTest : public PolicyTest { | 4362 class NetworkTimePolicyTest : public PolicyTest { |
4510 public: | 4363 public: |
4511 void SetUpCommandLine(base::CommandLine* command_line) override { | 4364 void SetUpCommandLine(base::CommandLine* command_line) override { |
4512 command_line->AppendSwitchASCII( | 4365 command_line->AppendSwitchASCII( |
4513 switches::kEnableFeatures, | 4366 switches::kEnableFeatures, |
4514 std::string(network_time::kNetworkTimeServiceQuerying.name) + | 4367 std::string(network_time::kNetworkTimeServiceQuerying.name) + |
4515 "<SSLNetworkTimeBrowserTestFieldTrial"); | 4368 "<SSLNetworkTimeBrowserTestFieldTrial"); |
4516 command_line->AppendSwitchASCII( | 4369 command_line->AppendSwitchASCII( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4577 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 4430 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
4578 base::MakeUnique<base::Value>(true), nullptr); | 4431 base::MakeUnique<base::Value>(true), nullptr); |
4579 UpdateProviderPolicy(policies); | 4432 UpdateProviderPolicy(policies); |
4580 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); | 4433 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/")); |
4581 interstitial_page = tab->GetInterstitialPage(); | 4434 interstitial_page = tab->GetInterstitialPage(); |
4582 ASSERT_TRUE(interstitial_page); | 4435 ASSERT_TRUE(interstitial_page); |
4583 EXPECT_EQ(1u, num_requests()); | 4436 EXPECT_EQ(1u, num_requests()); |
4584 } | 4437 } |
4585 | 4438 |
4586 } // namespace policy | 4439 } // namespace policy |
OLD | NEW |