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

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

Issue 819463002: Implement RevokePermission() method in PermissionService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add crbug references Created 5 years, 10 months 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/content_settings/permission_context_base.h" 5 #include "chrome/browser/content_settings/permission_context_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/content_settings/permission_queue_controller.h" 9 #include "chrome/browser/content_settings/permission_queue_controller.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 114
115 RespondToPermission(&permission_context, id, url, true); 115 RespondToPermission(&permission_context, id, url, true);
116 EXPECT_TRUE(permission_context.permission_set()); 116 EXPECT_TRUE(permission_context.permission_set());
117 EXPECT_TRUE(permission_context.permission_granted()); 117 EXPECT_TRUE(permission_context.permission_granted());
118 EXPECT_TRUE(permission_context.tab_context_updated()); 118 EXPECT_TRUE(permission_context.tab_context_updated());
119 119
120 ContentSetting setting = 120 ContentSetting setting =
121 profile()->GetHostContentSettingsMap()->GetContentSetting( 121 profile()->GetHostContentSettingsMap()->GetContentSetting(
122 url.GetOrigin(), url.GetOrigin(), 122 url.GetOrigin(), url.GetOrigin(),
123 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()); 123 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string());
124 EXPECT_EQ(CONTENT_SETTING_ALLOW , setting); 124 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
125 } 125 }
126 126
127 void TestAskAndDismiss_TestContent() { 127 void TestAskAndDismiss_TestContent() {
128 TestPermissionContext permission_context( 128 TestPermissionContext permission_context(
129 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 129 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
130 GURL url("http://www.google.es"); 130 GURL url("http://www.google.es");
131 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 131 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
132 132
133 const PermissionRequestID id( 133 const PermissionRequestID id(
134 web_contents()->GetRenderProcessHost()->GetID(), 134 web_contents()->GetRenderProcessHost()->GetID(),
135 web_contents()->GetRenderViewHost()->GetRoutingID(), 135 web_contents()->GetRenderViewHost()->GetRoutingID(),
136 -1, GURL()); 136 -1, GURL());
137 permission_context.RequestPermission( 137 permission_context.RequestPermission(
138 web_contents(), 138 web_contents(),
139 id, url, true, 139 id, url, true,
140 base::Bind(&TestPermissionContext::TrackPermissionDecision, 140 base::Bind(&TestPermissionContext::TrackPermissionDecision,
141 base::Unretained(&permission_context))); 141 base::Unretained(&permission_context)));
142 142
143 RespondToPermission(&permission_context, id, url, false); 143 RespondToPermission(&permission_context, id, url, false);
144 EXPECT_TRUE(permission_context.permission_set()); 144 EXPECT_TRUE(permission_context.permission_set());
145 EXPECT_FALSE(permission_context.permission_granted()); 145 EXPECT_FALSE(permission_context.permission_granted());
146 EXPECT_TRUE(permission_context.tab_context_updated()); 146 EXPECT_TRUE(permission_context.tab_context_updated());
147 147
148 ContentSetting setting = 148 ContentSetting setting =
149 profile()->GetHostContentSettingsMap()->GetContentSetting( 149 profile()->GetHostContentSettingsMap()->GetContentSetting(
150 url.GetOrigin(), url.GetOrigin(), 150 url.GetOrigin(), url.GetOrigin(),
151 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string()); 151 CONTENT_SETTINGS_TYPE_MIDI_SYSEX, std::string());
152 EXPECT_EQ(CONTENT_SETTING_ASK , setting); 152 EXPECT_EQ(CONTENT_SETTING_ASK, setting);
153 } 153 }
154 154
155 void TestRequestPermissionInvalidUrl(ContentSettingsType type) { 155 void TestRequestPermissionInvalidUrl(ContentSettingsType type) {
156 TestPermissionContext permission_context(profile(), type); 156 TestPermissionContext permission_context(profile(), type);
157 GURL url; 157 GURL url;
158 ASSERT_FALSE(url.is_valid()); 158 ASSERT_FALSE(url.is_valid());
159 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 159 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
160 160
161 const PermissionRequestID id( 161 const PermissionRequestID id(
162 web_contents()->GetRenderProcessHost()->GetID(), 162 web_contents()->GetRenderProcessHost()->GetID(),
163 web_contents()->GetRenderViewHost()->GetRoutingID(), 163 web_contents()->GetRenderViewHost()->GetRoutingID(),
164 -1, GURL()); 164 -1, GURL());
165 permission_context.RequestPermission( 165 permission_context.RequestPermission(
166 web_contents(), 166 web_contents(),
167 id, url, true, 167 id, url, true,
168 base::Bind(&TestPermissionContext::TrackPermissionDecision, 168 base::Bind(&TestPermissionContext::TrackPermissionDecision,
169 base::Unretained(&permission_context))); 169 base::Unretained(&permission_context)));
170 170
171 EXPECT_TRUE(permission_context.permission_set()); 171 EXPECT_TRUE(permission_context.permission_set());
172 EXPECT_FALSE(permission_context.permission_granted()); 172 EXPECT_FALSE(permission_context.permission_granted());
173 EXPECT_TRUE(permission_context.tab_context_updated()); 173 EXPECT_TRUE(permission_context.tab_context_updated());
174 174
175 ContentSetting setting = 175 ContentSetting setting =
176 profile()->GetHostContentSettingsMap()->GetContentSetting( 176 profile()->GetHostContentSettingsMap()->GetContentSetting(
177 url.GetOrigin(), url.GetOrigin(), type, std::string()); 177 url.GetOrigin(), url.GetOrigin(), type, std::string());
178 EXPECT_EQ(CONTENT_SETTING_ASK, setting); 178 EXPECT_EQ(CONTENT_SETTING_ASK, setting);
179 } 179 }
180 180
181 void TestGrantAndRevoke_TestContent(ContentSettingsType type,
182 ContentSetting expected_default) {
183 TestPermissionContext permission_context(profile(), type);
184 GURL url("http://www.google.com");
185 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
186
187 const PermissionRequestID id(
188 web_contents()->GetRenderProcessHost()->GetID(),
189 web_contents()->GetRenderViewHost()->GetRoutingID(),
190 -1, GURL());
191 permission_context.RequestPermission(
192 web_contents(),
193 id, url, true,
194 base::Bind(&TestPermissionContext::TrackPermissionDecision,
195 base::Unretained(&permission_context)));
196
197 RespondToPermission(&permission_context, id, url, true);
198 EXPECT_TRUE(permission_context.permission_set());
199 EXPECT_TRUE(permission_context.permission_granted());
200 EXPECT_TRUE(permission_context.tab_context_updated());
201
202 ContentSetting setting =
203 profile()->GetHostContentSettingsMap()->GetContentSetting(
204 url.GetOrigin(), url.GetOrigin(),
205 type, std::string());
206 EXPECT_EQ(CONTENT_SETTING_ALLOW, setting);
207
208 // Try to reset permission.
209 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin());
210 ContentSetting setting_after_reset =
211 profile()->GetHostContentSettingsMap()->GetContentSetting(
212 url.GetOrigin(), url.GetOrigin(),
213 type, std::string());
214 ContentSetting default_setting =
215 profile()->GetHostContentSettingsMap()->GetDefaultContentSetting(
216 type, nullptr);
217 EXPECT_EQ(default_setting, setting_after_reset);
218 }
219
181 private: 220 private:
182 // ChromeRenderViewHostTestHarness: 221 // ChromeRenderViewHostTestHarness:
183 void SetUp() override { 222 void SetUp() override {
184 ChromeRenderViewHostTestHarness::SetUp(); 223 ChromeRenderViewHostTestHarness::SetUp();
185 InfoBarService::CreateForWebContents(web_contents()); 224 InfoBarService::CreateForWebContents(web_contents());
186 PermissionBubbleManager::CreateForWebContents(web_contents()); 225 PermissionBubbleManager::CreateForWebContents(web_contents());
187 } 226 }
188 227
189 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); 228 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests);
190 }; 229 };
(...skipping 19 matching lines...) Expand all
210 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) { 249 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) {
211 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); 250 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION);
212 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 251 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
213 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 252 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
214 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 253 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
215 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 254 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
216 TestRequestPermissionInvalidUrl( 255 TestRequestPermissionInvalidUrl(
217 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); 256 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
218 #endif 257 #endif
219 } 258 }
259
260 // Simulates granting and revoking of permissions.
261 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) {
262 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
263 CONTENT_SETTING_ASK);
264 // TODO(timvolodine): notification permissions seem to work differently with
265 // infobars and bubbles (crbug.com/453784).
266 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
267 CONTENT_SETTING_ASK);
268 // TODO(timvolodine): infobars does not seem to implement push messaging
269 // permissions (crbug.com/453788).
270 #if defined(OS_ANDROID)
271 TestGrantAndRevoke_TestContent(
272 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
273 #endif
274 }
275
276 // Simulates granting and revoking of permissions using permission bubbles.
277 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithBubbles) {
278 StartUsingPermissionBubble();
279 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
280 CONTENT_SETTING_ASK);
281 #if defined(ENABLE_NOTIFICATIONS)
282 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
283 CONTENT_SETTING_ASK);
284 #endif
285 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
286 CONTENT_SETTING_ASK);
287 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
288 CONTENT_SETTING_ASK);
289 #if defined(OS_ANDROID)
Nico 2015/01/30 17:32:34 This is the same TODO as in the previous test, rig
timvolodine 2015/02/02 12:25:54 those todo's are for the infobar related tests, I'
290 TestGrantAndRevoke_TestContent(
291 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
292 #endif
293 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/permission_context_base.cc ('k') | content/browser/permissions/permission_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698