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

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

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

Powered by Google App Engine
This is Rietveld 408576698