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.
4
5 #include "content/test/webrtc_content_browsertest_base.h"
6
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"
15
16 #if defined(OS_CHROMEOS)
17 #include "chromeos/audio/cras_audio_handler.h"
18 #endif
19
20 namespace content {
21
SetUpCommandLine(CommandLine * command_line)22 void WebRtcContentBrowserTest::SetUpCommandLine(CommandLine* command_line) {
23 // We need fake devices in this test since we want to run on naked VMs. We
24 // assume these switches are set by default in content_browsertests.
25 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
26 switches::kUseFakeDeviceForMediaStream));
27 ASSERT_TRUE(CommandLine::ForCurrentProcess()->HasSwitch(
28 switches::kUseFakeUIForMediaStream));
29
30 // Always include loopback interface in network list, in case the test device
31 // doesn't have other interfaces available.
32 CommandLine::ForCurrentProcess()->AppendSwitch(
33 switches::kAllowLoopbackInPeerConnection);
34 }
35
SetUp()36 void WebRtcContentBrowserTest::SetUp() {
37 EnablePixelOutput();
38 #if defined(OS_CHROMEOS)
39 chromeos::CrasAudioHandler::InitializeForTesting();
40 #endif
41 ContentBrowserTest::SetUp();
42 }
43
TearDown()44 void WebRtcContentBrowserTest::TearDown() {
45 ContentBrowserTest::TearDown();
46 #if defined(OS_CHROMEOS)
47 chromeos::CrasAudioHandler::Shutdown();
48 #endif
49 }
50
51 // Executes |javascript|. The script is required to use
52 // window.domAutomationController.send to send a string value back to here.
ExecuteJavascriptAndReturnResult(const std::string & javascript)53 std::string WebRtcContentBrowserTest::ExecuteJavascriptAndReturnResult(
54 const std::string& javascript) {
55 std::string result;
56 EXPECT_TRUE(ExecuteScriptAndExtractString(shell()->web_contents(),
57 javascript,
58 &result));
59 return result;
60 }
61
ExecuteJavascriptAndWaitForOk(const std::string & javascript)62 void WebRtcContentBrowserTest::ExecuteJavascriptAndWaitForOk(
63 const std::string& javascript) {
64 std::string result = ExecuteJavascriptAndReturnResult(javascript);
65 if (result != "OK") {
66 printf("From javascript: %s", result.c_str());
67 FAIL();
68 }
69 }
70
GenerateGetUserMediaCall(const char * function_name,int min_width,int max_width,int min_height,int max_height,int min_frame_rate,int max_frame_rate) const71 std::string WebRtcContentBrowserTest::GenerateGetUserMediaCall(
72 const char* function_name,
73 int min_width,
74 int max_width,
75 int min_height,
76 int max_height,
77 int min_frame_rate,
78 int max_frame_rate) const {
79 return base::StringPrintf(
80 "%s({video: {mandatory: {minWidth: %d, maxWidth: %d, "
81 "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, "
82 "optional: []}});",
83 function_name,
84 min_width,
85 max_width,
86 min_height,
87 max_height,
88 min_frame_rate,
89 max_frame_rate);
90 }
91
DisableOpusIfOnAndroid()92 void WebRtcContentBrowserTest::DisableOpusIfOnAndroid() {
93 #if defined(OS_ANDROID)
94 // Always force iSAC 16K on Android for now (Opus is broken).
95 EXPECT_EQ("isac-forced",
96 ExecuteJavascriptAndReturnResult("forceIsac16KInSdp();"));
97 #endif
98 }
99
100 } // namespace content
101