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