Commit 8870e560 authored by lunalu's avatar lunalu Committed by Commit bot

Removed duplicated JS hasVideoInputDeviceOnSystem() test helper

BUG=509735

Review-Url: https://codereview.chromium.org/2310683003
Cr-Commit-Position: refs/heads/master@{#419008}
parent 649f34f7
......@@ -428,13 +428,6 @@ std::string WebRtcTestBase::GetStreamSize(
return result.substr(3);
}
bool WebRtcTestBase::HasWebcamAvailableOnSystem(
content::WebContents* tab_contents) const {
std::string result =
ExecuteJavascript("hasVideoInputDeviceOnSystem();", tab_contents);
return result == "has-video-input-device";
}
bool WebRtcTestBase::OnWin8() const {
#if defined(OS_WIN)
return base::win::GetVersion() > base::win::VERSION_WIN7;
......
......@@ -151,9 +151,6 @@ class WebRtcTestBase : public InProcessBrowserTest {
std::string GetStreamSize(content::WebContents* tab_contents,
const std::string& video_element) const;
// Methods to check what devices we have on the system.
bool HasWebcamAvailableOnSystem(content::WebContents* tab_contents) const;
// Returns true if we're on win 8.
bool OnWin8() const;
......
......@@ -78,8 +78,8 @@ IN_PROC_BROWSER_TEST_P(WebRtcWebcamBrowserTest,
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
if (!HasWebcamAvailableOnSystem(tab)) {
LOG(INFO) << "No webcam found on bot: skipping...";
if (!content::IsWebcamAvailableOnSystem(tab)) {
DVLOG(0) << "No webcam found on bot: skipping...";
return;
}
......
......@@ -27,27 +27,3 @@ function getSources() {
});
}
/**
* 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.
*/
function hasVideoInputDeviceOnSystem() {
MediaStreamTrack.getSources(function(devices) {
var hasVideoInputDevice = false;
devices.forEach(function(device) {
if (device.kind == 'video')
hasVideoInputDevice = true;
});
if (hasVideoInputDevice)
returnToTest('has-video-input-device');
else
returnToTest('no-video-input-devices');
});
}
......@@ -74,10 +74,8 @@ IN_PROC_BROWSER_TEST_F(WebRtcWebcamBrowserTest,
NavigateToURL(shell(), url);
std::string result;
ASSERT_TRUE(ExecuteScriptAndExtractString(
shell(), "hasVideoInputDeviceOnSystem()", &result));
if (result != "has-video-input-device") {
VLOG(0) << "No video device; skipping test...";
if (!IsWebcamAvailableOnSystem(shell()->web_contents())) {
DVLOG(0) << "No video device; skipping test...";
return;
}
......
......@@ -408,6 +408,30 @@ 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.
const char kHasVideoInputDeviceOnSystem[] =
"(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');"
"});"
"})()";
const char kHasVideoInputDevice[] = "has-video-input-device";
} // namespace
bool NavigateIframeToURL(WebContents* web_contents,
......@@ -742,6 +766,13 @@ void SimulateKeyPress(WebContents* web_contents,
ASSERT_EQ(modifiers, 0);
}
bool IsWebcamAvailableOnSystem(WebContents* web_contents) {
std::string result;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(
web_contents, kHasVideoInputDeviceOnSystem, &result));
return result == kHasVideoInputDevice;
}
RenderFrameHost* ConvertToRenderFrameHost(WebContents* web_contents) {
return web_contents->GetMainFrame();
}
......
......@@ -166,6 +166,9 @@ void SimulateKeyPress(WebContents* web_contents,
bool alt,
bool command);
// Method to check what devices we have on the system.
bool IsWebcamAvailableOnSystem(WebContents* web_contents);
// Allow ExecuteScript* methods to target either a WebContents or a
// RenderFrameHost. Targetting a WebContents means executing the script in the
// RenderFrameHost returned by WebContents::GetMainFrame(), which is the main
......
......@@ -263,19 +263,3 @@ function assertTrue(booleanExpression, description) {
}
}
// Returns has-video-input-device to the test if there's a webcam available on
// the system.
function hasVideoInputDeviceOnSystem() {
MediaStreamTrack.getSources(function(devices) {
var hasVideoInputDevice = false;
devices.forEach(function(device) {
if (device.kind == 'video')
hasVideoInputDevice = true;
});
if (hasVideoInputDevice)
sendValueToTest('has-video-input-device');
else
sendValueToTest('no-video-input-devices');
});
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment