Index: content/public/test/browser_test_utils.cc |
diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc |
index 802d4eba324aefe2afe3628832346c879ff54346..344759c29c684d42bef376315e117c9dbaf253f8 100644 |
--- a/content/public/test/browser_test_utils.cc |
+++ b/content/public/test/browser_test_utils.cc |
@@ -408,6 +408,28 @@ void AppendGzippedResource(const base::RefCountedMemory& encoded, |
} while (status != net::Filter::FILTER_DONE); |
} |
+// Queries for video input devices on the current system using the getSources |
+// API. |
+// |
+// This does not guarantee that a getUserMedia with video will succeed, as the |
+// camera could be busy for instance. |
+// |
+// Returns has-video-input-device to the test if there is a webcam available, |
+// no-video-input-devices otherwise. |
+static const std::string hasVideoInputDeviceOnSystem = |
sky
2016/09/13 21:32:34
There is no need for the static as this in an anon
lunalu1
2016/09/13 21:55:02
Done.
|
+ "(function() {" |
+ "navigator.mediaDevices.enumerateDevices()" |
+ ".then(function(devices) {" |
+ "devices.forEach(function(device) {" |
+ "if (device.kind == 'video') {" |
+ "returnToTest('has-video-input-device');" |
+ "return;" |
+ "}" |
+ "});" |
+ "returnToTest('no-video-input-devices');" |
+ "});" |
+ "})()"; |
+ |
} // namespace |
bool NavigateIframeToURL(WebContents* web_contents, |
@@ -742,6 +764,13 @@ void SimulateKeyPress(WebContents* web_contents, |
ASSERT_EQ(modifiers, 0); |
} |
+bool HasWebcamAvailableOnSystem(WebContents* web_contents) { |
+ std::string result; |
+ EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
+ web_contents, hasVideoInputDeviceOnSystem, &result)); |
+ return result == "has-video-input-device"; |
sky
2016/09/13 21:32:34
Can this be a constant?
lunalu1
2016/09/13 21:55:02
Done.
|
+} |
+ |
RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents) { |
return web_contents->GetMainFrame(); |
} |