| OLD | NEW |
| (Empty) |
| 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 "build/build_config.h" | |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | |
| 12 #include "content/public/common/content_switches.h" | |
| 13 #include "content/public/test/browser_test_utils.h" | |
| 14 #include "content/public/test/content_browser_test_utils.h" | |
| 15 #include "content/shell/browser/shell.h" | |
| 16 #include "media/base/media_switches.h" | |
| 17 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 18 | |
| 19 #if defined(OS_CHROMEOS) | |
| 20 #include "chromeos/audio/cras_audio_handler.h" | |
| 21 #endif | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 void WebRtcContentBrowserTest::SetUpCommandLine( | |
| 26 base::CommandLine* command_line) { | |
| 27 ASSERT_TRUE(base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 28 switches::kUseFakeDeviceForMediaStream)); | |
| 29 | |
| 30 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 31 switches::kEnforceWebRtcIPPermissionCheck); | |
| 32 | |
| 33 // Loopback interface is the non-default local address. They should only be in | |
| 34 // the candidate list if the ip handling policy is "default" AND the media | |
| 35 // permission is granted. | |
| 36 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 37 switches::kAllowLoopbackInPeerConnection); | |
| 38 } | |
| 39 | |
| 40 void WebRtcContentBrowserTest::SetUp() { | |
| 41 // We need pixel output when we dig pixels out of video tags for verification. | |
| 42 EnablePixelOutput(); | |
| 43 #if defined(OS_CHROMEOS) | |
| 44 chromeos::CrasAudioHandler::InitializeForTesting(); | |
| 45 #endif | |
| 46 ContentBrowserTest::SetUp(); | |
| 47 } | |
| 48 | |
| 49 void WebRtcContentBrowserTest::TearDown() { | |
| 50 ContentBrowserTest::TearDown(); | |
| 51 #if defined(OS_CHROMEOS) | |
| 52 chromeos::CrasAudioHandler::Shutdown(); | |
| 53 #endif | |
| 54 } | |
| 55 | |
| 56 void WebRtcContentBrowserTest::AppendUseFakeUIForMediaStreamFlag() { | |
| 57 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 58 switches::kUseFakeUIForMediaStream); | |
| 59 } | |
| 60 | |
| 61 // Executes |javascript|. The script is required to use | |
| 62 // window.domAutomationController.send to send a string value back to here. | |
| 63 std::string WebRtcContentBrowserTest::ExecuteJavascriptAndReturnResult( | |
| 64 const std::string& javascript) { | |
| 65 std::string result; | |
| 66 EXPECT_TRUE(ExecuteScriptAndExtractString(shell(), javascript, &result)) | |
| 67 << "Failed to execute javascript " << javascript << "."; | |
| 68 return result; | |
| 69 } | |
| 70 | |
| 71 void WebRtcContentBrowserTest::MakeTypicalCall(const std::string& javascript, | |
| 72 const std::string& html_file) { | |
| 73 ASSERT_TRUE(embedded_test_server()->Start()); | |
| 74 | |
| 75 GURL url(embedded_test_server()->GetURL(html_file)); | |
| 76 NavigateToURL(shell(), url); | |
| 77 | |
| 78 ExecuteJavascriptAndWaitForOk(javascript); | |
| 79 } | |
| 80 | |
| 81 void WebRtcContentBrowserTest::ExecuteJavascriptAndWaitForOk( | |
| 82 const std::string& javascript) { | |
| 83 std::string result = ExecuteJavascriptAndReturnResult(javascript); | |
| 84 if (result != "OK") { | |
| 85 if (result.empty()) | |
| 86 result = "(nothing)"; | |
| 87 printf("From javascript: %s\nWhen executing '%s'\n", result.c_str(), | |
| 88 javascript.c_str()); | |
| 89 FAIL(); | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 std::string WebRtcContentBrowserTest::GenerateGetUserMediaCall( | |
| 94 const char* function_name, | |
| 95 int min_width, | |
| 96 int max_width, | |
| 97 int min_height, | |
| 98 int max_height, | |
| 99 int min_frame_rate, | |
| 100 int max_frame_rate) const { | |
| 101 return base::StringPrintf( | |
| 102 "%s({video: {mandatory: {minWidth: %d, maxWidth: %d, " | |
| 103 "minHeight: %d, maxHeight: %d, minFrameRate: %d, maxFrameRate: %d}, " | |
| 104 "optional: []}});", | |
| 105 function_name, | |
| 106 min_width, | |
| 107 max_width, | |
| 108 min_height, | |
| 109 max_height, | |
| 110 min_frame_rate, | |
| 111 max_frame_rate); | |
| 112 } | |
| 113 | |
| 114 } // namespace content | |
| OLD | NEW |