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 "chrome/browser/media/webrtc_browsertest_base.h" | 5 #include "chrome/browser/media/webrtc_browsertest_base.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 WebRtcTestBase::~WebRtcTestBase() { | 95 WebRtcTestBase::~WebRtcTestBase() { |
96 if (detect_errors_in_javascript_) { | 96 if (detect_errors_in_javascript_) { |
97 EXPECT_FALSE(hit_javascript_errors_.Get()) | 97 EXPECT_FALSE(hit_javascript_errors_.Get()) |
98 << "Encountered javascript errors during test execution (Search " | 98 << "Encountered javascript errors during test execution (Search " |
99 << "for Uncaught or ERROR:CONSOLE in the test output)."; | 99 << "for Uncaught or ERROR:CONSOLE in the test output)."; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void WebRtcTestBase::GetUserMediaAndAccept( | 103 bool WebRtcTestBase::GetUserMediaAndAccept( |
104 content::WebContents* tab_contents) const { | 104 content::WebContents* tab_contents) const { |
105 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | 105 return GetUserMediaWithSpecificConstraintsAndAccept( |
106 kAudioVideoCallConstraints); | 106 tab_contents, kAudioVideoCallConstraints); |
107 } | 107 } |
108 | 108 |
109 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 109 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
110 content::WebContents* tab_contents, | 110 content::WebContents* tab_contents, |
111 const std::string& constraints) const { | 111 const std::string& constraints) const { |
112 infobars::InfoBar* infobar = | 112 infobars::InfoBar* infobar = |
113 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 113 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
114 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 114 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
115 CloseInfoBarInTab(tab_contents, infobar); | 115 CloseInfoBarInTab(tab_contents, infobar); |
116 | 116 |
117 // Wait for WebRTC to call the success callback. | 117 // Wait for WebRTC to call the success callback. |
118 const char kOkGotStream[] = "ok-got-stream"; | 118 const char kOkGotStream[] = "ok-got-stream"; |
119 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, | 119 return test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
120 tab_contents)); | 120 tab_contents); |
121 } | 121 } |
122 | 122 |
123 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | 123 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
124 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 124 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
125 kAudioVideoCallConstraints); | 125 kAudioVideoCallConstraints); |
126 } | 126 } |
127 | 127 |
128 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | 128 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
129 content::WebContents* tab_contents, | 129 content::WebContents* tab_contents, |
130 const std::string& constraints) const { | 130 const std::string& constraints) const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 } | 186 } |
187 | 187 |
188 content::WebContents* | 188 content::WebContents* |
189 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( | 189 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( |
190 const GURL& url, | 190 const GURL& url, |
191 const std::string& constraints) const { | 191 const std::string& constraints) const { |
192 chrome::AddTabAt(browser(), GURL(), -1, true); | 192 chrome::AddTabAt(browser(), GURL(), -1, true); |
193 ui_test_utils::NavigateToURL(browser(), url); | 193 ui_test_utils::NavigateToURL(browser(), url); |
194 content::WebContents* new_tab = | 194 content::WebContents* new_tab = |
195 browser()->tab_strip_model()->GetActiveWebContents(); | 195 browser()->tab_strip_model()->GetActiveWebContents(); |
196 GetUserMediaWithSpecificConstraintsAndAccept(new_tab, constraints); | 196 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| 197 new_tab, constraints)); |
197 return new_tab; | 198 return new_tab; |
198 } | 199 } |
199 | 200 |
200 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( | 201 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( |
201 const std::string& test_page) const { | 202 const std::string& test_page) const { |
202 return OpenPageAndGetUserMediaInNewTab( | 203 return OpenPageAndGetUserMediaInNewTab( |
203 embedded_test_server()->GetURL(test_page)); | 204 embedded_test_server()->GetURL(test_page)); |
204 } | 205 } |
205 | 206 |
206 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( | 207 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 } | 331 } |
331 | 332 |
332 void WebRtcTestBase::StartDetectingVideo( | 333 void WebRtcTestBase::StartDetectingVideo( |
333 content::WebContents* tab_contents, | 334 content::WebContents* tab_contents, |
334 const std::string& video_element) const { | 335 const std::string& video_element) const { |
335 std::string javascript = base::StringPrintf( | 336 std::string javascript = base::StringPrintf( |
336 "startDetection('%s', 320, 240)", video_element.c_str()); | 337 "startDetection('%s', 320, 240)", video_element.c_str()); |
337 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); | 338 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); |
338 } | 339 } |
339 | 340 |
340 void WebRtcTestBase::WaitForVideoToPlay( | 341 bool WebRtcTestBase::WaitForVideoToPlay( |
341 content::WebContents* tab_contents) const { | 342 content::WebContents* tab_contents) const { |
342 EXPECT_TRUE(test::PollingWaitUntil("isVideoPlaying()", "video-playing", | 343 bool is_video_playing = test::PollingWaitUntil( |
343 tab_contents)); | 344 "isVideoPlaying()", "video-playing", tab_contents); |
| 345 EXPECT_TRUE(is_video_playing); |
| 346 return is_video_playing; |
344 } | 347 } |
345 | 348 |
346 std::string WebRtcTestBase::GetStreamSize( | 349 std::string WebRtcTestBase::GetStreamSize( |
347 content::WebContents* tab_contents, | 350 content::WebContents* tab_contents, |
348 const std::string& video_element) const { | 351 const std::string& video_element) const { |
349 std::string javascript = | 352 std::string javascript = |
350 base::StringPrintf("getStreamSize('%s')", video_element.c_str()); | 353 base::StringPrintf("getStreamSize('%s')", video_element.c_str()); |
351 std::string result = ExecuteJavascript(javascript, tab_contents); | 354 std::string result = ExecuteJavascript(javascript, tab_contents); |
352 EXPECT_TRUE(StartsWithASCII(result, "ok-", true)); | 355 EXPECT_TRUE(StartsWithASCII(result, "ok-", true)); |
353 return result.substr(3); | 356 return result.substr(3); |
(...skipping 14 matching lines...) Expand all Loading... |
368 #endif | 371 #endif |
369 } | 372 } |
370 | 373 |
371 bool WebRtcTestBase::OnWin8() const { | 374 bool WebRtcTestBase::OnWin8() const { |
372 #if defined(OS_WIN) | 375 #if defined(OS_WIN) |
373 return base::win::GetVersion() > base::win::VERSION_WIN7; | 376 return base::win::GetVersion() > base::win::VERSION_WIN7; |
374 #else | 377 #else |
375 return false; | 378 return false; |
376 #endif | 379 #endif |
377 } | 380 } |
OLD | NEW |