Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/android/search_geolocation/search_geolocation_service_unittest.cc

Issue 2804913005: Don't use the DSE geolocation setting when chrome doesn't have location. (Closed)
Patch Set: Fix other test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/common/chrome_features.h" 15 #include "chrome/common/chrome_features.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
17 #include "components/content_settings/core/browser/host_content_settings_map.h" 18 #include "components/content_settings/core/browser/host_content_settings_map.h"
18 #include "components/content_settings/core/common/pref_names.h" 19 #include "components/content_settings/core/common/pref_names.h"
19 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
20 #include "components/sync_preferences/testing_pref_service_syncable.h" 21 #include "components/sync_preferences/testing_pref_service_syncable.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 22 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 public: 70 public:
70 void SetUp() override { 71 void SetUp() override {
71 scoped_feature_list_.InitAndEnableFeature( 72 scoped_feature_list_.InitAndEnableFeature(
72 features::kConsistentOmniboxGeolocation); 73 features::kConsistentOmniboxGeolocation);
73 74
74 profile_.reset(new TestingProfile); 75 profile_.reset(new TestingProfile);
75 76
76 auto test_delegate = base::MakeUnique<TestSearchEngineDelegate>(); 77 auto test_delegate = base::MakeUnique<TestSearchEngineDelegate>();
77 test_delegate_ = test_delegate.get(); 78 test_delegate_ = test_delegate.get();
78 GetService()->SetSearchEngineDelegateForTest(std::move(test_delegate)); 79 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));
79 } 86 }
80 87
81 void TearDown() override { 88 void TearDown() override {
82 test_delegate_ = nullptr; 89 test_delegate_ = nullptr;
83 profile_.reset(); 90 profile_.reset();
84 } 91 }
85 92
86 TestingProfile* profile() { return profile_.get(); } 93 TestingProfile* profile() { return profile_.get(); }
87 94
88 TestSearchEngineDelegate* test_delegate() { return test_delegate_; } 95 TestSearchEngineDelegate* test_delegate() { return test_delegate_; }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 ReinitializeService(true /* clear_pref */); 148 ReinitializeService(true /* clear_pref */);
142 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); 149 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL)));
143 EXPECT_TRUE(GetService()->GetDSEGeolocationSetting()); 150 EXPECT_TRUE(GetService()->GetDSEGeolocationSetting());
144 151
145 // DSE setting initialized to false if the content setting is BLOCK. 152 // DSE setting initialized to false if the content setting is BLOCK.
146 SetContentSetting(kGoogleURL, CONTENT_SETTING_BLOCK); 153 SetContentSetting(kGoogleURL, CONTENT_SETTING_BLOCK);
147 ReinitializeService(true /* clear_pref */); 154 ReinitializeService(true /* clear_pref */);
148 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); 155 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL)));
149 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); 156 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting());
150 157
151 // Nothing happens if the pref is already set when the service is initialized. 158 // Nothing happens if the pref is already set when the service is
159 // initialized.
152 SetContentSetting(kGoogleURL, CONTENT_SETTING_ASK); 160 SetContentSetting(kGoogleURL, CONTENT_SETTING_ASK);
153 ReinitializeService(false /* clear_pref */); 161 ReinitializeService(false /* clear_pref */);
154 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL))); 162 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleURL)));
155 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); 163 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting());
156 164
157 // For non-Google search engine, the setting may be initialized to true, but 165 // For non-Google search engine, the setting may be initialized to true, but
158 // it won't be used. 166 // it won't be used.
159 test_delegate()->SetDSECCTLD(kExampleURL); 167 test_delegate()->SetDSECCTLD(kExampleURL);
160 SetContentSetting(kExampleURL, CONTENT_SETTING_ALLOW); 168 SetContentSetting(kExampleURL, CONTENT_SETTING_ALLOW);
161 ReinitializeService(true /* clear_pref */); 169 ReinitializeService(true /* clear_pref */);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 test_delegate()->SetDSECCTLD(kExampleURL); 290 test_delegate()->SetDSECCTLD(kExampleURL);
283 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); 291 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL)));
284 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kExampleURL))); 292 EXPECT_FALSE(GetService()->UseDSEGeolocationSetting(ToOrigin(kExampleURL)));
285 293
286 // Go back to google.com.au. The setting should still be false because that's 294 // Go back to google.com.au. The setting should still be false because that's
287 // what it last was. 295 // what it last was.
288 test_delegate()->SetDSECCTLD(kGoogleAusURL); 296 test_delegate()->SetDSECCTLD(kGoogleAusURL);
289 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL))); 297 EXPECT_TRUE(GetService()->UseDSEGeolocationSetting(ToOrigin(kGoogleAusURL)));
290 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting()); 298 EXPECT_FALSE(GetService()->GetDSEGeolocationSetting());
291 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698