| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/android/search_geolocation/search_geolocation_service.h
" | 5 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h
" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/test/scoped_feature_list.h" | 12 #include "base/test/scoped_feature_list.h" |
| 13 #include "chrome/browser/android/mock_location_settings.h" | |
| 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 15 #include "chrome/common/chrome_features.h" | 14 #include "chrome/common/chrome_features.h" |
| 16 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 17 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 19 #include "components/content_settings/core/common/pref_names.h" | 18 #include "components/content_settings/core/common/pref_names.h" |
| 20 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
| 21 #include "components/sync_preferences/testing_pref_service_syncable.h" | 20 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 public: | 69 public: |
| 71 void SetUp() override { | 70 void SetUp() override { |
| 72 scoped_feature_list_.InitAndEnableFeature( | 71 scoped_feature_list_.InitAndEnableFeature( |
| 73 features::kConsistentOmniboxGeolocation); | 72 features::kConsistentOmniboxGeolocation); |
| 74 | 73 |
| 75 profile_.reset(new TestingProfile); | 74 profile_.reset(new TestingProfile); |
| 76 | 75 |
| 77 auto test_delegate = base::MakeUnique<TestSearchEngineDelegate>(); | 76 auto test_delegate = base::MakeUnique<TestSearchEngineDelegate>(); |
| 78 test_delegate_ = test_delegate.get(); | 77 test_delegate_ = test_delegate.get(); |
| 79 GetService()->SetSearchEngineDelegateForTest(std::move(test_delegate)); | 78 GetService()->SetSearchEngineDelegateForTest(std::move(test_delegate)); |
| 80 | |
| 81 auto mock_settings = base::MakeUnique<MockLocationSettings>(); | |
| 82 mock_settings->SetLocationStatus( | |
| 83 true /* has_android_location_permission */, | |
| 84 true /* is_system_location_setting_enabled */); | |
| 85 GetService()->SetLocationSettingsForTest(std::move(mock_settings)); | |
| 86 } | 79 } |
| 87 | 80 |
| 88 void TearDown() override { | 81 void TearDown() override { |
| 89 test_delegate_ = nullptr; | 82 test_delegate_ = nullptr; |
| 90 profile_.reset(); | 83 profile_.reset(); |
| 91 } | 84 } |
| 92 | 85 |
| 93 TestingProfile* profile() { return profile_.get(); } | 86 TestingProfile* profile() { return profile_.get(); } |
| 94 | 87 |
| 95 TestSearchEngineDelegate* test_delegate() { return test_delegate_; } | 88 TestSearchEngineDelegate* test_delegate() { return test_delegate_; } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 ReinitializeService(true /* clear_pref */); | 141 ReinitializeService(true /* clear_pref */); |
| 149 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); | 142 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); |
| 150 EXPECT_TRUE(GetService()->GetDSEGeolocationSetting()); | 143 EXPECT_TRUE(GetService()->GetDSEGeolocationSetting()); |
| 151 | 144 |
| 152 // DSE setting initialized to false if the content setting is BLOCK. | 145 // DSE setting initialized to false if the content setting is BLOCK. |
| 153 SetContentSetting(kGoogleURL, CONTENT_SETTING_BLOCK); | 146 SetContentSetting(kGoogleURL, CONTENT_SETTING_BLOCK); |
| 154 ReinitializeService(true /* clear_pref */); | 147 ReinitializeService(true /* clear_pref */); |
| 155 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); | 148 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); |
| 156 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); | 149 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); |
| 157 | 150 |
| 158 // Nothing happens if the pref is already set when the service is | 151 // Nothing happens if the pref is already set when the service is initialized. |
| 159 // initialized. | |
| 160 SetContentSetting(kGoogleURL, CONTENT_SETTING_ASK); | 152 SetContentSetting(kGoogleURL, CONTENT_SETTING_ASK); |
| 161 ReinitializeService(false /* clear_pref */); | 153 ReinitializeService(false /* clear_pref */); |
| 162 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); | 154 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); |
| 163 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); | 155 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); |
| 164 | 156 |
| 165 // For non-Google search engine, the setting may be initialized to true, but | 157 // For non-Google search engine, the setting may be initialized to true, but |
| 166 // it won't be used. | 158 // it won't be used. |
| 167 test_delegate()->SetDSECCTLD(kExampleURL); | 159 test_delegate()->SetDSECCTLD(kExampleURL); |
| 168 SetContentSetting(kExampleURL, CONTENT_SETTING_ALLOW); | 160 SetContentSetting(kExampleURL, CONTENT_SETTING_ALLOW); |
| 169 ReinitializeService(true /* clear_pref */); | 161 ReinitializeService(true /* clear_pref */); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 test_delegate()->SetDSECCTLD(kExampleURL); | 282 test_delegate()->SetDSECCTLD(kExampleURL); |
| 291 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); | 283 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); |
| 292 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kExampleURL))); | 284 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kExampleURL))); |
| 293 | 285 |
| 294 // Go back to google.com.au. The setting should still be false because that's | 286 // Go back to google.com.au. The setting should still be false because that's |
| 295 // what it last was. | 287 // what it last was. |
| 296 test_delegate()->SetDSECCTLD(kGoogleAusURL); | 288 test_delegate()->SetDSECCTLD(kGoogleAusURL); |
| 297 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); | 289 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); |
| 298 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); | 290 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); |
| 299 } | 291 } |
| OLD | NEW |