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

Side by Side Diff: chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc

Issue 2746853002: Change MediaStreamDevicesController::RequestPermissions to use the requesting WebContents (Closed)
Patch Set: Change MediaStreamDevicesController::RequestPermissions to use the requesting WebContents Created 3 years, 8 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
13 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h" 13 #include "chrome/browser/media/webrtc/media_stream_device_permissions.h"
14 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h" 14 #include "chrome/browser/media/webrtc/media_stream_devices_controller.h"
15 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h" 15 #include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
16 #include "chrome/browser/permissions/permission_context_base.h" 16 #include "chrome/browser/permissions/permission_context_base.h"
17 #include "chrome/browser/permissions/permission_request_manager.h" 17 #include "chrome/browser/permissions/permission_request_manager.h"
18 #include "chrome/browser/permissions/permission_util.h" 18 #include "chrome/browser/permissions/permission_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" 21 #include "chrome/browser/ui/tabs/tab_strip_model.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
24 #include "components/content_settings/core/browser/host_content_settings_map.h" 24 #include "components/content_settings/core/browser/host_content_settings_map.h"
25 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
26 #include "components/variations/variations_associated_data.h" 26 #include "components/variations/variations_associated_data.h"
27 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/common/media_stream_request.h" 28 #include "content/public/common/media_stream_request.h"
28 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 class MediaStreamDevicesControllerTest : public WebRtcTestBase { 32 class MediaStreamDevicesControllerTest : public WebRtcTestBase {
32 public: 33 public:
33 // TODO(raymes): When crbug.com/606138 is finished and the 34 // TODO(raymes): When crbug.com/606138 is finished and the
34 // PermissionRequestManager is used to show all prompts on Android/Desktop 35 // PermissionRequestManager is used to show all prompts on Android/Desktop
35 // we should remove PermissionPromptDelegate and just use 36 // we should remove PermissionPromptDelegate and just use
36 // MockPermissionPromptFactory instead. The APIs are the same. 37 // MockPermissionPromptFactory instead. The APIs are the same.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 const std::string& example_video_id() const { return example_video_id_; } 100 const std::string& example_video_id() const { return example_video_id_; }
100 101
101 content::MediaStreamRequestResult media_stream_result() const { 102 content::MediaStreamRequestResult media_stream_result() const {
102 return media_stream_result_; 103 return media_stream_result_;
103 } 104 }
104 105
105 void RequestPermissions(content::WebContents* web_contents, 106 void RequestPermissions(content::WebContents* web_contents,
106 const content::MediaStreamRequest& request, 107 const content::MediaStreamRequest& request,
107 const content::MediaResponseCallback& callback) { 108 const content::MediaResponseCallback& callback) {
108 MediaStreamDevicesController::RequestPermissionsWithDelegate( 109 MediaStreamDevicesController::RequestPermissionsWithDelegate(
109 web_contents, request, callback, &prompt_delegate_); 110 request, callback, &prompt_delegate_);
110 } 111 }
111 112
112 TestPermissionPromptDelegate* prompt_delegate() { return &prompt_delegate_; } 113 TestPermissionPromptDelegate* prompt_delegate() { return &prompt_delegate_; }
113 114
114 // Sets the device policy-controlled |access| for |example_url_| to be for the 115 // Sets the device policy-controlled |access| for |example_url_| to be for the
115 // selected |device_type|. 116 // selected |device_type|.
116 void SetDevicePolicy(DeviceType device_type, Access access) { 117 void SetDevicePolicy(DeviceType device_type, Access access) {
117 PrefService* prefs = Profile::FromBrowserContext( 118 PrefService* prefs = Profile::FromBrowserContext(
118 GetWebContents()->GetBrowserContext())->GetPrefs(); 119 GetWebContents()->GetBrowserContext())->GetPrefs();
119 const char* policy_name = NULL; 120 const char* policy_name = NULL;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 content::MediaStreamRequest CreateRequestWithType( 163 content::MediaStreamRequest CreateRequestWithType(
163 const std::string& audio_id, 164 const std::string& audio_id,
164 const std::string& video_id, 165 const std::string& video_id,
165 content::MediaStreamRequestType request_type) { 166 content::MediaStreamRequestType request_type) {
166 content::MediaStreamType audio_type = 167 content::MediaStreamType audio_type =
167 audio_id.empty() ? content::MEDIA_NO_SERVICE 168 audio_id.empty() ? content::MEDIA_NO_SERVICE
168 : content::MEDIA_DEVICE_AUDIO_CAPTURE; 169 : content::MEDIA_DEVICE_AUDIO_CAPTURE;
169 content::MediaStreamType video_type = 170 content::MediaStreamType video_type =
170 video_id.empty() ? content::MEDIA_NO_SERVICE 171 video_id.empty() ? content::MEDIA_NO_SERVICE
171 : content::MEDIA_DEVICE_VIDEO_CAPTURE; 172 : content::MEDIA_DEVICE_VIDEO_CAPTURE;
172 return content::MediaStreamRequest(0, 0, 0, example_url(), false, 173 EXPECT_EQ(example_url(),
173 request_type, audio_id, video_id, 174 GetWebContents()->GetMainFrame()->GetLastCommittedURL());
174 audio_type, video_type, false); 175 int render_process_id = GetWebContents()->GetRenderProcessHost()->GetID();
176 int render_frame_id = GetWebContents()->GetMainFrame()->GetRoutingID();
177 return content::MediaStreamRequest(
178 render_process_id, render_frame_id, 0, example_url(), false,
179 request_type, audio_id, video_id, audio_type, video_type, false);
175 } 180 }
176 181
177 content::MediaStreamRequest CreateRequest(const std::string& audio_id, 182 content::MediaStreamRequest CreateRequest(const std::string& audio_id,
178 const std::string& video_id) { 183 const std::string& video_id) {
179 return CreateRequestWithType(audio_id, video_id, 184 return CreateRequestWithType(audio_id, video_id,
180 content::MEDIA_DEVICE_ACCESS); 185 content::MEDIA_DEVICE_ACCESS);
181 } 186 }
182 187
183 void InitWithUrl(const GURL& url) { 188 void InitWithUrl(const GURL& url) {
184 DCHECK(example_url_.is_empty()); 189 DCHECK(example_url_.is_empty());
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), 802 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()),
798 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, 803 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
799 base::Unretained(this))); 804 base::Unretained(this)));
800 805
801 ASSERT_EQ(0u, prompt_delegate()->TotalRequestCount()); 806 ASSERT_EQ(0u, prompt_delegate()->TotalRequestCount());
802 807
803 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result()); 808 ASSERT_EQ(content::MEDIA_DEVICE_KILL_SWITCH_ON, media_stream_result());
804 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE)); 809 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
805 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE)); 810 ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
806 } 811 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698