Roll src/third_party/WebKit f007c95:0171005 (svn 185074:185088)
[chromium-blink-merge.git] / content / test / webrtc_content_browsertest_base.cc
blob252cd2595c573eb9bf54a7826bb25f9ddab67d98
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
3 // found in the LICENSE file.
5 #include "content/test/webrtc_content_browsertest_base.h"
7 #include "base/command_line.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/common/content_switches.h"
11 #include "content/public/test/browser_test_utils.h"
12 #include "content/public/test/content_browser_test_utils.h"
13 #include "content/shell/browser/shell.h"
14 #include "media/base/media_switches.h"
16 #if defined(OS_CHROMEOS)
17 #include "chromeos/audio/cras_audio_handler.h"
18 #endif
20 #if defined(OS_WIN)
21 #include "base/win/windows_version.h"
22 #endif
24 namespace content {
26 void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) {
27 // Assume this is set by the content test launcher.
28 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
29 switches::kUseFakeUIForMediaStream));
30 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
31 switches::kUseFakeDeviceForMediaStream));
33 // Always include loopback interface in network list, in case the test device
34 // doesn't have other interfaces available.
35 CommandLine::ForCurrentProcess()->AppendSwitch(
36 switches::kAllowLoopbackInPeerConnection);
39 void WebRtcContentBrowserTest::SetUp() {
40 // We need pixel output when we dig pixels out of video tags for verification.
41 EnablePixelOutput();
42 #if defined(OS_CHROMEOS)
43 chromeos::CrasAudioHandler::InitializeForTesting();
44 #endif
45 ContentBrowserTest::SetUp();
48 void WebRtcContentBrowserTest::TearDown() {
49 ContentBrowserTest::TearDown();
50 #if defined(OS_CHROMEOS)
51 chromeos::CrasAudioHandler::Shutdown();
52 #endif
55 // Executes |javascript|. The script is required to use
56 // window.domAutomationController.send to send a string value back to here.
57 std::string WebRtcContentBrowserTest::ExecuteJavascriptAndReturnResult(
58 const std::string& javascript) {
59 std::string result;
60 EXPECT_TRUE(ExecuteScriptAndExtractString(
61 shell()->web_contents(), javascript, &result))
62 << "Failed to execute javascript " << javascript << ".";
63 return result;
66 void WebRtcContentBrowserTest::ExecuteJavascriptAndWaitForOk(
67 const std::string& javascript) {
68 std::string result = ExecuteJavascriptAndReturnResult(javascript);
69 if (result != "OK") {
70 if (result.empty())
71 result = "(nothing)";
72 printf("From javascript: %s\nWhen executing '%s'\n", result.c_str(),
73 javascript.c_str());
74 FAIL();
78 std::string WebRtcContentBrowserTest::GenerateGetUserMediaCall(
79 const char* function_name,
80 int min_width,
81 int max_width,
82 int min_height,
83 int max_height,
84 int min_frame_rate,
85 int max_frame_rate) const {
86 return base::StringPrintf(
87 "%s({video: {mandatory: {minWidth: %d, maxWidth: %d, "
88 "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, "
89 "optional: []}});",
90 function_name,
91 min_width,
92 max_width,
93 min_height,
94 max_height,
95 min_frame_rate,
96 max_frame_rate);
99 void WebRtcContentBrowserTest::DisableOpusIfOnAndroid() {
100 #if defined(OS_ANDROID)
101 // Always force iSAC 16K on Android for now (Opus is broken).
102 EXPECT_EQ("isac-forced",
103 ExecuteJavascriptAndReturnResult("forceIsac16KInSdp();"));
104 #endif
107 bool WebRtcContentBrowserTest::OnWinXp() const {
108 #if defined(OS_WIN)
109 return base::win::GetVersion() <= base::win::VERSION_XP;
110 #else
111 return false;
112 #endif
115 } // namespace content