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/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/infobars/infobar.h" | 10 #include "chrome/browser/infobars/infobar.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 12 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
13 #include "chrome/browser/media/webrtc_browsertest_common.h" | 13 #include "chrome/browser/media/webrtc_browsertest_common.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
20 #include "net/test/embedded_test_server/embedded_test_server.h" | 20 #include "net/test/embedded_test_server/embedded_test_server.h" |
21 | 21 |
22 const char WebRtcTestBase::kAudioVideoCallConstraints[] = | 22 const char WebRtcTestBase::kAudioVideoCallConstraints[] = |
23 "'{audio: true, video: true}'"; | 23 "'{audio: true, video: true}'"; |
24 const char WebRtcTestBase::kAudioOnlyCallConstraints[] = "'{audio: true}'"; | 24 const char WebRtcTestBase::kAudioOnlyCallConstraints[] = "'{audio: true}'"; |
25 const char WebRtcTestBase::kVideoOnlyCallConstraints[] = "'{video: true}'"; | 25 const char WebRtcTestBase::kVideoOnlyCallConstraints[] = "'{video: true}'"; |
26 const char WebRtcTestBase::kFailedWithPermissionDeniedError[] = | 26 const char WebRtcTestBase::kFailedWithPermissionDeniedError[] = |
27 "failed-with-error-PermissionDeniedError"; | 27 "failed-with-error-PermissionDeniedError"; |
| 28 const char WebRtcTestBase::kFailedWithPermissionDismissedError[] = |
| 29 "failed-with-error-PermissionDismissedError"; |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 base::LazyInstance<bool> hit_javascript_errors_ = | 33 base::LazyInstance<bool> hit_javascript_errors_ = |
32 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
33 | 35 |
34 // Intercepts all log messages. We always attach this handler but only look at | 36 // Intercepts all log messages. We always attach this handler but only look at |
35 // the results if the test requests so. Note that this will only work if the | 37 // the results if the test requests so. Note that this will only work if the |
36 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they | 38 // WebrtcTestBase-inheriting test cases do not run in parallel (if they did they |
37 // would race to look at the log, which is global to all tests). | 39 // would race to look at the log, which is global to all tests). |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 111 |
110 void WebRtcTestBase::GetUserMediaAndDismiss( | 112 void WebRtcTestBase::GetUserMediaAndDismiss( |
111 content::WebContents* tab_contents) const { | 113 content::WebContents* tab_contents) const { |
112 InfoBar* infobar = | 114 InfoBar* infobar = |
113 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); | 115 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
114 infobar->delegate()->InfoBarDismissed(); | 116 infobar->delegate()->InfoBarDismissed(); |
115 CloseInfoBarInTab(tab_contents, infobar); | 117 CloseInfoBarInTab(tab_contents, infobar); |
116 | 118 |
117 // A dismiss should be treated like a deny. | 119 // A dismiss should be treated like a deny. |
118 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | 120 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
119 kFailedWithPermissionDeniedError, tab_contents)); | 121 kFailedWithPermissionDismissedError, |
| 122 tab_contents)); |
120 } | 123 } |
121 | 124 |
122 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, | 125 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
123 const std::string& constraints) const { | 126 const std::string& constraints) const { |
124 // Request user media: this will launch the media stream info bar. | 127 // Request user media: this will launch the media stream info bar. |
125 std::string result; | 128 std::string result; |
126 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 129 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
127 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); | 130 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); |
128 EXPECT_EQ("ok-requested", result); | 131 EXPECT_EQ("ok-requested", result); |
129 } | 132 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 std::string javascript = base::StringPrintf( | 262 std::string javascript = base::StringPrintf( |
260 "startDetection('%s', 320, 240)", video_element.c_str()); | 263 "startDetection('%s', 320, 240)", video_element.c_str()); |
261 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); | 264 EXPECT_EQ("ok-started", ExecuteJavascript(javascript, tab_contents)); |
262 } | 265 } |
263 | 266 |
264 void WebRtcTestBase::WaitForVideoToPlay( | 267 void WebRtcTestBase::WaitForVideoToPlay( |
265 content::WebContents* tab_contents) const { | 268 content::WebContents* tab_contents) const { |
266 EXPECT_TRUE(PollingWaitUntil("isVideoPlaying()", "video-playing", | 269 EXPECT_TRUE(PollingWaitUntil("isVideoPlaying()", "video-playing", |
267 tab_contents)); | 270 tab_contents)); |
268 } | 271 } |
OLD | NEW |