Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: chrome/browser/content_settings/content_settings_default_provider_unittest.cc

Issue 8539004: Replace SetContentSetting method of the content_settings::Provider interface with GetWebsiteSetting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "chrome/browser/content_settings/content_settings_default_provider.h" 6 #include "chrome/browser/content_settings/content_settings_default_provider.h"
7 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 7 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
8 #include "chrome/browser/content_settings/content_settings_utils.h" 8 #include "chrome/browser/content_settings/content_settings_utils.h"
9 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/common/pref_names.h" 10 #include "chrome/common/pref_names.h"
11 #include "chrome/test/base/testing_pref_service.h" 11 #include "chrome/test/base/testing_pref_service.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "content/test/test_browser_thread.h" 13 #include "content/test/test_browser_thread.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using ::testing::_; 17 using ::testing::_;
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 class DefaultProviderTest : public testing::Test { 20 class DefaultProviderTest : public testing::Test {
21 public: 21 public:
22 DefaultProviderTest() 22 DefaultProviderTest()
23 : ui_thread_(BrowserThread::UI, &message_loop_), 23 : ui_thread_(BrowserThread::UI, &message_loop_),
24 provider_(profile_.GetPrefs(), false) { 24 provider_(profile_.GetPrefs(), false) {
25 value_allow.reset(Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
26 value_block.reset(Value::CreateIntegerValue(CONTENT_SETTING_BLOCK));
25 } 27 }
26 ~DefaultProviderTest() { 28 ~DefaultProviderTest() {
27 provider_.ShutdownOnUIThread(); 29 provider_.ShutdownOnUIThread();
28 } 30 }
29 31
30 protected: 32 protected:
31 MessageLoop message_loop_; 33 MessageLoop message_loop_;
32 content::TestBrowserThread ui_thread_; 34 content::TestBrowserThread ui_thread_;
33 TestingProfile profile_; 35 TestingProfile profile_;
34 content_settings::DefaultProvider provider_; 36 content_settings::DefaultProvider provider_;
37 scoped_ptr<base::Value> value_allow;
Bernhard Bauer 2011/11/11 14:00:40 Class member names should end with an underscore.
markusheintz_ 2011/11/14 11:15:10 Yeah so true :( . But I don't need this any more.
38 scoped_ptr<base::Value> value_block;
35 }; 39 };
36 40
37 TEST_F(DefaultProviderTest, DefaultValues) { 41 TEST_F(DefaultProviderTest, DefaultValues) {
38 // Check setting defaults. 42 // Check setting defaults.
39 EXPECT_EQ(CONTENT_SETTING_ALLOW, 43 EXPECT_EQ(CONTENT_SETTING_ALLOW,
40 GetContentSetting(&provider_, 44 GetContentSetting(&provider_,
41 GURL(), 45 GURL(),
42 GURL(), 46 GURL(),
43 CONTENT_SETTINGS_TYPE_COOKIES, 47 CONTENT_SETTINGS_TYPE_COOKIES,
44 std::string(), 48 std::string(),
45 false)); 49 false));
46 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 50 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
47 ContentSettingsPattern::Wildcard(), 51 ContentSettingsPattern::Wildcard(),
48 CONTENT_SETTINGS_TYPE_COOKIES, 52 CONTENT_SETTINGS_TYPE_COOKIES,
49 std::string(), 53 std::string(),
50 CONTENT_SETTING_BLOCK); 54 value_block.get());
51 EXPECT_EQ(CONTENT_SETTING_BLOCK, 55 EXPECT_EQ(CONTENT_SETTING_BLOCK,
52 GetContentSetting(&provider_, 56 GetContentSetting(&provider_,
53 GURL(), 57 GURL(),
54 GURL(), 58 GURL(),
55 CONTENT_SETTINGS_TYPE_COOKIES, 59 CONTENT_SETTINGS_TYPE_COOKIES,
56 std::string(), 60 std::string(),
57 false)); 61 false));
58 62
59 EXPECT_EQ(CONTENT_SETTING_ASK, 63 EXPECT_EQ(CONTENT_SETTING_ASK,
60 GetContentSetting(&provider_, 64 GetContentSetting(&provider_,
61 GURL(), 65 GURL(),
62 GURL(), 66 GURL(),
63 CONTENT_SETTINGS_TYPE_GEOLOCATION, 67 CONTENT_SETTINGS_TYPE_GEOLOCATION,
64 std::string(), 68 std::string(),
65 false)); 69 false));
66 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 70 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
67 ContentSettingsPattern::Wildcard(), 71 ContentSettingsPattern::Wildcard(),
68 CONTENT_SETTINGS_TYPE_GEOLOCATION, 72 CONTENT_SETTINGS_TYPE_GEOLOCATION,
69 std::string(), 73 std::string(),
70 CONTENT_SETTING_BLOCK); 74 value_block.get());
71 EXPECT_EQ(CONTENT_SETTING_BLOCK, 75 EXPECT_EQ(CONTENT_SETTING_BLOCK,
72 GetContentSetting(&provider_, 76 GetContentSetting(&provider_,
73 GURL(), 77 GURL(),
74 GURL(), 78 GURL(),
75 CONTENT_SETTINGS_TYPE_GEOLOCATION, 79 CONTENT_SETTINGS_TYPE_GEOLOCATION,
76 std::string(), 80 std::string(),
77 false)); 81 false));
78 } 82 }
79 83
80 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { 84 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) {
81 GURL primary_url("http://www.google.com"); 85 GURL primary_url("http://www.google.com");
82 GURL secondary_url("http://www.google.com"); 86 GURL secondary_url("http://www.google.com");
83 87
84 EXPECT_EQ(CONTENT_SETTING_ALLOW, 88 EXPECT_EQ(CONTENT_SETTING_ALLOW,
85 GetContentSetting(&provider_, 89 GetContentSetting(&provider_,
86 primary_url, 90 primary_url,
87 secondary_url, 91 secondary_url,
88 CONTENT_SETTINGS_TYPE_COOKIES, 92 CONTENT_SETTINGS_TYPE_COOKIES,
89 std::string(), 93 std::string(),
90 false)); 94 false));
91 provider_.SetContentSetting(ContentSettingsPattern::FromURL(primary_url), 95 provider_.SetWebsiteSetting(ContentSettingsPattern::FromURL(primary_url),
92 ContentSettingsPattern::FromURL(secondary_url), 96 ContentSettingsPattern::FromURL(secondary_url),
93 CONTENT_SETTINGS_TYPE_COOKIES, 97 CONTENT_SETTINGS_TYPE_COOKIES,
94 std::string(), 98 std::string(),
95 CONTENT_SETTING_BLOCK); 99 value_block.get());
96 EXPECT_EQ(CONTENT_SETTING_ALLOW, 100 EXPECT_EQ(CONTENT_SETTING_ALLOW,
97 GetContentSetting(&provider_, 101 GetContentSetting(&provider_,
98 primary_url, 102 primary_url,
99 secondary_url, 103 secondary_url,
100 CONTENT_SETTINGS_TYPE_COOKIES, 104 CONTENT_SETTINGS_TYPE_COOKIES,
101 std::string(), 105 std::string(),
102 false)); 106 false));
103 } 107 }
104 108
105 TEST_F(DefaultProviderTest, Observer) { 109 TEST_F(DefaultProviderTest, Observer) {
106 content_settings::MockObserver mock_observer; 110 content_settings::MockObserver mock_observer;
107 EXPECT_CALL(mock_observer, 111 EXPECT_CALL(mock_observer,
108 OnContentSettingChanged( 112 OnContentSettingChanged(
109 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); 113 _, _, CONTENT_SETTINGS_TYPE_IMAGES, ""));
110 provider_.AddObserver(&mock_observer); 114 provider_.AddObserver(&mock_observer);
111 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 115 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
112 ContentSettingsPattern::Wildcard(), 116 ContentSettingsPattern::Wildcard(),
113 CONTENT_SETTINGS_TYPE_IMAGES, 117 CONTENT_SETTINGS_TYPE_IMAGES,
114 std::string(), 118 std::string(),
115 CONTENT_SETTING_BLOCK); 119 value_block.get());
116 120
117 EXPECT_CALL(mock_observer, 121 EXPECT_CALL(mock_observer,
118 OnContentSettingChanged( 122 OnContentSettingChanged(
119 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); 123 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
120 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 124 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
121 ContentSettingsPattern::Wildcard(), 125 ContentSettingsPattern::Wildcard(),
122 CONTENT_SETTINGS_TYPE_GEOLOCATION, 126 CONTENT_SETTINGS_TYPE_GEOLOCATION,
123 std::string(), 127 std::string(),
124 CONTENT_SETTING_BLOCK); 128 value_block.get());
125 } 129 }
126 130
127 131
128 TEST_F(DefaultProviderTest, ObserveDefaultPref) { 132 TEST_F(DefaultProviderTest, ObserveDefaultPref) {
129 PrefService* prefs = profile_.GetPrefs(); 133 PrefService* prefs = profile_.GetPrefs();
130 134
131 // Make a copy of the default pref value so we can reset it later. 135 // Make a copy of the default pref value so we can reset it later.
132 scoped_ptr<Value> default_value(prefs->FindPreference( 136 scoped_ptr<Value> default_value(prefs->FindPreference(
133 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 137 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
134 138
135 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 139 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
136 ContentSettingsPattern::Wildcard(), 140 ContentSettingsPattern::Wildcard(),
137 CONTENT_SETTINGS_TYPE_COOKIES, 141 CONTENT_SETTINGS_TYPE_COOKIES,
138 std::string(), 142 std::string(),
139 CONTENT_SETTING_BLOCK); 143 value_block.get());
140 EXPECT_EQ(CONTENT_SETTING_BLOCK, 144 EXPECT_EQ(CONTENT_SETTING_BLOCK,
141 GetContentSetting(&provider_, 145 GetContentSetting(&provider_,
142 GURL(), 146 GURL(),
143 GURL(), 147 GURL(),
144 CONTENT_SETTINGS_TYPE_COOKIES, 148 CONTENT_SETTINGS_TYPE_COOKIES,
145 std::string(), 149 std::string(),
146 false)); 150 false));
147 151
148 // Make a copy of the pref's new value so we can reset it later. 152 // Make a copy of the pref's new value so we can reset it later.
149 scoped_ptr<Value> new_value(prefs->FindPreference( 153 scoped_ptr<Value> new_value(prefs->FindPreference(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 EXPECT_EQ(CONTENT_SETTING_ALLOW, 186 EXPECT_EQ(CONTENT_SETTING_ALLOW,
183 GetContentSetting(&otr_provider, 187 GetContentSetting(&otr_provider,
184 GURL(), 188 GURL(),
185 GURL(), 189 GURL(),
186 CONTENT_SETTINGS_TYPE_COOKIES, 190 CONTENT_SETTINGS_TYPE_COOKIES,
187 std::string(), 191 std::string(),
188 true)); 192 true));
189 193
190 // Changing content settings on the main provider should also affect the 194 // Changing content settings on the main provider should also affect the
191 // incognito map. 195 // incognito map.
192 provider_.SetContentSetting(ContentSettingsPattern::Wildcard(), 196 provider_.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
193 ContentSettingsPattern::Wildcard(), 197 ContentSettingsPattern::Wildcard(),
194 CONTENT_SETTINGS_TYPE_COOKIES, 198 CONTENT_SETTINGS_TYPE_COOKIES,
195 std::string(), 199 std::string(),
196 CONTENT_SETTING_BLOCK); 200 value_block.get());
197 EXPECT_EQ(CONTENT_SETTING_BLOCK, 201 EXPECT_EQ(CONTENT_SETTING_BLOCK,
198 GetContentSetting(&provider_, 202 GetContentSetting(&provider_,
199 GURL(), 203 GURL(),
200 GURL(), 204 GURL(),
201 CONTENT_SETTINGS_TYPE_COOKIES, 205 CONTENT_SETTINGS_TYPE_COOKIES,
202 std::string(), 206 std::string(),
203 false)); 207 false));
204 208
205 EXPECT_EQ(CONTENT_SETTING_BLOCK, 209 EXPECT_EQ(CONTENT_SETTING_BLOCK,
206 GetContentSetting(&otr_provider, 210 GetContentSetting(&otr_provider,
207 GURL(), 211 GURL(),
208 GURL(), 212 GURL(),
209 CONTENT_SETTINGS_TYPE_COOKIES, 213 CONTENT_SETTINGS_TYPE_COOKIES,
210 std::string(), 214 std::string(),
211 true)); 215 true));
212 216
213 // Changing content settings on the incognito provider should be ignored. 217 // Changing content settings on the incognito provider should be ignored.
214 otr_provider.SetContentSetting(ContentSettingsPattern::Wildcard(), 218 otr_provider.SetWebsiteSetting(ContentSettingsPattern::Wildcard(),
215 ContentSettingsPattern::Wildcard(), 219 ContentSettingsPattern::Wildcard(),
216 CONTENT_SETTINGS_TYPE_COOKIES, 220 CONTENT_SETTINGS_TYPE_COOKIES,
217 std::string(), 221 std::string(),
218 CONTENT_SETTING_ALLOW); 222 value_allow.get());
219 EXPECT_EQ(CONTENT_SETTING_BLOCK, 223 EXPECT_EQ(CONTENT_SETTING_BLOCK,
220 GetContentSetting(&provider_, 224 GetContentSetting(&provider_,
221 GURL(), 225 GURL(),
222 GURL(), 226 GURL(),
223 CONTENT_SETTINGS_TYPE_COOKIES, 227 CONTENT_SETTINGS_TYPE_COOKIES,
224 std::string(), 228 std::string(),
225 false)); 229 false));
226 230
227 EXPECT_EQ(CONTENT_SETTING_BLOCK, 231 EXPECT_EQ(CONTENT_SETTING_BLOCK,
228 GetContentSetting(&otr_provider, 232 GetContentSetting(&otr_provider,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 283
280 EXPECT_EQ(CONTENT_SETTING_ALLOW, 284 EXPECT_EQ(CONTENT_SETTING_ALLOW,
281 GetContentSetting(&provider, 285 GetContentSetting(&provider,
282 GURL(), 286 GURL(),
283 GURL(), 287 GURL(),
284 CONTENT_SETTINGS_TYPE_GEOLOCATION, 288 CONTENT_SETTINGS_TYPE_GEOLOCATION,
285 std::string(), 289 std::string(),
286 false)); 290 false));
287 provider.ShutdownOnUIThread(); 291 provider.ShutdownOnUIThread();
288 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698