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->GetContentSettings(GURL("http://random-hostname.com/")); | |
|
jochen (gone - plz use gerrit)
2010/12/15 14:02:11
i think that doesn't work
markusheintz_
2010/12/15 14:08:35
Already fixed.
| |
| 41 } | |
| 42 | |
| 43 GeolocationContentSettingsMap* last_notifier; | |
| 44 ContentSettingsPattern last_pattern; | |
| 45 bool last_update_all; | |
| 46 bool last_update_all_types; | |
| 47 int counter; | |
| 48 ContentSettingsType last_type; | |
| 49 | |
| 50 private: | |
| 51 NotificationRegistrar registrar_; | |
| 52 }; | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 17 class GeolocationContentSettingsMapTests : public testing::Test { | 56 class GeolocationContentSettingsMapTests : public testing::Test { |
| 18 public: | 57 public: |
| 19 GeolocationContentSettingsMapTests() | 58 GeolocationContentSettingsMapTests() |
| 20 : ui_thread_(BrowserThread::UI, &message_loop_) { | 59 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 21 } | 60 } |
| 22 | 61 |
| 23 protected: | 62 protected: |
| 24 MessageLoop message_loop_; | 63 MessageLoop message_loop_; |
| 25 BrowserThread ui_thread_; | 64 BrowserThread ui_thread_; |
| 26 }; | 65 }; |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 map->GetContentSetting(GURL("http://a/"), | 273 map->GetContentSetting(GURL("http://a/"), |
| 235 GURL("http://bad-embedder"))); | 274 GURL("http://bad-embedder"))); |
| 236 EXPECT_EQ(CONTENT_SETTING_ASK, | 275 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 237 map->GetContentSetting(GURL("http://a/"), | 276 map->GetContentSetting(GURL("http://a/"), |
| 238 GURL("http://example.com"))); | 277 GURL("http://example.com"))); |
| 239 EXPECT_EQ(CONTENT_SETTING_ASK, | 278 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 240 map->GetContentSetting(GURL("http://bad_requester/"), | 279 map->GetContentSetting(GURL("http://bad_requester/"), |
| 241 GURL("http://b/"))); | 280 GURL("http://b/"))); |
| 242 } | 281 } |
| 243 | 282 |
| 244 } // namespace | 283 TEST_F(GeolocationContentSettingsMapTests, Observe) { |
| 284 TestingProfile profile; | |
| 285 GeolocationContentSettingsMap* map = | |
| 286 profile.GetGeolocationContentSettingsMap(); | |
| 287 StubSettingsObserver observer; | |
| 288 | |
| 289 EXPECT_EQ(CONTENT_SETTING_ASK, map->GetDefaultContentSetting()); | |
| 290 | |
| 291 // Test if a CONTENT_SETTING_CHANGE notification is sent after the geolocation | |
| 292 // default content setting was changed through calling the | |
| 293 // SetDefaultContentSetting method. | |
| 294 map->SetDefaultContentSetting(CONTENT_SETTING_BLOCK); | |
| 295 EXPECT_EQ(map, observer.last_notifier); | |
| 296 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
| 297 EXPECT_EQ(1, observer.counter); | |
| 298 | |
| 299 | |
| 300 // Test if a CONTENT_SETTING_CHANGE notification is sent after the preference | |
| 301 // GeolocationDefaultContentSetting was changed. | |
| 302 PrefService* prefs = profile.GetPrefs(); | |
| 303 prefs->SetInteger(prefs::kGeolocationDefaultContentSetting, | |
| 304 CONTENT_SETTING_ALLOW); | |
| 305 EXPECT_EQ(2, observer.counter); | |
| 306 EXPECT_EQ(map, observer.last_notifier); | |
| 307 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
| 308 EXPECT_EQ(CONTENT_SETTING_ALLOW, map->GetDefaultContentSetting()); | |
| 309 } | |
| OLD | NEW |