Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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> | 
| 11 #include <vector> | 11 #include <vector> | 
| 12 | 12 | 
| 13 #include "base/bind.h" | 13 #include "base/bind.h" | 
| 14 #include "base/feature_list.h" | 14 #include "base/feature_list.h" | 
| 15 #include "base/macros.h" | 15 #include "base/macros.h" | 
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" | 
| 17 #include "base/metrics/field_trial.h" | 17 #include "base/metrics/field_trial.h" | 
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" | 
| 19 #include "base/test/histogram_tester.h" | 19 #include "base/test/histogram_tester.h" | 
| 20 #include "base/test/mock_entropy_provider.h" | 20 #include "base/test/mock_entropy_provider.h" | 
| 21 #include "base/test/scoped_feature_list.h" | 21 #include "base/test/scoped_feature_list.h" | 
| 22 #include "build/build_config.h" | 22 #include "build/build_config.h" | 
| 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 23 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 
| 24 #include "chrome/browser/infobars/infobar_service.h" | 24 #include "chrome/browser/infobars/infobar_service.h" | 
| 25 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 25 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 
| 26 #include "chrome/browser/permissions/permission_queue_controller.h" | 26 #include "chrome/browser/permissions/permission_queue_controller.h" | 
| 27 #include "chrome/browser/permissions/permission_request_id.h" | 27 #include "chrome/browser/permissions/permission_request_id.h" | 
| 28 #include "chrome/browser/permissions/permission_uma_util.h" | 28 #include "chrome/browser/permissions/permission_uma_util.h" | 
| 29 #include "chrome/browser/permissions/permission_util.h" | 29 #include "chrome/browser/permissions/permission_util.h" | 
| 30 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" | |
| 30 #include "chrome/common/chrome_features.h" | 31 #include "chrome/common/chrome_features.h" | 
| 31 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" | 
| 32 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 33 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 
| 33 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" | 
| 34 #include "components/content_settings/core/browser/host_content_settings_map.h" | 35 #include "components/content_settings/core/browser/host_content_settings_map.h" | 
| 35 #include "components/content_settings/core/common/content_settings.h" | 36 #include "components/content_settings/core/common/content_settings.h" | 
| 36 #include "components/content_settings/core/common/content_settings_types.h" | 37 #include "components/content_settings/core/common/content_settings_types.h" | 
| 37 #include "components/safe_browsing_db/database_manager.h" | 38 #include "components/safe_browsing_db/database_manager.h" | 
| 38 #include "components/safe_browsing_db/test_database_manager.h" | 39 #include "components/safe_browsing_db/test_database_manager.h" | 
| 39 #include "components/variations/variations_associated_data.h" | 40 #include "components/variations/variations_associated_data.h" | 
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 if (response == CONTENT_SETTING_ALLOW) | 241 if (response == CONTENT_SETTING_ALLOW) | 
| 241 decision = PermissionAction::GRANTED; | 242 decision = PermissionAction::GRANTED; | 
| 242 else if (response == CONTENT_SETTING_BLOCK) | 243 else if (response == CONTENT_SETTING_BLOCK) | 
| 243 decision = PermissionAction::DENIED; | 244 decision = PermissionAction::DENIED; | 
| 244 context->GetInfoBarController()->OnPermissionSet( | 245 context->GetInfoBarController()->OnPermissionSet( | 
| 245 id, url, url, false /* user_gesture */, persist, decision); | 246 id, url, url, false /* user_gesture */, persist, decision); | 
| 246 #else | 247 #else | 
| 247 PermissionRequestManager* manager = | 248 PermissionRequestManager* manager = | 
| 248 PermissionRequestManager::FromWebContents(web_contents()); | 249 PermissionRequestManager::FromWebContents(web_contents()); | 
| 249 manager->TogglePersist(persist); | 250 manager->TogglePersist(persist); | 
| 250 switch (response) { | 251 using AutoResponseType = PermissionRequestManager::AutoResponseType; | 
| 251 case CONTENT_SETTING_ALLOW: | 252 AutoResponseType decision = AutoResponseType::DISMISS; | 
| 252 manager->Accept(); | 253 if (response == CONTENT_SETTING_ALLOW) | 
| 253 break; | 254 decision = AutoResponseType::ACCEPT_ALL; | 
| 254 case CONTENT_SETTING_BLOCK: | 255 else if (response == CONTENT_SETTING_BLOCK) | 
| 255 manager->Deny(); | 256 decision = AutoResponseType::DENY_ALL; | 
| 
 
raymes
2017/05/04 05:00:04
perhaps add
else
  NOTREACHED();
to maintain the
 
Timothy Loh
2017/05/04 08:22:30
The value of response is DCHECK'd above.
 
 | |
| 256 break; | 257 prompt_factory_->set_response_type(decision); | 
| 257 case CONTENT_SETTING_ASK: | |
| 258 manager->Closing(); | |
| 259 break; | |
| 260 default: | |
| 261 NOTREACHED(); | |
| 262 } | |
| 263 #endif | 258 #endif | 
| 264 } | 259 } | 
| 265 | 260 | 
| 266 void TestAskAndDecide_TestContent(ContentSettingsType content_settings_type, | 261 void TestAskAndDecide_TestContent(ContentSettingsType content_settings_type, | 
| 267 ContentSetting decision, | 262 ContentSetting decision, | 
| 268 bool persist) { | 263 bool persist) { | 
| 269 TestPermissionContext permission_context(profile(), content_settings_type); | 264 TestPermissionContext permission_context(profile(), content_settings_type); | 
| 270 GURL url("https://www.google.com"); | 265 GURL url("https://www.google.com"); | 
| 271 NavigateAndCommit(url); | 266 NavigateAndCommit(url); | 
| 267 LoadCompleted(); | |
| 
 
raymes
2017/05/04 05:00:04
Can this just go in NavigateAndCommit?
 
Timothy Loh
2017/05/04 08:22:30
It's defined in RenderViewHostTestHarness so no, b
 
raymes
2017/05/08 03:14:26
That sounds good. Or maybe NavigateToUrl
 
Timothy Loh
2017/05/08 04:06:51
Done (called it SetUpUrl)
 
 | |
| 272 base::HistogramTester histograms; | 268 base::HistogramTester histograms; | 
| 273 | 269 | 
| 274 const PermissionRequestID id( | 270 const PermissionRequestID id( | 
| 275 web_contents()->GetRenderProcessHost()->GetID(), | 271 web_contents()->GetRenderProcessHost()->GetID(), | 
| 276 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 272 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
| 277 permission_context.SetRespondPermissionCallback( | 273 permission_context.SetRespondPermissionCallback( | 
| 278 base::Bind(&PermissionContextBaseTests::RespondToPermission, | 274 base::Bind(&PermissionContextBaseTests::RespondToPermission, | 
| 279 base::Unretained(this), &permission_context, id, url, | 275 base::Unretained(this), &permission_context, id, url, | 
| 280 persist, decision)); | 276 persist, decision)); | 
| 281 permission_context.RequestPermission( | 277 permission_context.RequestPermission( | 
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 410 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 
| 415 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 411 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 
| 416 histograms.ExpectBucketCount( | 412 histograms.ExpectBucketCount( | 
| 417 "Permissions.AutoBlocker.EmbargoPromptSuppression", | 413 "Permissions.AutoBlocker.EmbargoPromptSuppression", | 
| 418 static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); | 414 static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); | 
| 419 } | 415 } | 
| 420 | 416 | 
| 421 void TestBlockOnSeveralDismissals_TestContent() { | 417 void TestBlockOnSeveralDismissals_TestContent() { | 
| 422 GURL url("https://www.google.com"); | 418 GURL url("https://www.google.com"); | 
| 423 NavigateAndCommit(url); | 419 NavigateAndCommit(url); | 
| 420 LoadCompleted(); | |
| 424 base::HistogramTester histograms; | 421 base::HistogramTester histograms; | 
| 425 | 422 | 
| 426 // First, ensure that > 3 dismissals behaves correctly. | 423 // First, ensure that > 3 dismissals behaves correctly. | 
| 427 for (uint32_t i = 0; i < 4; ++i) { | 424 for (uint32_t i = 0; i < 4; ++i) { | 
| 428 TestPermissionContext permission_context( | 425 TestPermissionContext permission_context( | 
| 429 profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION); | 426 profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION); | 
| 430 | 427 | 
| 431 const PermissionRequestID id( | 428 const PermissionRequestID id( | 
| 432 web_contents()->GetRenderProcessHost()->GetID(), | 429 web_contents()->GetRenderProcessHost()->GetID(), | 
| 433 web_contents()->GetMainFrame()->GetRoutingID(), i); | 430 web_contents()->GetMainFrame()->GetRoutingID(), i); | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 // Sanity check independence per permission type by checking two of them. | 479 // Sanity check independence per permission type by checking two of them. | 
| 483 DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, | 480 DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, | 
| 484 3); | 481 3); | 
| 485 DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 482 DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 
| 486 3); | 483 3); | 
| 487 } | 484 } | 
| 488 | 485 | 
| 489 void TestVariationBlockOnSeveralDismissals_TestContent() { | 486 void TestVariationBlockOnSeveralDismissals_TestContent() { | 
| 490 GURL url("https://www.google.com"); | 487 GURL url("https://www.google.com"); | 
| 491 NavigateAndCommit(url); | 488 NavigateAndCommit(url); | 
| 489 LoadCompleted(); | |
| 492 base::HistogramTester histograms; | 490 base::HistogramTester histograms; | 
| 493 | 491 | 
| 494 // Set up the custom parameter and custom value. | 492 // Set up the custom parameter and custom value. | 
| 495 base::FieldTrialList field_trials(nullptr); | 493 base::FieldTrialList field_trials(nullptr); | 
| 496 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( | 494 base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( | 
| 497 kPromptTrialName, kPromptGroupName); | 495 kPromptTrialName, kPromptGroupName); | 
| 498 std::map<std::string, std::string> params; | 496 std::map<std::string, std::string> params; | 
| 499 params[PermissionDecisionAutoBlocker::kPromptDismissCountKey] = "5"; | 497 params[PermissionDecisionAutoBlocker::kPromptDismissCountKey] = "5"; | 
| 500 ASSERT_TRUE(variations::AssociateVariationParams(kPromptTrialName, | 498 ASSERT_TRUE(variations::AssociateVariationParams(kPromptTrialName, | 
| 501 kPromptGroupName, params)); | 499 kPromptGroupName, params)); | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 variations::testing::ClearAllVariationParams(); | 587 variations::testing::ClearAllVariationParams(); | 
| 590 } | 588 } | 
| 591 | 589 | 
| 592 void TestRequestPermissionInvalidUrl( | 590 void TestRequestPermissionInvalidUrl( | 
| 593 ContentSettingsType content_settings_type) { | 591 ContentSettingsType content_settings_type) { | 
| 594 base::HistogramTester histograms; | 592 base::HistogramTester histograms; | 
| 595 TestPermissionContext permission_context(profile(), content_settings_type); | 593 TestPermissionContext permission_context(profile(), content_settings_type); | 
| 596 GURL url; | 594 GURL url; | 
| 597 ASSERT_FALSE(url.is_valid()); | 595 ASSERT_FALSE(url.is_valid()); | 
| 598 NavigateAndCommit(url); | 596 NavigateAndCommit(url); | 
| 597 LoadCompleted(); | |
| 599 | 598 | 
| 600 const PermissionRequestID id( | 599 const PermissionRequestID id( | 
| 601 web_contents()->GetRenderProcessHost()->GetID(), | 600 web_contents()->GetRenderProcessHost()->GetID(), | 
| 602 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 601 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
| 603 permission_context.RequestPermission( | 602 permission_context.RequestPermission( | 
| 604 web_contents(), id, url, true /* user_gesture */, | 603 web_contents(), id, url, true /* user_gesture */, | 
| 605 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 604 base::Bind(&TestPermissionContext::TrackPermissionDecision, | 
| 606 base::Unretained(&permission_context))); | 605 base::Unretained(&permission_context))); | 
| 607 | 606 | 
| 608 ASSERT_EQ(1u, permission_context.decisions().size()); | 607 ASSERT_EQ(1u, permission_context.decisions().size()); | 
| 609 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); | 608 EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); | 
| 610 EXPECT_TRUE(permission_context.tab_context_updated()); | 609 EXPECT_TRUE(permission_context.tab_context_updated()); | 
| 611 EXPECT_EQ(CONTENT_SETTING_ASK, | 610 EXPECT_EQ(CONTENT_SETTING_ASK, | 
| 612 permission_context.GetContentSettingFromMap(url, url)); | 611 permission_context.GetContentSettingFromMap(url, url)); | 
| 613 histograms.ExpectTotalCount( | 612 histograms.ExpectTotalCount( | 
| 614 "Permissions.AutoBlocker.EmbargoPromptSuppression", 0); | 613 "Permissions.AutoBlocker.EmbargoPromptSuppression", 0); | 
| 615 } | 614 } | 
| 616 | 615 | 
| 617 void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type, | 616 void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type, | 
| 618 ContentSetting expected_default) { | 617 ContentSetting expected_default) { | 
| 619 TestPermissionContext permission_context(profile(), content_settings_type); | 618 TestPermissionContext permission_context(profile(), content_settings_type); | 
| 620 GURL url("https://www.google.com"); | 619 GURL url("https://www.google.com"); | 
| 621 NavigateAndCommit(url); | 620 NavigateAndCommit(url); | 
| 621 LoadCompleted(); | |
| 622 | 622 | 
| 623 const PermissionRequestID id( | 623 const PermissionRequestID id( | 
| 624 web_contents()->GetRenderProcessHost()->GetID(), | 624 web_contents()->GetRenderProcessHost()->GetID(), | 
| 625 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 625 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
| 626 permission_context.SetRespondPermissionCallback( | 626 permission_context.SetRespondPermissionCallback( | 
| 627 base::Bind(&PermissionContextBaseTests::RespondToPermission, | 627 base::Bind(&PermissionContextBaseTests::RespondToPermission, | 
| 628 base::Unretained(this), &permission_context, id, url, true, | 628 base::Unretained(this), &permission_context, id, url, true, | 
| 629 CONTENT_SETTING_ALLOW)); | 629 CONTENT_SETTING_ALLOW)); | 
| 630 | 630 | 
| 631 permission_context.RequestPermission( | 631 permission_context.RequestPermission( | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); | 667 EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); | 
| 668 } | 668 } | 
| 669 | 669 | 
| 670 // Don't call this more than once in the same test, as it persists data to | 670 // Don't call this more than once in the same test, as it persists data to | 
| 671 // HostContentSettingsMap. | 671 // HostContentSettingsMap. | 
| 672 void TestParallelRequests(ContentSetting response) { | 672 void TestParallelRequests(ContentSetting response) { | 
| 673 TestPermissionContext permission_context( | 673 TestPermissionContext permission_context( | 
| 674 profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 674 profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 
| 675 GURL url("http://www.google.com"); | 675 GURL url("http://www.google.com"); | 
| 676 NavigateAndCommit(url); | 676 NavigateAndCommit(url); | 
| 677 LoadCompleted(); | |
| 677 | 678 | 
| 678 const PermissionRequestID id0( | 679 const PermissionRequestID id0( | 
| 679 web_contents()->GetRenderProcessHost()->GetID(), | 680 web_contents()->GetRenderProcessHost()->GetID(), | 
| 680 web_contents()->GetMainFrame()->GetRoutingID(), 0); | 681 web_contents()->GetMainFrame()->GetRoutingID(), 0); | 
| 681 const PermissionRequestID id1( | 682 const PermissionRequestID id1( | 
| 682 web_contents()->GetRenderProcessHost()->GetID(), | 683 web_contents()->GetRenderProcessHost()->GetID(), | 
| 683 web_contents()->GetMainFrame()->GetRoutingID(), 1); | 684 web_contents()->GetMainFrame()->GetRoutingID(), 1); | 
| 684 | 685 | 
| 685 bool persist = (response == CONTENT_SETTING_ALLOW || | 686 bool persist = (response == CONTENT_SETTING_ALLOW || | 
| 686 response == CONTENT_SETTING_BLOCK); | 687 response == CONTENT_SETTING_BLOCK); | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 712 } | 713 } | 
| 713 | 714 | 
| 714 void TestPermissionsBlacklisting( | 715 void TestPermissionsBlacklisting( | 
| 715 ContentSettingsType content_settings_type, | 716 ContentSettingsType content_settings_type, | 
| 716 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 717 scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 
| 717 const GURL& url, | 718 const GURL& url, | 
| 718 int timeout, | 719 int timeout, | 
| 719 ContentSetting expected_permission_status, | 720 ContentSetting expected_permission_status, | 
| 720 PermissionEmbargoStatus expected_embargo_reason) { | 721 PermissionEmbargoStatus expected_embargo_reason) { | 
| 721 NavigateAndCommit(url); | 722 NavigateAndCommit(url); | 
| 723 LoadCompleted(); | |
| 722 base::HistogramTester histograms; | 724 base::HistogramTester histograms; | 
| 723 base::test::ScopedFeatureList scoped_feature_list; | 725 base::test::ScopedFeatureList scoped_feature_list; | 
| 724 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); | 726 scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); | 
| 725 TestPermissionContext permission_context(profile(), content_settings_type); | 727 TestPermissionContext permission_context(profile(), content_settings_type); | 
| 726 PermissionDecisionAutoBlocker::GetForProfile(profile()) | 728 PermissionDecisionAutoBlocker::GetForProfile(profile()) | 
| 727 ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 729 ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 
| 728 timeout); | 730 timeout); | 
| 729 const PermissionRequestID id( | 731 const PermissionRequestID id( | 
| 730 web_contents()->GetRenderProcessHost()->GetID(), | 732 web_contents()->GetRenderProcessHost()->GetID(), | 
| 731 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 733 web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 754 } else { | 756 } else { | 
| 755 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 757 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 
| 756 } | 758 } | 
| 757 histograms.ExpectUniqueSample( | 759 histograms.ExpectUniqueSample( | 
| 758 "Permissions.AutoBlocker.EmbargoPromptSuppression", | 760 "Permissions.AutoBlocker.EmbargoPromptSuppression", | 
| 759 static_cast<int>(expected_embargo_reason), 1); | 761 static_cast<int>(expected_embargo_reason), 1); | 
| 760 histograms.ExpectUniqueSample("Permissions.AutoBlocker.EmbargoStatus", | 762 histograms.ExpectUniqueSample("Permissions.AutoBlocker.EmbargoStatus", | 
| 761 static_cast<int>(expected_embargo_reason), 1); | 763 static_cast<int>(expected_embargo_reason), 1); | 
| 762 } | 764 } | 
| 763 | 765 | 
| 766 void LoadCompleted() { | |
| 767 #if !defined(OS_ANDROID) | |
| 768 prompt_factory_->DocumentOnLoadCompletedInMainFrame(); | |
| 769 #endif | |
| 770 } | |
| 771 | |
| 764 private: | 772 private: | 
| 765 // ChromeRenderViewHostTestHarness: | 773 // ChromeRenderViewHostTestHarness: | 
| 766 void SetUp() override { | 774 void SetUp() override { | 
| 767 ChromeRenderViewHostTestHarness::SetUp(); | 775 ChromeRenderViewHostTestHarness::SetUp(); | 
| 768 #if defined(OS_ANDROID) | 776 #if defined(OS_ANDROID) | 
| 769 InfoBarService::CreateForWebContents(web_contents()); | 777 InfoBarService::CreateForWebContents(web_contents()); | 
| 770 #else | 778 #else | 
| 771 PermissionRequestManager::CreateForWebContents(web_contents()); | 779 PermissionRequestManager::CreateForWebContents(web_contents()); | 
| 780 PermissionRequestManager* manager = | |
| 781 PermissionRequestManager::FromWebContents(web_contents()); | |
| 782 prompt_factory_.reset(new MockPermissionPromptFactory(manager)); | |
| 783 manager->DisplayPendingRequests(); | |
| 772 #endif | 784 #endif | 
| 773 } | 785 } | 
| 774 | 786 | 
| 787 void TearDown() override { | |
| 788 prompt_factory_.reset(); | |
| 789 ChromeRenderViewHostTestHarness::TearDown(); | |
| 790 } | |
| 791 | |
| 775 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 792 DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 
| 
 
raymes
2017/05/04 05:00:04
This usually goes after all member variables.
 
Timothy Loh
2017/05/04 08:22:30
Fixed
 
 | |
| 793 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; | |
| 776 }; | 794 }; | 
| 777 | 795 | 
| 778 // Simulates clicking Accept. The permission should be granted and | 796 // Simulates clicking Accept. The permission should be granted and | 
| 779 // saved for future use. | 797 // saved for future use. | 
| 780 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) { | 798 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) { | 
| 781 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 799 TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 
| 782 CONTENT_SETTING_ALLOW, true); | 800 CONTENT_SETTING_ALLOW, true); | 
| 783 } | 801 } | 
| 784 | 802 | 
| 785 // Simulates clicking Accept. The permission should be granted, but not | 803 // Simulates clicking Accept. The permission should be granted, but not | 
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { | 925 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { | 
| 908 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 926 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 
| 909 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); | 927 new MockSafeBrowsingDatabaseManager(true /* perform_callback */); | 
| 910 const GURL url("https://www.example.com"); | 928 const GURL url("https://www.example.com"); | 
| 911 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 929 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 
| 912 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 930 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 
| 913 TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, | 931 TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, | 
| 914 url, 2000 /* timeout */, CONTENT_SETTING_ALLOW, | 932 url, 2000 /* timeout */, CONTENT_SETTING_ALLOW, | 
| 915 PermissionEmbargoStatus::NOT_EMBARGOED); | 933 PermissionEmbargoStatus::NOT_EMBARGOED); | 
| 916 } | 934 } | 
| OLD | NEW |