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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 #include "chrome/common/chrome_paths.h" | 88 #include "chrome/common/chrome_paths.h" |
89 #include "chrome/common/chrome_switches.h" | 89 #include "chrome/common/chrome_switches.h" |
90 #include "chrome/common/extensions/extension_constants.h" | 90 #include "chrome/common/extensions/extension_constants.h" |
91 #include "chrome/common/pref_names.h" | 91 #include "chrome/common/pref_names.h" |
92 #include "chrome/common/url_constants.h" | 92 #include "chrome/common/url_constants.h" |
93 #include "chrome/grit/generated_resources.h" | 93 #include "chrome/grit/generated_resources.h" |
94 #include "chrome/test/base/in_process_browser_test.h" | 94 #include "chrome/test/base/in_process_browser_test.h" |
95 #include "chrome/test/base/search_test_utils.h" | 95 #include "chrome/test/base/search_test_utils.h" |
96 #include "chrome/test/base/ui_test_utils.h" | 96 #include "chrome/test/base/ui_test_utils.h" |
97 #include "components/bookmarks/common/bookmark_pref_names.h" | 97 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 98 #include "components/component_updater/component_updater_service.h" |
98 #include "components/content_settings/core/common/content_settings.h" | 99 #include "components/content_settings/core/common/content_settings.h" |
99 #include "components/content_settings/core/common/content_settings_pattern.h" | 100 #include "components/content_settings/core/common/content_settings_pattern.h" |
100 #include "components/content_settings/core/common/pref_names.h" | 101 #include "components/content_settings/core/common/pref_names.h" |
101 #include "components/infobars/core/infobar.h" | 102 #include "components/infobars/core/infobar.h" |
102 #include "components/omnibox/browser/autocomplete_controller.h" | 103 #include "components/omnibox/browser/autocomplete_controller.h" |
103 #include "components/omnibox/browser/omnibox_edit_model.h" | 104 #include "components/omnibox/browser/omnibox_edit_model.h" |
104 #include "components/omnibox/browser/omnibox_view.h" | 105 #include "components/omnibox/browser/omnibox_view.h" |
105 #include "components/policy/core/browser/browser_policy_connector.h" | 106 #include "components/policy/core/browser/browser_policy_connector.h" |
106 #include "components/policy/core/common/external_data_fetcher.h" | 107 #include "components/policy/core/common/external_data_fetcher.h" |
107 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 108 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
108 #include "components/policy/core/common/policy_map.h" | 109 #include "components/policy/core/common/policy_map.h" |
109 #include "components/policy/core/common/policy_pref_names.h" | 110 #include "components/policy/core/common/policy_pref_names.h" |
110 #include "components/policy/core/common/policy_service.h" | 111 #include "components/policy/core/common/policy_service.h" |
111 #include "components/policy/core/common/policy_service_impl.h" | 112 #include "components/policy/core/common/policy_service_impl.h" |
112 #include "components/policy/core/common/policy_types.h" | 113 #include "components/policy/core/common/policy_types.h" |
113 #include "components/prefs/pref_service.h" | 114 #include "components/prefs/pref_service.h" |
114 #include "components/search/search.h" | 115 #include "components/search/search.h" |
115 #include "components/search_engines/template_url.h" | 116 #include "components/search_engines/template_url.h" |
116 #include "components/search_engines/template_url_service.h" | 117 #include "components/search_engines/template_url_service.h" |
117 #include "components/security_interstitials/core/controller_client.h" | 118 #include "components/security_interstitials/core/controller_client.h" |
118 #include "components/strings/grit/components_strings.h" | 119 #include "components/strings/grit/components_strings.h" |
119 #include "components/translate/core/browser/language_state.h" | 120 #include "components/translate/core/browser/language_state.h" |
120 #include "components/translate/core/browser/translate_infobar_delegate.h" | 121 #include "components/translate/core/browser/translate_infobar_delegate.h" |
| 122 #include "components/update_client/url_request_post_interceptor.h" |
121 #include "components/user_prefs/user_prefs.h" | 123 #include "components/user_prefs/user_prefs.h" |
122 #include "components/variations/service/variations_service.h" | 124 #include "components/variations/service/variations_service.h" |
123 #include "components/version_info/version_info.h" | 125 #include "components/version_info/version_info.h" |
124 #include "content/public/browser/browser_child_process_host_iterator.h" | 126 #include "content/public/browser/browser_child_process_host_iterator.h" |
125 #include "content/public/browser/browser_context.h" | 127 #include "content/public/browser/browser_context.h" |
126 #include "content/public/browser/browser_thread.h" | 128 #include "content/public/browser/browser_thread.h" |
127 #include "content/public/browser/child_process_data.h" | 129 #include "content/public/browser/child_process_data.h" |
128 #include "content/public/browser/download_item.h" | 130 #include "content/public/browser/download_item.h" |
129 #include "content/public/browser/download_manager.h" | 131 #include "content/public/browser/download_manager.h" |
130 #include "content/public/browser/gpu_data_manager.h" | 132 #include "content/public/browser/gpu_data_manager.h" |
(...skipping 3555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3686 WebRtcUdpPortRangeDisabled) { | 3688 WebRtcUdpPortRangeDisabled) { |
3687 std::string port_range; | 3689 std::string port_range; |
3688 const PrefService::Preference* pref = | 3690 const PrefService::Preference* pref = |
3689 user_prefs::UserPrefs::Get(browser()->profile()) | 3691 user_prefs::UserPrefs::Get(browser()->profile()) |
3690 ->FindPreference(prefs::kWebRTCUDPPortRange); | 3692 ->FindPreference(prefs::kWebRTCUDPPortRange); |
3691 pref->GetValue()->GetAsString(&port_range); | 3693 pref->GetValue()->GetAsString(&port_range); |
3692 EXPECT_TRUE(port_range.empty()); | 3694 EXPECT_TRUE(port_range.empty()); |
3693 } | 3695 } |
3694 #endif // defined(ENABLE_WEBRTC) | 3696 #endif // defined(ENABLE_WEBRTC) |
3695 | 3697 |
| 3698 // Tests the ComponentUpdater's EnabledComponentUpdates group policy by |
| 3699 // calling the OnDemand interface. It uses the network interceptor to inspect |
| 3700 // the presence of the updatedisabled="true" attribute in the update check |
| 3701 // request. The update check request is expected to fail, since CUP fails. |
| 3702 class ComponentUpdaterPolicyTest : public PolicyTest { |
| 3703 public: |
| 3704 ComponentUpdaterPolicyTest(); |
| 3705 ~ComponentUpdaterPolicyTest() override; |
| 3706 |
| 3707 protected: |
| 3708 using TestCaseAction = void (ComponentUpdaterPolicyTest::*)(); |
| 3709 using TestCase = std::pair<TestCaseAction, TestCaseAction>; |
| 3710 |
| 3711 // These test scenarios run as part of one test case by using the |
| 3712 // CallAsync helper, which calls OnDemand, then chains up to the next |
| 3713 // scenario when the OnDemandComplete callback fires. |
| 3714 void DefaultPolicy_GroupPolicySupported(); |
| 3715 void FinishDefaultPolicy_GroupPolicySupported(); |
| 3716 |
| 3717 void DefaultPolicy_GroupPolicyNotSupported(); |
| 3718 void FinishDefaultPolicy_GroupPolicyNotSupported(); |
| 3719 |
| 3720 void EnabledPolicy_GroupPolicySupported(); |
| 3721 void FinishEnabledPolicy_GroupPolicySupported(); |
| 3722 |
| 3723 void EnabledPolicy_GroupPolicyNotSupported(); |
| 3724 void FinishEnabledPolicy_GroupPolicyNotSupported(); |
| 3725 |
| 3726 void DisabledPolicy_GroupPolicySupported(); |
| 3727 void FinishDisabled_PolicyGroupPolicySupported(); |
| 3728 |
| 3729 void DisabledPolicy_GroupPolicyNotSupported(); |
| 3730 void FinishDisabledPolicy_GroupPolicyNotSupported(); |
| 3731 |
| 3732 void BeginTest(); |
| 3733 void EndTest(); |
| 3734 |
| 3735 void UpdateComponent(const update_client::CrxComponent& crx_component); |
| 3736 void CallAsync(TestCaseAction action); |
| 3737 void VerifyExpectations(bool update_disabled); |
| 3738 |
| 3739 void SetEnableComponentUpdates(bool enable_component_updates); |
| 3740 |
| 3741 static update_client::CrxComponent MakeCrxComponent( |
| 3742 bool supports_group_policy_enable_component_updates); |
| 3743 |
| 3744 TestCase cur_test_case_; |
| 3745 |
| 3746 static const char component_id_[]; |
| 3747 |
| 3748 static const bool kUpdateDisabled = true; |
| 3749 |
| 3750 private: |
| 3751 void OnDemandComplete(int error); |
| 3752 |
| 3753 std::unique_ptr<update_client::URLRequestPostInterceptorFactory> |
| 3754 interceptor_factory_; |
| 3755 |
| 3756 // This member is owned by the |interceptor_factory_|. |
| 3757 update_client::URLRequestPostInterceptor* post_interceptor_ = nullptr; |
| 3758 |
| 3759 // This member is owned by g_browser_process; |
| 3760 component_updater::ComponentUpdateService* cus_; |
| 3761 |
| 3762 DISALLOW_COPY_AND_ASSIGN(ComponentUpdaterPolicyTest); |
| 3763 }; |
| 3764 |
| 3765 const char ComponentUpdaterPolicyTest::component_id_[] = |
| 3766 "jebgalgnebhfojomionfpkfelancnnkf"; |
| 3767 |
| 3768 ComponentUpdaterPolicyTest::ComponentUpdaterPolicyTest() {} |
| 3769 |
| 3770 ComponentUpdaterPolicyTest::~ComponentUpdaterPolicyTest() {} |
| 3771 |
| 3772 void ComponentUpdaterPolicyTest::SetEnableComponentUpdates( |
| 3773 bool enable_component_updates) { |
| 3774 PolicyMap policies; |
| 3775 policies.Set( |
| 3776 key::kComponentUpdatesEnabled, POLICY_LEVEL_MANDATORY, |
| 3777 POLICY_SCOPE_MACHINE, POLICY_SOURCE_ENTERPRISE_DEFAULT, |
| 3778 base::WrapUnique(new base::FundamentalValue(enable_component_updates)), |
| 3779 nullptr); |
| 3780 UpdateProviderPolicy(policies); |
| 3781 } |
| 3782 |
| 3783 update_client::CrxComponent ComponentUpdaterPolicyTest::MakeCrxComponent( |
| 3784 bool supports_group_policy_enable_component_updates) { |
| 3785 class MockInstaller : public update_client::CrxInstaller { |
| 3786 public: |
| 3787 MockInstaller() {} |
| 3788 |
| 3789 MOCK_METHOD1(OnUpdateError, void(int error)); |
| 3790 MOCK_METHOD2(Install, |
| 3791 bool(const base::DictionaryValue& manifest, |
| 3792 const base::FilePath& unpack_path)); |
| 3793 MOCK_METHOD2(GetInstalledFile, |
| 3794 bool(const std::string& file, base::FilePath* installed_file)); |
| 3795 MOCK_METHOD0(Uninstall, bool()); |
| 3796 |
| 3797 private: |
| 3798 ~MockInstaller() override {} |
| 3799 }; |
| 3800 |
| 3801 // component id "jebgalgnebhfojomionfpkfelancnnkf". |
| 3802 static const uint8_t jebg_hash[] = { |
| 3803 0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, 0x8e, 0xd5, 0xfa, |
| 3804 0x54, 0xb0, 0xd2, 0xdd, 0xa5, 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, |
| 3805 0xf6, 0xc4, 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; |
| 3806 |
| 3807 // The component uses HTTPS only for network interception purposes. |
| 3808 update_client::CrxComponent crx_component; |
| 3809 crx_component.pk_hash.assign(std::begin(jebg_hash), std::end(jebg_hash)); |
| 3810 crx_component.version = Version("0.9"); |
| 3811 crx_component.installer = scoped_refptr<MockInstaller>(new MockInstaller()); |
| 3812 crx_component.requires_network_encryption = true; |
| 3813 crx_component.supports_group_policy_enable_component_updates = |
| 3814 supports_group_policy_enable_component_updates; |
| 3815 |
| 3816 return crx_component; |
| 3817 } |
| 3818 |
| 3819 void ComponentUpdaterPolicyTest::UpdateComponent( |
| 3820 const update_client::CrxComponent& crx_component) { |
| 3821 post_interceptor_->Reset(); |
| 3822 EXPECT_TRUE(post_interceptor_->ExpectRequest( |
| 3823 new update_client::PartialMatch("updatecheck"), 200)); |
| 3824 EXPECT_TRUE(cus_->RegisterComponent(crx_component)); |
| 3825 cus_->GetOnDemandUpdater().OnDemandUpdate( |
| 3826 component_id_, base::Bind(&ComponentUpdaterPolicyTest::OnDemandComplete, |
| 3827 base::Unretained(this))); |
| 3828 } |
| 3829 |
| 3830 void ComponentUpdaterPolicyTest::CallAsync(TestCaseAction action) { |
| 3831 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 3832 base::Bind(action, base::Unretained(this))); |
| 3833 } |
| 3834 |
| 3835 void ComponentUpdaterPolicyTest::OnDemandComplete(int error) { |
| 3836 CallAsync(cur_test_case_.second); |
| 3837 } |
| 3838 |
| 3839 void ComponentUpdaterPolicyTest::BeginTest() { |
| 3840 cus_ = g_browser_process->component_updater(); |
| 3841 |
| 3842 interceptor_factory_ = |
| 3843 base::MakeUnique<update_client::URLRequestPostInterceptorFactory>( |
| 3844 "https", "clients2.google.com", |
| 3845 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
| 3846 |
| 3847 post_interceptor_ = interceptor_factory_->CreateInterceptor( |
| 3848 base::FilePath(FILE_PATH_LITERAL("service/update2"))); |
| 3849 |
| 3850 cur_test_case_ = std::make_pair( |
| 3851 &ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicySupported, |
| 3852 &ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicySupported); |
| 3853 |
| 3854 CallAsync(cur_test_case_.first); |
| 3855 } |
| 3856 |
| 3857 void ComponentUpdaterPolicyTest::EndTest() { |
| 3858 interceptor_factory_ = nullptr; |
| 3859 cus_ = nullptr; |
| 3860 |
| 3861 base::MessageLoop::current()->QuitWhenIdle(); |
| 3862 } |
| 3863 |
| 3864 void ComponentUpdaterPolicyTest::VerifyExpectations(bool update_disabled) { |
| 3865 EXPECT_EQ(1, post_interceptor_->GetHitCount()) |
| 3866 << post_interceptor_->GetRequestsAsString(); |
| 3867 ASSERT_EQ(1, post_interceptor_->GetCount()) |
| 3868 << post_interceptor_->GetRequestsAsString(); |
| 3869 EXPECT_NE(std::string::npos, |
| 3870 post_interceptor_->GetRequests()[0].find(base::StringPrintf( |
| 3871 "<updatecheck%s/>", |
| 3872 update_disabled ? " updatedisabled=\"true\"" : ""))); |
| 3873 } |
| 3874 |
| 3875 void ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicySupported() { |
| 3876 UpdateComponent(MakeCrxComponent(true)); |
| 3877 } |
| 3878 |
| 3879 void ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicySupported() { |
| 3880 // Default policy && policy support -> updates are enabled. |
| 3881 VerifyExpectations(!kUpdateDisabled); |
| 3882 |
| 3883 cur_test_case_ = std::make_pair( |
| 3884 &ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicyNotSupported, |
| 3885 &ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicyNotSupported); |
| 3886 CallAsync(cur_test_case_.first); |
| 3887 } |
| 3888 |
| 3889 void ComponentUpdaterPolicyTest::DefaultPolicy_GroupPolicyNotSupported() { |
| 3890 UpdateComponent(MakeCrxComponent(false)); |
| 3891 } |
| 3892 |
| 3893 void ComponentUpdaterPolicyTest::FinishDefaultPolicy_GroupPolicyNotSupported() { |
| 3894 // Default policy && no policy support -> updates are enabled. |
| 3895 VerifyExpectations(!kUpdateDisabled); |
| 3896 |
| 3897 cur_test_case_ = std::make_pair( |
| 3898 &ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicySupported, |
| 3899 &ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicySupported); |
| 3900 CallAsync(cur_test_case_.first); |
| 3901 } |
| 3902 |
| 3903 void ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicySupported() { |
| 3904 SetEnableComponentUpdates(true); |
| 3905 UpdateComponent(MakeCrxComponent(true)); |
| 3906 } |
| 3907 |
| 3908 void ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicySupported() { |
| 3909 // Updates enabled policy && policy support -> updates are enabled. |
| 3910 VerifyExpectations(!kUpdateDisabled); |
| 3911 |
| 3912 cur_test_case_ = std::make_pair( |
| 3913 &ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicyNotSupported, |
| 3914 &ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicyNotSupported); |
| 3915 CallAsync(cur_test_case_.first); |
| 3916 } |
| 3917 |
| 3918 void ComponentUpdaterPolicyTest::EnabledPolicy_GroupPolicyNotSupported() { |
| 3919 SetEnableComponentUpdates(true); |
| 3920 UpdateComponent(MakeCrxComponent(false)); |
| 3921 } |
| 3922 |
| 3923 void ComponentUpdaterPolicyTest::FinishEnabledPolicy_GroupPolicyNotSupported() { |
| 3924 // Updates enabled policy && no policy support -> updates are enabled. |
| 3925 VerifyExpectations(!kUpdateDisabled); |
| 3926 |
| 3927 cur_test_case_ = std::make_pair( |
| 3928 &ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicySupported, |
| 3929 &ComponentUpdaterPolicyTest::FinishDisabled_PolicyGroupPolicySupported); |
| 3930 CallAsync(cur_test_case_.first); |
| 3931 } |
| 3932 |
| 3933 void ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicySupported() { |
| 3934 SetEnableComponentUpdates(false); |
| 3935 UpdateComponent(MakeCrxComponent(true)); |
| 3936 } |
| 3937 |
| 3938 void ComponentUpdaterPolicyTest::FinishDisabled_PolicyGroupPolicySupported() { |
| 3939 // Updates enabled policy && policy support -> updates are disabled. |
| 3940 VerifyExpectations(kUpdateDisabled); |
| 3941 |
| 3942 cur_test_case_ = std::make_pair( |
| 3943 &ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicyNotSupported, |
| 3944 &ComponentUpdaterPolicyTest:: |
| 3945 FinishDisabledPolicy_GroupPolicyNotSupported); |
| 3946 CallAsync(cur_test_case_.first); |
| 3947 } |
| 3948 |
| 3949 void ComponentUpdaterPolicyTest::DisabledPolicy_GroupPolicyNotSupported() { |
| 3950 SetEnableComponentUpdates(false); |
| 3951 UpdateComponent(MakeCrxComponent(false)); |
| 3952 } |
| 3953 |
| 3954 void ComponentUpdaterPolicyTest:: |
| 3955 FinishDisabledPolicy_GroupPolicyNotSupported() { |
| 3956 // Updates enabled policy && no policy support -> updates are enabled. |
| 3957 VerifyExpectations(!kUpdateDisabled); |
| 3958 |
| 3959 cur_test_case_ = TestCase(); |
| 3960 CallAsync(&ComponentUpdaterPolicyTest::EndTest); |
| 3961 } |
| 3962 |
| 3963 IN_PROC_BROWSER_TEST_F(ComponentUpdaterPolicyTest, EnabledComponentUpdates) { |
| 3964 BeginTest(); |
| 3965 base::RunLoop().Run(); |
| 3966 } |
| 3967 |
3696 #if !defined(OS_CHROMEOS) | 3968 #if !defined(OS_CHROMEOS) |
3697 // Similar to PolicyTest but sets the proper policy before the browser is | 3969 // Similar to PolicyTest but sets the proper policy before the browser is |
3698 // started. | 3970 // started. |
3699 class PolicyVariationsServiceTest : public PolicyTest { | 3971 class PolicyVariationsServiceTest : public PolicyTest { |
3700 public: | 3972 public: |
3701 void SetUpInProcessBrowserTestFixture() override { | 3973 void SetUpInProcessBrowserTestFixture() override { |
3702 PolicyTest::SetUpInProcessBrowserTestFixture(); | 3974 PolicyTest::SetUpInProcessBrowserTestFixture(); |
3703 PolicyMap policies; | 3975 PolicyMap policies; |
3704 policies.Set(key::kVariationsRestrictParameter, POLICY_LEVEL_MANDATORY, | 3976 policies.Set(key::kVariationsRestrictParameter, POLICY_LEVEL_MANDATORY, |
3705 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, | 3977 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD, |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4114 | 4386 |
4115 SetEmptyPolicy(); | 4387 SetEmptyPolicy(); |
4116 // Policy not set. | 4388 // Policy not set. |
4117 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); | 4389 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); |
4118 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); | 4390 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); |
4119 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); | 4391 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); |
4120 } | 4392 } |
4121 #endif // defined(OS_CHROMEOS) | 4393 #endif // defined(OS_CHROMEOS) |
4122 | 4394 |
4123 } // namespace policy | 4395 } // namespace policy |
OLD | NEW |