#include "components/permissions/permission_request_manager.h"
#include "components/permissions/permission_ui_selector.h"
#include "components/permissions/permission_uma_util.h"
+#include "components/permissions/permission_util.h"
#include "components/permissions/request_type.h"
#include "components/permissions/test/mock_permission_prompt_factory.h"
#include "components/permissions/test/mock_permission_request.h"
#include "content/public/test/test_renderer_host.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
+#include "ui/events/base_event_utils.h"
+#include "ui/events/event.h"
namespace permissions {
using QuietUiReason = PermissionUiSelector::QuietUiReason;
}
-class PermissionRequestManagerTest
- : public content::RenderViewHostTestHarness,
- public ::testing::WithParamInterface<bool> {
+class PermissionRequestManagerTest : public content::RenderViewHostTestHarness {
public:
PermissionRequestManagerTest()
: RenderViewHostTestHarness(
iframe_request_same_domain_(GURL("https://www.google.com/some/url"),
RequestType::kMidiSysex),
iframe_request_other_domain_(GURL("https://www.youtube.com"),
- RequestType::kGeolocation),
+ RequestType::kClipboard),
iframe_request_camera_other_domain_(GURL("https://www.youtube.com"),
RequestType::kStorageAccess),
iframe_request_mic_other_domain_(GURL("https://www.youtube.com"),
RequestType::kMicStream) {
-
- if (GetParam()) {
- feature_list_.InitWithFeatures(
- {permissions::features::kPermissionChip},
- {permissions::features::kPermissionQuietChip});
- } else {
- feature_list_.InitWithFeatures(
- {}, {permissions::features::kPermissionChip,
- permissions::features::kPermissionQuietChip});
- }
}
void SetUp() override {
content::RenderViewHostTestHarness::SetUp();
SetContents(CreateTestWebContents());
- NavigateAndCommit(GURL(permissions::MockPermissionRequest::kDefaultOrigin));
+ NavigateAndCommit(GURL(MockPermissionRequest::kDefaultOrigin));
PermissionRequestManager::CreateForWebContents(web_contents());
manager_ = PermissionRequestManager::FromWebContents(web_contents());
task_environment()->RunUntilIdle();
}
+ void OpenHelpCenterLink() {
+#if !BUILDFLAG(IS_ANDROID)
+ const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
+ ui::EventTimeForNow(), 0, 0);
+#else // BUILDFLAG(IS_ANDROID)
+ const ui::TouchEvent event(
+ ui::ET_TOUCH_MOVED, gfx::PointF(), gfx::PointF(), ui::EventTimeForNow(),
+ ui::PointerDetails(ui::EventPointerType::kTouch, 1));
+#endif
+ manager_->OpenHelpCenterLink(event);
+ task_environment()->RunUntilIdle();
+ }
+
void WaitForFrameLoad() {
// PermissionRequestManager ignores all parameters. Yay?
manager_->DOMContentLoaded(nullptr);
MockPermissionRequest iframe_request_other_domain_;
MockPermissionRequest iframe_request_camera_other_domain_;
MockPermissionRequest iframe_request_mic_other_domain_;
- raw_ptr<PermissionRequestManager> manager_;
+ raw_ptr<PermissionRequestManager, DanglingUntriaged> manager_;
std::unique_ptr<MockPermissionPromptFactory> prompt_factory_;
TestPermissionsClient client_;
base::test::ScopedFeatureList feature_list_;
// General
////////////////////////////////////////////////////////////////////////////////
-TEST_P(PermissionRequestManagerTest, NoRequests) {
+TEST_F(PermissionRequestManagerTest, NoRequests) {
WaitForBubbleToBeShown();
EXPECT_FALSE(prompt_factory_->is_visible());
}
-TEST_P(PermissionRequestManagerTest, SingleRequest) {
+TEST_F(PermissionRequestManagerTest, SingleRequest) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
EXPECT_TRUE(request1_.granted());
}
-TEST_P(PermissionRequestManagerTest, SequentialRequests) {
+TEST_F(PermissionRequestManagerTest, SequentialRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
EXPECT_TRUE(prompt_factory_->is_visible());
EXPECT_TRUE(request2_.granted());
}
-TEST_P(PermissionRequestManagerTest, ForgetRequestsOnPageNavigation) {
+TEST_F(PermissionRequestManagerTest, ForgetRequestsOnPageNavigation) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
EXPECT_TRUE(iframe_request_other_domain_.finished());
}
-TEST_P(PermissionRequestManagerTest, RequestsDontNeedUserGesture) {
+TEST_F(PermissionRequestManagerTest, RequestsDontNeedUserGesture) {
WaitForFrameLoad();
WaitForBubbleToBeShown();
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
EXPECT_TRUE(prompt_factory_->is_visible());
}
-TEST_P(PermissionRequestManagerTest, RequestsNotSupported) {
+TEST_F(PermissionRequestManagerTest, RequestsNotSupported) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
Accept();
// Requests grouping
////////////////////////////////////////////////////////////////////////////////
+// Android is the only platform that does not support the permission chip.
+#if BUILDFLAG(IS_ANDROID)
// Most requests should never be grouped.
-TEST_P(PermissionRequestManagerTest, TwoRequestsUngrouped) {
- // Grouping for chip feature is tested in ThreeRequestsStackOrderChip.
- if (GetParam())
- return;
-
+// Grouping for chip feature is tested in ThreeRequestsStackOrderChip.
+TEST_F(PermissionRequestManagerTest, TwoRequestsUngrouped) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
ASSERT_EQ(prompt_factory_->show_count(), 2);
}
-TEST_P(PermissionRequestManagerTest, ThreeRequestsStackOrderChip) {
- if (!GetParam())
- return;
-
+// Tests for non-Android platforms which support the permission chip.
+#else // BUILDFLAG(IS_ANDROID)
+TEST_F(PermissionRequestManagerTest, ThreeRequestsStackOrderChip) {
// Test new permissions order, requests shouldn't be grouped.
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
}
// Test new permissions order by adding requests one at a time.
-TEST_P(PermissionRequestManagerTest, ThreeRequestsOneByOneStackOrderChip) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, ThreeRequestsOneByOneStackOrderChip) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
Accept();
EXPECT_TRUE(request1_.granted());
}
+#endif // BUILDFLAG(IS_ANDROID)
// Only mic/camera requests from the same origin should be grouped.
-TEST_P(PermissionRequestManagerTest, MicCameraGrouped) {
+TEST_F(PermissionRequestManagerTest, MicCameraGrouped) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
WaitForBubbleToBeShown();
// If mic/camera requests come from different origins, they should not be
// grouped.
-TEST_P(PermissionRequestManagerTest, MicCameraDifferentOrigins) {
+TEST_F(PermissionRequestManagerTest, MicCameraDifferentOrigins) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
&iframe_request_mic_other_domain_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
#if !BUILDFLAG(IS_ANDROID)
// Only camera/ptz requests from the same origin should be grouped.
-TEST_P(PermissionRequestManagerTest, CameraPtzGrouped) {
+TEST_F(PermissionRequestManagerTest, CameraPtzGrouped) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
WaitForBubbleToBeShown();
EXPECT_TRUE(request_ptz_.granted());
}
-TEST_P(PermissionRequestManagerTest, CameraPtzDifferentOrigins) {
+TEST_F(PermissionRequestManagerTest, CameraPtzDifferentOrigins) {
// If camera/ptz requests come from different origins, they should not be
// grouped.
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
}
// Only mic/camera/ptz requests from the same origin should be grouped.
-TEST_P(PermissionRequestManagerTest, MicCameraPtzGrouped) {
+TEST_F(PermissionRequestManagerTest, MicCameraPtzGrouped) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
// If mic/camera/ptz requests come from different origins, they should not be
// grouped.
-TEST_P(PermissionRequestManagerTest, MicCameraPtzDifferentOrigins) {
+TEST_F(PermissionRequestManagerTest, MicCameraPtzDifferentOrigins) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
&iframe_request_mic_other_domain_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
#endif // !BUILDFLAG(IS_ANDROID)
// Tests mix of grouped media requests and non-groupable request.
-TEST_P(PermissionRequestManagerTest, MixOfMediaAndNotMediaRequests) {
+TEST_F(PermissionRequestManagerTest, MixOfMediaAndNotMediaRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
Accept();
}
+TEST_F(PermissionRequestManagerTest, OpenHelpCenterLink) {
+ manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
+ &iframe_request_camera_other_domain_);
+ WaitForBubbleToBeShown();
+ EXPECT_TRUE(prompt_factory_->is_visible());
+
+ OpenHelpCenterLink();
+ SUCCEED();
+}
+
+TEST_F(PermissionRequestManagerTest, OpenHelpCenterLink_RequestNotSupported) {
+ manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
+ WaitForBubbleToBeShown();
+ EXPECT_TRUE(prompt_factory_->is_visible());
+
+ EXPECT_DEATH_IF_SUPPORTED(OpenHelpCenterLink(), "");
+}
+
////////////////////////////////////////////////////////////////////////////////
// Tab switching
////////////////////////////////////////////////////////////////////////////////
#if BUILDFLAG(IS_ANDROID)
-TEST_P(PermissionRequestManagerTest, TwoRequestsTabSwitch) {
+TEST_F(PermissionRequestManagerTest, TwoRequestsTabSwitch) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
WaitForBubbleToBeShown();
}
#endif // BUILDFLAG(IS_ANDROID)
-TEST_P(PermissionRequestManagerTest, PermissionRequestWhileTabSwitchedAway) {
+TEST_F(PermissionRequestManagerTest, PermissionRequestWhileTabSwitchedAway) {
MockTabSwitchAway();
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
// Duplicated requests
////////////////////////////////////////////////////////////////////////////////
-TEST_P(PermissionRequestManagerTest, SameRequestRejected) {
+TEST_F(PermissionRequestManagerTest, SameRequestRejected) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
EXPECT_FALSE(request1_.finished());
EXPECT_FALSE(prompt_factory_->is_visible());
}
-TEST_P(PermissionRequestManagerTest, WeakDuplicateRequests) {
+TEST_F(PermissionRequestManagerTest, WeakDuplicateRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
auto dupe_request_1 = request1_.CreateDuplicateRequest();
}
};
-TEST_P(PermissionRequestManagerTest, WeakDuplicateRequestsAccept) {
+TEST_F(PermissionRequestManagerTest, WeakDuplicateRequestsAccept) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
EXPECT_EQ(0ul, manager_->duplicate_requests_.size());
}
-TEST_P(PermissionRequestManagerTest, DuplicateRequest) {
+TEST_F(PermissionRequestManagerTest, DuplicateRequest) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
WaitForBubbleToBeShown();
Accept();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(dupe_request2->finished());
EXPECT_TRUE(request2_.finished());
} else {
WaitForBubbleToBeShown();
Accept();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(dupe_request->finished());
EXPECT_TRUE(request1_.finished());
} else {
// Requests from iframes
////////////////////////////////////////////////////////////////////////////////
-TEST_P(PermissionRequestManagerTest, MainFrameNoRequestIFrameRequest) {
+TEST_F(PermissionRequestManagerTest, MainFrameNoRequestIFrameRequest) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
&iframe_request_same_domain_);
WaitForBubbleToBeShown();
EXPECT_TRUE(iframe_request_same_domain_.finished());
}
-TEST_P(PermissionRequestManagerTest, MainFrameAndIFrameRequestSameDomain) {
+TEST_F(PermissionRequestManagerTest, MainFrameAndIFrameRequestSameDomain) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
&iframe_request_same_domain_);
EXPECT_TRUE(prompt_factory_->is_visible());
ASSERT_EQ(1, prompt_factory_->request_count());
Closing();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(iframe_request_same_domain_.finished());
EXPECT_FALSE(request1_.finished());
} else {
Closing();
EXPECT_FALSE(prompt_factory_->is_visible());
- if (GetParam())
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(request1_.finished());
- else
+ } else {
EXPECT_TRUE(iframe_request_same_domain_.finished());
+ }
}
-TEST_P(PermissionRequestManagerTest, MainFrameAndIFrameRequestOtherDomain) {
+TEST_F(PermissionRequestManagerTest, MainFrameAndIFrameRequestOtherDomain) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
&iframe_request_other_domain_);
EXPECT_TRUE(prompt_factory_->is_visible());
Closing();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(iframe_request_other_domain_.finished());
EXPECT_FALSE(request1_.finished());
} else {
EXPECT_TRUE(prompt_factory_->is_visible());
Closing();
EXPECT_TRUE(iframe_request_other_domain_.finished());
- if (GetParam())
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(request1_.finished());
- else
+ } else {
EXPECT_TRUE(iframe_request_other_domain_.finished());
+ }
}
-TEST_P(PermissionRequestManagerTest, IFrameRequestWhenMainRequestVisible) {
+TEST_F(PermissionRequestManagerTest, IFrameRequestWhenMainRequestVisible) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
EXPECT_TRUE(prompt_factory_->is_visible());
WaitForFrameLoad();
ASSERT_EQ(prompt_factory_->request_count(), 1);
Closing();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(iframe_request_same_domain_.finished());
EXPECT_FALSE(request1_.finished());
} else {
ASSERT_EQ(prompt_factory_->request_count(), 1);
Closing();
EXPECT_TRUE(iframe_request_same_domain_.finished());
- if (GetParam())
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(request1_.finished());
- else
+ } else {
EXPECT_TRUE(iframe_request_same_domain_.finished());
+ }
}
-TEST_P(PermissionRequestManagerTest,
+TEST_F(PermissionRequestManagerTest,
IFrameRequestOtherDomainWhenMainRequestVisible) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
&iframe_request_other_domain_);
WaitForFrameLoad();
Closing();
- if (GetParam()) {
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(iframe_request_other_domain_.finished());
EXPECT_FALSE(request1_.finished());
} else {
EXPECT_TRUE(prompt_factory_->is_visible());
Closing();
- if (GetParam())
+ if (PermissionUtil::DoesPlatformSupportChip()) {
EXPECT_TRUE(request1_.finished());
- else
+ } else {
EXPECT_TRUE(iframe_request_other_domain_.finished());
+ }
}
////////////////////////////////////////////////////////////////////////////////
// This code path (calling Accept on a non-merged bubble, with no accepted
// permission) would never be used in actual Chrome, but its still tested for
// completeness.
-TEST_P(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) {
+TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) {
base::HistogramTester histograms;
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1);
}
-TEST_P(PermissionRequestManagerTest, UMAForTabSwitching) {
+TEST_F(PermissionRequestManagerTest, UMAForTabSwitching) {
base::HistogramTester histograms;
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
}
};
-TEST_P(PermissionRequestManagerTest,
+TEST_F(PermissionRequestManagerTest,
UiSelectorNotUsedForPermissionsOtherThanNotification) {
manager_->clear_permission_ui_selector_for_testing();
MockNotificationPermissionUiSelector::CreateForManager(
EXPECT_TRUE(request_camera_.granted());
}
-TEST_P(PermissionRequestManagerTest, UiSelectorUsedForNotifications) {
+TEST_F(PermissionRequestManagerTest, UiSelectorUsedForNotifications) {
const struct {
absl::optional<PermissionUiSelector::QuietUiReason> quiet_ui_reason;
absl::optional<base::TimeDelta> async_delay;
}
}
-TEST_P(PermissionRequestManagerTest,
+TEST_F(PermissionRequestManagerTest,
UiSelectionHappensSeparatelyForEachRequest) {
manager_->clear_permission_ui_selector_for_testing();
MockNotificationPermissionUiSelector::CreateForManager(
Accept();
}
-TEST_P(PermissionRequestManagerTest, SkipNextUiSelector) {
+TEST_F(PermissionRequestManagerTest, SkipNextUiSelector) {
manager_->clear_permission_ui_selector_for_testing();
MockNotificationPermissionUiSelector::CreateForManager(
manager_, QuietUiReason::kEnabledInPrefs,
Accept();
}
-TEST_P(PermissionRequestManagerTest, MultipleUiSelectors) {
+TEST_F(PermissionRequestManagerTest, MultipleUiSelectors) {
const struct {
std::vector<absl::optional<QuietUiReason>> quiet_ui_reasons;
std::vector<bool> simulate_delayed_decision;
}
}
-TEST_P(PermissionRequestManagerTest, SelectorsPredictionLikelihood) {
+TEST_F(PermissionRequestManagerTest, SelectorsPredictionLikelihood) {
using PredictionLikelihood = PermissionUmaUtil::PredictionGrantLikelihood;
const auto VeryLikely = PredictionLikelihood::
PermissionPrediction_Likelihood_DiscretizedLikelihood_VERY_LIKELY;
}
}
-TEST_P(PermissionRequestManagerTest, SelectorRequestTypes) {
+TEST_F(PermissionRequestManagerTest, SelectorRequestTypes) {
const struct {
RequestType request_type;
bool should_request_use_quiet_ui;
// Quiet UI chip. Low priority for Notifications & Geolocation.
////////////////////////////////////////////////////////////////////////////////
-TEST_P(PermissionRequestManagerTest, NotificationsSingleBubbleAndChipRequest) {
+TEST_F(PermissionRequestManagerTest, NotificationsSingleBubbleAndChipRequest) {
MockPermissionRequest request(RequestType::kNotifications,
PermissionRequestGestureType::GESTURE);
EXPECT_EQ(prompt_factory_->show_count(), 1);
}
+// Android is the only platform that does not support the permission chip.
+#if BUILDFLAG(IS_ANDROID)
// Quiet UI feature is disabled. Chip is disabled. No low priority requests, the
// first request is always shown.
//
// 1. Notification request shown
// 2. Geolocation request shown
// 3. Camera request shown
-TEST_P(PermissionRequestManagerTest,
+TEST_F(PermissionRequestManagerTest,
NotificationsGeolocationCameraBubbleRequest) {
- // permissions::features::kPermissionChip is enabled based on `GetParam()`.
- // That test is only for the default bubble.
- if (GetParam())
- return;
-
std::unique_ptr<MockPermissionRequest> request_notifications =
CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1);
EXPECT_EQ(prompt_factory_->show_count(), 3);
}
-// Quiet UI feature is disabled, no low priority requests, the last request is
-// always shown.
-//
-// Permissions requested in order:
-// 1. Notification (non abusive)
-// 2. Geolocation
-// 3. Camera
-//
-// Prompt display order:
-// 1. Notifications request shown but is preempted
-// 2. Geolocation request shown but is preempted
-// 3. Camera request shown
-// 4. Geolocation request shown again
-// 5. Notifications request shown again
-TEST_P(PermissionRequestManagerTest,
- NotificationsGeolocationCameraChipRequest) {
- // permissions::features::kPermissionChip is enabled based on `GetParam()`.
- // That test is only for the chip UI.
- if (!GetParam())
- return;
-
- std::unique_ptr<MockPermissionRequest> request_notifications =
- CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
- 1);
- std::unique_ptr<MockPermissionRequest> request_geolocation =
- CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
- 2);
- std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
- RequestType::kCameraStream, /*should_be_seen=*/true, 3);
-
- for (auto* kRequest : {request_camera.get(), request_geolocation.get(),
- request_notifications.get()}) {
- WaitAndAcceptPromptForRequest(kRequest);
- }
-
- EXPECT_EQ(prompt_factory_->show_count(), 5);
-}
-
+// Tests for non-Android platforms which support the permission chip.
+#else // BUILDFLAG(IS_ANDROID)
// Quiet UI feature is disabled, no low priority requests, the last request is
// always shown.
//
// Permissions requested in order:
// 1. Camera
-// 2. Notification (non abusive)
-// 3. Geolocation
+// 2. Clipboard
+// 3. MIDI
//
// Prompt display order:
// 1. Camera request shown but is preempted
-// 2. Notifications request shown but is preempted
-// 3. Geolocation request shown
-// 4. Notifications request shown again
+// 2. Clipboard request shown but is preempted
+// 3. MIDI request shown
+// 4. Clipboard request shown again
// 5. Camera request shown again
-TEST_P(PermissionRequestManagerTest,
+TEST_F(PermissionRequestManagerTest,
CameraNotificationsGeolocationChipRequest) {
- // permissions::features::kPermissionChip is enabled based on `GetParam()`.
- // That test is only for the chip.
- if (!GetParam())
- return;
-
std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
RequestType::kCameraStream, /*should_be_seen=*/true, 1);
- std::unique_ptr<MockPermissionRequest> request_notifications =
- CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
- 2);
- std::unique_ptr<MockPermissionRequest> request_geolocation =
- CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
- 3);
+ std::unique_ptr<MockPermissionRequest> request_clipboard =
+ CreateAndAddRequest(RequestType::kClipboard, /*should_be_seen=*/true, 2);
+ std::unique_ptr<MockPermissionRequest> request_midi =
+ CreateAndAddRequest(RequestType::kMidi, /*should_be_seen=*/true, 3);
- for (auto* kRequest : {request_geolocation.get(), request_notifications.get(),
- request_camera.get()}) {
+ for (auto* kRequest :
+ {request_midi.get(), request_clipboard.get(), request_camera.get()}) {
WaitAndAcceptPromptForRequest(kRequest);
}
//
// Prompt display order:
// 1. Mic
-// 2. Notification
+// 2. Clipboard
// 3. Geolocation
-TEST_P(PermissionRequestManagerTest, NewHighPriorityRequestDuringUIDecision) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, NewHighPriorityRequestDuringUIDecision) {
manager_->clear_permission_ui_selector_for_testing();
MockNotificationPermissionUiSelector::CreateForManager(
manager_, QuietUiReason::kTriggeredDueToAbusiveRequests,
task_environment()->FastForwardBy(base::Seconds(1));
- MockPermissionRequest request(RequestType::kNotifications,
+ MockPermissionRequest request(RequestType::kClipboard,
PermissionRequestGestureType::GESTURE);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
EXPECT_TRUE(request1_.granted());
}
-class PermissionRequestManagerTestQuietChip
- : public PermissionRequestManagerTest {
- public:
- PermissionRequestManagerTestQuietChip() {
- feature_list_.InitWithFeatureState(
- permissions::features::kPermissionQuietChip, true);
- }
-
- private:
- base::test::ScopedFeatureList feature_list_;
-};
-
// Verifies that the quiet UI chip is not ignored if another request came in
// less than 8.5 seconds after.
// Permissions requested in order:
// 1. Notifications request shown but is preempted because of quiet UI.
// 2. Geolocation request shown
// 3. Notifications request shown again
-TEST_P(PermissionRequestManagerTestQuietChip,
+TEST_F(PermissionRequestManagerTest,
AbusiveNotificationsGeolocationQuietUIChipRequest) {
MockNotificationPermissionUiSelector::CreateForManager(
manager_,
// Prompt display order:
// 1. Notifications request shown but is preempted because of quiet UI.
// 2. Geolocation request shown
-TEST_P(PermissionRequestManagerTestQuietChip,
- AbusiveNotificationsShownLongEnough) {
+TEST_F(PermissionRequestManagerTest, AbusiveNotificationsShownLongEnough) {
MockNotificationPermissionUiSelector::CreateForManager(
manager_,
PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
// 3. Camera request shown
// 4. Geolocation request shown again
// 5. Notifications quiet UI request shown again
-TEST_P(PermissionRequestManagerTestQuietChip,
+TEST_F(PermissionRequestManagerTest,
AbusiveNotificationsShownLongEnoughCamera) {
MockNotificationPermissionUiSelector::CreateForManager(
manager_,
// 1. Camera request shown
// 2. Geolocation request shown
// 3. Camera request shown
-TEST_P(PermissionRequestManagerTestQuietChip,
- CameraAbusiveNotificationsGeolocation) {
+TEST_F(PermissionRequestManagerTest, CameraAbusiveNotificationsGeolocation) {
MockNotificationPermissionUiSelector::CreateForManager(
manager_,
PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
// Prompt display order:
// 1. Camera request shown
// 2. MIDI request shown (or MIDI and then Camera, the order depends on
-// `GetParam()`)
+// `PermissionUtil::DoesPlatformSupportChip()`)
// 3. Geolocation request shown
// 4. Notifications request shown
// If Chip is enabled MIDI will replace Camera, hence 5 prompts will be
// shown. Otherwise 4.
-TEST_P(PermissionRequestManagerTestQuietChip,
+TEST_F(PermissionRequestManagerTest,
CameraAbusiveNotificationsGeolocationMIDI) {
MockNotificationPermissionUiSelector::CreateForManager(
manager_,
std::unique_ptr<MockPermissionRequest> request_midi;
- // If Chip is enabled, MIDI should be shown, otherwise MIDI should not be
- // shown.
- if (GetParam()) {
- request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
- /*should_be_seen=*/true, 2);
- } else {
- request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
- /*should_be_seen=*/false, 1);
- }
+ // Since the chip is enabled, MIDI should be shown.
+ request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
+ /*should_be_seen=*/true, 2);
// The second permission after quiet UI was requested in 8.5 second window,
// the quiet UI Notifiations request for an abusive origin is not
EXPECT_FALSE(request_notifications->granted());
EXPECT_FALSE(request_notifications->finished());
- WaitAndAcceptPromptForRequest(GetParam() ? request_midi.get()
- : request_camera.get());
- WaitAndAcceptPromptForRequest(GetParam() ? request_camera.get()
- : request_midi.get());
+ WaitAndAcceptPromptForRequest(request_midi.get());
+ WaitAndAcceptPromptForRequest(request_camera.get());
WaitAndAcceptPromptForRequest(request_geolocation.get());
WaitAndAcceptPromptForRequest(request_notifications.get());
- EXPECT_EQ(prompt_factory_->show_count(), GetParam() ? 5 : 4);
+ EXPECT_EQ(prompt_factory_->show_count(), 5);
}
// Verifies that non abusive chip behaves similar to others when Quiet UI Chip
// Prompt display order:
// 1. Camera request shown
// 2. MIDI request shown (or MIDI and then Camera, the order depends on
-// `GetParam()`)
+// `PermissionUtil::DoesPlatformSupportChip()`)
// 3. Geolocation request shown
// 4. Notifications request shown
// If Chip is enabled MIDI will replace Camera, hence 5 prompts will be
// shown. Otherwise 4.
-TEST_P(PermissionRequestManagerTestQuietChip,
+TEST_F(PermissionRequestManagerTest,
CameraNonAbusiveNotificationsGeolocationMIDI) {
std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
RequestType::kCameraStream, /*should_be_seen=*/true, 1);
// If Chip is enabled, MIDI should be shown, otherwise MIDI should not be
// shown.
- if (GetParam()) {
request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
/*should_be_seen=*/true, 2);
- } else {
- request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
- /*should_be_seen=*/false, 1);
- }
// The second permission after quiet UI was requested in 8.5 second window,
// the quiet UI Notifiations request for an abusive origin is not
EXPECT_FALSE(request_notifications->granted());
EXPECT_FALSE(request_notifications->finished());
- WaitAndAcceptPromptForRequest(GetParam() ? request_midi.get()
- : request_camera.get());
- WaitAndAcceptPromptForRequest(GetParam() ? request_camera.get()
- : request_midi.get());
+ WaitAndAcceptPromptForRequest(request_midi.get());
+ WaitAndAcceptPromptForRequest(request_camera.get());
WaitAndAcceptPromptForRequest(request_geolocation.get());
WaitAndAcceptPromptForRequest(request_notifications.get());
- EXPECT_EQ(prompt_factory_->show_count(), GetParam() ? 5 : 4);
+ EXPECT_EQ(prompt_factory_->show_count(), 5);
}
-INSTANTIATE_TEST_SUITE_P(All,
- PermissionRequestManagerTest,
- ::testing::Values(false, true));
-INSTANTIATE_TEST_SUITE_P(All,
- PermissionRequestManagerTestQuietChip,
- ::testing::Values(false, true));
-
// Verifies order of requests with mixed low-high priority requests input, with
// both chip and quiet chip enabled. New permissions are added and accepted one
// by one.
// 1. Mic
// 2. Multiple Download
// 3. Geolocation
-TEST_P(PermissionRequestManagerTestQuietChip, Mixed1Low2HighPriorityRequests) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, Mixed1Low2HighPriorityRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
WaitForBubbleToBeShown();
// 1. Mic
// 2. Notification
// 3. Geolocation
-TEST_P(PermissionRequestManagerTestQuietChip, Mixed2Low1HighRequests) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, Mixed2Low1HighRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
WaitForBubbleToBeShown();
// 1. Mic
// 2. Notification
// 3. Geolocation
-TEST_P(PermissionRequestManagerTestQuietChip,
- MultipleSimultaneous2Low1HighRequests) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, MultipleSimultaneous2Low1HighRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
MockPermissionRequest request(RequestType::kNotifications,
// 3. Midi
// 4. Notification
// 5. Geolocation
-TEST_P(PermissionRequestManagerTestQuietChip,
- MultipleSimultaneous2Low3HighRequests) {
- if (!GetParam())
- return;
+TEST_F(PermissionRequestManagerTest, MultipleSimultaneous2Low3HighRequests) {
MockPermissionRequest request_midi(RequestType::kMidiSysex,
PermissionRequestGestureType::GESTURE);
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_midi);
// 2. Mic
// 3. Notification
// 4. Geolocation
-TEST_P(PermissionRequestManagerTestQuietChip,
- MultipleSimultaneous2Low2HighRequests) {
- if (!GetParam())
- return;
-
+TEST_F(PermissionRequestManagerTest, MultipleSimultaneous2Low2HighRequests) {
manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
MockPermissionRequest request(RequestType::kNotifications,
PermissionRequestGestureType::GESTURE);
EXPECT_TRUE(request1_.granted());
}
-// Verifies order of requests with mixed low-high priority requests input, with
-// both chip and quiet chip enabled. Simultaneous new requests are coming while
-// we are waiting for UI selector decisions.
-//
-// Permissions requested in order:
-// 1. Geolocation (low), UI selector takes 2 seconds to decide.
-// 2. Notification(low) then mic (high)
-//
-// Prompt display order:
-// 1. Mic
-// 2. Geolocation will get delayed 2 seconds, then preempted to front of queue
-// 3. Notification
-TEST_P(PermissionRequestManagerTestQuietChip,
- NewHighPriorityRequestDuringUIDecision) {
- if (!GetParam())
- return;
-
- manager_->clear_permission_ui_selector_for_testing();
- MockNotificationPermissionUiSelector::CreateForManager(
- manager_, QuietUiReason::kTriggeredDueToAbusiveRequests,
- absl::make_optional<base::TimeDelta>(base::Seconds(2)));
- manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
-
- task_environment()->FastForwardBy(base::Seconds(1));
-
- MockPermissionRequest request(RequestType::kNotifications,
- PermissionRequestGestureType::GESTURE);
- manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
- manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
- WaitForBubbleToBeShown();
- manager_->clear_permission_ui_selector_for_testing();
-
- EXPECT_TRUE(prompt_factory_->is_visible());
- EXPECT_EQ(prompt_factory_->request_count(), 1);
- Accept();
- EXPECT_TRUE(request_mic_.granted());
- EXPECT_FALSE(request.granted());
- EXPECT_FALSE(request1_.granted());
- WaitForBubbleToBeShown();
-
- EXPECT_TRUE(prompt_factory_->is_visible());
- EXPECT_EQ(prompt_factory_->request_count(), 1);
- Accept();
- EXPECT_TRUE(request1_.granted());
- EXPECT_FALSE(request.granted());
- WaitForBubbleToBeShown();
-
- EXPECT_TRUE(prompt_factory_->is_visible());
- EXPECT_EQ(prompt_factory_->request_count(), 1);
- Accept();
- EXPECT_TRUE(request.granted());
-}
+#endif // BUILDFLAG(IS_ANDROID)
} // namespace permissions