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

Side by Side Diff: chrome/browser/geolocation/geolocation_content_settings_map_unittest.cc

Issue 7328018: Migrate default geolocation content setting to host content settings map. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "chrome/browser/content_settings/content_settings_details.h" 6 #include "chrome/browser/content_settings/content_settings_details.h"
7 #include "chrome/browser/content_settings/host_content_settings_map.h"
7 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" 8 #include "chrome/browser/geolocation/geolocation_content_settings_map.h"
8 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/prefs/scoped_user_pref_update.h" 10 #include "chrome/browser/prefs/scoped_user_pref_update.h"
10 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
13 #include "content/browser/browser_thread.h" 14 #include "content/browser/browser_thread.h"
14 #include "content/common/notification_registrar.h" 15 #include "content/common/notification_registrar.h"
15 #include "content/common/notification_service.h" 16 #include "content/common/notification_service.h"
16 #include "testing/gmock/include/gmock/gmock.h" 17 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 public: 63 public:
63 GeolocationContentSettingsMapTests() 64 GeolocationContentSettingsMapTests()
64 : ui_thread_(BrowserThread::UI, &message_loop_) { 65 : ui_thread_(BrowserThread::UI, &message_loop_) {
65 } 66 }
66 67
67 protected: 68 protected:
68 MessageLoop message_loop_; 69 MessageLoop message_loop_;
69 BrowserThread ui_thread_; 70 BrowserThread ui_thread_;
70 }; 71 };
71 72
72 TEST_F(GeolocationContentSettingsMapTests, DefaultValues) {
73 TestingProfile profile;
74 GeolocationContentSettingsMap* map =
75 profile.GetGeolocationContentSettingsMap();
76
77 // Check setting defaults.
78 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting());
79 map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK);
80 EXPECT_EQ(CONTENT_SETTING_BLOCK, map->GetDefaultContentSetting());
81 }
82
83 TEST_F(GeolocationContentSettingsMapTests, Embedder) { 73 TEST_F(GeolocationContentSettingsMapTests, Embedder) {
84 TestingProfile profile; 74 TestingProfile profile;
85 GeolocationContentSettingsMap* map = 75 GeolocationContentSettingsMap* map =
86 profile.GetGeolocationContentSettingsMap(); 76 profile.GetGeolocationContentSettingsMap();
87 GURL top_level("http://www.toplevel0.com/foo/bar"); 77 GURL top_level("http://www.toplevel0.com/foo/bar");
88 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(top_level, top_level)); 78 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetContentSetting(top_level, top_level));
89 // Now set the permission for requester_0. 79 // Now set the permission for requester_0.
90 map->SetContentSetting(top_level, top_level, CONTENT_SETTING_ALLOW); 80 map->SetContentSetting(top_level, top_level, CONTENT_SETTING_ALLOW);
91 EXPECT_EQ(CONTENT_SETTING_ALLOW, 81 EXPECT_EQ(CONTENT_SETTING_ALLOW,
92 map->GetContentSetting(top_level, top_level)); 82 map->GetContentSetting(top_level, top_level));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 EXPECT_EQ(CONTENT_SETTING_BLOCK, 226 EXPECT_EQ(CONTENT_SETTING_BLOCK,
237 map->GetContentSetting(requester_0, embedder_0)); 227 map->GetContentSetting(requester_0, embedder_0));
238 EXPECT_EQ(CONTENT_SETTING_ALLOW, 228 EXPECT_EQ(CONTENT_SETTING_ALLOW,
239 map->GetContentSetting(requester_0, embedder_1)); 229 map->GetContentSetting(requester_0, embedder_1));
240 EXPECT_EQ(CONTENT_SETTING_ASK, 230 EXPECT_EQ(CONTENT_SETTING_ASK,
241 map->GetContentSetting(requester_0, requester_0)); 231 map->GetContentSetting(requester_0, requester_0));
242 232
243 // Change the wildcard behavior. 233 // Change the wildcard behavior.
244 map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW); 234 map->SetContentSetting(requester_0, embedder_0, CONTENT_SETTING_ALLOW);
245 map->SetContentSetting(requester_0, empty_url, CONTENT_SETTING_BLOCK); 235 map->SetContentSetting(requester_0, empty_url, CONTENT_SETTING_BLOCK);
246 map->SetDefaultContentSetting(CONTENT_SETTING_ALLOW); 236 profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
237 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_ALLOW);
247 EXPECT_EQ(CONTENT_SETTING_ALLOW, 238 EXPECT_EQ(CONTENT_SETTING_ALLOW,
248 map->GetContentSetting(requester_0, embedder_0)); 239 map->GetContentSetting(requester_0, embedder_0));
249 EXPECT_EQ(CONTENT_SETTING_BLOCK, 240 EXPECT_EQ(CONTENT_SETTING_BLOCK,
250 map->GetContentSetting(requester_0, embedder_1)); 241 map->GetContentSetting(requester_0, embedder_1));
251 EXPECT_EQ(CONTENT_SETTING_ALLOW, 242 EXPECT_EQ(CONTENT_SETTING_ALLOW,
252 map->GetContentSetting(requester_0, requester_0)); 243 map->GetContentSetting(requester_0, requester_0));
253 } 244 }
254 245
255 TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) { 246 TEST_F(GeolocationContentSettingsMapTests, IgnoreInvalidURLsInPrefs) {
256 TestingProfile profile; 247 TestingProfile profile;
257 { 248 {
258 DictionaryPrefUpdate update(profile.GetPrefs(), 249 DictionaryPrefUpdate update(profile.GetPrefs(),
259 prefs::kGeolocationContentSettings); 250 prefs::kGeolocationContentSettings);
260 DictionaryValue* all_settings_dictionary = update.Get(); 251 DictionaryValue* all_settings_dictionary = update.Get();
261 // For simplicity, use the overloads that do path expansion. As '.' is the 252 // For simplicity, use the overloads that do path expansion. As '.' is the
262 // path separator, we can't have dotted hostnames (which is fine). 253 // path separator, we can't have dotted hostnames (which is fine).
263 all_settings_dictionary->SetInteger("http://a/.http://b/", 254 all_settings_dictionary->SetInteger("http://a/.http://b/",
264 CONTENT_SETTING_ALLOW); 255 CONTENT_SETTING_ALLOW);
265 all_settings_dictionary->SetInteger("bad_requester.http://b/", 256 all_settings_dictionary->SetInteger("bad_requester.http://b/",
266 CONTENT_SETTING_ALLOW); 257 CONTENT_SETTING_ALLOW);
267 all_settings_dictionary->SetInteger("http://a/.bad-embedder", 258 all_settings_dictionary->SetInteger("http://a/.bad-embedder",
268 CONTENT_SETTING_ALLOW); 259 CONTENT_SETTING_ALLOW);
269 } 260 }
270 261
271 GeolocationContentSettingsMap* map = 262 GeolocationContentSettingsMap* map =
272 profile.GetGeolocationContentSettingsMap(); 263 profile.GetGeolocationContentSettingsMap();
273 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting()); 264 EXPECT_EQ(CONTENT_SETTING_ASK,
265 profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
266 CONTENT_SETTINGS_TYPE_GEOLOCATION));
274 267
275 // Check the valid entry was read OK. 268 // Check the valid entry was read OK.
276 EXPECT_EQ(CONTENT_SETTING_ALLOW, 269 EXPECT_EQ(CONTENT_SETTING_ALLOW,
277 map->GetContentSetting(GURL("http://a/"), GURL("http://b/"))); 270 map->GetContentSetting(GURL("http://a/"), GURL("http://b/")));
278 // But everything else should be according to the default. 271 // But everything else should be according to the default.
279 EXPECT_EQ(CONTENT_SETTING_ASK, 272 EXPECT_EQ(CONTENT_SETTING_ASK,
280 map->GetContentSetting(GURL("http://a/"), 273 map->GetContentSetting(GURL("http://a/"),
281 GURL("http://bad-embedder"))); 274 GURL("http://bad-embedder")));
282 EXPECT_EQ(CONTENT_SETTING_ASK, 275 EXPECT_EQ(CONTENT_SETTING_ASK,
283 map->GetContentSetting(GURL("http://a/"), 276 map->GetContentSetting(GURL("http://a/"),
284 GURL("http://example.com"))); 277 GURL("http://example.com")));
285 EXPECT_EQ(CONTENT_SETTING_ASK, 278 EXPECT_EQ(CONTENT_SETTING_ASK,
286 map->GetContentSetting(GURL("http://bad_requester/"), 279 map->GetContentSetting(GURL("http://bad_requester/"),
287 GURL("http://b/"))); 280 GURL("http://b/")));
288 } 281 }
289 282
290 TEST_F(GeolocationContentSettingsMapTests, Observe) { 283 TEST_F(GeolocationContentSettingsMapTests, Observe) {
291 TestingProfile profile; 284 TestingProfile profile;
292 GeolocationContentSettingsMap* map = 285 GeolocationContentSettingsMap* map =
293 profile.GetGeolocationContentSettingsMap(); 286 profile.GetGeolocationContentSettingsMap();
294 MockGeolocationSettingsObserver observer; 287 MockGeolocationSettingsObserver observer;
295 288
296 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting()); 289 EXPECT_EQ(CONTENT_SETTING_ASK,
290 profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
291 CONTENT_SETTINGS_TYPE_GEOLOCATION));
297 292
298 // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after 293 // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after
299 // the geolocation default content setting was changed through calling the 294 // the geolocation default content setting was changed through calling the
300 // SetDefaultContentSetting method. 295 // SetDefaultContentSetting method.
301 EXPECT_CALL( 296 EXPECT_CALL(
302 observer, 297 observer,
303 OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT)); 298 OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
304 map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); 299 profile.GetHostContentSettingsMap()->SetDefaultContentSetting(
300 CONTENT_SETTINGS_TYPE_GEOLOCATION, CONTENT_SETTING_BLOCK);
305 ::testing::Mock::VerifyAndClearExpectations(&observer); 301 ::testing::Mock::VerifyAndClearExpectations(&observer);
306 302
307 // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after 303 // Test if a GEOLOCATION_SETTINGS_CHANGED notification is sent after the
308 // the preference kGeolocationDefaultContentSetting was changed. 304 // preference obsolete kGeolocationDefaultContentSetting was changed.
Bernhard Bauer 2011/07/15 13:31:44 Nit: swap "preference" and "obsolete".
markusheintz_ 2011/07/15 16:21:50 Done.
309 PrefService* prefs = profile.GetPrefs(); 305 PrefService* prefs = profile.GetPrefs();
310 EXPECT_CALL( 306 EXPECT_CALL(
311 observer, 307 observer,
312 OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT)); 308 OnContentSettingsChanged(map, CONTENT_SETTINGS_TYPE_DEFAULT));
313 prefs->SetInteger(prefs::kGeolocationDefaultContentSetting, 309 prefs->SetInteger(prefs::kGeolocationDefaultContentSetting,
314 CONTENT_SETTING_ALLOW); 310 CONTENT_SETTING_ALLOW);
315 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting()); 311
312 EXPECT_EQ(CONTENT_SETTING_ALLOW,
313 profile.GetHostContentSettingsMap()->GetDefaultContentSetting(
314 CONTENT_SETTINGS_TYPE_GEOLOCATION));
316 } 315 }
317 316
318 } // namespace 317 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698