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

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

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

Powered by Google App Engine
This is Rietveld 408576698