Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/geolocation/geolocation_content_settings_map.h" | 5 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
| 9 #include "chrome/browser/content_settings/content_settings_details.h" | |
| 9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 11 #include "chrome/common/notification_registrar.h" | |
| 12 #include "chrome/common/notification_service.h" | |
| 10 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/test/testing_profile.h" | 14 #include "chrome/test/testing_profile.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 16 |
| 14 | 17 |
| 15 namespace { | 18 namespace { |
| 16 | 19 |
| 20 class StubSettingsObserver : public NotificationObserver { | |
| 21 public: | |
| 22 StubSettingsObserver() : last_notifier(NULL), counter(0) { | |
| 23 registrar_.Add(this, NotificationType::GEOLOCATION_SETTINGS_CHANGED, | |
| 24 NotificationService::AllSources()); | |
| 25 } | |
| 26 | |
| 27 virtual void Observe(NotificationType type, | |
| 28 const NotificationSource& source, | |
| 29 const NotificationDetails& details) { | |
| 30 ++counter; | |
| 31 Source<GeolocationContentSettingsMap> content_settings(source); | |
| 32 Details<ContentSettingsDetails> settings_details(details); | |
| 33 last_notifier = content_settings.ptr(); | |
| 34 last_pattern = settings_details.ptr()->pattern(); | |
| 35 last_update_all = settings_details.ptr()->update_all(); | |
| 36 last_update_all_types = settings_details.ptr()->update_all_types(); | |
| 37 last_type = settings_details.ptr()->type(); | |
| 38 // This checks that calling a Get function from an observer doesn't | |
| 39 // deadlock. | |
| 40 last_notifier->GetContentSetting(GURL("http://random-hostname.com/"), | |
| 41 GURL("http://foo.random-hostname.com/")); | |
| 42 } | |
| 43 | |
| 44 GeolocationContentSettingsMap* last_notifier; | |
| 45 ContentSettingsPattern last_pattern; | |
| 46 bool last_update_all; | |
| 47 bool last_update_all_types; | |
| 48 int counter; | |
| 49 ContentSettingsType last_type; | |
| 50 | |
| 51 private: | |
| 52 NotificationRegistrar registrar_; | |
| 53 }; | |
| 54 | |
| 55 } // namespace | |
|
jochen (gone - plz use gerrit)
2010/12/15 15:05:52
please move back to end of file
markusheintz_
2010/12/15 15:24:08
Done.
| |
| 56 | |
| 17 class GeolocationContentSettingsMapTests : public testing::Test { | 57 class GeolocationContentSettingsMapTests : public testing::Test { |
| 18 public: | 58 public: |
| 19 GeolocationContentSettingsMapTests() | 59 GeolocationContentSettingsMapTests() |
| 20 : ui_thread_(BrowserThread::UI, &message_loop_) { | 60 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 21 } | 61 } |
| 22 | 62 |
| 23 protected: | 63 protected: |
| 24 MessageLoop message_loop_; | 64 MessageLoop message_loop_; |
| 25 BrowserThread ui_thread_; | 65 BrowserThread ui_thread_; |
| 26 }; | 66 }; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 map->GetContentSetting(GURL("http://a/"), | 274 map->GetContentSetting(GURL("http://a/"), |
| 235 GURL("http://bad-embedder"))); | 275 GURL("http://bad-embedder"))); |
| 236 EXPECT_EQ(CONTENT_SETTING_ASK, | 276 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 237 map->GetContentSetting(GURL("http://a/"), | 277 map->GetContentSetting(GURL("http://a/"), |
| 238 GURL("http://example.com"))); | 278 GURL("http://example.com"))); |
| 239 EXPECT_EQ(CONTENT_SETTING_ASK, | 279 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 240 map->GetContentSetting(GURL("http://bad_requester/"), | 280 map->GetContentSetting(GURL("http://bad_requester/"), |
| 241 GURL("http://b/"))); | 281 GURL("http://b/"))); |
| 242 } | 282 } |
| 243 | 283 |
| 244 } // namespace | 284 TEST_F(GeolocationContentSettingsMapTests, Observe) { |
| 285 TestingProfile profile; | |
| 286 GeolocationContentSettingsMap* map = | |
| 287 profile.GetGeolocationContentSettingsMap(); | |
| 288 StubSettingsObserver observer; | |
| 289 | |
| 290 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting()); | |
| 291 | |
| 292 // Test if a CONTENT_SETTING_CHANGE notification is sent after the geolocation | |
| 293 // default content setting was changed through calling the | |
| 294 // SetDefaultContentSetting method. | |
| 295 map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | |
| 296 EXPECT_EQ(map, observer.last_notifier); | |
| 297 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
| 298 EXPECT_EQ(1, observer.counter); | |
| 299 | |
| 300 | |
| 301 // Test if a CONTENT_SETTING_CHANGE notification is sent after the preference | |
| 302 // GeolocationDefaultContentSetting was changed. | |
| 303 PrefService* prefs = profile.GetPrefs(); | |
| 304 prefs->SetInteger(prefs::kGeolocationDefaultContentSetting, | |
| 305 CONTENT_SETTING_ALLOW); | |
| 306 EXPECT_EQ(2, observer.counter); | |
| 307 EXPECT_EQ(map, observer.last_notifier); | |
| 308 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
| 309 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting()); | |
| 310 } | |
| OLD | NEW |