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

Unified Diff: chrome/browser/media/media_stream_devices_controller_browsertest.cc

Issue 2123863004: ScreenCapture for Android phase1, part II (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_stream_devices_controller_browsertest.cc
diff --git a/chrome/browser/media/media_stream_devices_controller_browsertest.cc b/chrome/browser/media/media_stream_devices_controller_browsertest.cc
index 93bd2fb1b228729b796aa66a32332c3413a6ca30..1640af3deb907ac3bcfbf00a85d8db509abb8ac5 100644
--- a/chrome/browser/media/media_stream_devices_controller_browsertest.cc
+++ b/chrome/browser/media/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,21 @@ class MediaStreamDevicesControllerTest : public WebRtcTestBase {
// Checks whether the devices returned in OnMediaStreamResponse contains a
// microphone and/or camera device.
Sergey Ulanov 2016/08/19 05:54:15 update comment?
- bool DevicesContains(bool needs_mic, bool needs_cam) {
- bool has_mic = false;
- bool has_cam = false;
+ bool DevicesContains(bool needs_audio, bool needs_video) {
Sergey Ulanov 2016/08/19 05:54:15 I think it would be cleaner to replace this with a
+ bool has_audio = false;
+ bool has_video = false;
for (const auto& device : media_stream_devices_) {
if (device.type == content::MEDIA_DEVICE_AUDIO_CAPTURE)
- has_mic = true;
+ has_audio = true;
if (device.type == content::MEDIA_DEVICE_VIDEO_CAPTURE)
- has_cam = true;
+ has_video = true;
+#if defined(OS_ANDROID)
+ if (device.type == content::MEDIA_DESKTOP_VIDEO_CAPTURE)
+ has_video = true;
+#endif
}
- return needs_mic == has_mic && needs_cam == has_cam;
+ return needs_audio == has_audio && needs_video == has_video;
}
content::WebContents* GetWebContents() {
@@ -138,6 +144,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 +196,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_;
@@ -732,3 +744,27 @@ IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest,
EXPECT_FALSE(controller.IsAskingForAudio());
EXPECT_FALSE(controller.IsAskingForVideo());
}
+
+#if defined(OS_ANDROID)
+IN_PROC_BROWSER_TEST_F(MediaStreamDevicesControllerTest, RequestScreenCapture) {
Sergey Ulanov 2016/08/19 05:54:15 Also add a test for the case when access is denied
+ 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,
+ this));
+ ASSERT_TRUE(controller.IsAskingForScreenCapture());
+
+ // Accept the prompt.
+ controller.PermissionGranted();
+ ASSERT_EQ(content::MEDIA_DEVICE_OK, media_stream_result());
+ ASSERT_TRUE(DevicesContains(false, true));
+
+ // Check that re-requesting still requires prompting.
+ MediaStreamDevicesController controller2(
+ GetWebContents(), CreateRequest(std::string(), example_screen_id()),
+ base::Bind(&MediaStreamDevicesControllerTest::OnMediaStreamResponse,
+ this));
+ ASSERT_TRUE(controller2.IsAskingForScreenCapture());
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698