OLD | NEW |
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" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 controller->PermissionGranted(); | 42 controller->PermissionGranted(); |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 class MediaStreamDevicesControllerTest : public WebRtcTestBase { | 47 class MediaStreamDevicesControllerTest : public WebRtcTestBase { |
48 public: | 48 public: |
49 MediaStreamDevicesControllerTest() | 49 MediaStreamDevicesControllerTest() |
50 : example_audio_id_("fake_audio_dev"), | 50 : example_audio_id_("fake_audio_dev"), |
51 example_video_id_("fake_video_dev"), | 51 example_video_id_("fake_video_dev"), |
| 52 example_screen_id_("fake_screen_dev"), |
52 media_stream_result_(content::NUM_MEDIA_REQUEST_RESULTS) {} | 53 media_stream_result_(content::NUM_MEDIA_REQUEST_RESULTS) {} |
53 | 54 |
54 // Dummy callback for when we deny the current request directly. | 55 // Dummy callback for when we deny the current request directly. |
55 void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | 56 void OnMediaStreamResponse(const content::MediaStreamDevices& devices, |
56 content::MediaStreamRequestResult result, | 57 content::MediaStreamRequestResult result, |
57 std::unique_ptr<content::MediaStreamUI> ui) { | 58 std::unique_ptr<content::MediaStreamUI> ui) { |
58 media_stream_devices_ = devices; | 59 media_stream_devices_ = devices; |
59 media_stream_result_ = result; | 60 media_stream_result_ = result; |
60 } | 61 } |
61 | 62 |
62 protected: | 63 protected: |
63 enum DeviceType { DEVICE_TYPE_AUDIO, DEVICE_TYPE_VIDEO }; | 64 enum DeviceType { DEVICE_TYPE_AUDIO, DEVICE_TYPE_VIDEO }; |
64 enum Access { ACCESS_ALLOWED, ACCESS_DENIED }; | 65 enum Access { ACCESS_ALLOWED, ACCESS_DENIED }; |
65 | 66 |
66 const GURL& example_url() const { return example_url_; } | 67 const GURL& example_url() const { return example_url_; } |
67 | 68 |
68 TabSpecificContentSettings* GetContentSettings() { | 69 TabSpecificContentSettings* GetContentSettings() { |
69 return TabSpecificContentSettings::FromWebContents(GetWebContents()); | 70 return TabSpecificContentSettings::FromWebContents(GetWebContents()); |
70 } | 71 } |
71 | 72 |
72 const std::string& example_audio_id() const { return example_audio_id_; } | 73 const std::string& example_audio_id() const { return example_audio_id_; } |
73 const std::string& example_video_id() const { return example_video_id_; } | 74 const std::string& example_video_id() const { return example_video_id_; } |
| 75 const std::string& example_screen_id() const { return example_screen_id_; } |
74 | 76 |
75 content::MediaStreamRequestResult media_stream_result() const { | 77 content::MediaStreamRequestResult media_stream_result() const { |
76 return media_stream_result_; | 78 return media_stream_result_; |
77 } | 79 } |
78 | 80 |
79 // Sets the device policy-controlled |access| for |example_url_| to be for the | 81 // Sets the device policy-controlled |access| for |example_url_| to be for the |
80 // selected |device_type|. | 82 // selected |device_type|. |
81 void SetDevicePolicy(DeviceType device_type, Access access) { | 83 void SetDevicePolicy(DeviceType device_type, Access access) { |
82 PrefService* prefs = Profile::FromBrowserContext( | 84 PrefService* prefs = Profile::FromBrowserContext( |
83 GetWebContents()->GetBrowserContext())->GetPrefs(); | 85 GetWebContents()->GetBrowserContext())->GetPrefs(); |
(...skipping 18 matching lines...) Expand all Loading... |
102 content_settings->SetContentSettingDefaultScope( | 104 content_settings->SetContentSettingDefaultScope( |
103 example_url_, GURL(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, | 105 example_url_, GURL(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
104 std::string(), mic_setting); | 106 std::string(), mic_setting); |
105 content_settings->SetContentSettingDefaultScope( | 107 content_settings->SetContentSettingDefaultScope( |
106 example_url_, GURL(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, | 108 example_url_, GURL(), CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
107 std::string(), cam_setting); | 109 std::string(), cam_setting); |
108 } | 110 } |
109 | 111 |
110 // Checks whether the devices returned in OnMediaStreamResponse contains a | 112 // Checks whether the devices returned in OnMediaStreamResponse contains a |
111 // microphone and/or camera device. | 113 // microphone and/or camera device. |
112 bool DevicesContains(bool needs_mic, bool needs_cam) { | 114 bool DevicesContains(bool needs_audio, bool needs_video) { |
113 bool has_mic = false; | 115 bool has_audio = false; |
114 bool has_cam = false; | 116 bool has_video = false; |
115 for (const auto& device : media_stream_devices_) { | 117 for (const auto& device : media_stream_devices_) { |
116 if (device.type == content::MEDIA_DEVICE_AUDIO_CAPTURE) | 118 if (device.type == content::MEDIA_DEVICE_AUDIO_CAPTURE) |
117 has_mic = true; | 119 has_audio = true; |
118 if (device.type == content::MEDIA_DEVICE_VIDEO_CAPTURE) | 120 if (device.type == content::MEDIA_DEVICE_VIDEO_CAPTURE) |
119 has_cam = true; | 121 has_video = true; |
| 122 #if defined(OS_ANDROID) |
| 123 if (device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE) |
| 124 has_video = true; |
| 125 #endif |
120 } | 126 } |
121 | 127 |
122 return needs_mic == has_mic && needs_cam == has_cam; | 128 return needs_audio == has_audio && needs_video == has_video; |
123 } | 129 } |
124 | 130 |
125 content::WebContents* GetWebContents() { | 131 content::WebContents* GetWebContents() { |
126 return browser()->tab_strip_model()->GetActiveWebContents(); | 132 return browser()->tab_strip_model()->GetActiveWebContents(); |
127 } | 133 } |
128 | 134 |
129 // Creates a MediaStreamRequest, asking for those media types, which have a | 135 // Creates a MediaStreamRequest, asking for those media types, which have a |
130 // non-empty id string. | 136 // non-empty id string. |
131 content::MediaStreamRequest CreateRequestWithType( | 137 content::MediaStreamRequest CreateRequestWithType( |
132 const std::string& audio_id, | 138 const std::string& audio_id, |
133 const std::string& video_id, | 139 const std::string& video_id, |
134 content::MediaStreamRequestType request_type) { | 140 content::MediaStreamRequestType request_type) { |
135 content::MediaStreamType audio_type = | 141 content::MediaStreamType audio_type = |
136 audio_id.empty() ? content::MEDIA_NO_SERVICE | 142 audio_id.empty() ? content::MEDIA_NO_SERVICE |
137 : content::MEDIA_DEVICE_AUDIO_CAPTURE; | 143 : content::MEDIA_DEVICE_AUDIO_CAPTURE; |
138 content::MediaStreamType video_type = | 144 content::MediaStreamType video_type = |
139 video_id.empty() ? content::MEDIA_NO_SERVICE | 145 video_id.empty() ? content::MEDIA_NO_SERVICE |
140 : content::MEDIA_DEVICE_VIDEO_CAPTURE; | 146 : content::MEDIA_DEVICE_VIDEO_CAPTURE; |
| 147 #if defined(OS_ANDROID) |
| 148 if (!video_id.compare(example_screen_id())) |
| 149 video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE; |
| 150 #endif |
| 151 |
141 return content::MediaStreamRequest(0, 0, 0, example_url(), false, | 152 return content::MediaStreamRequest(0, 0, 0, example_url(), false, |
142 request_type, audio_id, video_id, | 153 request_type, audio_id, video_id, |
143 audio_type, video_type); | 154 audio_type, video_type); |
144 } | 155 } |
145 | 156 |
146 content::MediaStreamRequest CreateRequest(const std::string& audio_id, | 157 content::MediaStreamRequest CreateRequest(const std::string& audio_id, |
147 const std::string& video_id) { | 158 const std::string& video_id) { |
148 return CreateRequestWithType(audio_id, video_id, | 159 return CreateRequestWithType(audio_id, video_id, |
149 content::MEDIA_DEVICE_ACCESS); | 160 content::MEDIA_DEVICE_ACCESS); |
150 } | 161 } |
(...skipping 27 matching lines...) Expand all Loading... |
178 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id_, | 189 content::MEDIA_DEVICE_VIDEO_CAPTURE, example_video_id_, |
179 "Fake Video Device"); | 190 "Fake Video Device"); |
180 video_devices.push_back(fake_video_device); | 191 video_devices.push_back(fake_video_device); |
181 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( | 192 MediaCaptureDevicesDispatcher::GetInstance()->SetTestVideoCaptureDevices( |
182 video_devices); | 193 video_devices); |
183 } | 194 } |
184 | 195 |
185 GURL example_url_; | 196 GURL example_url_; |
186 const std::string example_audio_id_; | 197 const std::string example_audio_id_; |
187 const std::string example_video_id_; | 198 const std::string example_video_id_; |
| 199 const std::string example_screen_id_; |
188 | 200 |
189 content::MediaStreamDevices media_stream_devices_; | 201 content::MediaStreamDevices media_stream_devices_; |
190 content::MediaStreamRequestResult media_stream_result_; | 202 content::MediaStreamRequestResult media_stream_result_; |
191 }; | 203 }; |
192 | 204 |
193 // Request and allow microphone access. | 205 // Request and allow microphone access. |
194 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { | 206 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestAndAllowMic) { |
195 InitWithUrl(GURL("https://www.example.com")); | 207 InitWithUrl(GURL("https://www.example.com")); |
196 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); | 208 SetDevicePolicy(DEVICE_TYPE_AUDIO, ACCESS_ALLOWED); |
197 MediaStreamDevicesController controller( | 209 MediaStreamDevicesController controller( |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 MediaStreamDevicesController controller( | 737 MediaStreamDevicesController controller( |
726 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), | 738 GetWebContents(), CreateRequest(example_audio_id(), example_video_id()), |
727 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, | 739 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
728 base::Unretained(this))); | 740 base::Unretained(this))); |
729 | 741 |
730 EXPECT_FALSE(controller.IsAllowedForAudio()); | 742 EXPECT_FALSE(controller.IsAllowedForAudio()); |
731 EXPECT_FALSE(controller.IsAllowedForVideo()); | 743 EXPECT_FALSE(controller.IsAllowedForVideo()); |
732 EXPECT_FALSE(controller.IsAskingForAudio()); | 744 EXPECT_FALSE(controller.IsAskingForAudio()); |
733 EXPECT_FALSE(controller.IsAskingForVideo()); | 745 EXPECT_FALSE(controller.IsAskingForVideo()); |
734 } | 746 } |
| 747 |
| 748 #if defined(OS_ANDROID) |
| 749 IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestScreenCapture) { |
| 750 InitWithUrl(GURL("https://www.example.com")); |
| 751 // Test that a prompt is required. |
| 752 MediaStreamDevicesController controller( |
| 753 GetWebContents(), CreateRequest(std::string(), example_screen_id()), |
| 754 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 755 this)); |
| 756 ASSERT_TRUE(controller.IsAskingForScreenCapture()); |
| 757 |
| 758 // Accept the prompt. |
| 759 controller.PermissionGranted(); |
| 760 ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result()); |
| 761 ASSERT_TRUE(DevicesContains(false, true)); |
| 762 |
| 763 // Check that re-requesting still requires prompting. |
| 764 MediaStreamDevicesController controller2( |
| 765 GetWebContents(), CreateRequest(std::string(), example_screen_id()), |
| 766 base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse, |
| 767 this)); |
| 768 ASSERT_TRUE(controller2.IsAskingForScreenCapture()); |
| 769 } |
| 770 #endif |
OLD | NEW |