| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 host_content_settings_map->SetDefaultContentSetting( | 318 host_content_settings_map->SetDefaultContentSetting( |
| 319 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 319 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 320 } | 320 } |
| 321 | 321 |
| 322 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 322 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
| 323 TestingProfile profile; | 323 TestingProfile profile; |
| 324 HostContentSettingsMap* host_content_settings_map = | 324 HostContentSettingsMap* host_content_settings_map = |
| 325 profile.GetHostContentSettingsMap(); | 325 profile.GetHostContentSettingsMap(); |
| 326 | 326 |
| 327 PrefService* prefs = profile.GetPrefs(); | 327 PrefService* prefs = profile.GetPrefs(); |
| 328 | |
| 329 // Make a copy of the default pref value so we can reset it later. | |
| 330 scoped_ptr<base::Value> default_value(prefs->FindPreference( | |
| 331 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | |
| 332 | |
| 333 GURL host("http://example.com"); | 328 GURL host("http://example.com"); |
| 334 | 329 |
| 335 host_content_settings_map->SetDefaultContentSetting( | 330 host_content_settings_map->SetDefaultContentSetting( |
| 336 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 331 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 337 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 332 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 338 host_content_settings_map->GetContentSetting( | 333 host_content_settings_map->GetContentSetting( |
| 339 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 334 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 340 | 335 |
| 341 // Make a copy of the pref's new value so we can reset it later. | |
| 342 scoped_ptr<base::Value> new_value(prefs->FindPreference( | |
| 343 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | |
| 344 | |
| 345 // Clearing the backing pref should also clear the internal cache. | 336 // Clearing the backing pref should also clear the internal cache. |
| 346 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 337 prefs->ClearPref(prefs::kDefaultImagesSetting); |
| 347 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 338 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 348 host_content_settings_map->GetContentSetting( | 339 host_content_settings_map->GetContentSetting( |
| 349 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 340 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 350 | 341 |
| 351 // Reseting the pref to its previous value should update the cache. | 342 // Reseting the pref to its previous value should update the cache. |
| 352 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 343 prefs->SetInteger(prefs::kDefaultImagesSetting, CONTENT_SETTING_BLOCK); |
| 353 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 344 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 354 host_content_settings_map->GetContentSetting( | 345 host_content_settings_map->GetContentSetting( |
| 355 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 346 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 356 } | 347 } |
| 357 | 348 |
| 358 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 349 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
| 359 TestingProfile profile; | 350 TestingProfile profile; |
| 360 HostContentSettingsMap* host_content_settings_map = | 351 HostContentSettingsMap* host_content_settings_map = |
| 361 profile.GetHostContentSettingsMap(); | 352 profile.GetHostContentSettingsMap(); |
| 362 | 353 |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1016 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1007 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1017 host_content_settings_map->GetContentSetting( | 1008 host_content_settings_map->GetContentSetting( |
| 1018 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1009 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1019 host_content_settings_map->SetContentSetting( | 1010 host_content_settings_map->SetContentSetting( |
| 1020 pattern, | 1011 pattern, |
| 1021 ContentSettingsPattern::Wildcard(), | 1012 ContentSettingsPattern::Wildcard(), |
| 1022 CONTENT_SETTINGS_TYPE_IMAGES, | 1013 CONTENT_SETTINGS_TYPE_IMAGES, |
| 1023 std::string(), | 1014 std::string(), |
| 1024 CONTENT_SETTING_DEFAULT); | 1015 CONTENT_SETTING_DEFAULT); |
| 1025 } | 1016 } |
| OLD | NEW |