OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/content_settings/policy_content_settings_provider.h" |
| 6 |
| 7 #include "chrome/browser/content_settings/host_content_settings_map_unittest.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/common/url_constants.h" |
| 11 #include "chrome/test/testing_pref_service.h" |
| 12 #include "chrome/test/testing_profile.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 |
| 16 namespace { |
| 17 |
| 18 class PolicyContentSettingsProviderTest : public testing::Test { |
| 19 public: |
| 20 PolicyContentSettingsProviderTest() |
| 21 : ui_thread_(BrowserThread::UI, &message_loop_) { |
| 22 } |
| 23 |
| 24 protected: |
| 25 MessageLoop message_loop_; |
| 26 BrowserThread ui_thread_; |
| 27 }; |
| 28 |
| 29 TEST_F(PolicyContentSettingsProviderTest, DefaultValues) { |
| 30 TestingProfile profile; |
| 31 PolicyContentSettingsProvider provider(&profile); |
| 32 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 33 |
| 34 // By default, policies should be off. |
| 35 ASSERT_FALSE( |
| 36 provider.CanProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 37 ASSERT_FALSE( |
| 38 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 39 |
| 40 // Set managed-default-content-setting through the coresponding preferences. |
| 41 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, |
| 42 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 43 ASSERT_TRUE( |
| 44 provider.CanProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 45 ASSERT_TRUE( |
| 46 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 47 ASSERT_EQ(CONTENT_SETTING_BLOCK, |
| 48 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 49 |
| 50 // Remove managed-default-content-settings-preferences. |
| 51 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); |
| 52 ASSERT_FALSE( |
| 53 provider.CanProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 54 ASSERT_FALSE( |
| 55 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); |
| 56 } |
| 57 |
| 58 // When a default-content-setting is set to a managed setting a |
| 59 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen |
| 60 // if the managed setting is removed. |
| 61 TEST_F(PolicyContentSettingsProviderTest, ObserveManagedSettingsChange) { |
| 62 TestingProfile profile; |
| 63 StubSettingsObserver observer; |
| 64 // Make sure the content settings map exists. |
| 65 profile.GetHostContentSettingsMap(); |
| 66 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 67 |
| 68 // Set the managed default-content-setting. |
| 69 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, |
| 70 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 71 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); |
| 72 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 73 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 74 EXPECT_TRUE(observer.last_update_all); |
| 75 EXPECT_TRUE(observer.last_update_all_types); |
| 76 EXPECT_EQ(1, observer.counter); |
| 77 |
| 78 // Remove the managed default-content-setting. |
| 79 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 80 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); |
| 81 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 82 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 83 EXPECT_TRUE(observer.last_update_all); |
| 84 EXPECT_TRUE(observer.last_update_all_types); |
| 85 EXPECT_EQ(2, observer.counter); |
| 86 } |
| 87 |
| 88 } // namespace |
OLD | NEW |