Chromium Code Reviews| Index: chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
| diff --git a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
| index 7ce6e5968fb9a21bd635ccdd157f4442a9a2a713..cf5880fb75f405825145171307cc1d94e5817ea6 100644 |
| --- a/chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
| +++ b/chrome/browser/geolocation/geolocation_permission_context_unittest.cc |
| @@ -31,6 +31,8 @@ |
| #include "chrome/browser/permissions/permission_manager.h" |
| #include "chrome/browser/permissions/permission_request.h" |
| #include "chrome/browser/permissions/permission_request_id.h" |
| +#include "chrome/browser/permissions/permission_request_manager.h" |
| +#include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
| #include "chrome/common/chrome_features.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| @@ -61,9 +63,6 @@ |
| #include "components/prefs/pref_service.h" |
| #include "content/public/browser/permission_type.h" |
| #include "third_party/WebKit/public/platform/modules/permissions/permission_status.mojom.h" |
| -#else |
| -#include "chrome/browser/permissions/permission_request_manager.h" |
| -#include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" |
| #endif |
| #if BUILDFLAG(ENABLE_EXTENSIONS) |
| @@ -143,8 +142,14 @@ const char TestSearchEngineDelegate::kDSETestUrl[] = "https://www.dsetest.com"; |
| // GeolocationPermissionContextTests ------------------------------------------ |
| +enum class TestType { |
| + PERMISSION_REQUEST_MANAGER, |
| + PERMISSION_QUEUE_CONTROLLER, |
| +}; |
| + |
| class GeolocationPermissionContextTests |
| - : public ChromeRenderViewHostTestHarness { |
| + : public ChromeRenderViewHostTestHarness, |
| + public ::testing::WithParamInterface<TestType> { |
| protected: |
| // ChromeRenderViewHostTestHarness: |
| void SetUp() override; |
| @@ -174,13 +179,7 @@ class GeolocationPermissionContextTests |
| void AddNewTab(const GURL& url); |
| void CheckTabContentsState(const GURL& requesting_frame, |
| ContentSetting expected_content_setting); |
| -#if !defined(OS_ANDROID) |
| void SetupRequestManager(content::WebContents* web_contents); |
| - size_t GetBubblesQueueSize(PermissionRequestManager* manager); |
| - void AcceptBubble(PermissionRequestManager* manager); |
| - void DenyBubble(PermissionRequestManager* manager); |
| - void CloseBubble(PermissionRequestManager* manager); |
| -#endif |
| #if defined(OS_ANDROID) |
| bool RequestPermissionIsLSDShown(const GURL& origin); |
| bool RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin); |
| @@ -194,21 +193,29 @@ class GeolocationPermissionContextTests |
| GURL frame_1, |
| ContentSetting content_setting); |
| size_t GetNumberOfPrompts(); |
| + size_t GetNumberOfPrompts(content::WebContents* web_contents); |
| void AcceptPrompt(); |
| + void AcceptPrompt(content::WebContents* web_contents); |
| + void DenyPrompt(); |
| + void ClosePrompt(); |
| base::string16 GetPromptText(); |
| + void EnableFeature(base::test::ScopedFeatureList& scoped_feature_list, |
|
raymes
2017/05/17 04:24:49
in Chrome we never pass arguments by non-const ref
Timothy Loh
2017/05/19 01:43:01
Done.
|
| + const base::Feature& feature); |
| + |
| // owned by the browser context |
| GeolocationPermissionContext* geolocation_permission_context_; |
| ClosedInfoBarTracker closed_infobar_tracker_; |
| std::vector<std::unique_ptr<content::WebContents>> extra_tabs_; |
| -#if !defined(OS_ANDROID) |
| std::vector<std::unique_ptr<MockPermissionPromptFactory>> |
| mock_permission_prompt_factories_; |
| -#endif |
| // A map between renderer child id and a pair represending the bridge id and |
| // whether the requested permission was allowed. |
| base::hash_map<int, std::pair<int, bool> > responses_; |
| + |
| + // For testing the PermissionRequestManager on Android |
| + base::test::ScopedFeatureList scoped_feature_list_; |
| }; |
| PermissionRequestID GeolocationPermissionContextTests::RequestID( |
| @@ -285,11 +292,10 @@ void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { |
| extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
| #endif |
| -#if defined(OS_ANDROID) |
| - InfoBarService::CreateForWebContents(new_tab); |
| -#else |
| - SetupRequestManager(new_tab); |
| -#endif |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) |
| + SetupRequestManager(new_tab); |
| + else |
| + InfoBarService::CreateForWebContents(new_tab); |
| extra_tabs_.push_back(base::WrapUnique(new_tab)); |
| } |
| @@ -322,6 +328,14 @@ void GeolocationPermissionContextTests::SetUp() { |
| geolocation_permission_context_ = static_cast<GeolocationPermissionContext*>( |
| PermissionManager::Get(profile())->GetPermissionContext( |
| CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| + |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + // This feature enables the PRM for Android and no-ops on desktop. |
| + scoped_feature_list_.InitAndEnableFeature( |
| + features::kUseGroupedPermissionInfobars); |
| + SetupRequestManager(web_contents()); |
| + } |
| + |
| #if defined(OS_ANDROID) |
| static_cast<GeolocationPermissionContextAndroid*>( |
| geolocation_permission_context_) |
| @@ -332,20 +346,15 @@ void GeolocationPermissionContextTests::SetUp() { |
| MockLocationSettings::SetLocationSettingsDialogStatus(false /* enabled */, |
| GRANTED); |
| MockLocationSettings::ClearHasShownLocationSettingsDialog(); |
| -#else |
| - SetupRequestManager(web_contents()); |
| #endif |
| } |
| void GeolocationPermissionContextTests::TearDown() { |
| -#if !defined(OS_ANDROID) |
| mock_permission_prompt_factories_.clear(); |
| -#endif |
| extra_tabs_.clear(); |
| ChromeRenderViewHostTestHarness::TearDown(); |
| } |
| -#if !defined(OS_ANDROID) |
| void GeolocationPermissionContextTests::SetupRequestManager( |
| content::WebContents* web_contents) { |
| // Create PermissionRequestManager. |
| @@ -362,31 +371,12 @@ void GeolocationPermissionContextTests::SetupRequestManager( |
| permission_request_manager->DisplayPendingRequests(); |
| } |
| -size_t GeolocationPermissionContextTests::GetBubblesQueueSize( |
| - PermissionRequestManager* manager) { |
| - return manager->requests_.size(); |
| -} |
| - |
| -void GeolocationPermissionContextTests::AcceptBubble( |
| - PermissionRequestManager* manager) { |
| - manager->Accept(); |
| -} |
| - |
| -void GeolocationPermissionContextTests::DenyBubble( |
| - PermissionRequestManager* manager) { |
| - manager->Deny(); |
| -} |
| - |
| -void GeolocationPermissionContextTests::CloseBubble( |
| - PermissionRequestManager* manager) { |
| - manager->Closing(); |
| -} |
| -#endif |
| - |
| #if defined(OS_ANDROID) |
| + |
| bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown( |
| const GURL& origin) { |
| NavigateAndCommit(origin); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::ClearHasShownLocationSettingsDialog(); |
| RequestGeolocationPermission(web_contents(), RequestID(0), origin, true); |
| @@ -396,14 +386,12 @@ bool GeolocationPermissionContextTests::RequestPermissionIsLSDShown( |
| bool GeolocationPermissionContextTests:: |
| RequestPermissionIsLSDShownWithPermissionPrompt(const GURL& origin) { |
| NavigateAndCommit(origin); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::ClearHasShownLocationSettingsDialog(); |
| RequestGeolocationPermission(web_contents(), RequestID(0), origin, true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - EXPECT_TRUE(infobar_delegate); |
| - infobar_delegate->Accept(); |
| + EXPECT_EQ(1U, GetNumberOfPrompts()); |
| + AcceptPrompt(); |
| return MockLocationSettings::HasShownLocationSettingsDialog(); |
| } |
| @@ -425,10 +413,10 @@ void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted() { |
| void GeolocationPermissionContextTests::RequestManagerDocumentLoadCompleted( |
| content::WebContents* web_contents) { |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager::FromWebContents(web_contents)-> |
| - DocumentOnLoadCompletedInMainFrame(); |
| -#endif |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager::FromWebContents(web_contents) |
| + ->DocumentOnLoadCompletedInMainFrame(); |
| + } |
| } |
| ContentSetting GeolocationPermissionContextTests::GetGeolocationContentSetting( |
| @@ -451,46 +439,94 @@ void GeolocationPermissionContextTests::SetGeolocationContentSetting( |
| } |
| size_t GeolocationPermissionContextTests::GetNumberOfPrompts() { |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - return GetBubblesQueueSize(manager); |
| -#else |
| - return infobar_service()->infobar_count(); |
| -#endif |
| + return GetNumberOfPrompts(web_contents()); |
| +} |
| + |
| +size_t GeolocationPermissionContextTests::GetNumberOfPrompts( |
| + content::WebContents* web_contents) { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager* manager = |
| + PermissionRequestManager::FromWebContents(web_contents); |
| + return manager->requests_.size(); |
| + } |
| + |
| + return InfoBarService::FromWebContents(web_contents)->infobar_count(); |
| } |
| void GeolocationPermissionContextTests::AcceptPrompt() { |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - AcceptBubble(manager); |
| -#else |
| - infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar->delegate()->AsConfirmInfoBarDelegate(); |
| - infobar_delegate->Accept(); |
| -#endif |
| + return AcceptPrompt(web_contents()); |
| +} |
| + |
| +void GeolocationPermissionContextTests::AcceptPrompt( |
| + content::WebContents* web_contents) { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager* manager = |
| + PermissionRequestManager::FromWebContents(web_contents); |
| + manager->Accept(); |
| + } else { |
| + InfoBarService* infobar_service = |
| + InfoBarService::FromWebContents(web_contents); |
| + infobars::InfoBar* infobar = infobar_service->infobar_at(0); |
| + ConfirmInfoBarDelegate* infobar_delegate = |
| + infobar->delegate()->AsConfirmInfoBarDelegate(); |
| + ASSERT_TRUE(infobar_delegate); |
| + infobar_delegate->Accept(); |
| + infobar_service->RemoveInfoBar(infobar); |
|
raymes
2017/05/17 04:24:49
Question: do you know why all this removing happen
Timothy Loh
2017/05/19 01:43:01
Yeah, clean-up for a couple of tests which queue m
|
| + EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| + } |
| +} |
| + |
| +void GeolocationPermissionContextTests::DenyPrompt() { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager* manager = |
| + PermissionRequestManager::FromWebContents(web_contents()); |
| + manager->Deny(); |
| + } else { |
| + infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
|
raymes
2017/05/17 04:24:49
nit: why infobar_1?
Timothy Loh
2017/05/19 01:43:01
Bad copy-paste... fixed!
|
| + infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| + } |
| +} |
| + |
| +void GeolocationPermissionContextTests::ClosePrompt() { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager* manager = |
| + PermissionRequestManager::FromWebContents(web_contents()); |
| + manager->Closing(); |
| + } else { |
| + geolocation_permission_context_->CancelPermissionRequest(web_contents(), |
| + RequestID(0)); |
| + } |
| } |
| base::string16 GeolocationPermissionContextTests::GetPromptText() { |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - PermissionRequest* request = manager->requests_.front(); |
| - return base::ASCIIToUTF16(request->GetOrigin().spec()) + |
| - request->GetMessageTextFragment(); |
| -#else |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + PermissionRequestManager* manager = |
| + PermissionRequestManager::FromWebContents(web_contents()); |
| + PermissionRequest* request = manager->requests_.front(); |
| + return base::ASCIIToUTF16(request->GetOrigin().spec()) + |
| + request->GetMessageTextFragment(); |
| + } |
| + |
| infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| ConfirmInfoBarDelegate* infobar_delegate = |
| infobar->delegate()->AsConfirmInfoBarDelegate(); |
| return infobar_delegate->GetMessageText(); |
| -#endif |
| +} |
| + |
| +void GeolocationPermissionContextTests::EnableFeature( |
| + base::test::ScopedFeatureList& scoped_feature_list, |
| + const base::Feature& feature) { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + scoped_feature_list.InitWithFeatures( |
| + {features::kUseGroupedPermissionInfobars, feature}, {}); |
| + } else { |
| + scoped_feature_list.InitAndEnableFeature(feature); |
| + } |
| } |
| // Tests ---------------------------------------------------------------------- |
| -TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { |
| +TEST_P(GeolocationPermissionContextTests, SinglePermissionPrompt) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| RequestManagerDocumentLoadCompleted(); |
| @@ -501,8 +537,8 @@ TEST_F(GeolocationPermissionContextTests, SinglePermissionBubble) { |
| ASSERT_EQ(1U, GetNumberOfPrompts()); |
| } |
| -TEST_F(GeolocationPermissionContextTests, |
| - SinglePermissionBubbleFailsOnInsecureOrigin) { |
| +TEST_P(GeolocationPermissionContextTests, |
| + SinglePermissionPromptFailsOnInsecureOrigin) { |
| GURL requesting_frame("http://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| RequestManagerDocumentLoadCompleted(); |
| @@ -514,131 +550,106 @@ TEST_F(GeolocationPermissionContextTests, |
| } |
| #if defined(OS_ANDROID) |
| -TEST_F(GeolocationPermissionContextTests, SinglePermissionInfobar) { |
| - GURL requesting_frame("https://www.example.com/geolocation"); |
| - NavigateAndCommit(requesting_frame); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| - RequestGeolocationPermission( |
| - web_contents(), RequestID(0), requesting_frame, true); |
| - ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| - infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate); |
| - infobar_delegate->Cancel(); |
| - infobar_service()->RemoveInfoBar(infobar); |
| - EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
|
raymes
2017/05/17 04:24:49
Is this now covered somewhere else?
Timothy Loh
2017/05/19 01:43:01
This test and SinglePermissionBubble (renamed bubb
|
| -} |
| - |
| -// Infobar-only tests; Android doesn't support permission bubbles. |
| -TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| +// Tests concerning Android location settings permission |
| +TEST_P(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(true /* android */, |
| true /* system */); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission( |
| web_contents(), RequestID(0), requesting_frame, true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate_0 = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate_0); |
| - base::string16 text_0 = infobar_delegate_0->GetButtonLabel( |
| - ConfirmInfoBarDelegate::BUTTON_OK); |
| + EXPECT_EQ(1U, GetNumberOfPrompts()); |
| Reload(); |
| MockLocationSettings::SetLocationStatus(false /* android */, |
| true /* system */); |
| MockLocationSettings::SetCanPromptForAndroidPermission(false); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission( |
| web_contents(), RequestID(0), requesting_frame, true); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| } |
| -TEST_F(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) { |
| +TEST_P(GeolocationPermissionContextTests, AndroidEnabledCanPrompt) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(false /* android */, |
| true /* system */); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission( |
| web_contents(), RequestID(0), requesting_frame, true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate); |
| - infobar_delegate->Accept(); |
| + ASSERT_EQ(1U, GetNumberOfPrompts()); |
| + AcceptPrompt(); |
| CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| CheckPermissionMessageSent(0, true); |
| } |
| -TEST_F(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) { |
| +TEST_P(GeolocationPermissionContextTests, AndroidEnabledCantPrompt) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(false /* android */, |
| true /* system */); |
| MockLocationSettings::SetCanPromptForAndroidPermission(false); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| true); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| } |
| -TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) { |
| +TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDDisabled) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(true /* android */, |
| false /* system */); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission( |
| web_contents(), RequestID(0), requesting_frame, true); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog()); |
| } |
| -TEST_F(GeolocationPermissionContextTests, SystemLocationOnNoLSD) { |
| +TEST_P(GeolocationPermissionContextTests, SystemLocationOnNoLSD) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + RequestManagerDocumentLoadCompleted(); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate); |
| - infobar_delegate->Accept(); |
| + ASSERT_EQ(1U, GetNumberOfPrompts()); |
| + AcceptPrompt(); |
| CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| CheckPermissionMessageSent(0, true); |
| EXPECT_FALSE(MockLocationSettings::HasShownLocationSettingsDialog()); |
| } |
| -TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { |
| +TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { |
| base::HistogramTester tester; |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(true /* android */, |
| false /* system */); |
| MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, |
| GRANTED); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate); |
| - infobar_delegate->Accept(); |
| + ASSERT_EQ(1U, GetNumberOfPrompts()); |
| + AcceptPrompt(); |
| CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
| CheckPermissionMessageSent(0, true); |
| EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); |
| @@ -648,25 +659,23 @@ TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDAccept) { |
| tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 0); |
| } |
| -TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { |
| +TEST_P(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { |
| base::HistogramTester tester; |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| NavigateAndCommit(requesting_frame); |
| + RequestManagerDocumentLoadCompleted(); |
| MockLocationSettings::SetLocationStatus(true /* android */, |
| false /* system */); |
| MockLocationSettings::SetLocationSettingsDialogStatus(true /* enabled */, |
| DENIED); |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| true); |
| - EXPECT_EQ(1U, infobar_service()->infobar_count()); |
| - ConfirmInfoBarDelegate* infobar_delegate = |
| - infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate); |
| - infobar_delegate->Accept(); |
| + ASSERT_EQ(1U, GetNumberOfPrompts()); |
| + AcceptPrompt(); |
| CheckTabContentsState(requesting_frame, CONTENT_SETTING_BLOCK); |
| CheckPermissionMessageSent(0, false); |
| EXPECT_TRUE(MockLocationSettings::HasShownLocationSettingsDialog()); |
| @@ -676,10 +685,10 @@ TEST_F(GeolocationPermissionContextTests, SystemLocationOffLSDReject) { |
| tester.ExpectTotalCount("Geolocation.SettingsDialog.DenyEvent.NonDSE", 1); |
| } |
| -TEST_F(GeolocationPermissionContextTests, LSDBackOffDifferentSites) { |
| +TEST_P(GeolocationPermissionContextTests, LSDBackOffDifferentSites) { |
| base::HistogramTester tester; |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame_1("https://www.example.com/geolocation"); |
| GURL requesting_frame_2("https://www.example-2.com/geolocation"); |
| @@ -734,10 +743,10 @@ TEST_F(GeolocationPermissionContextTests, LSDBackOffDifferentSites) { |
| tester.ExpectTotalCount("Geolocation.SettingsDialog.SuppressEvent.DSE", 1); |
| } |
| -TEST_F(GeolocationPermissionContextTests, LSDBackOffTiming) { |
| +TEST_P(GeolocationPermissionContextTests, LSDBackOffTiming) { |
| base::HistogramTester tester; |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| @@ -822,9 +831,9 @@ TEST_F(GeolocationPermissionContextTests, LSDBackOffTiming) { |
| 2); |
| } |
| -TEST_F(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) { |
| +TEST_P(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| @@ -851,9 +860,9 @@ TEST_F(GeolocationPermissionContextTests, LSDBackOffPermissionStatus) { |
| requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) { |
| +TEST_P(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| @@ -881,10 +890,10 @@ TEST_F(GeolocationPermissionContextTests, LSDBackOffAskPromptsDespiteBackOff) { |
| RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, |
| +TEST_P(GeolocationPermissionContextTests, |
| LSDBackOffAcceptPermissionResetsBackOff) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| @@ -911,15 +920,20 @@ TEST_F(GeolocationPermissionContextTests, |
| EXPECT_TRUE( |
| RequestPermissionIsLSDShownWithPermissionPrompt(requesting_frame)); |
| + // Denying the LSD stops the content setting from being stored, so explicitly |
| + // set it to ALLOW. |
| + SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| + CONTENT_SETTING_ALLOW); |
| + |
| // And check that back in the lowest backoff state. |
| EXPECT_FALSE(RequestPermissionIsLSDShown(requesting_frame)); |
| AddDayOffsetForTesting(7); |
| EXPECT_TRUE(RequestPermissionIsLSDShown(requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) { |
| +TEST_P(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| SetGeolocationContentSetting(requesting_frame, requesting_frame, |
| @@ -954,7 +968,7 @@ TEST_F(GeolocationPermissionContextTests, LSDBackOffAcceptLSDResetsBackOff) { |
| } |
| #endif |
| -TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| +TEST_P(GeolocationPermissionContextTests, QueuedPermission) { |
| GURL requesting_frame_0("https://www.example.com/geolocation"); |
| GURL requesting_frame_1("https://www.example-2.com/geolocation"); |
| EXPECT_EQ( |
| @@ -984,14 +998,6 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
| CheckPermissionMessageSent(0, true); |
| -#if defined(OS_ANDROID) |
| - infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); |
| - infobar_service()->RemoveInfoBar(infobar_0); |
| - EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); |
| - closed_infobar_tracker_.Clear(); |
| -#endif |
| - |
| // Now we should have a new infobar for the second frame. |
| ASSERT_EQ(1U, GetNumberOfPrompts()); |
| base::string16 text_1 = GetPromptText(); |
| @@ -1000,14 +1006,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| EXPECT_NE(text_0, text_1); |
| // Cancel (block) this frame. |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - DenyBubble(manager); |
| -#else |
| - infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); |
| - infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| -#endif |
| + DenyPrompt(); |
| CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
| CheckPermissionMessageSent(1, false); |
| @@ -1020,7 +1019,7 @@ TEST_F(GeolocationPermissionContextTests, QueuedPermission) { |
| GetGeolocationContentSetting(requesting_frame_1, requesting_frame_0)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
| +TEST_P(GeolocationPermissionContextTests, HashIsIgnored) { |
| GURL url_a("https://www.example.com/geolocation#a"); |
| GURL url_b("https://www.example.com/geolocation#b"); |
| @@ -1030,11 +1029,7 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
| // Check permission is requested. |
| ASSERT_EQ(0U, GetNumberOfPrompts()); |
| -#if defined(OS_ANDROID) |
| - const bool user_gesture = false; |
| -#else |
| const bool user_gesture = true; |
| -#endif |
| RequestGeolocationPermission(web_contents(), RequestID(0), url_a, |
| user_gesture); |
| ASSERT_EQ(1U, GetNumberOfPrompts()); |
| @@ -1048,32 +1043,26 @@ TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { |
| CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
| CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
| CheckPermissionMessageSent(0, true); |
| - |
| - // Cleanup. |
| -#if defined(OS_ANDROID) |
| - infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| - infobar_service()->RemoveInfoBar(infobar); |
| - EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
| - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| -#endif |
| } |
| // TODO(felt): The bubble is rejecting file:// permission requests. |
| // Fix and enable this test. crbug.com/444047 |
| #if defined(OS_ANDROID) |
| -#define MAYBE_PermissionForFileScheme PermissionForFileScheme |
| +TEST_P(GeolocationPermissionContextTests, PermissionForFileScheme) { |
| #else |
| -#define MAYBE_PermissionForFileScheme DISABLED_PermissionForFileScheme |
| +TEST_P(GeolocationPermissionContextTests, DISABLED_PermissionForFileScheme) { |
| #endif |
| -TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) |
| + return; |
|
raymes
2017/05/17 04:24:49
Maybe remove the #ifdef above and just rely on thi
Timothy Loh
2017/05/19 01:43:01
Done.
|
| + |
| GURL requesting_frame("file://example/geolocation.html"); |
| NavigateAndCommit(requesting_frame); |
| RequestManagerDocumentLoadCompleted(); |
| // Check permission is requested. |
| ASSERT_EQ(0U, GetNumberOfPrompts()); |
| - RequestGeolocationPermission( |
| - web_contents(), RequestID(0), requesting_frame, true); |
| + RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame, |
| + true); |
| EXPECT_EQ(1U, GetNumberOfPrompts()); |
| // Accept the frame. |
| @@ -1082,12 +1071,11 @@ TEST_F(GeolocationPermissionContextTests, MAYBE_PermissionForFileScheme) { |
| CheckPermissionMessageSent(0, true); |
| // Make sure the setting is not stored. |
| - EXPECT_EQ( |
| - CONTENT_SETTING_ASK, |
| - GetGeolocationContentSetting(requesting_frame, requesting_frame)); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + GetGeolocationContentSetting(requesting_frame, requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| +TEST_P(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| GURL frame_0("https://www.example.com/geolocation"); |
| GURL frame_1("https://www.example-2.com/geolocation"); |
| EXPECT_EQ( |
| @@ -1112,14 +1100,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| ASSERT_FALSE(text_0.empty()); |
| // Simulate the frame going away; the request should be removed. |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - CloseBubble(manager); |
| -#else |
| - geolocation_permission_context_->CancelPermissionRequest(web_contents(), |
| - RequestID(0)); |
| -#endif |
| + ClosePrompt(); |
| // Check that the next pending request is created correctly. |
| base::string16 text_1 = GetPromptText(); |
| @@ -1137,7 +1118,7 @@ TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { |
| CONTENT_SETTING_ALLOW, GetGeolocationContentSetting(frame_1, frame_0)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| +TEST_P(GeolocationPermissionContextTests, InvalidURL) { |
| // Navigate to the first url. |
| GURL invalid_embedder("about:blank"); |
| GURL requesting_frame; |
| @@ -1152,7 +1133,7 @@ TEST_F(GeolocationPermissionContextTests, InvalidURL) { |
| CheckPermissionMessageSent(0, false); |
| } |
| -TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| +TEST_P(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| GURL url_a("https://www.example.com/geolocation"); |
| GURL url_b("https://www.example-2.com/geolocation"); |
| NavigateAndCommit(url_a); // Tab A0 |
| @@ -1161,14 +1142,6 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| RequestManagerDocumentLoadCompleted(); |
| RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); |
| RequestManagerDocumentLoadCompleted(extra_tabs_[1].get()); |
| -#if !defined(OS_ANDROID) |
| - PermissionRequestManager* manager_a0 = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - PermissionRequestManager* manager_b = |
| - PermissionRequestManager::FromWebContents(extra_tabs_[0].get()); |
| - PermissionRequestManager* manager_a1 = |
| - PermissionRequestManager::FromWebContents(extra_tabs_[1].get()); |
| -#endif |
| // Request permission in all three tabs. |
| RequestGeolocationPermission( |
| @@ -1178,54 +1151,34 @@ TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
| RequestGeolocationPermission( |
| extra_tabs_[1].get(), RequestIDForTab(1, 0), url_a, true); |
| ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. |
| -#if !defined(OS_ANDROID) |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| -#else |
| - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| - ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); |
| -#endif |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get())); |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[1].get())); |
| // Accept the permission in tab A0. |
| -#if !defined(OS_ANDROID) |
| - AcceptBubble(manager_a0); |
| -#else |
| - infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); |
| - ConfirmInfoBarDelegate* infobar_delegate_a0 = |
| - infobar_a0->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate_a0); |
| - infobar_delegate_a0->Accept(); |
| - infobar_service()->RemoveInfoBar(infobar_a0); |
| - EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); |
| -#endif |
| + AcceptPrompt(); |
| + if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) { |
| + EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| + } |
| CheckPermissionMessageSent(0, true); |
| // Because they're the same origin, this will cause tab A1's infobar to |
| // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
| // TODO(felt): Update this test when the bubble's behavior is changed. |
| // Either way, tab B should still have a pending permission request. |
| -#if !defined(OS_ANDROID) |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_b)); |
| -#else |
| - CheckPermissionMessageSentForTab(1, 0, true); |
| - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| -#endif |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get())); |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[1].get())); |
| + } else { |
| + CheckPermissionMessageSentForTab(1, 0, true); |
| + } |
| } |
| -TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| +TEST_P(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| GURL url_a("https://www.example.com/geolocation"); |
| GURL url_b("https://www.example-2.com/geolocation"); |
| NavigateAndCommit(url_a); // Tab A0. |
| AddNewTab(url_a); // Tab A1. |
| -#if !defined(OS_ANDROID) |
| RequestManagerDocumentLoadCompleted(); |
| RequestManagerDocumentLoadCompleted(extra_tabs_[0].get()); |
| - PermissionRequestManager* manager_a0 = |
| - PermissionRequestManager::FromWebContents(web_contents()); |
| - PermissionRequestManager* manager_a1 = |
| - PermissionRequestManager::FromWebContents(extra_tabs_[0].get()); |
| -#endif |
| // Request permission in both tabs; the extra tab will have two permission |
| // requests from two origins. |
| @@ -1235,60 +1188,36 @@ TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { |
| extra_tabs_[0].get(), RequestIDForTab(0, 0), url_a, true); |
| RequestGeolocationPermission( |
| extra_tabs_[0].get(), RequestIDForTab(0, 1), url_b, true); |
| -#if !defined(OS_ANDROID) |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_a0)); |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| -#else |
| - ASSERT_EQ(1U, infobar_service()->infobar_count()); |
| - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| -#endif |
| + |
| + ASSERT_EQ(1U, GetNumberOfPrompts()); |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get())); |
| // Accept the first request in tab A1. |
| -#if !defined(OS_ANDROID) |
| - AcceptBubble(manager_a1); |
| -#else |
| - infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); |
| - ConfirmInfoBarDelegate* infobar_delegate_a1 = |
| - infobar_a1->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate_a1); |
| - infobar_delegate_a1->Accept(); |
| - infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); |
| - EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| - EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); |
| -#endif |
| + AcceptPrompt(extra_tabs_[0].get()); |
| + if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) { |
| + EXPECT_EQ(2U, closed_infobar_tracker_.size()); |
| + } |
| CheckPermissionMessageSentForTab(0, 0, true); |
| // Because they're the same origin, this will cause tab A0's infobar to |
| // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
| // TODO(felt): Update this test when the bubble's behavior is changed. |
| -#if !defined(OS_ANDROID) |
| - EXPECT_EQ(1U, GetBubblesQueueSize(manager_a0)); |
| -#else |
| - EXPECT_EQ(0U, infobar_service()->infobar_count()); |
| - CheckPermissionMessageSent(0, true); |
| -#endif |
| + if (GetParam() == TestType::PERMISSION_REQUEST_MANAGER) { |
| + EXPECT_EQ(1U, GetNumberOfPrompts()); |
| + } else { |
| + EXPECT_EQ(0U, GetNumberOfPrompts()); |
| + CheckPermissionMessageSent(0, true); |
| + } |
| // The second request should now be visible in tab A1. |
| -#if !defined(OS_ANDROID) |
| - ASSERT_EQ(1U, GetBubblesQueueSize(manager_a1)); |
| -#else |
| - ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
| -#endif |
| + ASSERT_EQ(1U, GetNumberOfPrompts(extra_tabs_[0].get())); |
| // Accept the second request and check that it's gone. |
| -#if !defined(OS_ANDROID) |
| - AcceptBubble(manager_a1); |
| - EXPECT_EQ(0U, GetBubblesQueueSize(manager_a1)); |
| -#else |
| - infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); |
| - ConfirmInfoBarDelegate* infobar_delegate_1 = |
| - infobar_1->delegate()->AsConfirmInfoBarDelegate(); |
| - ASSERT_TRUE(infobar_delegate_1); |
| - infobar_delegate_1->Accept(); |
| -#endif |
| + AcceptPrompt(extra_tabs_[0].get()); |
| + EXPECT_EQ(0U, GetNumberOfPrompts(extra_tabs_[0].get())); |
| } |
| -TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| +TEST_P(GeolocationPermissionContextTests, TabDestroyed) { |
| GURL requesting_frame_0("https://www.example.com/geolocation"); |
| GURL requesting_frame_1("https://www.example-2.com/geolocation"); |
| EXPECT_EQ( |
| @@ -1311,12 +1240,12 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| ASSERT_EQ(1U, GetNumberOfPrompts()); |
| // Delete the tab contents. |
| -#if defined(OS_ANDROID) |
| - infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| - DeleteContents(); |
| - ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
| - ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| -#endif |
| + if (GetParam() == TestType::PERMISSION_QUEUE_CONTROLLER) { |
| + infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
| + DeleteContents(); |
| + ASSERT_EQ(1U, closed_infobar_tracker_.size()); |
| + ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
| + } |
| // The content settings should not have changed. |
| EXPECT_EQ( |
| @@ -1328,10 +1257,9 @@ TEST_F(GeolocationPermissionContextTests, TabDestroyed) { |
| } |
| #if defined(OS_ANDROID) |
| -TEST_F(GeolocationPermissionContextTests, SearchGeolocationInIncognito) { |
| +TEST_P(GeolocationPermissionContextTests, SearchGeolocationInIncognito) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature( |
| - features::kConsistentOmniboxGeolocation); |
| + EnableFeature(scoped_feature_list, features::kConsistentOmniboxGeolocation); |
| GURL requesting_frame(TestSearchEngineDelegate::kDSETestUrl); |
| // The DSE Geolocation setting should be used in incognito if it is BLOCK, |
| @@ -1360,7 +1288,7 @@ TEST_F(GeolocationPermissionContextTests, SearchGeolocationInIncognito) { |
| .content_setting); |
| } |
| -TEST_F(GeolocationPermissionContextTests, |
| +TEST_P(GeolocationPermissionContextTests, |
| GeolocationStatusAndroidDisabledLegacy) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| @@ -1390,9 +1318,9 @@ TEST_F(GeolocationPermissionContextTests, |
| requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) { |
| +TEST_P(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| @@ -1426,7 +1354,7 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusAndroidDisabled) { |
| requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, |
| +TEST_P(GeolocationPermissionContextTests, |
| GeolocationStatusSystemDisabledLegacy) { |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| @@ -1456,9 +1384,9 @@ TEST_F(GeolocationPermissionContextTests, |
| requesting_frame)); |
| } |
| -TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) { |
| +TEST_P(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) { |
| base::test::ScopedFeatureList scoped_feature_list; |
| - scoped_feature_list.InitAndEnableFeature(features::kLsdPermissionPrompt); |
| + EnableFeature(scoped_feature_list, features::kLsdPermissionPrompt); |
| GURL requesting_frame("https://www.example.com/geolocation"); |
| @@ -1511,3 +1439,16 @@ TEST_F(GeolocationPermissionContextTests, GeolocationStatusSystemDisabled) { |
| requesting_frame)); |
| } |
| #endif // defined(OS_ANDROID) |
| + |
| +#if defined(OS_ANDROID) |
| +INSTANTIATE_TEST_CASE_P( |
| + GeolocationPermissionContextTestsInstance, |
| + GeolocationPermissionContextTests, |
| + ::testing::Values(TestType::PERMISSION_REQUEST_MANAGER, |
| + TestType::PERMISSION_QUEUE_CONTROLLER)); |
| +#else |
| +INSTANTIATE_TEST_CASE_P( |
| + GeolocationPermissionContextTestsInstance, |
| + GeolocationPermissionContextTests, |
| + ::testing::Values(TestType::PERMISSION_REQUEST_MANAGER)); |
| +#endif |