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

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

Issue 2975593002: [vr] Deny permission requests in VR mode
Patch Set: . 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"
(...skipping 28 matching lines...) Expand all
39 GURL("http://www.google.com/some/url")), 39 GURL("http://www.google.com/some/url")),
40 iframe_request_other_domain_("iframe", 40 iframe_request_other_domain_("iframe",
41 PermissionRequestType::UNKNOWN, 41 PermissionRequestType::UNKNOWN,
42 GURL("http://www.youtube.com")), 42 GURL("http://www.youtube.com")),
43 iframe_request_mic_other_domain_( 43 iframe_request_mic_other_domain_(
44 "iframe", 44 "iframe",
45 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC, 45 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC,
46 GURL("http://www.youtube.com")) {} 46 GURL("http://www.youtube.com")) {}
47 ~PermissionRequestManagerTest() override {} 47 ~PermissionRequestManagerTest() override {}
48 48
49 class PermissionRequestManagerWrapper : public PermissionRequestManager {
50 public:
51 explicit PermissionRequestManagerWrapper(content::WebContents* web_contents)
52 : PermissionRequestManager(web_contents) {}
53 ~PermissionRequestManagerWrapper() override {}
54
55 void set_permission_requests_disabled(bool value) {
56 permission_requests_disabled_ = value;
57 }
58 bool PermissionRequestsDisabled() const override {
59 return permission_requests_disabled_;
60 }
61
62 private:
63 bool permission_requests_disabled_ = false;
64 };
65
49 void SetUp() override { 66 void SetUp() override {
50 ChromeRenderViewHostTestHarness::SetUp(); 67 ChromeRenderViewHostTestHarness::SetUp();
51 SetContents(CreateTestWebContents()); 68 SetContents(CreateTestWebContents());
52 NavigateAndCommit(GURL("http://www.google.com")); 69 NavigateAndCommit(GURL("http://www.google.com"));
53 70
54 manager_.reset(new PermissionRequestManager(web_contents())); 71 manager_.reset(new PermissionRequestManagerWrapper(web_contents()));
55 prompt_factory_.reset(new MockPermissionPromptFactory(manager_.get())); 72 prompt_factory_.reset(new MockPermissionPromptFactory(manager_.get()));
56 } 73 }
57 74
58 void TearDown() override { 75 void TearDown() override {
59 prompt_factory_.reset(); 76 prompt_factory_.reset();
60 manager_.reset(); 77 manager_.reset();
61 ChromeRenderViewHostTestHarness::TearDown(); 78 ChromeRenderViewHostTestHarness::TearDown();
62 } 79 }
63 80
64 void Accept() { 81 void Accept() {
(...skipping 29 matching lines...) Expand all
94 } 111 }
95 112
96 protected: 113 protected:
97 MockPermissionRequest request1_; 114 MockPermissionRequest request1_;
98 MockPermissionRequest request2_; 115 MockPermissionRequest request2_;
99 MockPermissionRequest request_mic_; 116 MockPermissionRequest request_mic_;
100 MockPermissionRequest request_camera_; 117 MockPermissionRequest request_camera_;
101 MockPermissionRequest iframe_request_same_domain_; 118 MockPermissionRequest iframe_request_same_domain_;
102 MockPermissionRequest iframe_request_other_domain_; 119 MockPermissionRequest iframe_request_other_domain_;
103 MockPermissionRequest iframe_request_mic_other_domain_; 120 MockPermissionRequest iframe_request_mic_other_domain_;
104 std::unique_ptr<PermissionRequestManager> manager_; 121 std::unique_ptr<PermissionRequestManagerWrapper> manager_;
105 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_; 122 std::unique_ptr<MockPermissionPromptFactory> prompt_factory_;
106 }; 123 };
107 124
108 TEST_F(PermissionRequestManagerTest, SingleRequest) { 125 TEST_F(PermissionRequestManagerTest, SingleRequest) {
109 manager_->AddRequest(&request1_); 126 manager_->AddRequest(&request1_);
110 manager_->DisplayPendingRequests(); 127 manager_->DisplayPendingRequests();
111 WaitForBubbleToBeShown(); 128 WaitForBubbleToBeShown();
112 129
113 EXPECT_TRUE(prompt_factory_->is_visible()); 130 EXPECT_TRUE(prompt_factory_->is_visible());
114 ASSERT_EQ(prompt_factory_->request_count(), 1); 131 ASSERT_EQ(prompt_factory_->request_count(), 1);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 653 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
637 static_cast<base::HistogramBase::Sample>( 654 static_cast<base::HistogramBase::Sample>(
638 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC), 655 PermissionRequestType::PERMISSION_MEDIASTREAM_MIC),
639 1); 656 1);
640 histograms.ExpectBucketCount( 657 histograms.ExpectBucketCount(
641 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied, 658 PermissionUmaUtil::kPermissionsPromptMergedBubbleDenied,
642 static_cast<base::HistogramBase::Sample>( 659 static_cast<base::HistogramBase::Sample>(
643 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA), 660 PermissionRequestType::PERMISSION_MEDIASTREAM_CAMERA),
644 1); 661 1);
645 } 662 }
663
664 TEST_F(PermissionRequestManagerTest, DisabledPermissionRequests) {
665 manager_->set_permission_requests_disabled(true);
raymes 2017/07/11 01:43:23 I think it would be better to simulate VR being en
666 manager_->AddRequest(&request1_);
667 EXPECT_FALSE(request1_.granted());
668 EXPECT_TRUE(request1_.finished());
669 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698