1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/command_line.h"
#include "base/memory/raw_ptr.h"
#include "base/task/deferred_sequenced_task_runner.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_base.h"
#include "chrome/browser/media/webrtc/webrtc_browsertest_common.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/network_service_instance.h"
#include "content/public/browser/network_service_util.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/sync_call_restrictions.h"
#include "net/nqe/network_quality_estimator.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_service_test.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/switches.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
static const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html";
static const char kKeygenAlgorithmRsa[] =
"{ name: \"RSASSA-PKCS1-v1_5\", modulusLength: 2048, publicExponent: "
"new Uint8Array([1, 0, 1]), hash: \"SHA-256\" }";
static const char kKeygenAlgorithmEcdsa[] =
"{ name: \"ECDSA\", namedCurve: \"P-256\" }";
// Top-level integration test for WebRTC. It always uses fake devices; see
// WebRtcWebcamBrowserTest for a test that acquires any real webcam on the
// system.
class WebRtcBrowserTest : public WebRtcTestBase {
public:
WebRtcBrowserTest() : left_tab_(nullptr), right_tab_(nullptr) {}
void SetUpInProcessBrowserTestFixture() override {
DetectErrorsInJavaScript(); // Look for errors in our rather complex js.
}
void SetUpCommandLine(base::CommandLine* command_line) override {
// Ensure the infobar is enabled, since we expect that in this test.
EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream));
// Flag used by TestWebAudioMediaStream to force garbage collection.
command_line->AppendSwitchASCII(blink::switches::kJavaScriptFlags,
"--expose-gc");
}
void RunsAudioVideoWebRTCCallInTwoTabs(
const std::string& video_codec = WebRtcTestBase::kUseDefaultVideoCodec,
bool prefer_hw_video_codec = false,
const std::string& offer_cert_keygen_alg =
WebRtcTestBase::kUseDefaultCertKeygen,
const std::string& answer_cert_keygen_alg =
WebRtcTestBase::kUseDefaultCertKeygen) {
StartServerAndOpenTabs();
SetupPeerconnectionWithLocalStream(left_tab_, offer_cert_keygen_alg);
SetupPeerconnectionWithLocalStream(right_tab_, answer_cert_keygen_alg);
if (!video_codec.empty()) {
SetDefaultVideoCodec(left_tab_, video_codec, prefer_hw_video_codec);
SetDefaultVideoCodec(right_tab_, video_codec, prefer_hw_video_codec);
}
NegotiateCall(left_tab_, right_tab_);
DetectVideoAndHangUp();
}
void RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate(
const std::string& cert_keygen_alg =
WebRtcTestBase::kUseDefaultCertKeygen) {
StartServerAndOpenTabs();
// Generate and clone a certificate, resulting in JavaScript variable
// |gCertificateClone| being set to the resulting clone.
DeleteDatabase(left_tab_);
OpenDatabase(left_tab_);
GenerateAndCloneCertificate(left_tab_, cert_keygen_alg);
CloseDatabase(left_tab_);
DeleteDatabase(left_tab_);
SetupPeerconnectionWithCertificateAndLocalStream(left_tab_,
"gCertificateClone");
SetupPeerconnectionWithLocalStream(right_tab_, cert_keygen_alg);
NegotiateCall(left_tab_, right_tab_);
VerifyLocalDescriptionContainsCertificate(left_tab_, "gCertificate");
DetectVideoAndHangUp();
}
uint32_t GetPeerToPeerConnectionsCountChangeFromNetworkService() {
uint32_t connection_count = 0u;
if (content::IsInProcessNetworkService()) {
base::RunLoop run_loop;
content::GetNetworkTaskRunner()->PostTask(
FROM_HERE, base::BindLambdaForTesting([&connection_count, &run_loop] {
connection_count =
network::NetworkService::GetNetworkServiceForTesting()
->network_quality_estimator()
->GetPeerToPeerConnectionsCountChange();
run_loop.Quit();
}));
run_loop.Run();
return connection_count;
}
mojo::Remote<network::mojom::NetworkServiceTest> network_service_test;
content::GetNetworkService()->BindTestInterfaceForTesting(
network_service_test.BindNewPipeAndPassReceiver());
// TODO(crbug.com/41423903): Make sure the network process is started to
// avoid a deadlock on Android.
network_service_test.FlushForTesting();
mojo::ScopedAllowSyncCallForTesting allow_sync_call;
bool available = network_service_test->GetPeerToPeerConnectionsCountChange(
&connection_count);
EXPECT_TRUE(available);
return connection_count;
}
protected:
void StartServerAndOpenTabs() {
ASSERT_TRUE(embedded_test_server()->Start());
left_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
right_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage);
}
void DetectVideoAndHangUp() {
StartDetectingVideo(left_tab_, "remote-view");
StartDetectingVideo(right_tab_, "remote-view");
#if !BUILDFLAG(IS_MAC)
// Video is choppy on Mac OS X. http://crbug.com/443542.
WaitForVideoToPlay(left_tab_);
WaitForVideoToPlay(right_tab_);
#endif
HangUp(left_tab_);
HangUp(right_tab_);
}
raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged> left_tab_;
raw_ptr<content::WebContents, AcrossTasksDanglingUntriaged> right_tab_;
};
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsVP8) {
RunsAudioVideoWebRTCCallInTwoTabs("VP8");
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsVP9) {
RunsAudioVideoWebRTCCallInTwoTabs("VP9");
}
#if BUILDFLAG(RTC_USE_H264)
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsH264) {
// Only run test if run-time feature corresponding to |rtc_use_h264| is on.
if (!base::FeatureList::IsEnabled(
blink::features::kWebRtcH264WithOpenH264FFmpeg)) {
LOG(WARNING)
<< "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. "
"Skipping WebRtcBrowserTest.RunsAudioVideoWebRTCCallInTwoTabsH264 "
"(test \"OK\")";
return;
}
RunsAudioVideoWebRTCCallInTwoTabs("H264", true /* prefer_hw_video_codec */);
}
#endif // BUILDFLAG(RTC_USE_H264)
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, TestWebAudioMediaStream) {
// This tests against crash regressions for the WebAudio-MediaStream
// integration.
ASSERT_TRUE(embedded_test_server()->Start());
GURL url(embedded_test_server()->GetURL("/webrtc/webaudio_crash.html"));
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
content::WebContents* tab =
browser()->tab_strip_model()->GetActiveWebContents();
// A sleep is necessary to be able to detect the crash.
test::SleepInJavascript(tab, 1000);
ASSERT_FALSE(tab->IsCrashed());
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsOfferRsaAnswerRsa) {
RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec,
false /* prefer_hw_video_codec */,
kKeygenAlgorithmRsa, kKeygenAlgorithmRsa);
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsOfferEcdsaAnswerEcdsa) {
RunsAudioVideoWebRTCCallInTwoTabs(
WebRtcTestBase::kUseDefaultVideoCodec, false /* prefer_hw_video_codec */,
kKeygenAlgorithmEcdsa, kKeygenAlgorithmEcdsa);
}
IN_PROC_BROWSER_TEST_F(
WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateRsa) {
RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate(kKeygenAlgorithmRsa);
}
// TODO(crbug.com/40818639): Flaky on Linux ASAN.
#if BUILDFLAG(IS_LINUX) && defined(ADDRESS_SANITIZER)
#define MAYBE_RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa \
DISABLED_RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa
#else
#define MAYBE_RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa \
RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa
#endif
IN_PROC_BROWSER_TEST_F(
WebRtcBrowserTest,
MAYBE_RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa) {
RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate(kKeygenAlgorithmEcdsa);
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsOfferRsaAnswerEcdsa) {
RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec,
false /* prefer_hw_video_codec */,
kKeygenAlgorithmRsa, kKeygenAlgorithmEcdsa);
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsOfferEcdsaAnswerRsa) {
RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec,
false /* prefer_hw_video_codec */,
kKeygenAlgorithmEcdsa, kKeygenAlgorithmRsa);
}
IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest,
GetPeerToPeerConnectionsCountChangeFromNetworkService) {
EXPECT_EQ(0u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
StartServerAndOpenTabs();
SetupPeerconnectionWithLocalStream(left_tab_);
SetupPeerconnectionWithLocalStream(right_tab_);
NegotiateCall(left_tab_, right_tab_);
EXPECT_EQ(2u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
DetectVideoAndHangUp();
EXPECT_EQ(0u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
}
IN_PROC_BROWSER_TEST_F(
WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsEmitsGatheringStateChange) {
StartServerAndOpenTabs();
SetupPeerconnectionWithLocalStream(left_tab_);
SetupPeerconnectionWithLocalStream(right_tab_);
NegotiateCall(left_tab_, right_tab_);
std::string ice_gatheringstate =
ExecuteJavascript("getLastGatheringState()", left_tab_);
EXPECT_EQ("complete", ice_gatheringstate);
DetectVideoAndHangUp();
}
IN_PROC_BROWSER_TEST_F(
WebRtcBrowserTest,
RunsAudioVideoWebRTCCallInTwoTabsEmitsGatheringStateChange_ConnectionCount) {
EXPECT_EQ(0u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
StartServerAndOpenTabs();
SetupPeerconnectionWithLocalStream(left_tab_);
SetupPeerconnectionWithLocalStream(right_tab_);
NegotiateCall(left_tab_, right_tab_);
EXPECT_EQ(2u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
std::string ice_gatheringstate =
ExecuteJavascript("getLastGatheringState()", left_tab_);
EXPECT_EQ("complete", ice_gatheringstate);
DetectVideoAndHangUp();
EXPECT_EQ(0u, GetPeerToPeerConnectionsCountChangeFromNetworkService());
}
|