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

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

Issue 1442083002: Stop inheriting push notification permissions from regular to incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review nits Created 5 years 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
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 "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/prefs/scoped_user_pref_update.h" 8 #include "base/prefs/scoped_user_pref_update.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
13 #include "components/content_settings/core/browser/content_settings_default_prov ider.h" 13 #include "components/content_settings/core/browser/content_settings_default_prov ider.h"
14 #include "components/content_settings/core/browser/content_settings_utils.h" 14 #include "components/content_settings/core/browser/content_settings_utils.h"
15 #include "components/content_settings/core/browser/website_settings_info.h" 15 #include "components/content_settings/core/browser/website_settings_info.h"
16 #include "components/content_settings/core/browser/website_settings_registry.h" 16 #include "components/content_settings/core/browser/website_settings_registry.h"
17 #include "components/content_settings/core/test/content_settings_test_utils.h" 17 #include "components/content_settings/core/test/content_settings_test_utils.h"
18 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 #include "url/gurl.h" 20 #include "url/gurl.h"
21 21
22 using ::testing::_; 22 using ::testing::_;
23 23
24 namespace content_settings {
25
24 class DefaultProviderTest : public testing::Test { 26 class DefaultProviderTest : public testing::Test {
25 public: 27 public:
26 DefaultProviderTest() 28 DefaultProviderTest()
27 : provider_(profile_.GetPrefs(), false) { 29 : provider_(profile_.GetPrefs(), false) {
28 } 30 }
29 ~DefaultProviderTest() override { provider_.ShutdownOnUIThread(); } 31 ~DefaultProviderTest() override { provider_.ShutdownOnUIThread(); }
30 32
31 protected: 33 protected:
32 content::TestBrowserThreadBundle thread_bundle_; 34 content::TestBrowserThreadBundle thread_bundle_;
33 TestingProfile profile_; 35 TestingProfile profile_;
34 content_settings::DefaultProvider provider_; 36 DefaultProvider provider_;
35 }; 37 };
36 38
37 TEST_F(DefaultProviderTest, DefaultValues) { 39 TEST_F(DefaultProviderTest, DefaultValues) {
38 // Check setting defaults. 40 // Check setting defaults.
39 EXPECT_EQ(CONTENT_SETTING_ALLOW, 41 EXPECT_EQ(CONTENT_SETTING_ALLOW,
40 GetContentSetting(&provider_, 42 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
41 GURL(), 43 CONTENT_SETTINGS_TYPE_COOKIES,
42 GURL(), 44 std::string(), false));
43 CONTENT_SETTINGS_TYPE_COOKIES,
44 std::string(),
45 false));
46 provider_.SetWebsiteSetting( 45 provider_.SetWebsiteSetting(
47 ContentSettingsPattern::Wildcard(), 46 ContentSettingsPattern::Wildcard(),
48 ContentSettingsPattern::Wildcard(), 47 ContentSettingsPattern::Wildcard(),
49 CONTENT_SETTINGS_TYPE_COOKIES, 48 CONTENT_SETTINGS_TYPE_COOKIES,
50 std::string(), 49 std::string(),
51 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 50 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
52 EXPECT_EQ(CONTENT_SETTING_BLOCK, 51 EXPECT_EQ(CONTENT_SETTING_BLOCK,
53 GetContentSetting(&provider_, 52 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
54 GURL(), 53 CONTENT_SETTINGS_TYPE_COOKIES,
55 GURL(), 54 std::string(), false));
56 CONTENT_SETTINGS_TYPE_COOKIES,
57 std::string(),
58 false));
59 55
60 EXPECT_EQ(CONTENT_SETTING_ASK, 56 EXPECT_EQ(CONTENT_SETTING_ASK,
61 GetContentSetting(&provider_, 57 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
62 GURL(), 58 CONTENT_SETTINGS_TYPE_GEOLOCATION,
63 GURL(), 59 std::string(), false));
64 CONTENT_SETTINGS_TYPE_GEOLOCATION,
65 std::string(),
66 false));
67 provider_.SetWebsiteSetting( 60 provider_.SetWebsiteSetting(
68 ContentSettingsPattern::Wildcard(), 61 ContentSettingsPattern::Wildcard(),
69 ContentSettingsPattern::Wildcard(), 62 ContentSettingsPattern::Wildcard(),
70 CONTENT_SETTINGS_TYPE_GEOLOCATION, 63 CONTENT_SETTINGS_TYPE_GEOLOCATION,
71 std::string(), 64 std::string(),
72 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 65 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
73 EXPECT_EQ(CONTENT_SETTING_BLOCK, 66 EXPECT_EQ(CONTENT_SETTING_BLOCK,
74 GetContentSetting(&provider_, 67 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
75 GURL(), 68 CONTENT_SETTINGS_TYPE_GEOLOCATION,
76 GURL(), 69 std::string(), false));
77 CONTENT_SETTINGS_TYPE_GEOLOCATION,
78 std::string(),
79 false));
80 70
81 scoped_ptr<base::Value> value( 71 scoped_ptr<base::Value> value(TestUtils::GetContentSettingValue(
82 GetContentSettingValue(&provider_, 72 &provider_, GURL("http://example.com/"), GURL("http://example.com/"),
83 GURL("http://example.com/"), 73 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, std::string(), false));
84 GURL("http://example.com/"),
85 CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
86 std::string(),
87 false));
88 EXPECT_FALSE(value.get()); 74 EXPECT_FALSE(value.get());
89 } 75 }
90 76
91 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) { 77 TEST_F(DefaultProviderTest, IgnoreNonDefaultSettings) {
92 GURL primary_url("http://www.google.com"); 78 GURL primary_url("http://www.google.com");
93 GURL secondary_url("http://www.google.com"); 79 GURL secondary_url("http://www.google.com");
94 80
95 EXPECT_EQ(CONTENT_SETTING_ALLOW, 81 EXPECT_EQ(CONTENT_SETTING_ALLOW,
96 GetContentSetting(&provider_, 82 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url,
97 primary_url, 83 CONTENT_SETTINGS_TYPE_COOKIES,
98 secondary_url, 84 std::string(), false));
99 CONTENT_SETTINGS_TYPE_COOKIES,
100 std::string(),
101 false));
102 scoped_ptr<base::Value> value( 85 scoped_ptr<base::Value> value(
103 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 86 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
104 bool owned = provider_.SetWebsiteSetting( 87 bool owned = provider_.SetWebsiteSetting(
105 ContentSettingsPattern::FromURL(primary_url), 88 ContentSettingsPattern::FromURL(primary_url),
106 ContentSettingsPattern::FromURL(secondary_url), 89 ContentSettingsPattern::FromURL(secondary_url),
107 CONTENT_SETTINGS_TYPE_COOKIES, 90 CONTENT_SETTINGS_TYPE_COOKIES,
108 std::string(), 91 std::string(),
109 value.get()); 92 value.get());
110 EXPECT_FALSE(owned); 93 EXPECT_FALSE(owned);
111 EXPECT_EQ(CONTENT_SETTING_ALLOW, 94 EXPECT_EQ(CONTENT_SETTING_ALLOW,
112 GetContentSetting(&provider_, 95 TestUtils::GetContentSetting(&provider_, primary_url, secondary_url,
113 primary_url, 96 CONTENT_SETTINGS_TYPE_COOKIES,
114 secondary_url, 97 std::string(), false));
115 CONTENT_SETTINGS_TYPE_COOKIES,
116 std::string(),
117 false));
118 } 98 }
119 99
120 TEST_F(DefaultProviderTest, Observer) { 100 TEST_F(DefaultProviderTest, Observer) {
121 content_settings::MockObserver mock_observer; 101 MockObserver mock_observer;
122 EXPECT_CALL(mock_observer, 102 EXPECT_CALL(mock_observer,
123 OnContentSettingChanged( 103 OnContentSettingChanged(
124 _, _, CONTENT_SETTINGS_TYPE_IMAGES, "")); 104 _, _, CONTENT_SETTINGS_TYPE_IMAGES, ""));
125 provider_.AddObserver(&mock_observer); 105 provider_.AddObserver(&mock_observer);
126 provider_.SetWebsiteSetting( 106 provider_.SetWebsiteSetting(
127 ContentSettingsPattern::Wildcard(), 107 ContentSettingsPattern::Wildcard(),
128 ContentSettingsPattern::Wildcard(), 108 ContentSettingsPattern::Wildcard(),
129 CONTENT_SETTINGS_TYPE_IMAGES, 109 CONTENT_SETTINGS_TYPE_IMAGES,
130 std::string(), 110 std::string(),
131 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 111 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
(...skipping 13 matching lines...) Expand all
145 TEST_F(DefaultProviderTest, ObservePref) { 125 TEST_F(DefaultProviderTest, ObservePref) {
146 PrefService* prefs = profile_.GetPrefs(); 126 PrefService* prefs = profile_.GetPrefs();
147 127
148 provider_.SetWebsiteSetting( 128 provider_.SetWebsiteSetting(
149 ContentSettingsPattern::Wildcard(), 129 ContentSettingsPattern::Wildcard(),
150 ContentSettingsPattern::Wildcard(), 130 ContentSettingsPattern::Wildcard(),
151 CONTENT_SETTINGS_TYPE_COOKIES, 131 CONTENT_SETTINGS_TYPE_COOKIES,
152 std::string(), 132 std::string(),
153 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 133 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
154 EXPECT_EQ(CONTENT_SETTING_BLOCK, 134 EXPECT_EQ(CONTENT_SETTING_BLOCK,
155 GetContentSetting(&provider_, 135 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
156 GURL(), 136 CONTENT_SETTINGS_TYPE_COOKIES,
157 GURL(), 137 std::string(), false));
158 CONTENT_SETTINGS_TYPE_COOKIES, 138 const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
159 std::string(), 139 CONTENT_SETTINGS_TYPE_COOKIES);
160 false));
161 const content_settings::WebsiteSettingsInfo* info =
162 content_settings::WebsiteSettingsRegistry::GetInstance()->Get(
163 CONTENT_SETTINGS_TYPE_COOKIES);
164 // Clearing the backing pref should also clear the internal cache. 140 // Clearing the backing pref should also clear the internal cache.
165 prefs->ClearPref(info->default_value_pref_name()); 141 prefs->ClearPref(info->default_value_pref_name());
166 EXPECT_EQ(CONTENT_SETTING_ALLOW, 142 EXPECT_EQ(CONTENT_SETTING_ALLOW,
167 GetContentSetting(&provider_, 143 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
168 GURL(), 144 CONTENT_SETTINGS_TYPE_COOKIES,
169 GURL(), 145 std::string(), false));
170 CONTENT_SETTINGS_TYPE_COOKIES,
171 std::string(),
172 false));
173 // Reseting the pref to its previous value should update the cache. 146 // Reseting the pref to its previous value should update the cache.
174 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK); 147 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK);
175 EXPECT_EQ(CONTENT_SETTING_BLOCK, 148 EXPECT_EQ(CONTENT_SETTING_BLOCK,
176 GetContentSetting(&provider_, 149 TestUtils::GetContentSetting(&provider_, GURL(), GURL(),
177 GURL(), 150 CONTENT_SETTINGS_TYPE_COOKIES,
178 GURL(), 151 std::string(), false));
179 CONTENT_SETTINGS_TYPE_COOKIES,
180 std::string(),
181 false));
182 } 152 }
183 153
184 TEST_F(DefaultProviderTest, OffTheRecord) { 154 TEST_F(DefaultProviderTest, OffTheRecord) {
185 content_settings::DefaultProvider otr_provider(profile_.GetPrefs(), true); 155 DefaultProvider otr_provider(profile_.GetPrefs(), true /* incognito */);
186 156
187 EXPECT_EQ(CONTENT_SETTING_ALLOW, 157 EXPECT_EQ(CONTENT_SETTING_ALLOW,
188 GetContentSetting(&provider_, 158 TestUtils::GetContentSetting(
189 GURL(), 159 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
190 GURL(), 160 std::string(), false /* include_incognito */));
191 CONTENT_SETTINGS_TYPE_COOKIES,
192 std::string(),
193 false));
194 EXPECT_EQ(CONTENT_SETTING_ALLOW, 161 EXPECT_EQ(CONTENT_SETTING_ALLOW,
195 GetContentSetting(&otr_provider, 162 TestUtils::GetContentSetting(
196 GURL(), 163 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
197 GURL(), 164 std::string(), true /* include_incognito */));
198 CONTENT_SETTINGS_TYPE_COOKIES,
199 std::string(),
200 true));
201 165
202 // Changing content settings on the main provider should also affect the 166 // Changing content settings on the main provider should also affect the
203 // incognito map. 167 // incognito map.
204 provider_.SetWebsiteSetting( 168 provider_.SetWebsiteSetting(
205 ContentSettingsPattern::Wildcard(), 169 ContentSettingsPattern::Wildcard(),
206 ContentSettingsPattern::Wildcard(), 170 ContentSettingsPattern::Wildcard(),
207 CONTENT_SETTINGS_TYPE_COOKIES, 171 CONTENT_SETTINGS_TYPE_COOKIES,
208 std::string(), 172 std::string(),
209 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 173 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
210 EXPECT_EQ(CONTENT_SETTING_BLOCK, 174 EXPECT_EQ(CONTENT_SETTING_BLOCK,
211 GetContentSetting(&provider_, 175 TestUtils::GetContentSetting(
212 GURL(), 176 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
213 GURL(), 177 std::string(), false /* include_incognito */));
214 CONTENT_SETTINGS_TYPE_COOKIES,
215 std::string(),
216 false));
217 178
218 EXPECT_EQ(CONTENT_SETTING_BLOCK, 179 EXPECT_EQ(CONTENT_SETTING_BLOCK,
219 GetContentSetting(&otr_provider, 180 TestUtils::GetContentSetting(
220 GURL(), 181 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
221 GURL(), 182 std::string(), true /* include_incognito */));
222 CONTENT_SETTINGS_TYPE_COOKIES,
223 std::string(),
224 true));
225 183
226 // Changing content settings on the incognito provider should be ignored. 184 // Changing content settings on the incognito provider should be ignored.
227 scoped_ptr<base::Value> value( 185 scoped_ptr<base::Value> value(
228 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 186 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
229 bool owned = otr_provider.SetWebsiteSetting( 187 bool owned = otr_provider.SetWebsiteSetting(
230 ContentSettingsPattern::Wildcard(), 188 ContentSettingsPattern::Wildcard(),
231 ContentSettingsPattern::Wildcard(), 189 ContentSettingsPattern::Wildcard(),
232 CONTENT_SETTINGS_TYPE_COOKIES, 190 CONTENT_SETTINGS_TYPE_COOKIES,
233 std::string(), 191 std::string(),
234 value.get()); 192 value.get());
235 EXPECT_FALSE(owned); 193 EXPECT_FALSE(owned);
236 EXPECT_EQ(CONTENT_SETTING_BLOCK, 194 EXPECT_EQ(CONTENT_SETTING_BLOCK,
237 GetContentSetting(&provider_, 195 TestUtils::GetContentSetting(
238 GURL(), 196 &provider_, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
239 GURL(), 197 std::string(), false /* include_incognito */));
240 CONTENT_SETTINGS_TYPE_COOKIES,
241 std::string(),
242 false));
243 198
244 EXPECT_EQ(CONTENT_SETTING_BLOCK, 199 EXPECT_EQ(CONTENT_SETTING_BLOCK,
245 GetContentSetting(&otr_provider, 200 TestUtils::GetContentSetting(
246 GURL(), 201 &otr_provider, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
247 GURL(), 202 std::string(), true /* include_incognito */));
248 CONTENT_SETTINGS_TYPE_COOKIES, 203
249 std::string(), 204 // Check that new OTR DefaultProviders also inherit the correct value.
250 true)); 205 DefaultProvider otr_provider2(profile_.GetPrefs(), true /* incognito */);
206 EXPECT_EQ(CONTENT_SETTING_BLOCK,
207 TestUtils::GetContentSetting(
208 &otr_provider2, GURL(), GURL(), CONTENT_SETTINGS_TYPE_COOKIES,
209 std::string(), true /* include_incognito */));
210
251 otr_provider.ShutdownOnUIThread(); 211 otr_provider.ShutdownOnUIThread();
212 otr_provider2.ShutdownOnUIThread();
252 } 213 }
214
215 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698