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

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

Issue 1146403004: MidiPermissionContext::GetPermission() returns BLOCK for insecure origins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 TestRequestPermissionNonSecureUrl(ContentSettingsType type) {
182 TestPermissionContext permission_context(profile(), type);
183 GURL url("http://www.google.com");
184 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
185
186 const PermissionRequestID id(
187 web_contents()->GetRenderProcessHost()->GetID(),
188 web_contents()->GetRenderViewHost()->GetRoutingID(),
189 -1, GURL());
190 permission_context.RequestPermission(
191 web_contents(),
192 id, url, true,
193 base::Bind(&TestPermissionContext::TrackPermissionDecision,
194 base::Unretained(&permission_context)));
195
196 EXPECT_TRUE(permission_context.permission_set());
197 EXPECT_FALSE(permission_context.permission_granted());
198 EXPECT_TRUE(permission_context.tab_context_updated());
199
200 ContentSetting setting =
201 profile()->GetHostContentSettingsMap()->GetContentSetting(
202 url.GetOrigin(), url.GetOrigin(), type, std::string());
203 EXPECT_EQ(CONTENT_SETTING_ASK, setting);
204 }
205
206 void TestGrantAndRevoke_TestContent(ContentSettingsType type, 181 void TestGrantAndRevoke_TestContent(ContentSettingsType type,
207 ContentSetting expected_default) { 182 ContentSetting expected_default) {
208 TestPermissionContext permission_context(profile(), type); 183 TestPermissionContext permission_context(profile(), type);
209 GURL url("https://www.google.com"); 184 GURL url("https://www.google.com");
210 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url); 185 content::WebContentsTester::For(web_contents())->NavigateAndCommit(url);
211 186
212 const PermissionRequestID id( 187 const PermissionRequestID id(
213 web_contents()->GetRenderProcessHost()->GetID(), 188 web_contents()->GetRenderProcessHost()->GetID(),
214 web_contents()->GetRenderViewHost()->GetRoutingID(), 189 web_contents()->GetRenderViewHost()->GetRoutingID(),
215 -1, GURL()); 190 -1, GURL());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION); 250 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION);
276 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 251 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
277 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX); 252 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
278 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING); 253 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING);
279 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 254 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
280 TestRequestPermissionInvalidUrl( 255 TestRequestPermissionInvalidUrl(
281 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); 256 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
282 #endif 257 #endif
283 } 258 }
284 259
285 // Simulates non-secure requesting URL.
286 // Web MIDI permission should be denied for non-secure origin.
287 // Simulates granting and revoking of permissions.
288 TEST_F(PermissionContextBaseTests, TestNonSecureRequestingUrl) {
289 TestRequestPermissionNonSecureUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
290 }
291
292 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) { 260 TEST_F(PermissionContextBaseTests, TestGrantAndRevoke) {
293 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION, 261 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
294 CONTENT_SETTING_ASK); 262 CONTENT_SETTING_ASK);
295 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 263 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
296 CONTENT_SETTING_ASK); 264 CONTENT_SETTING_ASK);
297 #if defined(OS_ANDROID) 265 #if defined(OS_ANDROID)
298 TestGrantAndRevoke_TestContent( 266 TestGrantAndRevoke_TestContent(
299 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); 267 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
300 #endif 268 #endif
301 // TODO(timvolodine): currently no test for 269 // TODO(timvolodine): currently no test for
(...skipping 15 matching lines...) Expand all
317 #endif 285 #endif
318 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX, 286 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
319 CONTENT_SETTING_ASK); 287 CONTENT_SETTING_ASK);
320 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, 288 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_PUSH_MESSAGING,
321 CONTENT_SETTING_ASK); 289 CONTENT_SETTING_ASK);
322 #if defined(OS_ANDROID) 290 #if defined(OS_ANDROID)
323 TestGrantAndRevoke_TestContent( 291 TestGrantAndRevoke_TestContent(
324 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); 292 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
325 #endif 293 #endif
326 } 294 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698