1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
10 #include "base/command_line.h"
11 #include "base/memory/raw_ptr.h"
12 #include "base/run_loop.h"
13 #include "base/test/metrics/histogram_tester.h"
14 #include "base/test/scoped_feature_list.h"
15 #include "base/threading/sequenced_task_runner_handle.h"
16 #include "build/build_config.h"
17 #include "components/permissions/features.h"
18 #include "components/permissions/permission_request.h"
19 #include "components/permissions/permission_request_manager.h"
20 #include "components/permissions/permission_ui_selector.h"
21 #include "components/permissions/permission_uma_util.h"
22 #include "components/permissions/request_type.h"
23 #include "components/permissions/test/mock_permission_prompt_factory.h"
24 #include "components/permissions/test/mock_permission_request.h"
25 #include "components/permissions/test/test_permissions_client.h"
26 #include "content/public/test/test_renderer_host.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "third_party/abseil-cpp/absl/types/optional.h"
30 namespace permissions {
33 using QuietUiReason = PermissionUiSelector::QuietUiReason;
36 class PermissionRequestManagerTest
37 : public content::RenderViewHostTestHarness,
38 public ::testing::WithParamInterface<bool> {
40 PermissionRequestManagerTest()
41 : RenderViewHostTestHarness(
42 base::test::TaskEnvironment::TimeSource::MOCK_TIME),
43 request1_(RequestType::kGeolocation,
44 PermissionRequestGestureType::GESTURE),
45 request2_(RequestType::kMultipleDownloads,
46 PermissionRequestGestureType::NO_GESTURE),
47 request_mic_(RequestType::kMicStream,
48 PermissionRequestGestureType::NO_GESTURE),
49 request_camera_(RequestType::kCameraStream,
50 PermissionRequestGestureType::NO_GESTURE),
51 #if !BUILDFLAG(IS_ANDROID)
52 request_ptz_(RequestType::kCameraPanTiltZoom,
53 PermissionRequestGestureType::NO_GESTURE),
55 iframe_request_same_domain_(GURL("https://www.google.com/some/url"),
56 RequestType::kMidiSysex),
57 iframe_request_other_domain_(GURL("https://www.youtube.com"),
58 RequestType::kGeolocation),
59 iframe_request_camera_other_domain_(GURL("https://www.youtube.com"),
60 RequestType::kStorageAccess),
61 iframe_request_mic_other_domain_(GURL("https://www.youtube.com"),
62 RequestType::kMicStream) {
65 feature_list_.InitWithFeatures(
66 {permissions::features::kPermissionChip},
67 {permissions::features::kPermissionQuietChip});
69 feature_list_.InitWithFeatures(
70 {}, {permissions::features::kPermissionChip,
71 permissions::features::kPermissionQuietChip});
75 void SetUp() override {
76 content::RenderViewHostTestHarness::SetUp();
77 SetContents(CreateTestWebContents());
78 NavigateAndCommit(GURL(permissions::MockPermissionRequest::kDefaultOrigin));
80 PermissionRequestManager::CreateForWebContents(web_contents());
81 manager_ = PermissionRequestManager::FromWebContents(web_contents());
82 manager_->set_enabled_app_level_notification_permission_for_testing(true);
83 prompt_factory_ = std::make_unique<MockPermissionPromptFactory>(manager_);
86 void TearDown() override {
87 prompt_factory_ = nullptr;
88 content::RenderViewHostTestHarness::TearDown();
93 task_environment()->RunUntilIdle();
98 task_environment()->RunUntilIdle();
103 task_environment()->RunUntilIdle();
106 void WaitForFrameLoad() {
107 // PermissionRequestManager ignores all parameters. Yay?
108 manager_->DOMContentLoaded(nullptr);
109 task_environment()->RunUntilIdle();
112 void WaitForBubbleToBeShown() {
113 manager_->DocumentOnLoadCompletedInPrimaryMainFrame();
114 task_environment()->RunUntilIdle();
117 void MockTabSwitchAway() {
118 manager_->OnVisibilityChanged(content::Visibility::HIDDEN);
121 void MockTabSwitchBack() {
122 manager_->OnVisibilityChanged(content::Visibility::VISIBLE);
125 virtual void NavigationEntryCommitted(
126 const content::LoadCommittedDetails& details) {
127 manager_->NavigationEntryCommitted(details);
130 std::unique_ptr<MockPermissionRequest> CreateAndAddRequest(
133 int expected_request_count) {
134 std::unique_ptr<MockPermissionRequest> request =
135 std::make_unique<MockPermissionRequest>(
136 type, PermissionRequestGestureType::GESTURE);
137 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), request.get());
138 WaitForBubbleToBeShown();
139 if (should_be_seen) {
140 EXPECT_TRUE(prompt_factory_->RequestTypeSeen(type));
142 EXPECT_FALSE(prompt_factory_->RequestTypeSeen(type));
144 EXPECT_EQ(prompt_factory_->TotalRequestCount(), expected_request_count);
149 void WaitAndAcceptPromptForRequest(MockPermissionRequest* request) {
150 WaitForBubbleToBeShown();
152 EXPECT_FALSE(request->finished());
153 EXPECT_TRUE(prompt_factory_->is_visible());
154 ASSERT_EQ(prompt_factory_->request_count(), 1);
157 EXPECT_TRUE(request->granted());
161 MockPermissionRequest request1_;
162 MockPermissionRequest request2_;
163 MockPermissionRequest request_mic_;
164 MockPermissionRequest request_camera_;
165 #if !BUILDFLAG(IS_ANDROID)
166 MockPermissionRequest request_ptz_;
168 MockPermissionRequest iframe_request_same_domain_;
169 MockPermissionRequest iframe_request_other_domain_;
170 MockPermissionRequest iframe_request_camera_other_domain_;
171 MockPermissionRequest iframe_request_mic_other_domain_;
172 raw_ptr<PermissionRequestManager> manager_;
173 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_;
174 TestPermissionsClient client_;
175 base::test::ScopedFeatureList feature_list_;
178 ////////////////////////////////////////////////////////////////////////////////
180 ////////////////////////////////////////////////////////////////////////////////
182 TEST_P(PermissionRequestManagerTest, NoRequests) {
183 WaitForBubbleToBeShown();
184 EXPECT_FALSE(prompt_factory_->is_visible());
187 TEST_P(PermissionRequestManagerTest, SingleRequest) {
188 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
189 WaitForBubbleToBeShown();
191 EXPECT_TRUE(prompt_factory_->is_visible());
192 ASSERT_EQ(prompt_factory_->request_count(), 1);
195 EXPECT_TRUE(request1_.granted());
198 TEST_P(PermissionRequestManagerTest, SequentialRequests) {
199 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
200 WaitForBubbleToBeShown();
201 EXPECT_TRUE(prompt_factory_->is_visible());
204 EXPECT_TRUE(request1_.granted());
205 EXPECT_FALSE(prompt_factory_->is_visible());
207 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
208 WaitForBubbleToBeShown();
209 EXPECT_TRUE(prompt_factory_->is_visible());
211 EXPECT_FALSE(prompt_factory_->is_visible());
212 EXPECT_TRUE(request2_.granted());
215 TEST_P(PermissionRequestManagerTest, ForgetRequestsOnPageNavigation) {
216 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
217 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
218 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
219 &iframe_request_other_domain_);
220 WaitForBubbleToBeShown();
222 EXPECT_TRUE(prompt_factory_->is_visible());
223 ASSERT_EQ(prompt_factory_->request_count(), 1);
225 NavigateAndCommit(GURL("http://www2.google.com/"));
226 WaitForBubbleToBeShown();
228 EXPECT_FALSE(prompt_factory_->is_visible());
229 EXPECT_TRUE(request1_.finished());
230 EXPECT_TRUE(request2_.finished());
231 EXPECT_TRUE(iframe_request_other_domain_.finished());
234 TEST_P(PermissionRequestManagerTest, RequestsDontNeedUserGesture) {
236 WaitForBubbleToBeShown();
237 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
238 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
239 &iframe_request_other_domain_);
240 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
241 task_environment()->RunUntilIdle();
243 EXPECT_TRUE(prompt_factory_->is_visible());
246 TEST_P(PermissionRequestManagerTest, RequestsNotSupported) {
247 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
248 WaitForBubbleToBeShown();
250 EXPECT_TRUE(request1_.granted());
252 manager_->set_web_contents_supports_permission_requests(false);
254 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
255 EXPECT_TRUE(request2_.cancelled());
258 ////////////////////////////////////////////////////////////////////////////////
260 ////////////////////////////////////////////////////////////////////////////////
262 // Most requests should never be grouped.
263 TEST_P(PermissionRequestManagerTest, TwoRequestsUngrouped) {
264 // Grouping for chip feature is tested in ThreeRequestsStackOrderChip.
268 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
269 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
271 WaitForBubbleToBeShown();
272 EXPECT_TRUE(prompt_factory_->is_visible());
273 ASSERT_EQ(prompt_factory_->request_count(), 1);
275 EXPECT_TRUE(request1_.granted());
277 WaitForBubbleToBeShown();
278 EXPECT_TRUE(prompt_factory_->is_visible());
279 ASSERT_EQ(prompt_factory_->request_count(), 1);
281 EXPECT_TRUE(request2_.granted());
283 ASSERT_EQ(prompt_factory_->show_count(), 2);
286 TEST_P(PermissionRequestManagerTest, ThreeRequestsStackOrderChip) {
290 // Test new permissions order, requests shouldn't be grouped.
291 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
292 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
293 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
294 WaitForBubbleToBeShown();
296 EXPECT_TRUE(prompt_factory_->is_visible());
297 EXPECT_EQ(prompt_factory_->request_count(), 1);
299 EXPECT_TRUE(request_mic_.granted());
300 EXPECT_FALSE(request2_.granted());
301 EXPECT_FALSE(request1_.granted());
302 WaitForBubbleToBeShown();
304 EXPECT_TRUE(prompt_factory_->is_visible());
305 EXPECT_EQ(prompt_factory_->request_count(), 1);
307 EXPECT_TRUE(request2_.granted());
308 EXPECT_FALSE(request1_.granted());
309 WaitForBubbleToBeShown();
311 EXPECT_TRUE(prompt_factory_->is_visible());
312 EXPECT_EQ(prompt_factory_->request_count(), 1);
314 EXPECT_TRUE(request1_.granted());
317 // Test new permissions order by adding requests one at a time.
318 TEST_P(PermissionRequestManagerTest, ThreeRequestsOneByOneStackOrderChip) {
322 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
323 WaitForBubbleToBeShown();
325 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
326 WaitForBubbleToBeShown();
328 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
329 WaitForBubbleToBeShown();
331 EXPECT_TRUE(prompt_factory_->is_visible());
332 EXPECT_EQ(prompt_factory_->request_count(), 1);
334 EXPECT_TRUE(request_mic_.granted());
335 EXPECT_FALSE(request2_.granted());
336 EXPECT_FALSE(request1_.granted());
337 WaitForBubbleToBeShown();
339 EXPECT_TRUE(prompt_factory_->is_visible());
340 EXPECT_EQ(prompt_factory_->request_count(), 1);
342 EXPECT_TRUE(request2_.granted());
343 EXPECT_FALSE(request1_.granted());
344 WaitForBubbleToBeShown();
346 EXPECT_TRUE(prompt_factory_->is_visible());
347 EXPECT_EQ(prompt_factory_->request_count(), 1);
349 EXPECT_TRUE(request1_.granted());
352 // Only mic/camera requests from the same origin should be grouped.
353 TEST_P(PermissionRequestManagerTest, MicCameraGrouped) {
354 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
355 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
356 WaitForBubbleToBeShown();
358 EXPECT_TRUE(prompt_factory_->is_visible());
359 ASSERT_EQ(prompt_factory_->request_count(), 2);
362 EXPECT_TRUE(request_mic_.granted());
363 EXPECT_TRUE(request_camera_.granted());
366 // If mic/camera requests come from different origins, they should not be
368 TEST_P(PermissionRequestManagerTest, MicCameraDifferentOrigins) {
369 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
370 &iframe_request_mic_other_domain_);
371 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
372 WaitForBubbleToBeShown();
374 EXPECT_TRUE(prompt_factory_->is_visible());
375 ASSERT_EQ(prompt_factory_->request_count(), 1);
378 #if !BUILDFLAG(IS_ANDROID)
379 // Only camera/ptz requests from the same origin should be grouped.
380 TEST_P(PermissionRequestManagerTest, CameraPtzGrouped) {
381 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
382 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
383 WaitForBubbleToBeShown();
385 EXPECT_TRUE(prompt_factory_->is_visible());
386 ASSERT_EQ(prompt_factory_->request_count(), 2);
389 EXPECT_TRUE(request_camera_.granted());
390 EXPECT_TRUE(request_ptz_.granted());
393 TEST_P(PermissionRequestManagerTest, CameraPtzDifferentOrigins) {
394 // If camera/ptz requests come from different origins, they should not be
396 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
397 &iframe_request_camera_other_domain_);
398 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
399 WaitForBubbleToBeShown();
401 EXPECT_TRUE(prompt_factory_->is_visible());
402 ASSERT_EQ(prompt_factory_->request_count(), 1);
405 // Only mic/camera/ptz requests from the same origin should be grouped.
406 TEST_P(PermissionRequestManagerTest, MicCameraPtzGrouped) {
407 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
408 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
409 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
410 WaitForBubbleToBeShown();
412 EXPECT_TRUE(prompt_factory_->is_visible());
413 ASSERT_EQ(prompt_factory_->request_count(), 3);
416 EXPECT_TRUE(request_mic_.granted());
417 EXPECT_TRUE(request_camera_.granted());
418 EXPECT_TRUE(request_ptz_.granted());
421 // If mic/camera/ptz requests come from different origins, they should not be
423 TEST_P(PermissionRequestManagerTest, MicCameraPtzDifferentOrigins) {
424 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
425 &iframe_request_mic_other_domain_);
426 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
427 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_ptz_);
428 WaitForBubbleToBeShown();
430 // Requests should be split into two groups and each one will contain less
431 // than 3 requests (1 request + 2 request for current logic and 2 requests + 1
432 // request for chip).
433 EXPECT_TRUE(prompt_factory_->is_visible());
434 ASSERT_LT(prompt_factory_->request_count(), 3);
437 EXPECT_TRUE(prompt_factory_->is_visible());
438 ASSERT_LT(prompt_factory_->request_count(), 3);
440 #endif // !BUILDFLAG(IS_ANDROID)
442 // Tests mix of grouped media requests and non-groupable request.
443 TEST_P(PermissionRequestManagerTest, MixOfMediaAndNotMediaRequests) {
444 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
445 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
446 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
447 WaitForBubbleToBeShown();
449 // Requests should be split into two groups and each one will contain less
450 // than 3 requests (1 request + 2 request for current logic and 2 requests + 1
451 // request for chip).
452 EXPECT_TRUE(prompt_factory_->is_visible());
453 ASSERT_LT(prompt_factory_->request_count(), 3);
455 WaitForBubbleToBeShown();
457 EXPECT_TRUE(prompt_factory_->is_visible());
458 ASSERT_LT(prompt_factory_->request_count(), 3);
462 ////////////////////////////////////////////////////////////////////////////////
464 ////////////////////////////////////////////////////////////////////////////////
466 TEST_P(PermissionRequestManagerTest, TwoRequestsTabSwitch) {
467 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
468 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
469 WaitForBubbleToBeShown();
471 EXPECT_TRUE(prompt_factory_->is_visible());
472 ASSERT_EQ(prompt_factory_->request_count(), 2);
475 #if BUILDFLAG(IS_ANDROID)
476 EXPECT_TRUE(prompt_factory_->is_visible());
478 EXPECT_FALSE(prompt_factory_->is_visible());
482 WaitForBubbleToBeShown();
483 EXPECT_TRUE(prompt_factory_->is_visible());
484 ASSERT_EQ(prompt_factory_->request_count(), 2);
487 EXPECT_TRUE(request_mic_.granted());
488 EXPECT_TRUE(request_camera_.granted());
491 TEST_P(PermissionRequestManagerTest, PermissionRequestWhileTabSwitchedAway) {
493 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
494 WaitForBubbleToBeShown();
495 EXPECT_FALSE(prompt_factory_->is_visible());
498 WaitForBubbleToBeShown();
499 EXPECT_TRUE(prompt_factory_->is_visible());
502 ////////////////////////////////////////////////////////////////////////////////
503 // Duplicated requests
504 ////////////////////////////////////////////////////////////////////////////////
506 TEST_P(PermissionRequestManagerTest, SameRequestRejected) {
507 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
508 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
509 EXPECT_FALSE(request1_.finished());
511 WaitForBubbleToBeShown();
512 EXPECT_TRUE(prompt_factory_->is_visible());
513 ASSERT_EQ(prompt_factory_->request_count(), 1);
515 task_environment()->RunUntilIdle();
516 EXPECT_TRUE(request1_.granted());
517 EXPECT_FALSE(prompt_factory_->is_visible());
520 TEST_P(PermissionRequestManagerTest, DuplicateRequest) {
521 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
522 WaitForBubbleToBeShown();
523 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
525 auto dupe_request = request1_.CreateDuplicateRequest();
526 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
528 EXPECT_FALSE(dupe_request->finished());
529 EXPECT_FALSE(request1_.finished());
531 auto dupe_request2 = request2_.CreateDuplicateRequest();
532 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
533 dupe_request2.get());
534 EXPECT_FALSE(dupe_request2->finished());
535 EXPECT_FALSE(request2_.finished());
537 WaitForBubbleToBeShown();
540 EXPECT_TRUE(dupe_request2->finished());
541 EXPECT_TRUE(request2_.finished());
543 EXPECT_TRUE(dupe_request->finished());
544 EXPECT_TRUE(request1_.finished());
547 WaitForBubbleToBeShown();
550 EXPECT_TRUE(dupe_request->finished());
551 EXPECT_TRUE(request1_.finished());
553 EXPECT_TRUE(dupe_request2->finished());
554 EXPECT_TRUE(request2_.finished());
558 ////////////////////////////////////////////////////////////////////////////////
559 // Requests from iframes
560 ////////////////////////////////////////////////////////////////////////////////
562 TEST_P(PermissionRequestManagerTest, MainFrameNoRequestIFrameRequest) {
563 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
564 &iframe_request_same_domain_);
565 WaitForBubbleToBeShown();
568 EXPECT_TRUE(prompt_factory_->is_visible());
570 EXPECT_TRUE(iframe_request_same_domain_.finished());
573 TEST_P(PermissionRequestManagerTest, MainFrameAndIFrameRequestSameDomain) {
574 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
575 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
576 &iframe_request_same_domain_);
578 WaitForBubbleToBeShown();
580 EXPECT_TRUE(prompt_factory_->is_visible());
581 ASSERT_EQ(1, prompt_factory_->request_count());
584 EXPECT_TRUE(iframe_request_same_domain_.finished());
585 EXPECT_FALSE(request1_.finished());
587 EXPECT_TRUE(request1_.finished());
588 EXPECT_FALSE(iframe_request_same_domain_.finished());
591 WaitForBubbleToBeShown();
592 EXPECT_TRUE(prompt_factory_->is_visible());
593 ASSERT_EQ(1, prompt_factory_->request_count());
596 EXPECT_FALSE(prompt_factory_->is_visible());
598 EXPECT_TRUE(request1_.finished());
600 EXPECT_TRUE(iframe_request_same_domain_.finished());
603 TEST_P(PermissionRequestManagerTest, MainFrameAndIFrameRequestOtherDomain) {
604 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
605 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
606 &iframe_request_other_domain_);
608 WaitForBubbleToBeShown();
610 EXPECT_TRUE(prompt_factory_->is_visible());
613 EXPECT_TRUE(iframe_request_other_domain_.finished());
614 EXPECT_FALSE(request1_.finished());
616 EXPECT_TRUE(request1_.finished());
617 EXPECT_FALSE(iframe_request_other_domain_.finished());
620 EXPECT_TRUE(prompt_factory_->is_visible());
622 EXPECT_TRUE(iframe_request_other_domain_.finished());
624 EXPECT_TRUE(request1_.finished());
626 EXPECT_TRUE(iframe_request_other_domain_.finished());
629 TEST_P(PermissionRequestManagerTest, IFrameRequestWhenMainRequestVisible) {
630 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
631 WaitForBubbleToBeShown();
632 EXPECT_TRUE(prompt_factory_->is_visible());
634 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
635 &iframe_request_same_domain_);
637 ASSERT_EQ(prompt_factory_->request_count(), 1);
640 EXPECT_TRUE(iframe_request_same_domain_.finished());
641 EXPECT_FALSE(request1_.finished());
643 EXPECT_TRUE(request1_.finished());
644 EXPECT_FALSE(iframe_request_same_domain_.finished());
647 EXPECT_TRUE(prompt_factory_->is_visible());
648 ASSERT_EQ(prompt_factory_->request_count(), 1);
650 EXPECT_TRUE(iframe_request_same_domain_.finished());
652 EXPECT_TRUE(request1_.finished());
654 EXPECT_TRUE(iframe_request_same_domain_.finished());
657 TEST_P(PermissionRequestManagerTest,
658 IFrameRequestOtherDomainWhenMainRequestVisible) {
659 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
660 WaitForBubbleToBeShown();
661 EXPECT_TRUE(prompt_factory_->is_visible());
663 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
664 &iframe_request_other_domain_);
668 EXPECT_TRUE(iframe_request_other_domain_.finished());
669 EXPECT_FALSE(request1_.finished());
671 EXPECT_TRUE(request1_.finished());
672 EXPECT_FALSE(iframe_request_other_domain_.finished());
675 EXPECT_TRUE(prompt_factory_->is_visible());
678 EXPECT_TRUE(request1_.finished());
680 EXPECT_TRUE(iframe_request_other_domain_.finished());
683 ////////////////////////////////////////////////////////////////////////////////
685 ////////////////////////////////////////////////////////////////////////////////
687 // This code path (calling Accept on a non-merged bubble, with no accepted
688 // permission) would never be used in actual Chrome, but its still tested for
690 TEST_P(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) {
691 base::HistogramTester histograms;
693 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
694 WaitForBubbleToBeShown();
695 // No need to test UMA for showing prompts again, they were tested in
696 // UMAForSimpleAcceptedBubble.
699 histograms.ExpectUniqueSample(PermissionUmaUtil::kPermissionsPromptDenied,
700 static_cast<base::HistogramBase::Sample>(
701 RequestTypeForUma::PERMISSION_GEOLOCATION),
705 TEST_P(PermissionRequestManagerTest, UMAForTabSwitching) {
706 base::HistogramTester histograms;
708 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
709 WaitForBubbleToBeShown();
710 histograms.ExpectUniqueSample(PermissionUmaUtil::kPermissionsPromptShown,
711 static_cast<base::HistogramBase::Sample>(
712 RequestTypeForUma::PERMISSION_GEOLOCATION),
717 histograms.ExpectUniqueSample(PermissionUmaUtil::kPermissionsPromptShown,
718 static_cast<base::HistogramBase::Sample>(
719 RequestTypeForUma::PERMISSION_GEOLOCATION),
723 ////////////////////////////////////////////////////////////////////////////////
725 ////////////////////////////////////////////////////////////////////////////////
727 // Simulate a PermissionUiSelector that simply returns a predefined |ui_to_use|
729 class MockNotificationPermissionUiSelector : public PermissionUiSelector {
731 explicit MockNotificationPermissionUiSelector(
732 absl::optional<QuietUiReason> quiet_ui_reason,
733 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
734 prediction_likelihood,
735 absl::optional<base::TimeDelta> async_delay)
736 : quiet_ui_reason_(quiet_ui_reason),
737 prediction_likelihood_(prediction_likelihood),
738 async_delay_(async_delay) {}
740 void SelectUiToUse(PermissionRequest* request,
741 DecisionMadeCallback callback) override {
742 Decision decision(quiet_ui_reason_, Decision::ShowNoWarning());
744 base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
745 FROM_HERE, base::BindOnce(std::move(callback), decision),
746 async_delay_.value());
748 std::move(callback).Run(decision);
752 bool IsPermissionRequestSupported(RequestType request_type) override {
753 return request_type == RequestType::kNotifications ||
754 request_type == RequestType::kGeolocation;
757 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
758 PredictedGrantLikelihoodForUKM() override {
759 return prediction_likelihood_;
762 static void CreateForManager(
763 PermissionRequestManager* manager,
764 absl::optional<QuietUiReason> quiet_ui_reason,
765 absl::optional<base::TimeDelta> async_delay,
766 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
767 prediction_likelihood = absl::nullopt) {
768 manager->add_permission_ui_selector_for_testing(
769 std::make_unique<MockNotificationPermissionUiSelector>(
770 quiet_ui_reason, prediction_likelihood, async_delay));
774 absl::optional<QuietUiReason> quiet_ui_reason_;
775 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
776 prediction_likelihood_;
777 absl::optional<base::TimeDelta> async_delay_;
780 // Same as the MockNotificationPermissionUiSelector but handling only the
781 // Camera stream request type
782 class MockCameraStreamPermissionUiSelector
783 : public MockNotificationPermissionUiSelector {
785 explicit MockCameraStreamPermissionUiSelector(
786 absl::optional<QuietUiReason> quiet_ui_reason,
787 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
788 prediction_likelihood,
789 absl::optional<base::TimeDelta> async_delay)
790 : MockNotificationPermissionUiSelector(quiet_ui_reason,
791 prediction_likelihood,
794 bool IsPermissionRequestSupported(RequestType request_type) override {
795 return request_type == RequestType::kCameraStream;
798 static void CreateForManager(
799 PermissionRequestManager* manager,
800 absl::optional<QuietUiReason> quiet_ui_reason,
801 absl::optional<base::TimeDelta> async_delay,
802 absl::optional<PermissionUmaUtil::PredictionGrantLikelihood>
803 prediction_likelihood = absl::nullopt) {
804 manager->add_permission_ui_selector_for_testing(
805 std::make_unique<MockCameraStreamPermissionUiSelector>(
806 quiet_ui_reason, prediction_likelihood, async_delay));
810 TEST_P(PermissionRequestManagerTest,
811 UiSelectorNotUsedForPermissionsOtherThanNotification) {
812 manager_->clear_permission_ui_selector_for_testing();
813 MockNotificationPermissionUiSelector::CreateForManager(
814 manager_, PermissionUiSelector::QuietUiReason::kEnabledInPrefs,
815 absl::nullopt /* async_delay */);
817 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_camera_);
818 WaitForBubbleToBeShown();
820 ASSERT_TRUE(prompt_factory_->is_visible());
821 ASSERT_TRUE(prompt_factory_->RequestTypeSeen(request_camera_.request_type()));
822 EXPECT_FALSE(manager_->ShouldCurrentRequestUseQuietUI());
825 EXPECT_TRUE(request_camera_.granted());
828 TEST_P(PermissionRequestManagerTest, UiSelectorUsedForNotifications) {
830 absl::optional<PermissionUiSelector::QuietUiReason> quiet_ui_reason;
831 absl::optional<base::TimeDelta> async_delay;
833 {QuietUiReason::kEnabledInPrefs, absl::make_optional<base::TimeDelta>()},
834 {PermissionUiSelector::Decision::UseNormalUi(),
835 absl::make_optional<base::TimeDelta>()},
836 {QuietUiReason::kEnabledInPrefs, absl::nullopt},
837 {PermissionUiSelector::Decision::UseNormalUi(), absl::nullopt},
840 for (const auto& test : kTests) {
841 manager_->clear_permission_ui_selector_for_testing();
842 MockNotificationPermissionUiSelector::CreateForManager(
843 manager_, test.quiet_ui_reason, test.async_delay);
845 MockPermissionRequest request(RequestType::kNotifications,
846 PermissionRequestGestureType::GESTURE);
848 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
849 WaitForBubbleToBeShown();
851 EXPECT_TRUE(prompt_factory_->is_visible());
852 EXPECT_TRUE(prompt_factory_->RequestTypeSeen(request.request_type()));
853 EXPECT_EQ(!!test.quiet_ui_reason,
854 manager_->ShouldCurrentRequestUseQuietUI());
857 EXPECT_TRUE(request.granted());
861 TEST_P(PermissionRequestManagerTest,
862 UiSelectionHappensSeparatelyForEachRequest) {
863 manager_->clear_permission_ui_selector_for_testing();
864 MockNotificationPermissionUiSelector::CreateForManager(
865 manager_, QuietUiReason::kEnabledInPrefs,
866 absl::make_optional<base::TimeDelta>());
867 MockPermissionRequest request1(RequestType::kNotifications,
868 PermissionRequestGestureType::GESTURE);
869 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1);
870 WaitForBubbleToBeShown();
871 EXPECT_TRUE(manager_->ShouldCurrentRequestUseQuietUI());
874 MockPermissionRequest request2(RequestType::kNotifications,
875 PermissionRequestGestureType::GESTURE);
876 manager_->clear_permission_ui_selector_for_testing();
877 MockNotificationPermissionUiSelector::CreateForManager(
878 manager_, PermissionUiSelector::Decision::UseNormalUi(),
879 absl::make_optional<base::TimeDelta>());
880 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2);
881 WaitForBubbleToBeShown();
882 EXPECT_FALSE(manager_->ShouldCurrentRequestUseQuietUI());
886 TEST_P(PermissionRequestManagerTest, MultipleUiSelectors) {
889 std::vector<absl::optional<QuietUiReason>> quiet_ui_reasons;
890 std::vector<bool> simulate_delayed_decision;
891 absl::optional<QuietUiReason> expected_reason;
893 // Simple sync selectors, first one should take priority.
894 {{QuietUiReason::kTriggeredByCrowdDeny, QuietUiReason::kEnabledInPrefs},
896 QuietUiReason::kTriggeredByCrowdDeny},
897 // First selector is async but should still take priority even if it
899 {{QuietUiReason::kTriggeredByCrowdDeny, QuietUiReason::kEnabledInPrefs},
901 QuietUiReason::kTriggeredByCrowdDeny},
902 // The first selector that has a quiet ui decision should be used.
903 {{absl::nullopt, absl::nullopt,
904 QuietUiReason::kTriggeredDueToAbusiveContent,
905 QuietUiReason::kEnabledInPrefs},
906 {false, true, true, false},
907 QuietUiReason::kTriggeredDueToAbusiveContent},
908 // If all selectors return a normal ui, it should use a normal ui.
909 {{absl::nullopt, absl::nullopt}, {false, true}, absl::nullopt},
911 // Use a bunch of selectors both async and sync.
912 {{absl::nullopt, absl::nullopt, absl::nullopt, absl::nullopt,
913 absl::nullopt, QuietUiReason::kTriggeredDueToAbusiveRequests,
914 absl::nullopt, QuietUiReason::kEnabledInPrefs},
915 {false, true, false, true, true, true, false, false},
916 QuietUiReason::kTriggeredDueToAbusiveRequests},
917 // Use a bunch of selectors all sync.
918 {{absl::nullopt, absl::nullopt, absl::nullopt, absl::nullopt,
919 absl::nullopt, QuietUiReason::kTriggeredDueToAbusiveRequests,
920 absl::nullopt, QuietUiReason::kEnabledInPrefs},
921 {false, false, false, false, false, false, false, false},
922 QuietUiReason::kTriggeredDueToAbusiveRequests},
923 // Use a bunch of selectors all async.
924 {{absl::nullopt, absl::nullopt, absl::nullopt, absl::nullopt,
925 absl::nullopt, QuietUiReason::kTriggeredDueToAbusiveRequests,
926 absl::nullopt, QuietUiReason::kEnabledInPrefs},
927 {true, true, true, true, true, true, true, true},
928 QuietUiReason::kTriggeredDueToAbusiveRequests},
931 for (const auto& test : kTests) {
932 manager_->clear_permission_ui_selector_for_testing();
933 for (size_t i = 0; i < test.quiet_ui_reasons.size(); ++i) {
934 MockNotificationPermissionUiSelector::CreateForManager(
935 manager_, test.quiet_ui_reasons[i],
936 test.simulate_delayed_decision[i]
937 ? absl::make_optional<base::TimeDelta>()
941 MockPermissionRequest request(RequestType::kNotifications,
942 PermissionRequestGestureType::GESTURE);
944 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
945 WaitForBubbleToBeShown();
947 EXPECT_TRUE(prompt_factory_->is_visible());
948 EXPECT_TRUE(prompt_factory_->RequestTypeSeen(request.request_type()));
949 if (test.expected_reason.has_value()) {
950 EXPECT_EQ(test.expected_reason, manager_->ReasonForUsingQuietUi());
952 EXPECT_FALSE(manager_->ShouldCurrentRequestUseQuietUI());
956 EXPECT_TRUE(request.granted());
960 TEST_P(PermissionRequestManagerTest, SelectorsPredictionLikelihood) {
961 using PredictionLikelihood = PermissionUmaUtil::PredictionGrantLikelihood;
962 const auto VeryLikely = PredictionLikelihood::
963 PermissionPrediction_Likelihood_DiscretizedLikelihood_VERY_LIKELY;
964 const auto Neutral = PredictionLikelihood::
965 PermissionPrediction_Likelihood_DiscretizedLikelihood_NEUTRAL;
968 std::vector<bool> enable_quiet_uis;
969 std::vector<absl::optional<PredictionLikelihood>> prediction_likelihoods;
970 absl::optional<PredictionLikelihood> expected_prediction_likelihood;
972 // Sanity check: prediction likelihood is populated correctly.
973 {{true}, {VeryLikely}, VeryLikely},
974 {{false}, {Neutral}, Neutral},
976 // Prediction likelihood is populated only if the selector was considered.
977 {{true, true}, {absl::nullopt, VeryLikely}, absl::nullopt},
978 {{false, true}, {absl::nullopt, VeryLikely}, VeryLikely},
979 {{false, false}, {absl::nullopt, VeryLikely}, VeryLikely},
981 // First considered selector is preserved.
982 {{true, true}, {Neutral, VeryLikely}, Neutral},
983 {{false, true}, {Neutral, VeryLikely}, Neutral},
984 {{false, false}, {Neutral, VeryLikely}, Neutral},
987 for (const auto& test : kTests) {
988 manager_->clear_permission_ui_selector_for_testing();
989 for (size_t i = 0; i < test.enable_quiet_uis.size(); ++i) {
990 MockNotificationPermissionUiSelector::CreateForManager(
992 test.enable_quiet_uis[i]
993 ? absl::optional<QuietUiReason>(QuietUiReason::kEnabledInPrefs)
995 absl::nullopt /* async_delay */, test.prediction_likelihoods[i]);
998 MockPermissionRequest request(RequestType::kNotifications,
999 PermissionRequestGestureType::GESTURE);
1001 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1002 WaitForBubbleToBeShown();
1004 EXPECT_TRUE(prompt_factory_->is_visible());
1005 EXPECT_TRUE(prompt_factory_->RequestTypeSeen(request.request_type()));
1006 EXPECT_EQ(test.expected_prediction_likelihood,
1007 manager_->prediction_grant_likelihood_for_testing());
1010 EXPECT_TRUE(request.granted());
1014 TEST_P(PermissionRequestManagerTest, SelectorRequestTypes) {
1016 RequestType request_type;
1017 bool should_request_use_quiet_ui;
1019 {RequestType::kNotifications, true},
1020 {RequestType::kGeolocation, true},
1021 {RequestType::kCameraStream, false},
1023 manager_->clear_permission_ui_selector_for_testing();
1024 MockNotificationPermissionUiSelector::CreateForManager(
1025 manager_, QuietUiReason::kEnabledInPrefs,
1026 absl::make_optional<base::TimeDelta>());
1027 for (const auto& test : kTests) {
1028 MockPermissionRequest request(test.request_type,
1029 PermissionRequestGestureType::GESTURE);
1030 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1031 WaitForBubbleToBeShown();
1032 EXPECT_EQ(test.should_request_use_quiet_ui,
1033 manager_->ShouldCurrentRequestUseQuietUI());
1036 // Adding a mock PermissionUiSelector that handles Camera stream.
1037 MockCameraStreamPermissionUiSelector::CreateForManager(
1038 manager_, QuietUiReason::kEnabledInPrefs,
1039 absl::make_optional<base::TimeDelta>());
1040 // Now the RequestType::kCameraStream should show a quiet UI as well
1041 MockPermissionRequest request2(RequestType::kCameraStream,
1042 PermissionRequestGestureType::GESTURE);
1043 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2);
1044 WaitForBubbleToBeShown();
1045 EXPECT_TRUE(manager_->ShouldCurrentRequestUseQuietUI());
1049 ////////////////////////////////////////////////////////////////////////////////
1050 // Quiet UI chip. Low priority for Notifications & Geolocation.
1051 ////////////////////////////////////////////////////////////////////////////////
1053 TEST_P(PermissionRequestManagerTest, NotificationsSingleBubbleAndChipRequest) {
1054 MockPermissionRequest request(RequestType::kNotifications,
1055 PermissionRequestGestureType::GESTURE);
1057 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1058 WaitForBubbleToBeShown();
1060 EXPECT_TRUE(prompt_factory_->is_visible());
1061 ASSERT_EQ(prompt_factory_->request_count(), 1);
1064 EXPECT_TRUE(request.granted());
1065 EXPECT_EQ(prompt_factory_->show_count(), 1);
1068 // Quiet UI feature is disabled. Chip is disabled. No low priority requests, the
1069 // first request is always shown.
1071 // Permissions requested in order:
1072 // 1. Notification (non abusive)
1076 // Prompt display order:
1077 // 1. Notification request shown
1078 // 2. Geolocation request shown
1079 // 3. Camera request shown
1080 TEST_P(PermissionRequestManagerTest,
1081 NotificationsGeolocationCameraBubbleRequest) {
1082 // permissions::features::kPermissionChip is enabled based on `GetParam()`.
1083 // That test is only for the default bubble.
1087 std::unique_ptr<MockPermissionRequest> request_notifications =
1088 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1090 std::unique_ptr<MockPermissionRequest> request_geolocation =
1091 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/false,
1093 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1094 RequestType::kCameraStream, /*should_be_seen=*/false, 1);
1096 for (auto* kRequest : {request_notifications.get(), request_geolocation.get(),
1097 request_camera.get()}) {
1098 WaitAndAcceptPromptForRequest(kRequest);
1101 EXPECT_EQ(prompt_factory_->show_count(), 3);
1104 // Quiet UI feature is disabled, no low priority requests, the last request is
1107 // Permissions requested in order:
1108 // 1. Notification (non abusive)
1112 // Prompt display order:
1113 // 1. Notifications request shown but is preempted
1114 // 2. Geolocation request shown but is preempted
1115 // 3. Camera request shown
1116 // 4. Geolocation request shown again
1117 // 5. Notifications request shown again
1118 TEST_P(PermissionRequestManagerTest,
1119 NotificationsGeolocationCameraChipRequest) {
1120 // permissions::features::kPermissionChip is enabled based on `GetParam()`.
1121 // That test is only for the chip UI.
1125 std::unique_ptr<MockPermissionRequest> request_notifications =
1126 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1128 std::unique_ptr<MockPermissionRequest> request_geolocation =
1129 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
1131 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1132 RequestType::kCameraStream, /*should_be_seen=*/true, 3);
1134 for (auto* kRequest : {request_camera.get(), request_geolocation.get(),
1135 request_notifications.get()}) {
1136 WaitAndAcceptPromptForRequest(kRequest);
1139 EXPECT_EQ(prompt_factory_->show_count(), 5);
1142 // Quiet UI feature is disabled, no low priority requests, the last request is
1145 // Permissions requested in order:
1147 // 2. Notification (non abusive)
1150 // Prompt display order:
1151 // 1. Camera request shown but is preempted
1152 // 2. Notifications request shown but is preempted
1153 // 3. Geolocation request shown
1154 // 4. Notifications request shown again
1155 // 5. Camera request shown again
1156 TEST_P(PermissionRequestManagerTest,
1157 CameraNotificationsGeolocationChipRequest) {
1158 // permissions::features::kPermissionChip is enabled based on `GetParam()`.
1159 // That test is only for the chip.
1163 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1164 RequestType::kCameraStream, /*should_be_seen=*/true, 1);
1165 std::unique_ptr<MockPermissionRequest> request_notifications =
1166 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1168 std::unique_ptr<MockPermissionRequest> request_geolocation =
1169 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
1172 for (auto* kRequest : {request_geolocation.get(), request_notifications.get(),
1173 request_camera.get()}) {
1174 WaitAndAcceptPromptForRequest(kRequest);
1177 EXPECT_EQ(prompt_factory_->show_count(), 5);
1180 // Verifies order of simultaneous requests, with quiet chip enabled.
1181 // Simultaneous new requests are coming while we are waiting for UI selector
1184 // Permissions requested in order:
1185 // 1. Geolocation, UI selector takes 2 seconds to decide.
1186 // 2. Notification then mic. Notification will preempt geolocation
1188 // Prompt display order:
1192 TEST_P(PermissionRequestManagerTest, NewHighPriorityRequestDuringUIDecision) {
1196 manager_->clear_permission_ui_selector_for_testing();
1197 MockNotificationPermissionUiSelector::CreateForManager(
1198 manager_, QuietUiReason::kTriggeredDueToAbusiveRequests,
1199 absl::make_optional<base::TimeDelta>(base::Seconds(2)));
1200 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1202 task_environment()->FastForwardBy(base::Seconds(1));
1204 MockPermissionRequest request(RequestType::kNotifications,
1205 PermissionRequestGestureType::GESTURE);
1206 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1207 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1208 WaitForBubbleToBeShown();
1209 manager_->clear_permission_ui_selector_for_testing();
1211 EXPECT_TRUE(prompt_factory_->is_visible());
1212 EXPECT_EQ(prompt_factory_->request_count(), 1);
1214 EXPECT_TRUE(request_mic_.granted());
1215 EXPECT_FALSE(request.granted());
1216 EXPECT_FALSE(request1_.granted());
1217 WaitForBubbleToBeShown();
1219 EXPECT_TRUE(prompt_factory_->is_visible());
1220 EXPECT_EQ(prompt_factory_->request_count(), 1);
1222 EXPECT_TRUE(request.granted());
1223 EXPECT_FALSE(request1_.granted());
1224 WaitForBubbleToBeShown();
1226 EXPECT_TRUE(prompt_factory_->is_visible());
1227 EXPECT_EQ(prompt_factory_->request_count(), 1);
1229 EXPECT_TRUE(request1_.granted());
1232 class PermissionRequestManagerTestQuietChip
1233 : public PermissionRequestManagerTest {
1235 PermissionRequestManagerTestQuietChip() {
1236 feature_list_.InitWithFeatureState(
1237 permissions::features::kPermissionQuietChip, true);
1241 base::test::ScopedFeatureList feature_list_;
1244 // Verifies that the quiet UI chip is not ignored if another request came in
1245 // less than 8.5 seconds after.
1246 // Permissions requested in order:
1247 // 1. Notification (abusive)
1248 // 2. After less than 8.5 seconds Geolocation
1250 // Prompt display order:
1251 // 1. Notifications request shown but is preempted because of quiet UI.
1252 // 2. Geolocation request shown
1253 // 3. Notifications request shown again
1254 TEST_P(PermissionRequestManagerTestQuietChip,
1255 AbusiveNotificationsGeolocationQuietUIChipRequest) {
1256 MockNotificationPermissionUiSelector::CreateForManager(
1258 PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
1259 absl::nullopt /* async_delay */);
1261 std::unique_ptr<MockPermissionRequest> request_notifications =
1262 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1265 // Less then 8.5 seconds.
1266 manager_->set_current_request_first_display_time_for_testing(
1267 base::Time::Now() - base::Milliseconds(5000));
1269 std::unique_ptr<MockPermissionRequest> request_geolocation =
1270 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
1273 WaitAndAcceptPromptForRequest(request_geolocation.get());
1274 WaitAndAcceptPromptForRequest(request_notifications.get());
1276 EXPECT_EQ(prompt_factory_->show_count(), 3);
1279 // Verifies that the quiet UI chip is ignored if another request came in more
1280 // than 8.5 seconds after.
1282 // Permissions requested in order:
1283 // 1. Notification (abusive)
1284 // 2. After more than 8.5 seconds Geolocation
1286 // Prompt display order:
1287 // 1. Notifications request shown but is preempted because of quiet UI.
1288 // 2. Geolocation request shown
1289 TEST_P(PermissionRequestManagerTestQuietChip,
1290 AbusiveNotificationsShownLongEnough) {
1291 MockNotificationPermissionUiSelector::CreateForManager(
1293 PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
1294 absl::nullopt /* async_delay */);
1296 std::unique_ptr<MockPermissionRequest> request_notifications =
1297 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1300 // More then 8.5 seconds.
1301 manager_->set_current_request_first_display_time_for_testing(
1302 base::Time::Now() - base::Milliseconds(9000));
1304 std::unique_ptr<MockPermissionRequest> request_geolocation =
1305 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
1308 // The second permission was requested after 8.5 second window, the quiet UI
1309 // Notifiations request for an abusive origin is automatically ignored.
1310 EXPECT_FALSE(request_notifications->granted());
1311 EXPECT_TRUE(request_notifications->finished());
1313 WaitAndAcceptPromptForRequest(request_geolocation.get());
1315 EXPECT_EQ(prompt_factory_->show_count(), 2);
1318 // Verifies that the quiet UI chip is not ignored if another request came in
1319 // more than 8.5 seconds after. Verify different requests priority. Camera
1320 // request is shown despite being requested last.
1322 // Permissions requested in order:
1323 // 1. Notification (abusive)
1324 // 2. After less than 8.5 seconds Geolocation
1327 // Prompt display order:
1328 // 1. Notifications request shown but is preempted because of quiet UI.
1329 // 2. Geolocation request shown but is preempted because of low priority.
1330 // 3. Camera request shown
1331 // 4. Geolocation request shown again
1332 // 5. Notifications quiet UI request shown again
1333 TEST_P(PermissionRequestManagerTestQuietChip,
1334 AbusiveNotificationsShownLongEnoughCamera) {
1335 MockNotificationPermissionUiSelector::CreateForManager(
1337 PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
1338 absl::nullopt /* async_delay */);
1340 std::unique_ptr<MockPermissionRequest> request_notifications =
1341 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/true,
1343 // Less then 8.5 seconds.
1344 manager_->set_current_request_first_display_time_for_testing(
1345 base::Time::Now() - base::Milliseconds(5000));
1347 std::unique_ptr<MockPermissionRequest> request_geolocation =
1348 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/true,
1350 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1351 RequestType::kCameraStream, /*should_be_seen=*/true, 3);
1353 // The second permission was requested in 8.5 second window, the quiet UI
1354 // Notifiations request for an abusive origin is not automatically ignored.
1355 EXPECT_FALSE(request_notifications->granted());
1356 EXPECT_FALSE(request_notifications->finished());
1358 for (auto* kRequest : {request_camera.get(), request_geolocation.get(),
1359 request_notifications.get()}) {
1360 WaitAndAcceptPromptForRequest(kRequest);
1363 EXPECT_EQ(prompt_factory_->show_count(), 5);
1366 // Verifies that the quiet UI chip is not ignored if another request came in
1367 // more than 8.5 seconds after. Verify different requests priority. Camera
1368 // request is not preemted.
1370 // Permissions requested in order:
1372 // 2. Notification (abusive)
1373 // 3. After less than 8.5 seconds Geolocation
1375 // Prompt display order:
1376 // 1. Camera request shown
1377 // 2. Geolocation request shown
1378 // 3. Camera request shown
1379 TEST_P(PermissionRequestManagerTestQuietChip,
1380 CameraAbusiveNotificationsGeolocation) {
1381 MockNotificationPermissionUiSelector::CreateForManager(
1383 PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
1384 absl::nullopt /* async_delay */);
1386 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1387 RequestType::kCameraStream, /*should_be_seen=*/true, 1);
1389 // Quiet UI is not shown because Camera has higher priority.
1390 std::unique_ptr<MockPermissionRequest> request_notifications =
1391 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/false,
1393 // Less then 8.5 seconds.
1394 manager_->set_current_request_first_display_time_for_testing(
1395 base::Time::Now() - base::Milliseconds(5000));
1397 // Geolocation is not shown because Camera has higher priority.
1398 std::unique_ptr<MockPermissionRequest> request_geolocation =
1399 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/false,
1402 // The second permission after quiet UI was requested in 8.5 second window,
1403 // the quiet UI Notifiations request for an abusive origin is not
1404 // automatically ignored.
1405 EXPECT_FALSE(request_notifications->granted());
1406 EXPECT_FALSE(request_notifications->finished());
1408 for (auto* kRequest : {request_camera.get(), request_geolocation.get(),
1409 request_notifications.get()}) {
1410 WaitAndAcceptPromptForRequest(kRequest);
1413 EXPECT_EQ(prompt_factory_->show_count(), 3);
1416 // Verifies that the quiet UI chip is not ignored if another request came in
1417 // more than 8.5 seconds after. Verify different requests priority. Camera
1418 // request is not preemted.
1420 // Permissions requested in order:
1422 // 2. Notification (abusive)
1423 // 3. After less than 8.5 seconds Geolocation
1426 // Prompt display order:
1427 // 1. Camera request shown
1428 // 2. MIDI request shown (or MIDI and then Camera, the order depends on
1430 // 3. Geolocation request shown
1431 // 4. Notifications request shown
1432 // If Chip is enabled MIDI will replace Camera, hence 5 prompts will be
1433 // shown. Otherwise 4.
1434 TEST_P(PermissionRequestManagerTestQuietChip,
1435 CameraAbusiveNotificationsGeolocationMIDI) {
1436 MockNotificationPermissionUiSelector::CreateForManager(
1438 PermissionUiSelector::QuietUiReason::kTriggeredDueToAbusiveRequests,
1439 absl::nullopt /* async_delay */);
1441 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1442 RequestType::kCameraStream, /*should_be_seen=*/true, 1);
1444 // Quiet UI is not shown because Camera has higher priority.
1445 std::unique_ptr<MockPermissionRequest> request_notifications =
1446 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/false,
1448 // Less then 8.5 seconds.
1449 manager_->set_current_request_first_display_time_for_testing(
1450 base::Time::Now() - base::Milliseconds(5000));
1452 // Geolocation is not shown because Camera has higher priority.
1453 std::unique_ptr<MockPermissionRequest> request_geolocation =
1454 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/false,
1457 std::unique_ptr<MockPermissionRequest> request_midi;
1459 // If Chip is enabled, MIDI should be shown, otherwise MIDI should not be
1462 request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
1463 /*should_be_seen=*/true, 2);
1465 request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
1466 /*should_be_seen=*/false, 1);
1469 // The second permission after quiet UI was requested in 8.5 second window,
1470 // the quiet UI Notifiations request for an abusive origin is not
1471 // automatically ignored.
1472 EXPECT_FALSE(request_notifications->granted());
1473 EXPECT_FALSE(request_notifications->finished());
1475 WaitAndAcceptPromptForRequest(GetParam() ? request_midi.get()
1476 : request_camera.get());
1477 WaitAndAcceptPromptForRequest(GetParam() ? request_camera.get()
1478 : request_midi.get());
1479 WaitAndAcceptPromptForRequest(request_geolocation.get());
1480 WaitAndAcceptPromptForRequest(request_notifications.get());
1482 EXPECT_EQ(prompt_factory_->show_count(), GetParam() ? 5 : 4);
1485 // Verifies that non abusive chip behaves similar to others when Quiet UI Chip
1488 // Permissions requested in order:
1490 // 2. Notification (non abusive)
1491 // 3. After less than 8.5 seconds Geolocation
1494 // Prompt display order:
1495 // 1. Camera request shown
1496 // 2. MIDI request shown (or MIDI and then Camera, the order depends on
1498 // 3. Geolocation request shown
1499 // 4. Notifications request shown
1500 // If Chip is enabled MIDI will replace Camera, hence 5 prompts will be
1501 // shown. Otherwise 4.
1502 TEST_P(PermissionRequestManagerTestQuietChip,
1503 CameraNonAbusiveNotificationsGeolocationMIDI) {
1504 std::unique_ptr<MockPermissionRequest> request_camera = CreateAndAddRequest(
1505 RequestType::kCameraStream, /*should_be_seen=*/true, 1);
1507 // Quiet UI is not shown because Camera has higher priority.
1508 std::unique_ptr<MockPermissionRequest> request_notifications =
1509 CreateAndAddRequest(RequestType::kNotifications, /*should_be_seen=*/false,
1511 // Less then 8.5 seconds.
1512 manager_->set_current_request_first_display_time_for_testing(
1513 base::Time::Now() - base::Milliseconds(5000));
1515 // Geolocation is not shown because Camera has higher priority.
1516 std::unique_ptr<MockPermissionRequest> request_geolocation =
1517 CreateAndAddRequest(RequestType::kGeolocation, /*should_be_seen=*/false,
1520 std::unique_ptr<MockPermissionRequest> request_midi;
1522 // If Chip is enabled, MIDI should be shown, otherwise MIDI should not be
1525 request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
1526 /*should_be_seen=*/true, 2);
1528 request_midi = CreateAndAddRequest(RequestType::kMidiSysex,
1529 /*should_be_seen=*/false, 1);
1532 // The second permission after quiet UI was requested in 8.5 second window,
1533 // the quiet UI Notifiations request for an abusive origin is not
1534 // automatically ignored.
1535 EXPECT_FALSE(request_notifications->granted());
1536 EXPECT_FALSE(request_notifications->finished());
1538 WaitAndAcceptPromptForRequest(GetParam() ? request_midi.get()
1539 : request_camera.get());
1540 WaitAndAcceptPromptForRequest(GetParam() ? request_camera.get()
1541 : request_midi.get());
1542 WaitAndAcceptPromptForRequest(request_geolocation.get());
1543 WaitAndAcceptPromptForRequest(request_notifications.get());
1545 EXPECT_EQ(prompt_factory_->show_count(), GetParam() ? 5 : 4);
1548 INSTANTIATE_TEST_SUITE_P(All,
1549 PermissionRequestManagerTest,
1550 ::testing::Values(false, true));
1551 INSTANTIATE_TEST_SUITE_P(All,
1552 PermissionRequestManagerTestQuietChip,
1553 ::testing::Values(false, true));
1555 // Verifies order of requests with mixed low-high priority requests input, with
1556 // both chip and quiet chip enabled. New permissions are added and accepted one
1559 // Permissions requested in order:
1560 // 1. Multiple Download (high)
1561 // 2. Geolocation (low)
1564 // Prompt display order:
1566 // 2. Multiple Download
1568 TEST_P(PermissionRequestManagerTestQuietChip, Mixed1Low2HighPriorityRequests) {
1572 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
1573 WaitForBubbleToBeShown();
1575 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1576 WaitForBubbleToBeShown();
1578 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1579 WaitForBubbleToBeShown();
1581 EXPECT_TRUE(prompt_factory_->is_visible());
1582 EXPECT_EQ(prompt_factory_->request_count(), 1);
1584 EXPECT_TRUE(request_mic_.granted());
1585 EXPECT_FALSE(request2_.granted());
1586 EXPECT_FALSE(request1_.granted());
1587 WaitForBubbleToBeShown();
1589 EXPECT_TRUE(prompt_factory_->is_visible());
1590 EXPECT_EQ(prompt_factory_->request_count(), 1);
1592 EXPECT_TRUE(request2_.granted());
1593 EXPECT_FALSE(request1_.granted());
1594 WaitForBubbleToBeShown();
1596 EXPECT_TRUE(prompt_factory_->is_visible());
1597 EXPECT_EQ(prompt_factory_->request_count(), 1);
1599 EXPECT_TRUE(request1_.granted());
1602 // Verifies order of requests with mixed low-high priority requests input, with
1603 // both chip and quiet chip enabled. New permissions are added and accepted one
1606 // Permissions requested in order:
1607 // 1. Geolocation (low)
1609 // 3. Notification (low)
1611 // Prompt display order:
1615 TEST_P(PermissionRequestManagerTestQuietChip, Mixed2Low1HighRequests) {
1619 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1620 WaitForBubbleToBeShown();
1622 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1623 WaitForBubbleToBeShown();
1625 MockPermissionRequest request(RequestType::kNotifications,
1626 PermissionRequestGestureType::GESTURE);
1627 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1628 WaitForBubbleToBeShown();
1630 EXPECT_TRUE(prompt_factory_->is_visible());
1631 EXPECT_EQ(prompt_factory_->request_count(), 1);
1633 EXPECT_TRUE(request_mic_.granted());
1634 EXPECT_FALSE(request.granted());
1635 EXPECT_FALSE(request1_.granted());
1636 WaitForBubbleToBeShown();
1638 EXPECT_TRUE(prompt_factory_->is_visible());
1639 EXPECT_EQ(prompt_factory_->request_count(), 1);
1641 EXPECT_TRUE(request.granted());
1642 EXPECT_FALSE(request1_.granted());
1643 WaitForBubbleToBeShown();
1645 EXPECT_TRUE(prompt_factory_->is_visible());
1646 EXPECT_EQ(prompt_factory_->request_count(), 1);
1648 EXPECT_TRUE(request1_.granted());
1651 // Verifies order of requests with mixed low-high priority requests input, added
1652 // simultaneously, with both chip and quiet chip enabled.
1654 // Permissions requested in order:
1655 // 1. Geolocation (low)
1657 // 3. Notification (low)
1659 // Prompt display order:
1663 TEST_P(PermissionRequestManagerTestQuietChip,
1664 MultipleSimultaneous2Low1HighRequests) {
1668 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1669 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1670 MockPermissionRequest request(RequestType::kNotifications,
1671 PermissionRequestGestureType::GESTURE);
1672 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1673 WaitForBubbleToBeShown();
1675 EXPECT_TRUE(prompt_factory_->is_visible());
1676 EXPECT_EQ(prompt_factory_->request_count(), 1);
1678 EXPECT_TRUE(request_mic_.granted());
1679 EXPECT_FALSE(request.granted());
1680 EXPECT_FALSE(request1_.granted());
1681 WaitForBubbleToBeShown();
1683 EXPECT_TRUE(prompt_factory_->is_visible());
1684 EXPECT_EQ(prompt_factory_->request_count(), 1);
1686 EXPECT_TRUE(request.granted());
1687 EXPECT_FALSE(request1_.granted());
1688 WaitForBubbleToBeShown();
1690 EXPECT_TRUE(prompt_factory_->is_visible());
1691 EXPECT_EQ(prompt_factory_->request_count(), 1);
1693 EXPECT_TRUE(request1_.granted());
1696 // Verifies order of requests with mixed low-high priority requests input,
1697 // added simultaneously, with both chip and quiet chip enabled.
1699 // Permissions requested in order:
1701 // 2. Geolocation (low)
1703 // 4. Notification (low)
1704 // 5. Multiple Download (high)
1706 // Prompt display order:
1707 // 1. Multiple Download
1712 TEST_P(PermissionRequestManagerTestQuietChip,
1713 MultipleSimultaneous2Low3HighRequests) {
1716 MockPermissionRequest request_midi(RequestType::kMidiSysex,
1717 PermissionRequestGestureType::GESTURE);
1718 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_midi);
1719 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1720 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1721 MockPermissionRequest request_notification(
1722 RequestType::kNotifications, PermissionRequestGestureType::GESTURE);
1723 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(),
1724 &request_notification);
1725 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
1726 WaitForBubbleToBeShown();
1728 EXPECT_TRUE(prompt_factory_->is_visible());
1729 EXPECT_EQ(prompt_factory_->request_count(), 1);
1731 EXPECT_FALSE(request_mic_.granted());
1732 EXPECT_TRUE(request2_.granted());
1733 EXPECT_FALSE(request_notification.granted());
1734 EXPECT_FALSE(request1_.granted());
1735 EXPECT_FALSE(request_midi.granted());
1736 WaitForBubbleToBeShown();
1738 EXPECT_TRUE(prompt_factory_->is_visible());
1739 EXPECT_EQ(prompt_factory_->request_count(), 1);
1741 EXPECT_TRUE(request_mic_.granted());
1742 EXPECT_FALSE(request_notification.granted());
1743 EXPECT_FALSE(request1_.granted());
1744 EXPECT_FALSE(request_midi.granted());
1745 WaitForBubbleToBeShown();
1747 EXPECT_TRUE(prompt_factory_->is_visible());
1748 EXPECT_EQ(prompt_factory_->request_count(), 1);
1750 EXPECT_FALSE(request_notification.granted());
1751 EXPECT_FALSE(request1_.granted());
1752 EXPECT_TRUE(request_midi.granted());
1753 WaitForBubbleToBeShown();
1755 EXPECT_TRUE(prompt_factory_->is_visible());
1756 EXPECT_EQ(prompt_factory_->request_count(), 1);
1758 EXPECT_TRUE(request_notification.granted());
1759 EXPECT_FALSE(request1_.granted());
1760 WaitForBubbleToBeShown();
1762 EXPECT_TRUE(prompt_factory_->is_visible());
1763 EXPECT_EQ(prompt_factory_->request_count(), 1);
1765 EXPECT_TRUE(request1_.granted());
1768 // Verifies order of requests with mixed low-high priority requests input, added
1769 // simultaneously several times, with both chip and quiet chip enabled.
1771 // Permissions requested in order:
1772 // 1. Geolocation(low) then Notification(low)
1773 // 2. Mic (high) then multiple downloads (high)
1774 // Prompt display order:
1775 // 1. Multiple Download
1779 TEST_P(PermissionRequestManagerTestQuietChip,
1780 MultipleSimultaneous2Low2HighRequests) {
1784 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1785 MockPermissionRequest request(RequestType::kNotifications,
1786 PermissionRequestGestureType::GESTURE);
1787 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1788 WaitForBubbleToBeShown();
1790 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1791 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request2_);
1792 WaitForBubbleToBeShown();
1794 EXPECT_TRUE(prompt_factory_->is_visible());
1795 EXPECT_EQ(prompt_factory_->request_count(), 1);
1797 EXPECT_TRUE(request2_.granted());
1798 EXPECT_FALSE(request_mic_.granted());
1799 EXPECT_FALSE(request.granted());
1800 EXPECT_FALSE(request1_.granted());
1801 WaitForBubbleToBeShown();
1803 EXPECT_TRUE(prompt_factory_->is_visible());
1804 EXPECT_EQ(prompt_factory_->request_count(), 1);
1806 EXPECT_TRUE(request_mic_.granted());
1807 EXPECT_FALSE(request.granted());
1808 EXPECT_FALSE(request1_.granted());
1809 WaitForBubbleToBeShown();
1811 EXPECT_TRUE(prompt_factory_->is_visible());
1812 EXPECT_EQ(prompt_factory_->request_count(), 1);
1814 EXPECT_TRUE(request.granted());
1815 EXPECT_FALSE(request1_.granted());
1816 WaitForBubbleToBeShown();
1818 EXPECT_TRUE(prompt_factory_->is_visible());
1819 EXPECT_EQ(prompt_factory_->request_count(), 1);
1821 EXPECT_TRUE(request1_.granted());
1824 // Verifies order of requests with mixed low-high priority requests input, with
1825 // both chip and quiet chip enabled. Simultaneous new requests are coming while
1826 // we are waiting for UI selector decisions.
1828 // Permissions requested in order:
1829 // 1. Geolocation (low), UI selector takes 2 seconds to decide.
1830 // 2. Notification(low) then mic (high)
1832 // Prompt display order:
1834 // 2. Geolocation will get delayed 2 seconds, then preempted to front of queue
1836 TEST_P(PermissionRequestManagerTestQuietChip,
1837 NewHighPriorityRequestDuringUIDecision) {
1841 manager_->clear_permission_ui_selector_for_testing();
1842 MockNotificationPermissionUiSelector::CreateForManager(
1843 manager_, QuietUiReason::kTriggeredDueToAbusiveRequests,
1844 absl::make_optional<base::TimeDelta>(base::Seconds(2)));
1845 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request1_);
1847 task_environment()->FastForwardBy(base::Seconds(1));
1849 MockPermissionRequest request(RequestType::kNotifications,
1850 PermissionRequestGestureType::GESTURE);
1851 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request);
1852 manager_->AddRequest(web_contents()->GetPrimaryMainFrame(), &request_mic_);
1853 WaitForBubbleToBeShown();
1854 manager_->clear_permission_ui_selector_for_testing();
1856 EXPECT_TRUE(prompt_factory_->is_visible());
1857 EXPECT_EQ(prompt_factory_->request_count(), 1);
1859 EXPECT_TRUE(request_mic_.granted());
1860 EXPECT_FALSE(request.granted());
1861 EXPECT_FALSE(request1_.granted());
1862 WaitForBubbleToBeShown();
1864 EXPECT_TRUE(prompt_factory_->is_visible());
1865 EXPECT_EQ(prompt_factory_->request_count(), 1);
1867 EXPECT_TRUE(request1_.granted());
1868 EXPECT_FALSE(request.granted());
1869 WaitForBubbleToBeShown();
1871 EXPECT_TRUE(prompt_factory_->is_visible());
1872 EXPECT_EQ(prompt_factory_->request_count(), 1);
1874 EXPECT_TRUE(request.granted());
1877 } // namespace permissions