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

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

Issue 2675483002: Replace PermissionType in chrome/ with ContentSettingsType (Closed)
Patch Set: ready Created 3 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/permissions/permission_context_base.h" 5 #include "chrome/browser/permissions/permission_context_base.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 19 matching lines...) Expand all
30 #include "chrome/common/chrome_switches.h" 30 #include "chrome/common/chrome_switches.h"
31 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 31 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
32 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
33 #include "components/content_settings/core/browser/host_content_settings_map.h" 33 #include "components/content_settings/core/browser/host_content_settings_map.h"
34 #include "components/content_settings/core/common/content_settings.h" 34 #include "components/content_settings/core/common/content_settings.h"
35 #include "components/content_settings/core/common/content_settings_types.h" 35 #include "components/content_settings/core/common/content_settings_types.h"
36 #include "components/safe_browsing_db/database_manager.h" 36 #include "components/safe_browsing_db/database_manager.h"
37 #include "components/safe_browsing_db/test_database_manager.h" 37 #include "components/safe_browsing_db/test_database_manager.h"
38 #include "components/variations/variations_associated_data.h" 38 #include "components/variations/variations_associated_data.h"
39 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
40 #include "content/public/browser/permission_type.h"
41 #include "content/public/browser/render_frame_host.h" 40 #include "content/public/browser/render_frame_host.h"
42 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
43 #include "content/public/test/mock_render_process_host.h" 42 #include "content/public/test/mock_render_process_host.h"
44 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
45 44
46 #if !defined(OS_ANDROID) 45 #if !defined(OS_ANDROID)
47 #include "chrome/browser/permissions/permission_request_manager.h" 46 #include "chrome/browser/permissions/permission_request_manager.h"
48 #endif 47 #endif
49 48
50 const char* const kPermissionsKillSwitchFieldStudy = 49 const char* const kPermissionsKillSwitchFieldStudy =
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 private: 91 private:
93 bool perform_callback_; 92 bool perform_callback_;
94 std::map<GURL, std::set<std::string>> permissions_blacklist_; 93 std::map<GURL, std::set<std::string>> permissions_blacklist_;
95 94
96 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager); 95 DISALLOW_COPY_AND_ASSIGN(MockSafeBrowsingDatabaseManager);
97 }; 96 };
98 97
99 class TestPermissionContext : public PermissionContextBase { 98 class TestPermissionContext : public PermissionContextBase {
100 public: 99 public:
101 TestPermissionContext(Profile* profile, 100 TestPermissionContext(Profile* profile,
102 const content::PermissionType permission_type,
103 const ContentSettingsType content_settings_type) 101 const ContentSettingsType content_settings_type)
104 : PermissionContextBase(profile, permission_type, content_settings_type), 102 : PermissionContextBase(profile, content_settings_type),
105 tab_context_updated_(false) {} 103 tab_context_updated_(false) {}
106 104
107 ~TestPermissionContext() override {} 105 ~TestPermissionContext() override {}
108 106
109 #if defined(OS_ANDROID) 107 #if defined(OS_ANDROID)
110 PermissionQueueController* GetInfoBarController() { 108 PermissionQueueController* GetInfoBarController() {
111 return GetQueueController(); 109 return GetQueueController();
112 } 110 }
113 #endif 111 #endif
114 112
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 // Callback for responding to a permission once the request has been completed 190 // Callback for responding to a permission once the request has been completed
193 // (valid URL, kill switch disabled, not blacklisted) 191 // (valid URL, kill switch disabled, not blacklisted)
194 base::Closure respond_permission_; 192 base::Closure respond_permission_;
195 DISALLOW_COPY_AND_ASSIGN(TestPermissionContext); 193 DISALLOW_COPY_AND_ASSIGN(TestPermissionContext);
196 }; 194 };
197 195
198 class TestKillSwitchPermissionContext : public TestPermissionContext { 196 class TestKillSwitchPermissionContext : public TestPermissionContext {
199 public: 197 public:
200 TestKillSwitchPermissionContext( 198 TestKillSwitchPermissionContext(
201 Profile* profile, 199 Profile* profile,
202 const content::PermissionType permission_type,
203 const ContentSettingsType content_settings_type) 200 const ContentSettingsType content_settings_type)
204 : TestPermissionContext(profile, permission_type, content_settings_type), 201 : TestPermissionContext(profile, content_settings_type),
205 field_trial_list_(base::MakeUnique<base::FieldTrialList>( 202 field_trial_list_(base::MakeUnique<base::FieldTrialList>(
206 base::MakeUnique<base::MockEntropyProvider>())) {} 203 base::MakeUnique<base::MockEntropyProvider>())) {}
207 204
208 void ResetFieldTrialList() { 205 void ResetFieldTrialList() {
209 // Destroy the existing FieldTrialList before creating a new one to avoid 206 // Destroy the existing FieldTrialList before creating a new one to avoid
210 // a DCHECK. 207 // a DCHECK.
211 field_trial_list_.reset(); 208 field_trial_list_.reset();
212 field_trial_list_ = base::MakeUnique<base::FieldTrialList>( 209 field_trial_list_ = base::MakeUnique<base::FieldTrialList>(
213 base::MakeUnique<base::MockEntropyProvider>()); 210 base::MakeUnique<base::MockEntropyProvider>());
214 variations::testing::ClearAllVariationParams(); 211 variations::testing::ClearAllVariationParams();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 break; 252 break;
256 case CONTENT_SETTING_ASK: 253 case CONTENT_SETTING_ASK:
257 manager->Closing(); 254 manager->Closing();
258 break; 255 break;
259 default: 256 default:
260 NOTREACHED(); 257 NOTREACHED();
261 } 258 }
262 #endif 259 #endif
263 } 260 }
264 261
265 void TestAskAndDecide_TestContent(content::PermissionType permission, 262 void TestAskAndDecide_TestContent(ContentSettingsType content_settings_type,
266 ContentSettingsType content_settings_type,
267 ContentSetting decision, 263 ContentSetting decision,
268 bool persist) { 264 bool persist) {
269 TestPermissionContext permission_context(profile(), permission, 265 TestPermissionContext permission_context(profile(), content_settings_type);
270 content_settings_type);
271 GURL url("https://www.google.com"); 266 GURL url("https://www.google.com");
272 NavigateAndCommit(url); 267 NavigateAndCommit(url);
273 base::HistogramTester histograms; 268 base::HistogramTester histograms;
274 269
275 const PermissionRequestID id( 270 const PermissionRequestID id(
276 web_contents()->GetRenderProcessHost()->GetID(), 271 web_contents()->GetRenderProcessHost()->GetID(),
277 web_contents()->GetMainFrame()->GetRoutingID(), 272 web_contents()->GetMainFrame()->GetRoutingID(),
278 -1); 273 -1);
279 permission_context.SetRespondPermissionCallback( 274 permission_context.SetRespondPermissionCallback(
280 base::Bind(&PermissionContextBaseTests::RespondToPermission, 275 base::Bind(&PermissionContextBaseTests::RespondToPermission,
(...skipping 12 matching lines...) Expand all
293 if (decision == CONTENT_SETTING_ALLOW) 288 if (decision == CONTENT_SETTING_ALLOW)
294 decision_string = "Accepted"; 289 decision_string = "Accepted";
295 else if (decision == CONTENT_SETTING_BLOCK) 290 else if (decision == CONTENT_SETTING_BLOCK)
296 decision_string = "Denied"; 291 decision_string = "Denied";
297 else if (decision == CONTENT_SETTING_ASK) 292 else if (decision == CONTENT_SETTING_ASK)
298 decision_string = "Dismissed"; 293 decision_string = "Dismissed";
299 294
300 if (decision_string.size()) { 295 if (decision_string.size()) {
301 histograms.ExpectUniqueSample( 296 histograms.ExpectUniqueSample(
302 "Permissions.Prompt." + decision_string + ".PriorDismissCount." + 297 "Permissions.Prompt." + decision_string + ".PriorDismissCount." +
303 PermissionUtil::GetPermissionString(permission), 298 PermissionUtil::GetPermissionString(content_settings_type),
304 0, 1); 299 0, 1);
305 histograms.ExpectUniqueSample( 300 histograms.ExpectUniqueSample(
306 "Permissions.Prompt." + decision_string + ".PriorIgnoreCount." + 301 "Permissions.Prompt." + decision_string + ".PriorIgnoreCount." +
307 PermissionUtil::GetPermissionString(permission), 302 PermissionUtil::GetPermissionString(content_settings_type),
308 0, 1); 303 0, 1);
309 } 304 }
310 305
311 if (persist) { 306 if (persist) {
312 EXPECT_EQ(decision, 307 EXPECT_EQ(decision,
313 permission_context.GetContentSettingFromMap(url, url)); 308 permission_context.GetContentSettingFromMap(url, url));
314 } else { 309 } else {
315 EXPECT_EQ(CONTENT_SETTING_ASK, 310 EXPECT_EQ(CONTENT_SETTING_ASK,
316 permission_context.GetContentSettingFromMap(url, url)); 311 permission_context.GetContentSettingFromMap(url, url));
317 } 312 }
318 } 313 }
319 314
320 void DismissMultipleTimesAndExpectBlock( 315 void DismissMultipleTimesAndExpectBlock(
321 const GURL& url, 316 const GURL& url,
322 content::PermissionType permission_type,
323 ContentSettingsType content_settings_type, 317 ContentSettingsType content_settings_type,
324 uint32_t iterations) { 318 uint32_t iterations) {
325 base::HistogramTester histograms; 319 base::HistogramTester histograms;
326 320
327 // Dismiss |iterations| times. The final dismiss should change the decision 321 // Dismiss |iterations| times. The final dismiss should change the decision
328 // from dismiss to block, and hence change the persisted content setting. 322 // from dismiss to block, and hence change the persisted content setting.
329 for (uint32_t i = 0; i < iterations; ++i) { 323 for (uint32_t i = 0; i < iterations; ++i) {
330 ContentSetting expected = 324 ContentSetting expected =
331 (i < 2) ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK; 325 (i < 2) ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK;
332 TestPermissionContext permission_context( 326 TestPermissionContext permission_context(profile(),
333 profile(), permission_type, content_settings_type); 327 content_settings_type);
334 const PermissionRequestID id( 328 const PermissionRequestID id(
335 web_contents()->GetRenderProcessHost()->GetID(), 329 web_contents()->GetRenderProcessHost()->GetID(),
336 web_contents()->GetMainFrame()->GetRoutingID(), i); 330 web_contents()->GetMainFrame()->GetRoutingID(), i);
337 331
338 permission_context.SetRespondPermissionCallback( 332 permission_context.SetRespondPermissionCallback(
339 base::Bind(&PermissionContextBaseTests::RespondToPermission, 333 base::Bind(&PermissionContextBaseTests::RespondToPermission,
340 base::Unretained(this), &permission_context, id, url, 334 base::Unretained(this), &permission_context, id, url,
341 false, CONTENT_SETTING_ASK)); 335 false, CONTENT_SETTING_ASK));
342 336
343 permission_context.RequestPermission( 337 permission_context.RequestPermission(
344 web_contents(), id, url, true /* user_gesture */, 338 web_contents(), id, url, true /* user_gesture */,
345 base::Bind(&TestPermissionContext::TrackPermissionDecision, 339 base::Bind(&TestPermissionContext::TrackPermissionDecision,
346 base::Unretained(&permission_context))); 340 base::Unretained(&permission_context)));
347 histograms.ExpectTotalCount( 341 histograms.ExpectTotalCount(
348 "Permissions.Prompt.Dismissed.PriorDismissCount." + 342 "Permissions.Prompt.Dismissed.PriorDismissCount." +
349 PermissionUtil::GetPermissionString(permission_type), 343 PermissionUtil::GetPermissionString(content_settings_type),
350 i + 1); 344 i + 1);
351 histograms.ExpectBucketCount( 345 histograms.ExpectBucketCount(
352 "Permissions.Prompt.Dismissed.PriorDismissCount." + 346 "Permissions.Prompt.Dismissed.PriorDismissCount." +
353 PermissionUtil::GetPermissionString(permission_type), 347 PermissionUtil::GetPermissionString(content_settings_type),
354 i, 1); 348 i, 1);
355 ASSERT_EQ(1u, permission_context.decisions().size()); 349 ASSERT_EQ(1u, permission_context.decisions().size());
356 EXPECT_EQ(expected, permission_context.decisions()[0]); 350 EXPECT_EQ(expected, permission_context.decisions()[0]);
357 EXPECT_TRUE(permission_context.tab_context_updated()); 351 EXPECT_TRUE(permission_context.tab_context_updated());
358 EXPECT_EQ(expected, permission_context.GetPermissionStatus(url, url)); 352 EXPECT_EQ(expected, permission_context.GetPermissionStatus(url, url));
359 } 353 }
360 354
361 TestPermissionContext permission_context(profile(), permission_type, 355 TestPermissionContext permission_context(profile(), content_settings_type);
362 content_settings_type);
363 const PermissionRequestID id( 356 const PermissionRequestID id(
364 web_contents()->GetRenderProcessHost()->GetID(), 357 web_contents()->GetRenderProcessHost()->GetID(),
365 web_contents()->GetMainFrame()->GetRoutingID(), -1); 358 web_contents()->GetMainFrame()->GetRoutingID(), -1);
366 359
367 permission_context.SetRespondPermissionCallback( 360 permission_context.SetRespondPermissionCallback(
368 base::Bind(&PermissionContextBaseTests::RespondToPermission, 361 base::Bind(&PermissionContextBaseTests::RespondToPermission,
369 base::Unretained(this), &permission_context, id, url, false, 362 base::Unretained(this), &permission_context, id, url, false,
370 CONTENT_SETTING_ASK)); 363 CONTENT_SETTING_ASK));
371 364
372 permission_context.RequestPermission( 365 permission_context.RequestPermission(
373 web_contents(), id, url, true /* user_gesture */, 366 web_contents(), id, url, true /* user_gesture */,
374 base::Bind(&TestPermissionContext::TrackPermissionDecision, 367 base::Bind(&TestPermissionContext::TrackPermissionDecision,
375 base::Unretained(&permission_context))); 368 base::Unretained(&permission_context)));
376 369
377 EXPECT_EQ(CONTENT_SETTING_BLOCK, 370 EXPECT_EQ(CONTENT_SETTING_BLOCK,
378 permission_context.GetPermissionStatus(url, url)); 371 permission_context.GetPermissionStatus(url, url));
379 } 372 }
380 373
381 void TestBlockOnSeveralDismissals_TestContent() { 374 void TestBlockOnSeveralDismissals_TestContent() {
382 GURL url("https://www.google.com"); 375 GURL url("https://www.google.com");
383 NavigateAndCommit(url); 376 NavigateAndCommit(url);
384 base::HistogramTester histograms; 377 base::HistogramTester histograms;
385 378
386 // First, ensure that > 3 dismissals behaves correctly. 379 // First, ensure that > 3 dismissals behaves correctly.
387 for (uint32_t i = 0; i < 4; ++i) { 380 for (uint32_t i = 0; i < 4; ++i) {
388 TestPermissionContext permission_context( 381 TestPermissionContext permission_context(
389 profile(), content::PermissionType::GEOLOCATION, 382 profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION);
390 CONTENT_SETTINGS_TYPE_GEOLOCATION);
391 383
392 const PermissionRequestID id( 384 const PermissionRequestID id(
393 web_contents()->GetRenderProcessHost()->GetID(), 385 web_contents()->GetRenderProcessHost()->GetID(),
394 web_contents()->GetMainFrame()->GetRoutingID(), i); 386 web_contents()->GetMainFrame()->GetRoutingID(), i);
395 387
396 permission_context.SetRespondPermissionCallback( 388 permission_context.SetRespondPermissionCallback(
397 base::Bind(&PermissionContextBaseTests::RespondToPermission, 389 base::Bind(&PermissionContextBaseTests::RespondToPermission,
398 base::Unretained(this), &permission_context, id, url, 390 base::Unretained(this), &permission_context, id, url,
399 false, CONTENT_SETTING_ASK)); 391 false, CONTENT_SETTING_ASK));
400 permission_context.RequestPermission( 392 permission_context.RequestPermission(
(...skipping 19 matching lines...) Expand all
420 CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA); 412 CONTENT_SETTINGS_TYPE_PERMISSION_AUTOBLOCKER_DATA);
421 413
422 base::test::ScopedFeatureList feature_list; 414 base::test::ScopedFeatureList feature_list;
423 feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften); 415 feature_list.InitAndEnableFeature(features::kBlockPromptsIfDismissedOften);
424 416
425 EXPECT_TRUE( 417 EXPECT_TRUE(
426 base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften)); 418 base::FeatureList::IsEnabled(features::kBlockPromptsIfDismissedOften));
427 419
428 // Sanity check independence per permission type by checking two of them. 420 // Sanity check independence per permission type by checking two of them.
429 DismissMultipleTimesAndExpectBlock(url, 421 DismissMultipleTimesAndExpectBlock(url,
430 content::PermissionType::GEOLOCATION,
431 CONTENT_SETTINGS_TYPE_GEOLOCATION, 3); 422 CONTENT_SETTINGS_TYPE_GEOLOCATION, 3);
432 DismissMultipleTimesAndExpectBlock(url, 423 DismissMultipleTimesAndExpectBlock(url,
433 content::PermissionType::NOTIFICATIONS,
434 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3); 424 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, 3);
435 } 425 }
436 426
437 void TestVariationBlockOnSeveralDismissals_TestContent() { 427 void TestVariationBlockOnSeveralDismissals_TestContent() {
438 GURL url("https://www.google.com"); 428 GURL url("https://www.google.com");
439 NavigateAndCommit(url); 429 NavigateAndCommit(url);
440 base::HistogramTester histograms; 430 base::HistogramTester histograms;
441 431
442 // Set up the custom parameter and custom value. 432 // Set up the custom parameter and custom value.
443 base::FieldTrialList field_trials(nullptr); 433 base::FieldTrialList field_trials(nullptr);
(...skipping 19 matching lines...) Expand all
463 453
464 { 454 {
465 std::map<std::string, std::string> actual_params; 455 std::map<std::string, std::string> actual_params;
466 EXPECT_TRUE(variations::GetVariationParamsByFeature( 456 EXPECT_TRUE(variations::GetVariationParamsByFeature(
467 features::kBlockPromptsIfDismissedOften, &actual_params)); 457 features::kBlockPromptsIfDismissedOften, &actual_params));
468 EXPECT_EQ(params, actual_params); 458 EXPECT_EQ(params, actual_params);
469 } 459 }
470 460
471 for (uint32_t i = 0; i < 5; ++i) { 461 for (uint32_t i = 0; i < 5; ++i) {
472 TestPermissionContext permission_context( 462 TestPermissionContext permission_context(
473 profile(), content::PermissionType::MIDI_SYSEX, 463 profile(), CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
474 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
475 464
476 ContentSetting expected = 465 ContentSetting expected =
477 (i < 4) ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK; 466 (i < 4) ? CONTENT_SETTING_ASK : CONTENT_SETTING_BLOCK;
478 const PermissionRequestID id( 467 const PermissionRequestID id(
479 web_contents()->GetRenderProcessHost()->GetID(), 468 web_contents()->GetRenderProcessHost()->GetID(),
480 web_contents()->GetMainFrame()->GetRoutingID(), i); 469 web_contents()->GetMainFrame()->GetRoutingID(), i);
481 permission_context.SetRespondPermissionCallback( 470 permission_context.SetRespondPermissionCallback(
482 base::Bind(&PermissionContextBaseTests::RespondToPermission, 471 base::Bind(&PermissionContextBaseTests::RespondToPermission,
483 base::Unretained(this), &permission_context, id, url, 472 base::Unretained(this), &permission_context, id, url,
484 false, CONTENT_SETTING_ASK)); 473 false, CONTENT_SETTING_ASK));
485 permission_context.RequestPermission( 474 permission_context.RequestPermission(
486 web_contents(), id, url, true /* user_gesture */, 475 web_contents(), id, url, true /* user_gesture */,
487 base::Bind(&TestPermissionContext::TrackPermissionDecision, 476 base::Bind(&TestPermissionContext::TrackPermissionDecision,
488 base::Unretained(&permission_context))); 477 base::Unretained(&permission_context)));
489 478
490 EXPECT_EQ(1u, permission_context.decisions().size()); 479 EXPECT_EQ(1u, permission_context.decisions().size());
491 ASSERT_EQ(expected, permission_context.decisions()[0]); 480 ASSERT_EQ(expected, permission_context.decisions()[0]);
492 EXPECT_TRUE(permission_context.tab_context_updated()); 481 EXPECT_TRUE(permission_context.tab_context_updated());
493 EXPECT_EQ(expected, permission_context.GetPermissionStatus(url, url)); 482 EXPECT_EQ(expected, permission_context.GetPermissionStatus(url, url));
494 483
495 histograms.ExpectTotalCount( 484 histograms.ExpectTotalCount(
496 "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i + 1); 485 "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i + 1);
497 histograms.ExpectBucketCount( 486 histograms.ExpectBucketCount(
498 "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i, 1); 487 "Permissions.Prompt.Dismissed.PriorDismissCount.MidiSysEx", i, 1);
499 } 488 }
500 489
501 // Ensure that we finish in the block state. 490 // Ensure that we finish in the block state.
502 TestPermissionContext permission_context( 491 TestPermissionContext permission_context(profile(),
503 profile(), content::PermissionType::MIDI_SYSEX, 492 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
504 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
505 EXPECT_EQ(CONTENT_SETTING_BLOCK, 493 EXPECT_EQ(CONTENT_SETTING_BLOCK,
506 permission_context.GetPermissionStatus(url, url)); 494 permission_context.GetPermissionStatus(url, url));
507 variations::testing::ClearAllVariationParams(); 495 variations::testing::ClearAllVariationParams();
508 } 496 }
509 497
510 void TestRequestPermissionInvalidUrl( 498 void TestRequestPermissionInvalidUrl(
511 content::PermissionType permission_type,
512 ContentSettingsType content_settings_type) { 499 ContentSettingsType content_settings_type) {
513 TestPermissionContext permission_context(profile(), permission_type, 500 TestPermissionContext permission_context(profile(), content_settings_type);
514 content_settings_type);
515 GURL url; 501 GURL url;
516 ASSERT_FALSE(url.is_valid()); 502 ASSERT_FALSE(url.is_valid());
517 NavigateAndCommit(url); 503 NavigateAndCommit(url);
518 504
519 const PermissionRequestID id( 505 const PermissionRequestID id(
520 web_contents()->GetRenderProcessHost()->GetID(), 506 web_contents()->GetRenderProcessHost()->GetID(),
521 web_contents()->GetMainFrame()->GetRoutingID(), 507 web_contents()->GetMainFrame()->GetRoutingID(),
522 -1); 508 -1);
523 permission_context.RequestPermission( 509 permission_context.RequestPermission(
524 web_contents(), 510 web_contents(),
525 id, url, true /* user_gesture */, 511 id, url, true /* user_gesture */,
526 base::Bind(&TestPermissionContext::TrackPermissionDecision, 512 base::Bind(&TestPermissionContext::TrackPermissionDecision,
527 base::Unretained(&permission_context))); 513 base::Unretained(&permission_context)));
528 514
529 ASSERT_EQ(1u, permission_context.decisions().size()); 515 ASSERT_EQ(1u, permission_context.decisions().size());
530 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); 516 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]);
531 EXPECT_TRUE(permission_context.tab_context_updated()); 517 EXPECT_TRUE(permission_context.tab_context_updated());
532 EXPECT_EQ(CONTENT_SETTING_ASK, 518 EXPECT_EQ(CONTENT_SETTING_ASK,
533 permission_context.GetContentSettingFromMap(url, url)); 519 permission_context.GetContentSettingFromMap(url, url));
534 } 520 }
535 521
536 void TestGrantAndRevoke_TestContent(content::PermissionType permission_type, 522 void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type,
537 ContentSettingsType content_settings_type,
538 ContentSetting expected_default) { 523 ContentSetting expected_default) {
539 TestPermissionContext permission_context(profile(), permission_type, 524 TestPermissionContext permission_context(profile(), content_settings_type);
540 content_settings_type);
541 GURL url("https://www.google.com"); 525 GURL url("https://www.google.com");
542 NavigateAndCommit(url); 526 NavigateAndCommit(url);
543 527
544 const PermissionRequestID id( 528 const PermissionRequestID id(
545 web_contents()->GetRenderProcessHost()->GetID(), 529 web_contents()->GetRenderProcessHost()->GetID(),
546 web_contents()->GetMainFrame()->GetRoutingID(), 530 web_contents()->GetMainFrame()->GetRoutingID(),
547 -1); 531 -1);
548 permission_context.SetRespondPermissionCallback( 532 permission_context.SetRespondPermissionCallback(
549 base::Bind(&PermissionContextBaseTests::RespondToPermission, 533 base::Bind(&PermissionContextBaseTests::RespondToPermission,
550 base::Unretained(this), &permission_context, id, url, true, 534 base::Unretained(this), &permission_context, id, url, true,
(...skipping 15 matching lines...) Expand all
566 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin()); 550 permission_context.ResetPermission(url.GetOrigin(), url.GetOrigin());
567 ContentSetting setting_after_reset = 551 ContentSetting setting_after_reset =
568 permission_context.GetContentSettingFromMap(url, url); 552 permission_context.GetContentSettingFromMap(url, url);
569 ContentSetting default_setting = 553 ContentSetting default_setting =
570 HostContentSettingsMapFactory::GetForProfile(profile()) 554 HostContentSettingsMapFactory::GetForProfile(profile())
571 ->GetDefaultContentSetting(content_settings_type, nullptr); 555 ->GetDefaultContentSetting(content_settings_type, nullptr);
572 EXPECT_EQ(default_setting, setting_after_reset); 556 EXPECT_EQ(default_setting, setting_after_reset);
573 } 557 }
574 558
575 void TestGlobalPermissionsKillSwitch( 559 void TestGlobalPermissionsKillSwitch(
576 content::PermissionType permission_type,
577 ContentSettingsType content_settings_type) { 560 ContentSettingsType content_settings_type) {
578 TestKillSwitchPermissionContext permission_context( 561 TestKillSwitchPermissionContext permission_context(profile(),
579 profile(), permission_type, content_settings_type); 562 content_settings_type);
580 permission_context.ResetFieldTrialList(); 563 permission_context.ResetFieldTrialList();
581 564
582 EXPECT_FALSE(permission_context.IsPermissionKillSwitchOn()); 565 EXPECT_FALSE(permission_context.IsPermissionKillSwitchOn());
583 std::map<std::string, std::string> params; 566 std::map<std::string, std::string> params;
584 params[PermissionUtil::GetPermissionString(permission_type)] = 567 params[PermissionUtil::GetPermissionString(content_settings_type)] =
585 kPermissionsKillSwitchBlockedValue; 568 kPermissionsKillSwitchBlockedValue;
586 variations::AssociateVariationParams( 569 variations::AssociateVariationParams(
587 kPermissionsKillSwitchFieldStudy, kPermissionsKillSwitchTestGroup, 570 kPermissionsKillSwitchFieldStudy, kPermissionsKillSwitchTestGroup,
588 params); 571 params);
589 base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy, 572 base::FieldTrialList::CreateFieldTrial(kPermissionsKillSwitchFieldStudy,
590 kPermissionsKillSwitchTestGroup); 573 kPermissionsKillSwitchTestGroup);
591 EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); 574 EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn());
592 } 575 }
593 576
594 // Don't call this more than once in the same test, as it persists data to 577 // Don't call this more than once in the same test, as it persists data to
595 // HostContentSettingsMap. 578 // HostContentSettingsMap.
596 void TestParallelRequests(ContentSetting response) { 579 void TestParallelRequests(ContentSetting response) {
597 TestPermissionContext permission_context( 580 TestPermissionContext permission_context(
598 profile(), content::PermissionType::NOTIFICATIONS, 581 profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
599 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
600 GURL url("http://www.google.com"); 582 GURL url("http://www.google.com");
601 NavigateAndCommit(url); 583 NavigateAndCommit(url);
602 584
603 const PermissionRequestID id0( 585 const PermissionRequestID id0(
604 web_contents()->GetRenderProcessHost()->GetID(), 586 web_contents()->GetRenderProcessHost()->GetID(),
605 web_contents()->GetMainFrame()->GetRoutingID(), 0); 587 web_contents()->GetMainFrame()->GetRoutingID(), 0);
606 const PermissionRequestID id1( 588 const PermissionRequestID id1(
607 web_contents()->GetRenderProcessHost()->GetID(), 589 web_contents()->GetRenderProcessHost()->GetID(),
608 web_contents()->GetMainFrame()->GetRoutingID(), 1); 590 web_contents()->GetMainFrame()->GetRoutingID(), 1);
609 591
(...skipping 20 matching lines...) Expand all
630 612
631 ASSERT_EQ(2u, permission_context.decisions().size()); 613 ASSERT_EQ(2u, permission_context.decisions().size());
632 EXPECT_EQ(response, permission_context.decisions()[0]); 614 EXPECT_EQ(response, permission_context.decisions()[0]);
633 EXPECT_EQ(response, permission_context.decisions()[1]); 615 EXPECT_EQ(response, permission_context.decisions()[1]);
634 EXPECT_TRUE(permission_context.tab_context_updated()); 616 EXPECT_TRUE(permission_context.tab_context_updated());
635 617
636 EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); 618 EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url));
637 } 619 }
638 620
639 void TestPermissionsBlacklisting( 621 void TestPermissionsBlacklisting(
640 content::PermissionType permission_type,
641 ContentSettingsType content_settings_type, 622 ContentSettingsType content_settings_type,
642 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, 623 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager,
643 const GURL& url, 624 const GURL& url,
644 int timeout, 625 int timeout,
645 ContentSetting expected_permission_status) { 626 ContentSetting expected_permission_status) {
646 NavigateAndCommit(url); 627 NavigateAndCommit(url);
647 base::test::ScopedFeatureList scoped_feature_list; 628 base::test::ScopedFeatureList scoped_feature_list;
648 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); 629 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist);
649 TestPermissionContext permission_context(profile(), permission_type, 630 TestPermissionContext permission_context(profile(), content_settings_type);
650 content_settings_type);
651 PermissionDecisionAutoBlocker::GetForProfile(profile()) 631 PermissionDecisionAutoBlocker::GetForProfile(profile())
652 ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, 632 ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager,
653 timeout); 633 timeout);
654 const PermissionRequestID id( 634 const PermissionRequestID id(
655 web_contents()->GetRenderProcessHost()->GetID(), 635 web_contents()->GetRenderProcessHost()->GetID(),
656 web_contents()->GetMainFrame()->GetRoutingID(), -1); 636 web_contents()->GetMainFrame()->GetRoutingID(), -1);
657 637
658 // A response only needs to be made to the permission request if we do not 638 // A response only needs to be made to the permission request if we do not
659 // expect he permission to be blacklisted, therefore set the response 639 // expect he permission to be blacklisted, therefore set the response
660 // callback. 640 // callback.
(...skipping 27 matching lines...) Expand all
688 PermissionRequestManager::CreateForWebContents(web_contents()); 668 PermissionRequestManager::CreateForWebContents(web_contents());
689 #endif 669 #endif
690 } 670 }
691 671
692 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); 672 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests);
693 }; 673 };
694 674
695 // Simulates clicking Accept. The permission should be granted and 675 // Simulates clicking Accept. The permission should be granted and
696 // saved for future use. 676 // saved for future use.
697 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) { 677 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) {
698 TestAskAndDecide_TestContent(content::PermissionType::NOTIFICATIONS, 678 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
699 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
700 CONTENT_SETTING_ALLOW, true); 679 CONTENT_SETTING_ALLOW, true);
701 } 680 }
702 681
703 // Simulates clicking Accept. The permission should be granted, but not 682 // Simulates clicking Accept. The permission should be granted, but not
704 // persisted. 683 // persisted.
705 TEST_F(PermissionContextBaseTests, TestAskAndGrantNoPersist) { 684 TEST_F(PermissionContextBaseTests, TestAskAndGrantNoPersist) {
706 TestAskAndDecide_TestContent(content::PermissionType::NOTIFICATIONS, 685 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
707 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
708 CONTENT_SETTING_ALLOW, false); 686 CONTENT_SETTING_ALLOW, false);
709 } 687 }
710 688
711 // Simulates clicking Block. The permission should be denied and 689 // Simulates clicking Block. The permission should be denied and
712 // saved for future use. 690 // saved for future use.
713 TEST_F(PermissionContextBaseTests, TestAskAndBlockPersist) { 691 TEST_F(PermissionContextBaseTests, TestAskAndBlockPersist) {
714 TestAskAndDecide_TestContent(content::PermissionType::GEOLOCATION, 692 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
715 CONTENT_SETTINGS_TYPE_GEOLOCATION,
716 CONTENT_SETTING_BLOCK, true); 693 CONTENT_SETTING_BLOCK, true);
717 } 694 }
718 695
719 // Simulates clicking Block. The permission should be denied, but not persisted. 696 // Simulates clicking Block. The permission should be denied, but not persisted.
720 TEST_F(PermissionContextBaseTests, TestAskAndBlockNoPersist) { 697 TEST_F(PermissionContextBaseTests, TestAskAndBlockNoPersist) {
721 TestAskAndDecide_TestContent(content::PermissionType::GEOLOCATION, 698 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
722 CONTENT_SETTINGS_TYPE_GEOLOCATION,
723 CONTENT_SETTING_BLOCK, false); 699 CONTENT_SETTING_BLOCK, false);
724 } 700 }
725 701
726 // Simulates clicking Dismiss (X) in the infobar/bubble. 702 // Simulates clicking Dismiss (X) in the infobar/bubble.
727 // The permission should be denied but not saved for future use. 703 // The permission should be denied but not saved for future use.
728 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) { 704 TEST_F(PermissionContextBaseTests, TestAskAndDismiss) {
729 TestAskAndDecide_TestContent(content::PermissionType::MIDI_SYSEX, 705 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
730 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
731 CONTENT_SETTING_ASK, false); 706 CONTENT_SETTING_ASK, false);
732 } 707 }
733 708
734 // Simulates clicking Dismiss (X) in the infobar/bubble with the block on too 709 // Simulates clicking Dismiss (X) in the infobar/bubble with the block on too
735 // many dismissals feature active. The permission should be blocked after 710 // many dismissals feature active. The permission should be blocked after
736 // several dismissals. 711 // several dismissals.
737 TEST_F(PermissionContextBaseTests, TestDismissUntilBlocked) { 712 TEST_F(PermissionContextBaseTests, TestDismissUntilBlocked) {
738 TestBlockOnSeveralDismissals_TestContent(); 713 TestBlockOnSeveralDismissals_TestContent();
739 } 714 }
740 715
741 // Test setting a custom number of dismissals before block via variations. 716 // Test setting a custom number of dismissals before block via variations.
742 TEST_F(PermissionContextBaseTests, TestDismissVariations) { 717 TEST_F(PermissionContextBaseTests, TestDismissVariations) {
743 TestVariationBlockOnSeveralDismissals_TestContent(); 718 TestVariationBlockOnSeveralDismissals_TestContent();
744 } 719 }
745 720
746 // Simulates non-valid requesting URL. 721 // Simulates non-valid requesting URL.
747 // The permission should be denied but not saved for future use. 722 // The permission should be denied but not saved for future use.
748 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) { 723 TEST_F(PermissionContextBaseTests, TestNonValidRequestingUrl) {
749 TestRequestPermissionInvalidUrl(content::PermissionType::GEOLOCATION, 724 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_GEOLOCATION);
750 CONTENT_SETTINGS_TYPE_GEOLOCATION); 725 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
751 TestRequestPermissionInvalidUrl(content::PermissionType::NOTIFICATIONS, 726 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
752 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 727 TestRequestPermissionInvalidUrl(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
753 TestRequestPermissionInvalidUrl(content::PermissionType::MIDI_SYSEX,
754 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
755 TestRequestPermissionInvalidUrl(content::PermissionType::PUSH_MESSAGING,
756 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
757 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 728 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
758 TestRequestPermissionInvalidUrl( 729 TestRequestPermissionInvalidUrl(
759 content::PermissionType::PROTECTED_MEDIA_IDENTIFIER,
760 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); 730 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
761 #endif 731 #endif
762 } 732 }
763 733
764 #if defined(OS_ANDROID) 734 #if defined(OS_ANDROID)
765 // This test is specific to Android because other platforms use bubbles. 735 // This test is specific to Android because other platforms use bubbles.
766 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithInfobars) { 736 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithInfobars) {
767 TestGrantAndRevoke_TestContent(content::PermissionType::GEOLOCATION, 737 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
768 CONTENT_SETTINGS_TYPE_GEOLOCATION,
769 CONTENT_SETTING_ASK); 738 CONTENT_SETTING_ASK);
770 TestGrantAndRevoke_TestContent(content::PermissionType::MIDI_SYSEX, 739 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
771 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
772 CONTENT_SETTING_ASK); 740 CONTENT_SETTING_ASK);
773 TestGrantAndRevoke_TestContent( 741 TestGrantAndRevoke_TestContent(
774 content::PermissionType::PROTECTED_MEDIA_IDENTIFIER,
775 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK); 742 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER, CONTENT_SETTING_ASK);
776 // TODO(timvolodine): currently no test for 743 // TODO(timvolodine): currently no test for
777 // CONTENT_SETTINGS_TYPE_NOTIFICATIONS because notification permissions work 744 // CONTENT_SETTINGS_TYPE_NOTIFICATIONS because notification permissions work
778 // differently with infobars as compared to bubbles (crbug.com/453784). 745 // differently with infobars as compared to bubbles (crbug.com/453784).
779 } 746 }
780 #endif 747 #endif
781 748
782 #if !defined(OS_ANDROID) 749 #if !defined(OS_ANDROID)
783 // Simulates granting and revoking of permissions using permission bubbles. 750 // Simulates granting and revoking of permissions using permission bubbles.
784 // This test shouldn't run on mobile because mobile platforms use infobars. 751 // This test shouldn't run on mobile because mobile platforms use infobars.
785 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithBubbles) { 752 TEST_F(PermissionContextBaseTests, TestGrantAndRevokeWithBubbles) {
786 TestGrantAndRevoke_TestContent(content::PermissionType::GEOLOCATION, 753 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_GEOLOCATION,
787 CONTENT_SETTINGS_TYPE_GEOLOCATION,
788 CONTENT_SETTING_ASK); 754 CONTENT_SETTING_ASK);
789 TestGrantAndRevoke_TestContent(content::PermissionType::NOTIFICATIONS, 755 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
790 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
791 CONTENT_SETTING_ASK); 756 CONTENT_SETTING_ASK);
792 TestGrantAndRevoke_TestContent(content::PermissionType::MIDI_SYSEX, 757 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
793 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
794 CONTENT_SETTING_ASK); 758 CONTENT_SETTING_ASK);
795 TestGrantAndRevoke_TestContent(content::PermissionType::PUSH_MESSAGING, 759 TestGrantAndRevoke_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
796 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
797 CONTENT_SETTING_ASK); 760 CONTENT_SETTING_ASK);
798 } 761 }
799 #endif 762 #endif
800 763
801 // Tests the global kill switch by enabling/disabling the Field Trials. 764 // Tests the global kill switch by enabling/disabling the Field Trials.
802 TEST_F(PermissionContextBaseTests, TestGlobalKillSwitch) { 765 TEST_F(PermissionContextBaseTests, TestGlobalKillSwitch) {
803 TestGlobalPermissionsKillSwitch(content::PermissionType::GEOLOCATION, 766 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_GEOLOCATION);
804 CONTENT_SETTINGS_TYPE_GEOLOCATION); 767 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
805 TestGlobalPermissionsKillSwitch(content::PermissionType::NOTIFICATIONS, 768 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
806 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); 769 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
807 TestGlobalPermissionsKillSwitch(content::PermissionType::MIDI_SYSEX, 770 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_DURABLE_STORAGE);
808 CONTENT_SETTINGS_TYPE_MIDI_SYSEX);
809 TestGlobalPermissionsKillSwitch(content::PermissionType::PUSH_MESSAGING,
810 CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
811 TestGlobalPermissionsKillSwitch(content::PermissionType::DURABLE_STORAGE,
812 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE);
813 #if defined(OS_ANDROID) || defined(OS_CHROMEOS) 771 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
814 TestGlobalPermissionsKillSwitch( 772 TestGlobalPermissionsKillSwitch(
815 content::PermissionType::PROTECTED_MEDIA_IDENTIFIER,
816 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER); 773 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER);
817 #endif 774 #endif
818 TestGlobalPermissionsKillSwitch(content::PermissionType::AUDIO_CAPTURE, 775 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
819 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 776 TestGlobalPermissionsKillSwitch(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
820 TestGlobalPermissionsKillSwitch(content::PermissionType::VIDEO_CAPTURE,
821 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
822 } 777 }
823 778
824 TEST_F(PermissionContextBaseTests, TestParallelRequestsAllowed) { 779 TEST_F(PermissionContextBaseTests, TestParallelRequestsAllowed) {
825 TestParallelRequests(CONTENT_SETTING_ALLOW); 780 TestParallelRequests(CONTENT_SETTING_ALLOW);
826 } 781 }
827 782
828 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) { 783 TEST_F(PermissionContextBaseTests, TestParallelRequestsBlocked) {
829 TestParallelRequests(CONTENT_SETTING_BLOCK); 784 TestParallelRequests(CONTENT_SETTING_BLOCK);
830 } 785 }
831 786
832 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) { 787 TEST_F(PermissionContextBaseTests, TestParallelRequestsDismissed) {
833 TestParallelRequests(CONTENT_SETTING_ASK); 788 TestParallelRequests(CONTENT_SETTING_ASK);
834 } 789 }
835 790
836 // Tests a blacklisted (URL, permission) pair has had its permission request 791 // Tests a blacklisted (URL, permission) pair has had its permission request
837 // blocked. 792 // blocked.
838 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingBlocked) { 793 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingBlocked) {
839 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = 794 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
840 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); 795 new MockSafeBrowsingDatabaseManager(true /* perform_callback */);
841 const GURL url("https://www.example.com"); 796 const GURL url("https://www.example.com");
842 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; 797 std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
843 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); 798 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
844 TestPermissionsBlacklisting(content::PermissionType::GEOLOCATION, 799 TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager,
845 CONTENT_SETTINGS_TYPE_GEOLOCATION, db_manager,
846 url, 2000 /* timeout */, CONTENT_SETTING_BLOCK); 800 url, 2000 /* timeout */, CONTENT_SETTING_BLOCK);
847 } 801 }
848 802
849 // Tests that a URL that is blacklisted for one permission can still request 803 // Tests that a URL that is blacklisted for one permission can still request
850 // another and grant another. 804 // another and grant another.
851 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { 805 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) {
852 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = 806 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager =
853 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); 807 new MockSafeBrowsingDatabaseManager(true /* perform_callback */);
854 const GURL url("https://www.example.com"); 808 const GURL url("https://www.example.com");
855 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; 809 std::set<std::string> blacklisted_permissions{"GEOLOCATION"};
856 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); 810 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions);
857 TestPermissionsBlacklisting(content::PermissionType::NOTIFICATIONS, 811 TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager,
858 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager,
859 url, 2000 /* timeout */, CONTENT_SETTING_ALLOW); 812 url, 2000 /* timeout */, CONTENT_SETTING_ALLOW);
860 } 813 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698