| Index: chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc
|
| diff --git a/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc b/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc
|
| index 36dd8f6ab5bfc18f69a3a5d235efb3c8ceabfc9f..09ae0a8030e08487945de7ff85d815d3d7e9f42d 100644
|
| --- a/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc
|
| +++ b/chrome/browser/media/webrtc/media_stream_devices_controller_browsertest.cc
|
| @@ -49,6 +49,7 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
|
| MediaStreamDevicesControllerTest()
|
| : example_audio_id_("fake_audio_dev"),
|
| example_video_id_("fake_video_dev"),
|
| + example_screen_id_("fake_screen_dev"),
|
| media_stream_result_(content::NUM_MEDIA_REQUEST_RESULTS) {}
|
|
|
| // Dummy callback for when we deny the current request directly.
|
| @@ -71,6 +72,7 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
|
|
|
| const std::string& example_audio_id() const { return example_audio_id_; }
|
| const std::string& example_video_id() const { return example_video_id_; }
|
| + const std::string& example_screen_id() const { return example_screen_id_; }
|
|
|
| content::MediaStreamRequestResult media_stream_result() const {
|
| return media_stream_result_;
|
| @@ -109,17 +111,13 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
|
|
|
| // Checks whether the devices returned in OnMediaStreamResponse contains a
|
| // microphone and/or camera device.
|
| - bool DevicesContains(bool needs_mic, bool needs_cam) {
|
| - bool has_mic = false;
|
| - bool has_cam = false;
|
| + bool CheckDevicesListContains(content::MediaStreamType type) {
|
| for (const auto& device : media_stream_devices_) {
|
| - if (device.type == content::MEDIA_DEVICE_AUDIO_CAPTURE)
|
| - has_mic = true;
|
| - if (device.type == content::MEDIA_DEVICE_VIDEO_CAPTURE)
|
| - has_cam = true;
|
| + if (device.type == type) {
|
| + return true;
|
| + }
|
| }
|
| -
|
| - return needs_mic == has_mic && needs_cam == has_cam;
|
| + return false;
|
| }
|
|
|
| content::WebContents* GetWebContents() {
|
| @@ -138,6 +136,11 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
|
| content::MediaStreamType video_type =
|
| video_id.empty() ? content::MEDIA_NO_SERVICE
|
| : content::MEDIA_DEVICE_VIDEO_CAPTURE;
|
| +#if defined(OS_ANDROID)
|
| + if (!video_id.compare(example_screen_id()))
|
| + video_type = content::MEDIA_DESKTOP_VIDEO_CAPTURE;
|
| +#endif
|
| +
|
| return content::MediaStreamRequest(0, 0, 0, example_url(), false,
|
| request_type, audio_id, video_id,
|
| audio_type, video_type);
|
| @@ -185,6 +188,7 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
|
| GURL example_url_;
|
| const std::string example_audio_id_;
|
| const std::string example_video_id_;
|
| + const std::string example_screen_id_;
|
|
|
| content::MediaStreamDevices media_stream_devices_;
|
| content::MediaStreamRequestResult media_stream_result_;
|
| @@ -637,8 +641,10 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, ContentSettings) {
|
| // Check the media stream result is expected and the devices returned are
|
| // expected;
|
| ASSERT_EQ(test.ExpectedMediaStreamResult(), media_stream_result());
|
| - ASSERT_TRUE(
|
| - DevicesContains(test.ExpectMicAllowed(), test.ExpectCamAllowed()));
|
| + ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE),
|
| + test.ExpectMicAllowed());
|
| + ASSERT_EQ(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE),
|
| + test.ExpectCamAllowed());
|
| }
|
| }
|
|
|
| @@ -655,7 +661,8 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| ASSERT_FALSE(controller.IsAskingForVideo());
|
|
|
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
|
| - ASSERT_TRUE(DevicesContains(false, true));
|
| + ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| @@ -672,7 +679,8 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| // Accept the prompt.
|
| controller.PermissionGranted();
|
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
|
| - ASSERT_TRUE(DevicesContains(true, true));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
|
|
|
| // Check that re-requesting allows without prompting.
|
| MediaStreamDevicesController controller2(
|
| @@ -683,7 +691,8 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| ASSERT_FALSE(controller2.IsAskingForVideo());
|
|
|
| ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
|
| - ASSERT_TRUE(DevicesContains(true, true));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DEVICE_VIDEO_CAPTURE));
|
| }
|
|
|
| // For Pepper request from insecure origin, even if it's ALLOW, it won't be
|
| @@ -732,3 +741,53 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| EXPECT_FALSE(controller.IsAskingForAudio());
|
| EXPECT_FALSE(controller.IsAskingForVideo());
|
| }
|
| +
|
| +#if defined(OS_ANDROID)
|
| +IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| + RequestAndAllowScreenCapture) {
|
| + InitWithUrl(GURL("https://www.example.com"));
|
| + // Test that a prompt is required.
|
| + MediaStreamDevicesController controller(
|
| + GetWebContents(), CreateRequest(std::string(), example_screen_id()),
|
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
|
| + base::Unretained(this)));
|
| + ASSERT_TRUE(controller.IsAskingForScreenCapture());
|
| +
|
| + // Accept the prompt.
|
| + controller.PermissionGranted();
|
| + ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
|
| + ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
|
| + ASSERT_TRUE(CheckDevicesListContains(content::MEDIA_DESKTOP_VIDEO_CAPTURE));
|
| +
|
| + // Check that re-requesting still requires prompting.
|
| + MediaStreamDevicesController controller2(
|
| + GetWebContents(), CreateRequest(std::string(), example_screen_id()),
|
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
|
| + base::Unretained(this)));
|
| + ASSERT_TRUE(controller2.IsAskingForScreenCapture());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
|
| + RequestAndBlockScreenCapture) {
|
| + InitWithUrl(GURL("https://www.example.com"));
|
| + // Test that a prompt is required.
|
| + MediaStreamDevicesController controller(
|
| + GetWebContents(), CreateRequest(std::string(), example_screen_id()),
|
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
|
| + base::Unretained(this)));
|
| + ASSERT_TRUE(controller.IsAskingForScreenCapture());
|
| +
|
| + // Block the prompt.
|
| + controller.PermissionDenied();
|
| + ASSERT_NE(content::MEDIA_DEVICE_OK, media_stream_result());
|
| + ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DEVICE_AUDIO_CAPTURE));
|
| + ASSERT_FALSE(CheckDevicesListContains(content::MEDIA_DESKTOP_VIDEO_CAPTURE));
|
| +
|
| + // Check that re-requesting still requires prompting.
|
| + MediaStreamDevicesController controller2(
|
| + GetWebContents(), CreateRequest(std::string(), example_screen_id()),
|
| + base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
|
| + base::Unretained(this)));
|
| + ASSERT_TRUE(controller2.IsAskingForScreenCapture());
|
| +}
|
| +#endif // defined(OS_ANDROID)
|
|
|