OLD | NEW |
| (Empty) |
1 // Copyright 2013 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 "base/command_line.h" | |
6 #include "base/strings/stringprintf.h" | |
7 #include "build/build_config.h" | |
8 #include "chrome/browser/media/webrtc_browsertest_base.h" | |
9 #include "chrome/browser/media/webrtc_browsertest_common.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/browser_tabstrip.h" | |
12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
13 #include "chrome/common/chrome_switches.h" | |
14 #include "chrome/test/base/in_process_browser_test.h" | |
15 #include "chrome/test/base/ui_test_utils.h" | |
16 #include "content/public/common/content_switches.h" | |
17 #include "content/public/common/feature_h264_with_openh264_ffmpeg.h" | |
18 #include "content/public/common/features.h" | |
19 #include "content/public/test/browser_test_utils.h" | |
20 #include "media/base/media_switches.h" | |
21 #include "net/test/embedded_test_server/embedded_test_server.h" | |
22 | |
23 static const char kMainWebrtcTestHtmlPage[] = | |
24 "/webrtc/webrtc_jsep01_test.html"; | |
25 | |
26 static const char kKeygenAlgorithmRsa[] = | |
27 "{ name: \"RSASSA-PKCS1-v1_5\", modulusLength: 2048, publicExponent: " | |
28 "new Uint8Array([1, 0, 1]), hash: \"SHA-256\" }"; | |
29 static const char kKeygenAlgorithmEcdsa[] = | |
30 "{ name: \"ECDSA\", namedCurve: \"P-256\" }"; | |
31 | |
32 // Top-level integration test for WebRTC. It always uses fake devices; see | |
33 // WebRtcWebcamBrowserTest for a test that acquires any real webcam on the | |
34 // system. | |
35 class WebRtcBrowserTest : public WebRtcTestBase { | |
36 public: | |
37 WebRtcBrowserTest() : left_tab_(nullptr), right_tab_(nullptr) {} | |
38 | |
39 void SetUpInProcessBrowserTestFixture() override { | |
40 DetectErrorsInJavaScript(); // Look for errors in our rather complex js. | |
41 } | |
42 | |
43 void SetUpCommandLine(base::CommandLine* command_line) override { | |
44 // Ensure the infobar is enabled, since we expect that in this test. | |
45 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)); | |
46 | |
47 // Always use fake devices. | |
48 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | |
49 | |
50 // Flag used by TestWebAudioMediaStream to force garbage collection. | |
51 command_line->AppendSwitchASCII(switches::kJavaScriptFlags, "--expose-gc"); | |
52 } | |
53 | |
54 void RunsAudioVideoWebRTCCallInTwoTabs( | |
55 const std::string& video_codec = WebRtcTestBase::kUseDefaultVideoCodec, | |
56 const std::string& offer_cert_keygen_alg = | |
57 WebRtcTestBase::kUseDefaultCertKeygen, | |
58 const std::string& answer_cert_keygen_alg = | |
59 WebRtcTestBase::kUseDefaultCertKeygen) { | |
60 StartServerAndOpenTabs(); | |
61 | |
62 SetupPeerconnectionWithLocalStream(left_tab_, offer_cert_keygen_alg); | |
63 SetupPeerconnectionWithLocalStream(right_tab_, answer_cert_keygen_alg); | |
64 | |
65 if (!video_codec.empty()) { | |
66 SetDefaultVideoCodec(left_tab_, video_codec); | |
67 SetDefaultVideoCodec(right_tab_, video_codec); | |
68 } | |
69 NegotiateCall(left_tab_, right_tab_); | |
70 | |
71 DetectVideoAndHangUp(); | |
72 } | |
73 | |
74 void RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate( | |
75 const std::string& cert_keygen_alg = | |
76 WebRtcTestBase::kUseDefaultCertKeygen) { | |
77 StartServerAndOpenTabs(); | |
78 | |
79 // Generate and clone a certificate, resulting in JavaScript variable | |
80 // |gCertificateClone| being set to the resulting clone. | |
81 DeleteDatabase(left_tab_); | |
82 OpenDatabase(left_tab_); | |
83 GenerateAndCloneCertificate(left_tab_, cert_keygen_alg); | |
84 CloseDatabase(left_tab_); | |
85 DeleteDatabase(left_tab_); | |
86 | |
87 SetupPeerconnectionWithCertificateAndLocalStream( | |
88 left_tab_, "gCertificateClone"); | |
89 SetupPeerconnectionWithLocalStream(right_tab_, cert_keygen_alg); | |
90 | |
91 NegotiateCall(left_tab_, right_tab_); | |
92 | |
93 DetectVideoAndHangUp(); | |
94 } | |
95 | |
96 protected: | |
97 void StartServerAndOpenTabs() { | |
98 ASSERT_TRUE(embedded_test_server()->Start()); | |
99 left_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
100 right_tab_ = OpenTestPageAndGetUserMediaInNewTab(kMainWebrtcTestHtmlPage); | |
101 } | |
102 | |
103 void DetectVideoAndHangUp() { | |
104 StartDetectingVideo(left_tab_, "remote-view"); | |
105 StartDetectingVideo(right_tab_, "remote-view"); | |
106 #if !defined(OS_MACOSX) | |
107 // Video is choppy on Mac OS X. http://crbug.com/443542. | |
108 WaitForVideoToPlay(left_tab_); | |
109 WaitForVideoToPlay(right_tab_); | |
110 #endif | |
111 HangUp(left_tab_); | |
112 HangUp(right_tab_); | |
113 } | |
114 | |
115 content::WebContents* left_tab_; | |
116 content::WebContents* right_tab_; | |
117 }; | |
118 | |
119 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
120 RunsAudioVideoWebRTCCallInTwoTabsVP8) { | |
121 RunsAudioVideoWebRTCCallInTwoTabs("VP8"); | |
122 } | |
123 | |
124 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
125 RunsAudioVideoWebRTCCallInTwoTabsVP9) { | |
126 RunsAudioVideoWebRTCCallInTwoTabs("VP9"); | |
127 } | |
128 | |
129 #if BUILDFLAG(RTC_USE_H264) | |
130 | |
131 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
132 RunsAudioVideoWebRTCCallInTwoTabsH264) { | |
133 // Only run test if run-time feature corresponding to |rtc_use_h264| is on. | |
134 if (!base::FeatureList::IsEnabled(content::kWebRtcH264WithOpenH264FFmpeg)) { | |
135 LOG(WARNING) << "Run-time feature WebRTC-H264WithOpenH264FFmpeg disabled. " | |
136 "Skipping WebRtcBrowserTest.RunsAudioVideoWebRTCCallInTwoTabsH264 " | |
137 "(test \"OK\")"; | |
138 return; | |
139 } | |
140 RunsAudioVideoWebRTCCallInTwoTabs("H264"); | |
141 } | |
142 | |
143 #endif // BUILDFLAG(RTC_USE_H264) | |
144 | |
145 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, TestWebAudioMediaStream) { | |
146 // This tests against crash regressions for the WebAudio-MediaStream | |
147 // integration. | |
148 ASSERT_TRUE(embedded_test_server()->Start()); | |
149 GURL url(embedded_test_server()->GetURL("/webrtc/webaudio_crash.html")); | |
150 ui_test_utils::NavigateToURL(browser(), url); | |
151 content::WebContents* tab = | |
152 browser()->tab_strip_model()->GetActiveWebContents(); | |
153 | |
154 // A sleep is necessary to be able to detect the crash. | |
155 test::SleepInJavascript(tab, 1000); | |
156 | |
157 ASSERT_FALSE(tab->IsCrashed()); | |
158 } | |
159 | |
160 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
161 RunsAudioVideoWebRTCCallInTwoTabsOfferRsaAnswerRsa) { | |
162 RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec, | |
163 kKeygenAlgorithmRsa, | |
164 kKeygenAlgorithmRsa); | |
165 } | |
166 | |
167 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
168 RunsAudioVideoWebRTCCallInTwoTabsOfferEcdsaAnswerEcdsa) { | |
169 RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec, | |
170 kKeygenAlgorithmEcdsa, | |
171 kKeygenAlgorithmEcdsa); | |
172 } | |
173 | |
174 IN_PROC_BROWSER_TEST_F( | |
175 WebRtcBrowserTest, | |
176 RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateRsa) { | |
177 RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate(kKeygenAlgorithmRsa); | |
178 } | |
179 | |
180 IN_PROC_BROWSER_TEST_F( | |
181 WebRtcBrowserTest, | |
182 RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificateEcdsa) { | |
183 RunsAudioVideoWebRTCCallInTwoTabsWithClonedCertificate(kKeygenAlgorithmEcdsa); | |
184 } | |
185 | |
186 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
187 RunsAudioVideoWebRTCCallInTwoTabsOfferRsaAnswerEcdsa) { | |
188 RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec, | |
189 kKeygenAlgorithmRsa, | |
190 kKeygenAlgorithmEcdsa); | |
191 } | |
192 | |
193 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
194 RunsAudioVideoWebRTCCallInTwoTabsOfferEcdsaAnswerRsa) { | |
195 RunsAudioVideoWebRTCCallInTwoTabs(WebRtcTestBase::kUseDefaultVideoCodec, | |
196 kKeygenAlgorithmEcdsa, | |
197 kKeygenAlgorithmRsa); | |
198 } | |
199 | |
200 IN_PROC_BROWSER_TEST_F(WebRtcBrowserTest, | |
201 RunsAudioVideoWebRTCCallInTwoTabsGetStats) { | |
202 StartServerAndOpenTabs(); | |
203 SetupPeerconnectionWithLocalStream(left_tab_); | |
204 SetupPeerconnectionWithLocalStream(right_tab_); | |
205 NegotiateCall(left_tab_, right_tab_); | |
206 | |
207 VerifyStatsGenerated(left_tab_); | |
208 | |
209 DetectVideoAndHangUp(); | |
210 } | |
OLD | NEW |