| 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; | 
|  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     SetUpUrl(url); | 
|  272     base::HistogramTester histograms; |  267     base::HistogramTester histograms; | 
|  273  |  268  | 
|  274     const PermissionRequestID id( |  269     const PermissionRequestID id( | 
|  275         web_contents()->GetRenderProcessHost()->GetID(), |  270         web_contents()->GetRenderProcessHost()->GetID(), | 
|  276         web_contents()->GetMainFrame()->GetRoutingID(), -1); |  271         web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
|  277     permission_context.SetRespondPermissionCallback( |  272     permission_context.SetRespondPermissionCallback( | 
|  278         base::Bind(&PermissionContextBaseTests::RespondToPermission, |  273         base::Bind(&PermissionContextBaseTests::RespondToPermission, | 
|  279                    base::Unretained(this), &permission_context, id, url, |  274                    base::Unretained(this), &permission_context, id, url, | 
|  280                    persist, decision)); |  275                    persist, decision)); | 
|  281     permission_context.RequestPermission( |  276     permission_context.RequestPermission( | 
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  413         nullptr /* render_frame_host */, url, url); |  408         nullptr /* render_frame_host */, url, url); | 
|  414     EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |  409     EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 
|  415     EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |  410     EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 
|  416     histograms.ExpectBucketCount( |  411     histograms.ExpectBucketCount( | 
|  417         "Permissions.AutoBlocker.EmbargoPromptSuppression", |  412         "Permissions.AutoBlocker.EmbargoPromptSuppression", | 
|  418         static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); |  413         static_cast<int>(PermissionEmbargoStatus::REPEATED_DISMISSALS), 1); | 
|  419   } |  414   } | 
|  420  |  415  | 
|  421   void TestBlockOnSeveralDismissals_TestContent() { |  416   void TestBlockOnSeveralDismissals_TestContent() { | 
|  422     GURL url("https://www.google.com"); |  417     GURL url("https://www.google.com"); | 
|  423     NavigateAndCommit(url); |  418     SetUpUrl(url); | 
|  424     base::HistogramTester histograms; |  419     base::HistogramTester histograms; | 
|  425  |  420  | 
|  426     // First, ensure that > 3 dismissals behaves correctly. |  421     // First, ensure that > 3 dismissals behaves correctly. | 
|  427     for (uint32_t i = 0; i < 4; ++i) { |  422     for (uint32_t i = 0; i < 4; ++i) { | 
|  428       TestPermissionContext permission_context( |  423       TestPermissionContext permission_context( | 
|  429           profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION); |  424           profile(), CONTENT_SETTINGS_TYPE_GEOLOCATION); | 
|  430  |  425  | 
|  431       const PermissionRequestID id( |  426       const PermissionRequestID id( | 
|  432           web_contents()->GetRenderProcessHost()->GetID(), |  427           web_contents()->GetRenderProcessHost()->GetID(), | 
|  433           web_contents()->GetMainFrame()->GetRoutingID(), i); |  428           web_contents()->GetMainFrame()->GetRoutingID(), i); | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  481  |  476  | 
|  482     // Sanity check independence per permission type by checking two of them. |  477     // Sanity check independence per permission type by checking two of them. | 
|  483     DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, |  478     DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_GEOLOCATION, | 
|  484                                        3); |  479                                        3); | 
|  485     DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |  480     DismissMultipleTimesAndExpectBlock(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 
|  486                                        3); |  481                                        3); | 
|  487   } |  482   } | 
|  488  |  483  | 
|  489   void TestVariationBlockOnSeveralDismissals_TestContent() { |  484   void TestVariationBlockOnSeveralDismissals_TestContent() { | 
|  490     GURL url("https://www.google.com"); |  485     GURL url("https://www.google.com"); | 
|  491     NavigateAndCommit(url); |  486     SetUpUrl(url); | 
|  492     base::HistogramTester histograms; |  487     base::HistogramTester histograms; | 
|  493  |  488  | 
|  494     // Set up the custom parameter and custom value. |  489     // Set up the custom parameter and custom value. | 
|  495     base::FieldTrialList field_trials(nullptr); |  490     base::FieldTrialList field_trials(nullptr); | 
|  496     base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( |  491     base::FieldTrial* trial = base::FieldTrialList::CreateFieldTrial( | 
|  497         kPromptTrialName, kPromptGroupName); |  492         kPromptTrialName, kPromptGroupName); | 
|  498     std::map<std::string, std::string> params; |  493     std::map<std::string, std::string> params; | 
|  499     params[PermissionDecisionAutoBlocker::kPromptDismissCountKey] = "5"; |  494     params[PermissionDecisionAutoBlocker::kPromptDismissCountKey] = "5"; | 
|  500     ASSERT_TRUE(variations::AssociateVariationParams(kPromptTrialName, |  495     ASSERT_TRUE(variations::AssociateVariationParams(kPromptTrialName, | 
|  501                                                      kPromptGroupName, params)); |  496                                                      kPromptGroupName, params)); | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  588     EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |  583     EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 
|  589     variations::testing::ClearAllVariationParams(); |  584     variations::testing::ClearAllVariationParams(); | 
|  590   } |  585   } | 
|  591  |  586  | 
|  592   void TestRequestPermissionInvalidUrl( |  587   void TestRequestPermissionInvalidUrl( | 
|  593       ContentSettingsType content_settings_type) { |  588       ContentSettingsType content_settings_type) { | 
|  594     base::HistogramTester histograms; |  589     base::HistogramTester histograms; | 
|  595     TestPermissionContext permission_context(profile(), content_settings_type); |  590     TestPermissionContext permission_context(profile(), content_settings_type); | 
|  596     GURL url; |  591     GURL url; | 
|  597     ASSERT_FALSE(url.is_valid()); |  592     ASSERT_FALSE(url.is_valid()); | 
|  598     NavigateAndCommit(url); |  593     SetUpUrl(url); | 
|  599  |  594  | 
|  600     const PermissionRequestID id( |  595     const PermissionRequestID id( | 
|  601         web_contents()->GetRenderProcessHost()->GetID(), |  596         web_contents()->GetRenderProcessHost()->GetID(), | 
|  602         web_contents()->GetMainFrame()->GetRoutingID(), -1); |  597         web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
|  603     permission_context.RequestPermission( |  598     permission_context.RequestPermission( | 
|  604         web_contents(), id, url, true /* user_gesture */, |  599         web_contents(), id, url, true /* user_gesture */, | 
|  605         base::Bind(&TestPermissionContext::TrackPermissionDecision, |  600         base::Bind(&TestPermissionContext::TrackPermissionDecision, | 
|  606                    base::Unretained(&permission_context))); |  601                    base::Unretained(&permission_context))); | 
|  607  |  602  | 
|  608     ASSERT_EQ(1u, permission_context.decisions().size()); |  603     ASSERT_EQ(1u, permission_context.decisions().size()); | 
|  609     EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); |  604     EXPECT_EQ(CONTENT_SETTING_BLOCK, permission_context.decisions()[0]); | 
|  610     EXPECT_TRUE(permission_context.tab_context_updated()); |  605     EXPECT_TRUE(permission_context.tab_context_updated()); | 
|  611     EXPECT_EQ(CONTENT_SETTING_ASK, |  606     EXPECT_EQ(CONTENT_SETTING_ASK, | 
|  612               permission_context.GetContentSettingFromMap(url, url)); |  607               permission_context.GetContentSettingFromMap(url, url)); | 
|  613     histograms.ExpectTotalCount( |  608     histograms.ExpectTotalCount( | 
|  614         "Permissions.AutoBlocker.EmbargoPromptSuppression", 0); |  609         "Permissions.AutoBlocker.EmbargoPromptSuppression", 0); | 
|  615   } |  610   } | 
|  616  |  611  | 
|  617   void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type, |  612   void TestGrantAndRevoke_TestContent(ContentSettingsType content_settings_type, | 
|  618                                       ContentSetting expected_default) { |  613                                       ContentSetting expected_default) { | 
|  619     TestPermissionContext permission_context(profile(), content_settings_type); |  614     TestPermissionContext permission_context(profile(), content_settings_type); | 
|  620     GURL url("https://www.google.com"); |  615     GURL url("https://www.google.com"); | 
|  621     NavigateAndCommit(url); |  616     SetUpUrl(url); | 
|  622  |  617  | 
|  623     const PermissionRequestID id( |  618     const PermissionRequestID id( | 
|  624         web_contents()->GetRenderProcessHost()->GetID(), |  619         web_contents()->GetRenderProcessHost()->GetID(), | 
|  625         web_contents()->GetMainFrame()->GetRoutingID(), -1); |  620         web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
|  626     permission_context.SetRespondPermissionCallback( |  621     permission_context.SetRespondPermissionCallback( | 
|  627         base::Bind(&PermissionContextBaseTests::RespondToPermission, |  622         base::Bind(&PermissionContextBaseTests::RespondToPermission, | 
|  628                    base::Unretained(this), &permission_context, id, url, true, |  623                    base::Unretained(this), &permission_context, id, url, true, | 
|  629                    CONTENT_SETTING_ALLOW)); |  624                    CONTENT_SETTING_ALLOW)); | 
|  630  |  625  | 
|  631     permission_context.RequestPermission( |  626     permission_context.RequestPermission( | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  666                                            kPermissionsKillSwitchTestGroup); |  661                                            kPermissionsKillSwitchTestGroup); | 
|  667     EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); |  662     EXPECT_TRUE(permission_context.IsPermissionKillSwitchOn()); | 
|  668   } |  663   } | 
|  669  |  664  | 
|  670   // Don't call this more than once in the same test, as it persists data to |  665   // Don't call this more than once in the same test, as it persists data to | 
|  671   // HostContentSettingsMap. |  666   // HostContentSettingsMap. | 
|  672   void TestParallelRequests(ContentSetting response) { |  667   void TestParallelRequests(ContentSetting response) { | 
|  673     TestPermissionContext permission_context( |  668     TestPermissionContext permission_context( | 
|  674         profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |  669         profile(), CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 
|  675     GURL url("http://www.google.com"); |  670     GURL url("http://www.google.com"); | 
|  676     NavigateAndCommit(url); |  671     SetUpUrl(url); | 
|  677  |  672  | 
|  678     const PermissionRequestID id0( |  673     const PermissionRequestID id0( | 
|  679         web_contents()->GetRenderProcessHost()->GetID(), |  674         web_contents()->GetRenderProcessHost()->GetID(), | 
|  680         web_contents()->GetMainFrame()->GetRoutingID(), 0); |  675         web_contents()->GetMainFrame()->GetRoutingID(), 0); | 
|  681     const PermissionRequestID id1( |  676     const PermissionRequestID id1( | 
|  682         web_contents()->GetRenderProcessHost()->GetID(), |  677         web_contents()->GetRenderProcessHost()->GetID(), | 
|  683         web_contents()->GetMainFrame()->GetRoutingID(), 1); |  678         web_contents()->GetMainFrame()->GetRoutingID(), 1); | 
|  684  |  679  | 
|  685     bool persist = (response == CONTENT_SETTING_ALLOW || |  680     bool persist = (response == CONTENT_SETTING_ALLOW || | 
|  686                     response == CONTENT_SETTING_BLOCK); |  681                     response == CONTENT_SETTING_BLOCK); | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  711     EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); |  706     EXPECT_EQ(response, permission_context.GetContentSettingFromMap(url, url)); | 
|  712   } |  707   } | 
|  713  |  708  | 
|  714   void TestPermissionsBlacklisting( |  709   void TestPermissionsBlacklisting( | 
|  715       ContentSettingsType content_settings_type, |  710       ContentSettingsType content_settings_type, | 
|  716       scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, |  711       scoped_refptr<safe_browsing::SafeBrowsingDatabaseManager> db_manager, | 
|  717       const GURL& url, |  712       const GURL& url, | 
|  718       int timeout, |  713       int timeout, | 
|  719       ContentSetting expected_permission_status, |  714       ContentSetting expected_permission_status, | 
|  720       PermissionEmbargoStatus expected_embargo_reason) { |  715       PermissionEmbargoStatus expected_embargo_reason) { | 
|  721     NavigateAndCommit(url); |  716     SetUpUrl(url); | 
|  722     base::HistogramTester histograms; |  717     base::HistogramTester histograms; | 
|  723     base::test::ScopedFeatureList scoped_feature_list; |  718     base::test::ScopedFeatureList scoped_feature_list; | 
|  724     scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); |  719     scoped_feature_list.InitAndEnableFeature(features::kPermissionsBlacklist); | 
|  725     TestPermissionContext permission_context(profile(), content_settings_type); |  720     TestPermissionContext permission_context(profile(), content_settings_type); | 
|  726     PermissionDecisionAutoBlocker::GetForProfile(profile()) |  721     PermissionDecisionAutoBlocker::GetForProfile(profile()) | 
|  727         ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |  722         ->SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 
|  728                                                              timeout); |  723                                                              timeout); | 
|  729     const PermissionRequestID id( |  724     const PermissionRequestID id( | 
|  730         web_contents()->GetRenderProcessHost()->GetID(), |  725         web_contents()->GetRenderProcessHost()->GetID(), | 
|  731         web_contents()->GetMainFrame()->GetRoutingID(), -1); |  726         web_contents()->GetMainFrame()->GetRoutingID(), -1); | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  754     } else { |  749     } else { | 
|  755       EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |  750       EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 
|  756     } |  751     } | 
|  757     histograms.ExpectUniqueSample( |  752     histograms.ExpectUniqueSample( | 
|  758         "Permissions.AutoBlocker.EmbargoPromptSuppression", |  753         "Permissions.AutoBlocker.EmbargoPromptSuppression", | 
|  759         static_cast<int>(expected_embargo_reason), 1); |  754         static_cast<int>(expected_embargo_reason), 1); | 
|  760     histograms.ExpectUniqueSample("Permissions.AutoBlocker.EmbargoStatus", |  755     histograms.ExpectUniqueSample("Permissions.AutoBlocker.EmbargoStatus", | 
|  761                                   static_cast<int>(expected_embargo_reason), 1); |  756                                   static_cast<int>(expected_embargo_reason), 1); | 
|  762   } |  757   } | 
|  763  |  758  | 
 |  759   void SetUpUrl(const GURL& url) { | 
 |  760     NavigateAndCommit(url); | 
 |  761 #if !defined(OS_ANDROID) | 
 |  762     prompt_factory_->DocumentOnLoadCompletedInMainFrame(); | 
 |  763 #endif | 
 |  764   } | 
 |  765  | 
|  764  private: |  766  private: | 
|  765   // ChromeRenderViewHostTestHarness: |  767   // ChromeRenderViewHostTestHarness: | 
|  766   void SetUp() override { |  768   void SetUp() override { | 
|  767     ChromeRenderViewHostTestHarness::SetUp(); |  769     ChromeRenderViewHostTestHarness::SetUp(); | 
|  768 #if defined(OS_ANDROID) |  770 #if defined(OS_ANDROID) | 
|  769     InfoBarService::CreateForWebContents(web_contents()); |  771     InfoBarService::CreateForWebContents(web_contents()); | 
|  770 #else |  772 #else | 
|  771     PermissionRequestManager::CreateForWebContents(web_contents()); |  773     PermissionRequestManager::CreateForWebContents(web_contents()); | 
 |  774     PermissionRequestManager* manager = | 
 |  775         PermissionRequestManager::FromWebContents(web_contents()); | 
 |  776     prompt_factory_.reset(new MockPermissionPromptFactory(manager)); | 
 |  777     manager->DisplayPendingRequests(); | 
|  772 #endif |  778 #endif | 
|  773   } |  779   } | 
|  774  |  780  | 
 |  781   void TearDown() override { | 
 |  782     prompt_factory_.reset(); | 
 |  783     ChromeRenderViewHostTestHarness::TearDown(); | 
 |  784   } | 
 |  785  | 
 |  786   std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; | 
 |  787  | 
|  775   DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); |  788   DISALLOW_COPY_AND_ASSIGN(PermissionContextBaseTests); | 
|  776 }; |  789 }; | 
|  777  |  790  | 
|  778 // Simulates clicking Accept. The permission should be granted and |  791 // Simulates clicking Accept. The permission should be granted and | 
|  779 // saved for future use. |  792 // saved for future use. | 
|  780 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) { |  793 TEST_F(PermissionContextBaseTests, TestAskAndGrantPersist) { | 
|  781   TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |  794   TestAskAndDecide_TestContent(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | 
|  782                                CONTENT_SETTING_ALLOW, true); |  795                                CONTENT_SETTING_ALLOW, true); | 
|  783 } |  796 } | 
|  784  |  797  | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  907 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { |  920 TEST_F(PermissionContextBaseTests, TestPermissionsBlacklistingAllowed) { | 
|  908   scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |  921   scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 
|  909       new MockSafeBrowsingDatabaseManager(true /* perform_callback */); |  922       new MockSafeBrowsingDatabaseManager(true /* perform_callback */); | 
|  910   const GURL url("https://www.example.com"); |  923   const GURL url("https://www.example.com"); | 
|  911   std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |  924   std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 
|  912   db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |  925   db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 
|  913   TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, |  926   TestPermissionsBlacklisting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, db_manager, | 
|  914                               url, 2000 /* timeout */, CONTENT_SETTING_ALLOW, |  927                               url, 2000 /* timeout */, CONTENT_SETTING_ALLOW, | 
|  915                               PermissionEmbargoStatus::NOT_EMBARGOED); |  928                               PermissionEmbargoStatus::NOT_EMBARGOED); | 
|  916 } |  929 } | 
| OLD | NEW |