| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/process/launch.h" | 8 #include "base/process/launch.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/test_timeouts.h" | 12 #include "base/test/test_timeouts.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/infobars/infobar.h" | 16 #include "chrome/browser/infobars/infobar.h" |
| 17 #include "chrome/browser/infobars/infobar_service.h" | 17 #include "chrome/browser/infobars/infobar_service.h" |
| 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 18 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| 19 #include "chrome/browser/media/webrtc_browsertest_base.h" |
| 19 #include "chrome/browser/media/webrtc_browsertest_common.h" | 20 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 20 #include "chrome/browser/media/webrtc_log_uploader.h" | 21 #include "chrome/browser/media/webrtc_log_uploader.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_tabstrip.h" | 24 #include "chrome/browser/ui/browser_tabstrip.h" |
| 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 27 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 28 #include "chrome/test/base/ui_test_utils.h" |
| 28 #include "chrome/test/ui/ui_test.h" | 29 #include "chrome/test/ui/ui_test.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 40 #endif | 41 #endif |
| 41 | 42 |
| 42 static const char kMainWebrtcTestHtmlPage[] = | 43 static const char kMainWebrtcTestHtmlPage[] = |
| 43 "/webrtc/webrtc_jsep01_test.html"; | 44 "/webrtc/webrtc_jsep01_test.html"; |
| 44 | 45 |
| 45 static const char kTestLoggingSessionId[] = "0123456789abcdef"; | 46 static const char kTestLoggingSessionId[] = "0123456789abcdef"; |
| 46 | 47 |
| 47 // Top-level integration test for WebRTC. Requires a real webcam and microphone | 48 // Top-level integration test for WebRTC. Requires a real webcam and microphone |
| 48 // on the running system. This test is not meant to run in the main browser | 49 // on the running system. This test is not meant to run in the main browser |
| 49 // test suite since normal tester machines do not have webcams. | 50 // test suite since normal tester machines do not have webcams. |
| 50 class WebrtcBrowserTest : public InProcessBrowserTest { | 51 class WebrtcBrowserTest : public WebrtcTestBase { |
| 51 public: | 52 public: |
| 52 // See comment in test where this class is used for purpose. | 53 // See comment in test where this class is used for purpose. |
| 53 class BrowserMessageFilter : public content::BrowserMessageFilter { | 54 class BrowserMessageFilter : public content::BrowserMessageFilter { |
| 54 public: | 55 public: |
| 55 explicit BrowserMessageFilter( | 56 explicit BrowserMessageFilter( |
| 56 const base::Closure& on_channel_closing) | 57 const base::Closure& on_channel_closing) |
| 57 : on_channel_closing_(on_channel_closing) {} | 58 : on_channel_closing_(on_channel_closing) {} |
| 58 | 59 |
| 59 virtual void OnChannelClosing() OVERRIDE { | 60 virtual void OnChannelClosing() OVERRIDE { |
| 60 // Posting on the file thread ensures that the callback is run after | 61 // Posting on the file thread ensures that the callback is run after |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // Convenience method which executes the provided javascript in the context | 103 // Convenience method which executes the provided javascript in the context |
| 103 // of the provided web contents and returns what it evaluated to. | 104 // of the provided web contents and returns what it evaluated to. |
| 104 std::string ExecuteJavascript(const std::string& javascript, | 105 std::string ExecuteJavascript(const std::string& javascript, |
| 105 content::WebContents* tab_contents) { | 106 content::WebContents* tab_contents) { |
| 106 std::string result; | 107 std::string result; |
| 107 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 108 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 108 tab_contents, javascript, &result)); | 109 tab_contents, javascript, &result)); |
| 109 return result; | 110 return result; |
| 110 } | 111 } |
| 111 | 112 |
| 112 void GetUserMedia(content::WebContents* tab_contents) { | |
| 113 content::WindowedNotificationObserver infobar_added( | |
| 114 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | |
| 115 content::NotificationService::AllSources()); | |
| 116 | |
| 117 // Request user media: this will launch the media stream info bar. | |
| 118 EXPECT_EQ("ok-requested", ExecuteJavascript( | |
| 119 "getUserMedia('{video: true, audio: true}');", tab_contents)); | |
| 120 | |
| 121 // Wait for the bar to pop up, then accept. | |
| 122 infobar_added.Wait(); | |
| 123 content::Details<InfoBarAddedDetails> details(infobar_added.details()); | |
| 124 MediaStreamInfoBarDelegate* media_infobar = | |
| 125 details->AsMediaStreamInfoBarDelegate(); | |
| 126 media_infobar->Accept(); | |
| 127 | |
| 128 // Wait for WebRTC to call the success callback. | |
| 129 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult();", | |
| 130 "ok-got-stream", | |
| 131 tab_contents)); | |
| 132 } | |
| 133 | |
| 134 // Ensures we didn't get any errors asynchronously (e.g. while no javascript | 113 // Ensures we didn't get any errors asynchronously (e.g. while no javascript |
| 135 // call from this test was outstanding). | 114 // call from this test was outstanding). |
| 136 // TODO(phoglund): this becomes obsolete when we switch to communicating with | 115 // TODO(phoglund): this becomes obsolete when we switch to communicating with |
| 137 // the DOM message queue. | 116 // the DOM message queue. |
| 138 void AssertNoAsynchronousErrors(content::WebContents* tab_contents) { | 117 void AssertNoAsynchronousErrors(content::WebContents* tab_contents) { |
| 139 EXPECT_EQ("ok-no-errors", | 118 EXPECT_EQ("ok-no-errors", |
| 140 ExecuteJavascript("getAnyTestFailures()", tab_contents)); | 119 ExecuteJavascript("getAnyTestFailures()", tab_contents)); |
| 141 } | 120 } |
| 142 | 121 |
| 143 // The peer connection server lets our two tabs find each other and talk to | 122 // The peer connection server lets our two tabs find each other and talk to |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 }; | 214 }; |
| 236 | 215 |
| 237 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, | 216 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, |
| 238 MANUAL_RunsAudioVideoWebRTCCallInTwoTabs) { | 217 MANUAL_RunsAudioVideoWebRTCCallInTwoTabs) { |
| 239 EXPECT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 218 EXPECT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 240 | 219 |
| 241 ui_test_utils::NavigateToURL( | 220 ui_test_utils::NavigateToURL( |
| 242 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 221 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 243 content::WebContents* left_tab = | 222 content::WebContents* left_tab = |
| 244 browser()->tab_strip_model()->GetActiveWebContents(); | 223 browser()->tab_strip_model()->GetActiveWebContents(); |
| 245 GetUserMedia(left_tab); | 224 GetUserMediaAndAccept(left_tab); |
| 246 | 225 |
| 247 chrome::AddBlankTabAt(browser(), -1, true); | 226 chrome::AddBlankTabAt(browser(), -1, true); |
| 248 content::WebContents* right_tab = | 227 content::WebContents* right_tab = |
| 249 browser()->tab_strip_model()->GetActiveWebContents(); | 228 browser()->tab_strip_model()->GetActiveWebContents(); |
| 250 ui_test_utils::NavigateToURL( | 229 ui_test_utils::NavigateToURL( |
| 251 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 230 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 252 GetUserMedia(right_tab); | 231 GetUserMediaAndAccept(right_tab); |
| 253 | 232 |
| 254 ConnectToPeerConnectionServer("peer 1", left_tab); | 233 ConnectToPeerConnectionServer("peer 1", left_tab); |
| 255 ConnectToPeerConnectionServer("peer 2", right_tab); | 234 ConnectToPeerConnectionServer("peer 2", right_tab); |
| 256 | 235 |
| 257 EstablishCall(left_tab, right_tab); | 236 EstablishCall(left_tab, right_tab); |
| 258 | 237 |
| 259 AssertNoAsynchronousErrors(left_tab); | 238 AssertNoAsynchronousErrors(left_tab); |
| 260 AssertNoAsynchronousErrors(right_tab); | 239 AssertNoAsynchronousErrors(right_tab); |
| 261 | 240 |
| 262 StartDetectingVideo(left_tab, "remote-view"); | 241 StartDetectingVideo(left_tab, "remote-view"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 274 } | 253 } |
| 275 | 254 |
| 276 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, | 255 IN_PROC_BROWSER_TEST_F(WebrtcBrowserTest, |
| 277 MANUAL_TestMediaStreamTrackEnableDisable) { | 256 MANUAL_TestMediaStreamTrackEnableDisable) { |
| 278 EXPECT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 257 EXPECT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 279 | 258 |
| 280 ui_test_utils::NavigateToURL( | 259 ui_test_utils::NavigateToURL( |
| 281 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 260 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 282 content::WebContents* left_tab = | 261 content::WebContents* left_tab = |
| 283 browser()->tab_strip_model()->GetActiveWebContents(); | 262 browser()->tab_strip_model()->GetActiveWebContents(); |
| 284 GetUserMedia(left_tab); | 263 GetUserMediaAndAccept(left_tab); |
| 285 | 264 |
| 286 chrome::AddBlankTabAt(browser(), -1, true); | 265 chrome::AddBlankTabAt(browser(), -1, true); |
| 287 content::WebContents* right_tab = | 266 content::WebContents* right_tab = |
| 288 browser()->tab_strip_model()->GetActiveWebContents(); | 267 browser()->tab_strip_model()->GetActiveWebContents(); |
| 289 ui_test_utils::NavigateToURL( | 268 ui_test_utils::NavigateToURL( |
| 290 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 269 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 291 GetUserMedia(right_tab); | 270 GetUserMediaAndAccept(right_tab); |
| 292 | 271 |
| 293 ConnectToPeerConnectionServer("peer 1", left_tab); | 272 ConnectToPeerConnectionServer("peer 1", left_tab); |
| 294 ConnectToPeerConnectionServer("peer 2", right_tab); | 273 ConnectToPeerConnectionServer("peer 2", right_tab); |
| 295 | 274 |
| 296 EstablishCall(left_tab, right_tab); | 275 EstablishCall(left_tab, right_tab); |
| 297 | 276 |
| 298 AssertNoAsynchronousErrors(left_tab); | 277 AssertNoAsynchronousErrors(left_tab); |
| 299 AssertNoAsynchronousErrors(right_tab); | 278 AssertNoAsynchronousErrors(right_tab); |
| 300 | 279 |
| 301 StartDetectingVideo(left_tab, "remote-view"); | 280 StartDetectingVideo(left_tab, "remote-view"); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 command_line->AppendSwitch(switches::kEnableMetricsReportingForTesting); | 341 command_line->AppendSwitch(switches::kEnableMetricsReportingForTesting); |
| 363 | 342 |
| 364 // Tell the uploader to save the multipart to a buffer instead of uploading. | 343 // Tell the uploader to save the multipart to a buffer instead of uploading. |
| 365 std::string multipart; | 344 std::string multipart; |
| 366 g_browser_process->webrtc_log_uploader()-> | 345 g_browser_process->webrtc_log_uploader()-> |
| 367 OverrideUploadWithBufferForTesting(&multipart); | 346 OverrideUploadWithBufferForTesting(&multipart); |
| 368 ui_test_utils::NavigateToURL( | 347 ui_test_utils::NavigateToURL( |
| 369 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 348 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 370 content::WebContents* left_tab = | 349 content::WebContents* left_tab = |
| 371 browser()->tab_strip_model()->GetActiveWebContents(); | 350 browser()->tab_strip_model()->GetActiveWebContents(); |
| 372 GetUserMedia(left_tab); | 351 GetUserMediaAndAccept(left_tab); |
| 373 | 352 |
| 374 chrome::AddBlankTabAt(browser(), -1, true); | 353 chrome::AddBlankTabAt(browser(), -1, true); |
| 375 content::WebContents* right_tab = | 354 content::WebContents* right_tab = |
| 376 browser()->tab_strip_model()->GetActiveWebContents(); | 355 browser()->tab_strip_model()->GetActiveWebContents(); |
| 377 ui_test_utils::NavigateToURL( | 356 ui_test_utils::NavigateToURL( |
| 378 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); | 357 browser(), embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage)); |
| 379 GetUserMedia(right_tab); | 358 GetUserMediaAndAccept(right_tab); |
| 380 | 359 |
| 381 ConnectToPeerConnectionServer("peer 1", left_tab); | 360 ConnectToPeerConnectionServer("peer 1", left_tab); |
| 382 ConnectToPeerConnectionServer("peer 2", right_tab); | 361 ConnectToPeerConnectionServer("peer 2", right_tab); |
| 383 | 362 |
| 384 EstablishCall(left_tab, right_tab, true); | 363 EstablishCall(left_tab, right_tab, true); |
| 385 | 364 |
| 386 AssertNoAsynchronousErrors(left_tab); | 365 AssertNoAsynchronousErrors(left_tab); |
| 387 AssertNoAsynchronousErrors(right_tab); | 366 AssertNoAsynchronousErrors(right_tab); |
| 388 | 367 |
| 389 StartDetectingVideo(left_tab, "remote-view"); | 368 StartDetectingVideo(left_tab, "remote-view"); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 multipart_lines[25].c_str()); | 461 multipart_lines[25].c_str()); |
| 483 EXPECT_STREQ("Content-Type: application/gzip", | 462 EXPECT_STREQ("Content-Type: application/gzip", |
| 484 multipart_lines[26].c_str()); | 463 multipart_lines[26].c_str()); |
| 485 EXPECT_TRUE(multipart_lines[27].empty()); | 464 EXPECT_TRUE(multipart_lines[27].empty()); |
| 486 EXPECT_TRUE(multipart_lines[28].empty()); // The removed zip part. | 465 EXPECT_TRUE(multipart_lines[28].empty()); // The removed zip part. |
| 487 std::string final_delimiter = boundary; | 466 std::string final_delimiter = boundary; |
| 488 final_delimiter += "--"; | 467 final_delimiter += "--"; |
| 489 EXPECT_STREQ(final_delimiter.c_str(), multipart_lines[29].c_str()); | 468 EXPECT_STREQ(final_delimiter.c_str(), multipart_lines[29].c_str()); |
| 490 EXPECT_TRUE(multipart_lines[30].empty()); | 469 EXPECT_TRUE(multipart_lines[30].empty()); |
| 491 } | 470 } |
| OLD | NEW |