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

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

Issue 2952003003: Log site engagement scores for permission actions (Closed)
Patch Set: use histogram_functions Created 3 years, 5 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"
11 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/engagement/site_engagement_service.h"
13 #include "chrome/browser/permissions/mock_permission_request.h" 14 #include "chrome/browser/permissions/mock_permission_request.h"
14 #include "chrome/browser/permissions/permission_request.h" 15 #include "chrome/browser/permissions/permission_request.h"
15 #include "chrome/browser/permissions/permission_request_manager.h" 16 #include "chrome/browser/permissions/permission_request_manager.h"
16 #include "chrome/browser/permissions/permission_uma_util.h" 17 #include "chrome/browser/permissions/permission_uma_util.h"
17 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h" 18 #include "chrome/browser/ui/permission_bubble/mock_permission_prompt_factory.h"
18 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 20 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
21 #include "chrome/test/base/testing_profile.h"
20 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
21 23
24 const double kTestEngagementScore = 29;
25
22 class PermissionRequestManagerTest : public ChromeRenderViewHostTestHarness { 26 class PermissionRequestManagerTest : public ChromeRenderViewHostTestHarness {
23 public: 27 public:
24 PermissionRequestManagerTest() 28 PermissionRequestManagerTest()
25 : ChromeRenderViewHostTestHarness(), 29 : ChromeRenderViewHostTestHarness(),
26 request1_("test1", 30 request1_("test1",
27 PermissionRequestType::QUOTA, 31 PermissionRequestType::QUOTA,
28 PermissionRequestGestureType::GESTURE), 32 PermissionRequestGestureType::GESTURE),
29 request2_("test2", 33 request2_("test2",
30 PermissionRequestType::DOWNLOAD, 34 PermissionRequestType::DOWNLOAD,
31 PermissionRequestGestureType::NO_GESTURE), 35 PermissionRequestGestureType::NO_GESTURE),
32 request_mic_("mic", 36 request_mic_("mic",
33 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC, 37 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC,
34 PermissionRequestGestureType::NO_GESTURE), 38 PermissionRequestGestureType::NO_GESTURE),
35 request_camera_("cam", 39 request_camera_("cam",
36 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA, 40 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA,
37 PermissionRequestGestureType::NO_GESTURE), 41 PermissionRequestGestureType::NO_GESTURE),
38 iframe_request_same_domain_("iframe", 42 iframe_request_same_domain_(
39 PermissionRequestType::UNKNOWN, 43 "iframe",
40 GURL("http://www.google.com/some/url")), 44 PermissionRequestType::PERMISSION_NOTIFICATIONS,
41 iframe_request_other_domain_("iframe", 45 GURL("http://www.google.com/some/url")),
42 PermissionRequestType::UNKNOWN, 46 iframe_request_other_domain_(
43 GURL("http://www.youtube.com")), 47 "iframe",
48 PermissionRequestType::PERMISSION_GEOLOCATION,
49 GURL("http://www.youtube.com")),
44 iframe_request_mic_other_domain_( 50 iframe_request_mic_other_domain_(
45 "iframe", 51 "iframe",
46 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC, 52 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC,
47 GURL("http://www.youtube.com")) {} 53 GURL("http://www.youtube.com")) {}
48 ~PermissionRequestManagerTest() override {} 54 ~PermissionRequestManagerTest() override {}
49 55
50 void SetUp() override { 56 void SetUp() override {
51 ChromeRenderViewHostTestHarness::SetUp(); 57 ChromeRenderViewHostTestHarness::SetUp();
52 SetContents(CreateTestWebContents()); 58 SetContents(CreateTestWebContents());
53 NavigateAndCommit(GURL("http://www.google.com")); 59 url_ = GURL("http://www.google.com");
60 NavigateAndCommit(url_);
61
62 SiteEngagementService::Get(profile())->ResetBaseScoreForURL(
63 url_, kTestEngagementScore);
54 64
55 PermissionRequestManager::CreateForWebContents(web_contents()); 65 PermissionRequestManager::CreateForWebContents(web_contents());
56 manager_ = PermissionRequestManager::FromWebContents(web_contents()); 66 manager_ = PermissionRequestManager::FromWebContents(web_contents());
57 prompt_factory_.reset(new MockPermissionPromptFactory(manager_)); 67 prompt_factory_.reset(new MockPermissionPromptFactory(manager_));
58 } 68 }
59 69
60 void TearDown() override { 70 void TearDown() override {
61 prompt_factory_.reset(); 71 prompt_factory_.reset();
62 ChromeRenderViewHostTestHarness::TearDown(); 72 ChromeRenderViewHostTestHarness::TearDown();
63 } 73 }
(...skipping 24 matching lines...) Expand all
88 void MockTabSwitchAway() { manager_->HideBubble(); } 98 void MockTabSwitchAway() { manager_->HideBubble(); }
89 99
90 void MockTabSwitchBack() { manager_->DisplayPendingRequests(); } 100 void MockTabSwitchBack() { manager_->DisplayPendingRequests(); }
91 101
92 virtual void NavigationEntryCommitted( 102 virtual void NavigationEntryCommitted(
93 const content::LoadCommittedDetails& details) { 103 const content::LoadCommittedDetails& details) {
94 manager_->NavigationEntryCommitted(details); 104 manager_->NavigationEntryCommitted(details);
95 } 105 }
96 106
97 protected: 107 protected:
108 GURL url_;
98 MockPermissionRequest request1_; 109 MockPermissionRequest request1_;
99 MockPermissionRequest request2_; 110 MockPermissionRequest request2_;
100 MockPermissionRequest request_mic_; 111 MockPermissionRequest request_mic_;
101 MockPermissionRequest request_camera_; 112 MockPermissionRequest request_camera_;
102 MockPermissionRequest iframe_request_same_domain_; 113 MockPermissionRequest iframe_request_same_domain_;
103 MockPermissionRequest iframe_request_other_domain_; 114 MockPermissionRequest iframe_request_other_domain_;
104 MockPermissionRequest iframe_request_mic_other_domain_; 115 MockPermissionRequest iframe_request_mic_other_domain_;
105 PermissionRequestManager* manager_; 116 PermissionRequestManager* manager_;
106 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; 117 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_;
107 }; 118 };
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 519 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
509 1); 520 1);
510 histograms.ExpectUniqueSample( 521 histograms.ExpectUniqueSample(
511 PermissionUmaUtil::kPermissionsPromptShownGesture, 522 PermissionUmaUtil::kPermissionsPromptShownGesture,
512 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 523 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
513 1); 524 1);
514 histograms.ExpectTotalCount( 525 histograms.ExpectTotalCount(
515 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0); 526 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0);
516 histograms.ExpectUniqueSample( 527 histograms.ExpectUniqueSample(
517 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 1, 1); 528 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 1, 1);
529 histograms.ExpectTotalCount("Permissions.Engagement.Accepted.Quota", 0);
518 530
519 Accept(); 531 Accept();
520 histograms.ExpectUniqueSample( 532 histograms.ExpectUniqueSample(
521 PermissionUmaUtil::kPermissionsPromptAccepted, 533 PermissionUmaUtil::kPermissionsPromptAccepted,
522 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 534 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
523 1); 535 1);
524 histograms.ExpectTotalCount( 536 histograms.ExpectTotalCount(
525 PermissionUmaUtil::kPermissionsPromptDenied, 0); 537 PermissionUmaUtil::kPermissionsPromptDenied, 0);
526 538
527 histograms.ExpectUniqueSample( 539 histograms.ExpectUniqueSample(
528 PermissionUmaUtil::kPermissionsPromptAcceptedGesture, 540 PermissionUmaUtil::kPermissionsPromptAcceptedGesture,
529 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA), 541 static_cast<base::HistogramBase::Sample>(PermissionRequestType::QUOTA),
530 1); 542 1);
531 histograms.ExpectTotalCount( 543 histograms.ExpectTotalCount(
532 PermissionUmaUtil::kPermissionsPromptAcceptedNoGesture, 0); 544 PermissionUmaUtil::kPermissionsPromptAcceptedNoGesture, 0);
545 histograms.ExpectUniqueSample("Permissions.Engagement.Accepted.Quota",
546 kTestEngagementScore, 1);
533 } 547 }
534 548
535 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedNoGestureBubble) { 549 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedNoGestureBubble) {
536 base::HistogramTester histograms; 550 base::HistogramTester histograms;
537 551
538 manager_->AddRequest(&request2_); 552 manager_->AddRequest(&request2_);
539 manager_->DisplayPendingRequests(); 553 manager_->DisplayPendingRequests();
540 WaitForBubbleToBeShown(); 554 WaitForBubbleToBeShown();
541 555
542 histograms.ExpectTotalCount( 556 histograms.ExpectTotalCount(
543 PermissionUmaUtil::kPermissionsPromptShownGesture, 0); 557 PermissionUmaUtil::kPermissionsPromptShownGesture, 0);
544 histograms.ExpectUniqueSample( 558 histograms.ExpectUniqueSample(
545 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 559 PermissionUmaUtil::kPermissionsPromptShownNoGesture,
546 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD), 560 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD),
547 1); 561 1);
562 histograms.ExpectTotalCount("Permissions.Engagement.Denied.MultipleDownload",
563 0);
548 // No need to test the other UMA for showing prompts again, they were tested 564 // No need to test the other UMA for showing prompts again, they were tested
549 // in UMAForSimpleAcceptedBubble. 565 // in UMAForSimpleAcceptedBubble.
550 566
551 Deny(); 567 Deny();
552 histograms.ExpectTotalCount( 568 histograms.ExpectTotalCount(
553 PermissionUmaUtil::kPermissionsPromptAccepted, 0); 569 PermissionUmaUtil::kPermissionsPromptAccepted, 0);
554 histograms.ExpectUniqueSample( 570 histograms.ExpectUniqueSample(
555 PermissionUmaUtil::kPermissionsPromptDenied, 571 PermissionUmaUtil::kPermissionsPromptDenied,
556 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD), 572 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD),
557 1); 573 1);
558 574
559 histograms.ExpectUniqueSample( 575 histograms.ExpectUniqueSample(
560 PermissionUmaUtil::kPermissionsPromptDeniedNoGesture, 576 PermissionUmaUtil::kPermissionsPromptDeniedNoGesture,
561 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD), 577 static_cast<base::HistogramBase::Sample>(PermissionRequestType::DOWNLOAD),
562 1); 578 1);
563 histograms.ExpectTotalCount( 579 histograms.ExpectTotalCount(
564 PermissionUmaUtil::kPermissionsPromptDeniedGesture, 0); 580 PermissionUmaUtil::kPermissionsPromptDeniedGesture, 0);
581 histograms.ExpectUniqueSample(
582 "Permissions.Engagement.Denied.MultipleDownload", kTestEngagementScore,
583 1);
565 } 584 }
566 585
567 // This code path (calling Accept on a non-merged bubble, with no accepted 586 // This code path (calling Accept on a non-merged bubble, with no accepted
568 // permission) would never be used in actual Chrome, but its still tested for 587 // permission) would never be used in actual Chrome, but its still tested for
569 // completeness. 588 // completeness.
570 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) { 589 TEST_F(PermissionRequestManagerTest, UMAForSimpleDeniedBubbleAlternatePath) {
571 base::HistogramTester histograms; 590 base::HistogramTester histograms;
572 591
573 manager_->AddRequest(&request1_); 592 manager_->AddRequest(&request1_);
574 manager_->DisplayPendingRequests(); 593 manager_->DisplayPendingRequests();
(...skipping 29 matching lines...) Expand all
604 PermissionUmaUtil::kPermissionsPromptMergedBubbleTypes, 623 PermissionUmaUtil::kPermissionsPromptMergedBubbleTypes,
605 static_cast<base::HistogramBase::Sample>( 624 static_cast<base::HistogramBase::Sample>(
606 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 625 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
607 1); 626 1);
608 histograms.ExpectUniqueSample( 627 histograms.ExpectUniqueSample(
609 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 2, 1); 628 PermissionUmaUtil::kPermissionsPromptRequestsPerPrompt, 2, 1);
610 histograms.ExpectTotalCount( 629 histograms.ExpectTotalCount(
611 PermissionUmaUtil::kPermissionsPromptShownGesture, 0); 630 PermissionUmaUtil::kPermissionsPromptShownGesture, 0);
612 histograms.ExpectTotalCount( 631 histograms.ExpectTotalCount(
613 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0); 632 PermissionUmaUtil::kPermissionsPromptShownNoGesture, 0);
633 histograms.ExpectTotalCount(
634 "Permissions.Engagement.Accepted.AudioAndVideoCapture", 0);
614 635
615 Accept(); 636 Accept();
616 637
617 histograms.ExpectUniqueSample( 638 histograms.ExpectUniqueSample(
618 PermissionUmaUtil::kPermissionsPromptAccepted, 639 PermissionUmaUtil::kPermissionsPromptAccepted,
619 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE), 640 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE),
620 1); 641 1);
621 histograms.ExpectBucketCount( 642 histograms.ExpectBucketCount(
622 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted, 643 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted,
623 static_cast<base::HistogramBase::Sample>( 644 static_cast<base::HistogramBase::Sample>(
624 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC), 645 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
625 1); 646 1);
626 histograms.ExpectBucketCount( 647 histograms.ExpectBucketCount(
627 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted, 648 PermissionUmaUtil::kPermissionsPromptMergedBubbleAccepted,
628 static_cast<base::HistogramBase::Sample>( 649 static_cast<base::HistogramBase::Sample>(
629 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 650 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
630 1); 651 1);
652 histograms.ExpectUniqueSample(
653 "Permissions.Engagement.Accepted.AudioAndVideoCapture",
654 kTestEngagementScore, 1);
631 } 655 }
632 656
633 TEST_F(PermissionRequestManagerTest, UMAForMergedDeniedBubble) { 657 TEST_F(PermissionRequestManagerTest, UMAForMergedDeniedBubble) {
634 base::HistogramTester histograms; 658 base::HistogramTester histograms;
635 659
636 manager_->AddRequest(&request_mic_); 660 manager_->AddRequest(&request_mic_);
637 manager_->AddRequest(&request_camera_); 661 manager_->AddRequest(&request_camera_);
638 manager_->DisplayPendingRequests(); 662 manager_->DisplayPendingRequests();
639 WaitForBubbleToBeShown(); 663 WaitForBubbleToBeShown();
664 histograms.ExpectTotalCount(
665 "Permissions.Engagement.Denied.AudioAndVideoCapture", 0);
640 // No need to test UMA for showing prompts again, they were tested in 666 // No need to test UMA for showing prompts again, they were tested in
641 // UMAForMergedAcceptedBubble. 667 // UMAForMergedAcceptedBubble.
642 668
643 Deny(); 669 Deny();
644 670
645 histograms.ExpectUniqueSample( 671 histograms.ExpectUniqueSample(
646 PermissionUmaUtil::kPermissionsPromptDenied, 672 PermissionUmaUtil::kPermissionsPromptDenied,
647 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE), 673 static_cast<base::HistogramBase::Sample>(PermissionRequestType::MULTIPLE),
648 1); 674 1);
649 histograms.ExpectBucketCount( 675 histograms.ExpectBucketCount(
650 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 676 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
651 static_cast<base::HistogramBase::Sample>( 677 static_cast<base::HistogramBase::Sample>(
652 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC), 678 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
653 1); 679 1);
654 histograms.ExpectBucketCount( 680 histograms.ExpectBucketCount(
655 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 681 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
656 static_cast<base::HistogramBase::Sample>( 682 static_cast<base::HistogramBase::Sample>(
657 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 683 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
658 1); 684 1);
685 histograms.ExpectUniqueSample(
686 "Permissions.Engagement.Denied.AudioAndVideoCapture",
687 kTestEngagementScore, 1);
659 } 688 }
689
690 TEST_F(PermissionRequestManagerTest, UMAForIgnores) {
691 base::HistogramTester histograms;
692
693 manager_->AddRequest(&request1_);
694 manager_->DisplayPendingRequests();
695 WaitForBubbleToBeShown();
696 histograms.ExpectTotalCount("Permissions.Engagement.Ignored.Quota", 0);
697
698 GURL youtube("http://www.youtube.com/");
699 NavigateAndCommit(youtube);
700 histograms.ExpectUniqueSample("Permissions.Engagement.Ignored.Quota",
701 kTestEngagementScore, 1);
702
703 MockPermissionRequest youtube_request(
704 "request2", PermissionRequestType::PERMISSION_GEOLOCATION, youtube);
705 manager_->AddRequest(&youtube_request);
706 manager_->DisplayPendingRequests();
707 WaitForBubbleToBeShown();
708
709 NavigateAndCommit(GURL("http://www.google.com/"));
710 histograms.ExpectUniqueSample("Permissions.Engagement.Ignored.Geolocation", 0,
711 1);
712 }
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