Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/permissions/permission_request_manager_unittest.cc

Issue 2922933002: Remove |accept_states_| from PermissionRequestManager (Closed)
Patch Set: Remove |accept_states_| from PermissionRequestManager Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 }; 110 };
111 111
112 TEST_F(PermissionRequestManagerTest, SingleRequest) { 112 TEST_F(PermissionRequestManagerTest, SingleRequest) {
113 manager_->AddRequest(&request1_); 113 manager_->AddRequest(&request1_);
114 manager_->DisplayPendingRequests(); 114 manager_->DisplayPendingRequests();
115 WaitForBubbleToBeShown(); 115 WaitForBubbleToBeShown();
116 116
117 EXPECT_TRUE(prompt_factory_->is_visible()); 117 EXPECT_TRUE(prompt_factory_->is_visible());
118 ASSERT_EQ(prompt_factory_->request_count(), 1); 118 ASSERT_EQ(prompt_factory_->request_count(), 1);
119 119
120 ToggleAccept(0, true);
121 Accept(); 120 Accept();
122 EXPECT_TRUE(request1_.granted()); 121 EXPECT_TRUE(request1_.granted());
123 } 122 }
124 123
125 TEST_F(PermissionRequestManagerTest, SingleRequestViewFirst) { 124 TEST_F(PermissionRequestManagerTest, SingleRequestViewFirst) {
126 manager_->DisplayPendingRequests(); 125 manager_->DisplayPendingRequests();
127 manager_->AddRequest(&request1_); 126 manager_->AddRequest(&request1_);
128 WaitForBubbleToBeShown(); 127 WaitForBubbleToBeShown();
129 128
130 EXPECT_TRUE(prompt_factory_->is_visible()); 129 EXPECT_TRUE(prompt_factory_->is_visible());
131 ASSERT_EQ(prompt_factory_->request_count(), 1); 130 ASSERT_EQ(prompt_factory_->request_count(), 1);
132 131
133 ToggleAccept(0, true);
134 Accept(); 132 Accept();
135 EXPECT_TRUE(request1_.granted()); 133 EXPECT_TRUE(request1_.granted());
136 } 134 }
137 135
138 // Most requests should never be grouped. 136 // Most requests should never be grouped.
139 TEST_F(PermissionRequestManagerTest, TwoRequestsUngrouped) { 137 TEST_F(PermissionRequestManagerTest, TwoRequestsUngrouped) {
140 manager_->AddRequest(&request1_); 138 manager_->AddRequest(&request1_);
141 manager_->AddRequest(&request2_); 139 manager_->AddRequest(&request2_);
142 manager_->DisplayPendingRequests(); 140 manager_->DisplayPendingRequests();
143 141
(...skipping 13 matching lines...) Expand all
157 // Only mic/camera requests from the same origin should be grouped. 155 // Only mic/camera requests from the same origin should be grouped.
158 TEST_F(PermissionRequestManagerTest, MicCameraGrouped) { 156 TEST_F(PermissionRequestManagerTest, MicCameraGrouped) {
159 manager_->AddRequest(&request_mic_); 157 manager_->AddRequest(&request_mic_);
160 manager_->AddRequest(&request_camera_); 158 manager_->AddRequest(&request_camera_);
161 manager_->DisplayPendingRequests(); 159 manager_->DisplayPendingRequests();
162 WaitForBubbleToBeShown(); 160 WaitForBubbleToBeShown();
163 161
164 EXPECT_TRUE(prompt_factory_->is_visible()); 162 EXPECT_TRUE(prompt_factory_->is_visible());
165 ASSERT_EQ(prompt_factory_->request_count(), 2); 163 ASSERT_EQ(prompt_factory_->request_count(), 2);
166 164
167 ToggleAccept(0, true);
168 ToggleAccept(1, true);
169 Accept(); 165 Accept();
170 EXPECT_TRUE(request_mic_.granted()); 166 EXPECT_TRUE(request_mic_.granted());
171 EXPECT_TRUE(request_camera_.granted()); 167 EXPECT_TRUE(request_camera_.granted());
172 168
173 // If the requests come from different origins, they should not be grouped. 169 // If the requests come from different origins, they should not be grouped.
174 manager_->AddRequest(&iframe_request_mic_other_domain_); 170 manager_->AddRequest(&iframe_request_mic_other_domain_);
175 manager_->AddRequest(&request_camera_); 171 manager_->AddRequest(&request_camera_);
176 WaitForBubbleToBeShown(); 172 WaitForBubbleToBeShown();
177 173
178 EXPECT_TRUE(prompt_factory_->is_visible()); 174 EXPECT_TRUE(prompt_factory_->is_visible());
179 ASSERT_EQ(prompt_factory_->request_count(), 1); 175 ASSERT_EQ(prompt_factory_->request_count(), 1);
180 } 176 }
181 177
182 TEST_F(PermissionRequestManagerTest, TwoRequestsTabSwitch) { 178 TEST_F(PermissionRequestManagerTest, TwoRequestsTabSwitch) {
183 manager_->AddRequest(&request_mic_); 179 manager_->AddRequest(&request_mic_);
184 manager_->AddRequest(&request_camera_); 180 manager_->AddRequest(&request_camera_);
185 manager_->DisplayPendingRequests(); 181 manager_->DisplayPendingRequests();
186 WaitForBubbleToBeShown(); 182 WaitForBubbleToBeShown();
187 183
188 EXPECT_TRUE(prompt_factory_->is_visible()); 184 EXPECT_TRUE(prompt_factory_->is_visible());
189 ASSERT_EQ(prompt_factory_->request_count(), 2); 185 ASSERT_EQ(prompt_factory_->request_count(), 2);
190 186
191 ToggleAccept(0, true);
192 ToggleAccept(1, false);
193
194 MockTabSwitchAway(); 187 MockTabSwitchAway();
195 EXPECT_FALSE(prompt_factory_->is_visible()); 188 EXPECT_FALSE(prompt_factory_->is_visible());
196 189
197 MockTabSwitchBack(); 190 MockTabSwitchBack();
198 WaitForBubbleToBeShown(); 191 WaitForBubbleToBeShown();
199 EXPECT_TRUE(prompt_factory_->is_visible()); 192 EXPECT_TRUE(prompt_factory_->is_visible());
200 ASSERT_EQ(prompt_factory_->request_count(), 2); 193 ASSERT_EQ(prompt_factory_->request_count(), 2);
201 194
202 Accept(); 195 Accept();
203 EXPECT_TRUE(request_mic_.granted()); 196 EXPECT_TRUE(request_mic_.granted());
204 EXPECT_FALSE(request_camera_.granted()); 197 EXPECT_TRUE(request_camera_.granted());
205 } 198 }
206 199
207 TEST_F(PermissionRequestManagerTest, NoRequests) { 200 TEST_F(PermissionRequestManagerTest, NoRequests) {
208 manager_->DisplayPendingRequests(); 201 manager_->DisplayPendingRequests();
209 WaitForBubbleToBeShown(); 202 WaitForBubbleToBeShown();
210 EXPECT_FALSE(prompt_factory_->is_visible()); 203 EXPECT_FALSE(prompt_factory_->is_visible());
211 } 204 }
212 205
213 TEST_F(PermissionRequestManagerTest, NoView) { 206 TEST_F(PermissionRequestManagerTest, NoView) {
214 manager_->AddRequest(&request1_); 207 manager_->AddRequest(&request1_);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 1); 499 1);
507 histograms.ExpectUniqueSample( 500 histograms.ExpectUniqueSample(
508 PermissionUmaUtil::kPermissionsPromptShownGesture, 501 PermissionUmaUtil::kPermissionsPromptShownGesture,
509 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 502 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
510 1); 503 1);
511 histograms.ExpectTotalCount( 504 histograms.ExpectTotalCount(
512 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0); 505 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0);
513 histograms.ExpectUniqueSample( 506 histograms.ExpectUniqueSample(
514 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 1, 1); 507 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 1, 1);
515 508
516 ToggleAccept(0, true);
517 Accept(); 509 Accept();
518 histograms.ExpectUniqueSample( 510 histograms.ExpectUniqueSample(
519 PermissionUmaUtil::kPermissionsPromptAccepted, 511 PermissionUmaUtil::kPermissionsPromptAccepted,
520 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 512 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
521 1); 513 1);
522 histograms.ExpectTotalCount( 514 histograms.ExpectTotalCount(
523 PermissionUmaUtil::kPermissionsPromptDenied, 0); 515 PermissionUmaUtil::kPermissionsPromptDenied, 0);
524 516
525 histograms.ExpectUniqueSample( 517 histograms.ExpectUniqueSample(
526 PermissionUmaUtil::kPermissionsPromptAcceptedGesture, 518 PermissionUmaUtil::kPermissionsPromptAcceptedGesture,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // completeness. 559 // completeness.
568 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) { 560 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) {
569 base::HistogramTester histograms; 561 base::HistogramTester histograms;
570 562
571 manager_->AddRequest(&request1_); 563 manager_->AddRequest(&request1_);
572 manager_->DisplayPendingRequests(); 564 manager_->DisplayPendingRequests();
573 WaitForBubbleToBeShown(); 565 WaitForBubbleToBeShown();
574 // No need to test UMA for showing prompts again, they were tested in 566 // No need to test UMA for showing prompts again, they were tested in
575 // UMAForSimpleAcceptedBubble. 567 // UMAForSimpleAcceptedBubble.
576 568
577 ToggleAccept(0, false); 569 Deny();
578 Accept();
579 histograms.ExpectUniqueSample( 570 histograms.ExpectUniqueSample(
580 PermissionUmaUtil::kPermissionsPromptDenied, 571 PermissionUmaUtil::kPermissionsPromptDenied,
581 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 572 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
582 1); 573 1);
583 } 574 }
584 575
585 TEST_F(PermissionRequestManagerTest, UMAForMergedAcceptedBubble) { 576 TEST_F(PermissionRequestManagerTest, UMAForMergedAcceptedBubble) {
586 base::HistogramTester histograms; 577 base::HistogramTester histograms;
587 578
588 manager_->AddRequest(&request_mic_); 579 manager_->AddRequest(&request_mic_);
(...skipping 15 matching lines...) Expand all
604 static_cast<base::HistogramBase::Sample>( 595 static_cast<base::HistogramBase::Sample>(
605 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 596 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
606 1); 597 1);
607 histograms.ExpectUniqueSample( 598 histograms.ExpectUniqueSample(
608 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 2, 1); 599 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 2, 1);
609 histograms.ExpectTotalCount( 600 histograms.ExpectTotalCount(
610 PermissionUmaUtil::kPermissionsPromptShownGesture, 0); 601 PermissionUmaUtil::kPermissionsPromptShownGesture, 0);
611 histograms.ExpectTotalCount( 602 histograms.ExpectTotalCount(
612 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0); 603 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0);
613 604
614 ToggleAccept(0, true);
615 ToggleAccept(1, true);
616 Accept(); 605 Accept();
617 606
618 histograms.ExpectUniqueSample( 607 histograms.ExpectUniqueSample(
619 PermissionUmaUtil::kPermissionsPromptAccepted, 608 PermissionUmaUtil::kPermissionsPromptAccepted,
620 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE), 609 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE),
621 1); 610 1);
622 histograms.ExpectBucketCount( 611 histograms.ExpectBucketCount(
623 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted, 612 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted,
624 static_cast<base::HistogramBase::Sample>( 613 static_cast<base::HistogramBase::Sample>(
625 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC), 614 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
626 1); 615 1);
627 histograms.ExpectBucketCount( 616 histograms.ExpectBucketCount(
628 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted, 617 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted,
629 static_cast<base::HistogramBase::Sample>( 618 static_cast<base::HistogramBase::Sample>(
630 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 619 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
631 1); 620 1);
632 } 621 }
633 622
634 TEST_F(PermissionRequestManagerTest, UMAForMergedMixedBubble) {
635 base::HistogramTester histograms;
636
637 manager_->AddRequest(&request_mic_);
638 manager_->AddRequest(&request_camera_);
639 manager_->DisplayPendingRequests();
640 WaitForBubbleToBeShown();
641 // No need to test UMA for showing prompts again, they were tested in
642 // UMAForMergedAcceptedBubble.
643
644 ToggleAccept(0, true);
645 ToggleAccept(1, false);
646 Accept();
647
648 histograms.ExpectUniqueSample(
649 PermissionUmaUtil::kPermissionsPromptDenied,
650 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE),
651 1);
652 histograms.ExpectBucketCount(
653 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted,
654 static_cast<base::HistogramBase::Sample>(
655 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
656 1);
657 histograms.ExpectBucketCount(
658 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
659 static_cast<base::HistogramBase::Sample>(
660 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
661 1);
662 }
663
664 TEST_F(PermissionRequestManagerTest, UMAForMergedDeniedBubble) { 623 TEST_F(PermissionRequestManagerTest, UMAForMergedDeniedBubble) {
665 base::HistogramTester histograms; 624 base::HistogramTester histograms;
666 625
667 manager_->AddRequest(&request_mic_); 626 manager_->AddRequest(&request_mic_);
668 manager_->AddRequest(&request_camera_); 627 manager_->AddRequest(&request_camera_);
669 manager_->DisplayPendingRequests(); 628 manager_->DisplayPendingRequests();
670 WaitForBubbleToBeShown(); 629 WaitForBubbleToBeShown();
671 // No need to test UMA for showing prompts again, they were tested in 630 // No need to test UMA for showing prompts again, they were tested in
672 // UMAForMergedAcceptedBubble. 631 // UMAForMergedAcceptedBubble.
673 632
674 ToggleAccept(0, false); 633 Deny();
675 ToggleAccept(1, false);
676 Accept();
677 634
678 histograms.ExpectUniqueSample( 635 histograms.ExpectUniqueSample(
679 PermissionUmaUtil::kPermissionsPromptDenied, 636 PermissionUmaUtil::kPermissionsPromptDenied,
680 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE), 637 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE),
681 1); 638 1);
682 histograms.ExpectBucketCount( 639 histograms.ExpectBucketCount(
683 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 640 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
684 static_cast<base::HistogramBase::Sample>( 641 static_cast<base::HistogramBase::Sample>(
685 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC), 642 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
686 1); 643 1);
687 histograms.ExpectBucketCount( 644 histograms.ExpectBucketCount(
688 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 645 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
689 static_cast<base::HistogramBase::Sample>( 646 static_cast<base::HistogramBase::Sample>(
690 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 647 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
691 1); 648 1);
692 } 649 }
OLDNEW
« no previous file with comments | « chrome/browser/permissions/permission_request_manager.cc ('k') | chrome/browser/permissions/permission_uma_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698