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 // TODO(markusheintz): I think it would be better to send notifications only | |
69 // for a specific content-settings-type. | |
markusheintz_
2010/12/08 14:03:06
sure can do, pls remove this TODO and add a bug an
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
Done.
| |
70 | |
71 // Set the managed default-content-setting. | |
72 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | |
73 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | |
74 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); | |
75 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); | |
76 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
77 EXPECT_TRUE(observer.last_update_all); | |
78 EXPECT_TRUE(observer.last_update_all_types); | |
79 EXPECT_EQ(1, observer.counter); | |
80 | |
81 // Remove the managed default-content-setting. | |
82 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | |
83 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier); | |
84 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | |
85 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); | |
86 EXPECT_TRUE(observer.last_update_all); | |
87 EXPECT_TRUE(observer.last_update_all_types); | |
88 EXPECT_EQ(2, observer.counter); | |
89 } | |
90 | |
91 } // namespace | |
OLD | NEW |