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" |
11 #include "chrome/browser/infobars/infobar.h" | |
12 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 12 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
14 #include "chrome/browser/media/webrtc_browsertest_common.h" | 13 #include "chrome/browser/media/webrtc_browsertest_common.h" |
15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_tabstrip.h" | 15 #include "chrome/browser/ui/browser_tabstrip.h" |
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "components/infobars/core/infobar.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
21 #include "net/test/embedded_test_server/embedded_test_server.h" | 21 #include "net/test/embedded_test_server/embedded_test_server.h" |
22 | 22 |
23 const char WebRtcTestBase::kAudioVideoCallConstraints[] = | 23 const char WebRtcTestBase::kAudioVideoCallConstraints[] = |
24 "'{audio: true, video: true}'"; | 24 "'{audio: true, video: true}'"; |
25 const char WebRtcTestBase::kAudioVideoCallConstraintsQVGA[] = | 25 const char WebRtcTestBase::kAudioVideoCallConstraintsQVGA[] = |
26 "'{audio: true, video: {mandatory: {minWidth: 320, maxWidth: 320, " | 26 "'{audio: true, video: {mandatory: {minWidth: 320, maxWidth: 320, " |
27 " minHeight: 240, maxHeight: 240}}}'"; | 27 " minHeight: 240, maxHeight: 240}}}'"; |
28 const char WebRtcTestBase::kAudioVideoCallConstraints360p[] = | 28 const char WebRtcTestBase::kAudioVideoCallConstraints360p[] = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 void WebRtcTestBase::GetUserMediaAndAccept( | 92 void WebRtcTestBase::GetUserMediaAndAccept( |
93 content::WebContents* tab_contents) const { | 93 content::WebContents* tab_contents) const { |
94 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | 94 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, |
95 kAudioVideoCallConstraints); | 95 kAudioVideoCallConstraints); |
96 } | 96 } |
97 | 97 |
98 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 98 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
99 content::WebContents* tab_contents, | 99 content::WebContents* tab_contents, |
100 const std::string& constraints) const { | 100 const std::string& constraints) const { |
101 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 101 infobars::InfoBar* infobar = |
| 102 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
102 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); | 103 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
103 CloseInfoBarInTab(tab_contents, infobar); | 104 CloseInfoBarInTab(tab_contents, infobar); |
104 | 105 |
105 // Wait for WebRTC to call the success callback. | 106 // Wait for WebRTC to call the success callback. |
106 const char kOkGotStream[] = "ok-got-stream"; | 107 const char kOkGotStream[] = "ok-got-stream"; |
107 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, | 108 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
108 tab_contents)); | 109 tab_contents)); |
109 } | 110 } |
110 | 111 |
111 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | 112 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
112 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 113 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
113 kAudioVideoCallConstraints); | 114 kAudioVideoCallConstraints); |
114 } | 115 } |
115 | 116 |
116 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | 117 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
117 content::WebContents* tab_contents, | 118 content::WebContents* tab_contents, |
118 const std::string& constraints) const { | 119 const std::string& constraints) const { |
119 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 120 infobars::InfoBar* infobar = |
| 121 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
120 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | 122 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
121 CloseInfoBarInTab(tab_contents, infobar); | 123 CloseInfoBarInTab(tab_contents, infobar); |
122 | 124 |
123 // Wait for WebRTC to call the fail callback. | 125 // Wait for WebRTC to call the fail callback. |
124 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 126 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
125 kFailedWithPermissionDeniedError, | 127 kFailedWithPermissionDeniedError, |
126 tab_contents)); | 128 tab_contents)); |
127 } | 129 } |
128 | 130 |
129 void WebRtcTestBase::GetUserMediaAndDismiss( | 131 void WebRtcTestBase::GetUserMediaAndDismiss( |
130 content::WebContents* tab_contents) const { | 132 content::WebContents* tab_contents) const { |
131 InfoBar* infobar = | 133 infobars::InfoBar* infobar = |
132 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); | 134 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
133 infobar->delegate()->InfoBarDismissed(); | 135 infobar->delegate()->InfoBarDismissed(); |
134 CloseInfoBarInTab(tab_contents, infobar); | 136 CloseInfoBarInTab(tab_contents, infobar); |
135 | 137 |
136 // A dismiss should be treated like a deny. | 138 // A dismiss should be treated like a deny. |
137 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 139 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
138 kFailedWithPermissionDismissedError, | 140 kFailedWithPermissionDismissedError, |
139 tab_contents)); | 141 tab_contents)); |
140 } | 142 } |
141 | 143 |
142 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, | 144 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
143 const std::string& constraints) const { | 145 const std::string& constraints) const { |
144 // Request user media: this will launch the media stream info bar. | 146 // Request user media: this will launch the media stream info bar. |
145 std::string result; | 147 std::string result; |
146 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 148 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
147 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); | 149 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); |
148 EXPECT_EQ("ok-requested", result); | 150 EXPECT_EQ("ok-requested", result); |
149 } | 151 } |
150 | 152 |
151 InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( | 153 infobars::InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( |
152 content::WebContents* tab_contents, | 154 content::WebContents* tab_contents, |
153 const std::string& constraints) const { | 155 const std::string& constraints) const { |
154 content::WindowedNotificationObserver infobar_added( | 156 content::WindowedNotificationObserver infobar_added( |
155 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 157 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
156 content::NotificationService::AllSources()); | 158 content::NotificationService::AllSources()); |
157 | 159 |
158 // Request user media: this will launch the media stream info bar. | 160 // Request user media: this will launch the media stream info bar. |
159 GetUserMedia(tab_contents, constraints); | 161 GetUserMedia(tab_contents, constraints); |
160 | 162 |
161 // Wait for the bar to pop up, then return it. | 163 // Wait for the bar to pop up, then return it. |
162 infobar_added.Wait(); | 164 infobar_added.Wait(); |
163 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); | 165 content::Details<infobars::InfoBar::AddedDetails> details( |
| 166 infobar_added.details()); |
164 EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); | 167 EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); |
165 return details.ptr(); | 168 return details.ptr(); |
166 } | 169 } |
167 | 170 |
168 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( | 171 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( |
169 const GURL& url) const { | 172 const GURL& url) const { |
170 return OpenPageAndGetUserMediaInNewTabWithConstraints( | 173 return OpenPageAndGetUserMediaInNewTabWithConstraints( |
171 url, kAudioVideoCallConstraints); | 174 url, kAudioVideoCallConstraints); |
172 } | 175 } |
173 | 176 |
(...skipping 24 matching lines...) Expand all Loading... |
198 content::WindowedNotificationObserver infobar_added( | 201 content::WindowedNotificationObserver infobar_added( |
199 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 202 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
200 content::NotificationService::AllSources()); | 203 content::NotificationService::AllSources()); |
201 | 204 |
202 ui_test_utils::NavigateToURL(browser(), url); | 205 ui_test_utils::NavigateToURL(browser(), url); |
203 | 206 |
204 infobar_added.Wait(); | 207 infobar_added.Wait(); |
205 | 208 |
206 content::WebContents* tab_contents = | 209 content::WebContents* tab_contents = |
207 browser()->tab_strip_model()->GetActiveWebContents(); | 210 browser()->tab_strip_model()->GetActiveWebContents(); |
208 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); | 211 content::Details<infobars::InfoBar::AddedDetails> details( |
209 InfoBar* infobar = details.ptr(); | 212 infobar_added.details()); |
| 213 infobars::InfoBar* infobar = details.ptr(); |
210 EXPECT_TRUE(infobar); | 214 EXPECT_TRUE(infobar); |
211 infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept(); | 215 infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept(); |
212 | 216 |
213 CloseInfoBarInTab(tab_contents, infobar); | 217 CloseInfoBarInTab(tab_contents, infobar); |
214 return tab_contents; | 218 return tab_contents; |
215 } | 219 } |
216 | 220 |
217 void WebRtcTestBase::CloseInfoBarInTab( | 221 void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents, |
218 content::WebContents* tab_contents, | 222 infobars::InfoBar* infobar) const { |
219 InfoBar* infobar) const { | |
220 content::WindowedNotificationObserver infobar_removed( | 223 content::WindowedNotificationObserver infobar_removed( |
221 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 224 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
222 content::NotificationService::AllSources()); | 225 content::NotificationService::AllSources()); |
223 | 226 |
224 InfoBarService* infobar_service = | 227 InfoBarService* infobar_service = |
225 InfoBarService::FromWebContents(tab_contents); | 228 InfoBarService::FromWebContents(tab_contents); |
226 infobar_service->RemoveInfoBar(infobar); | 229 infobar_service->RemoveInfoBar(infobar); |
227 | 230 |
228 infobar_removed.Wait(); | 231 infobar_removed.Wait(); |
229 } | 232 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 EXPECT_TRUE(StartsWithASCII(result, "ok-", true)); | 313 EXPECT_TRUE(StartsWithASCII(result, "ok-", true)); |
311 return result.substr(3); | 314 return result.substr(3); |
312 } | 315 } |
313 | 316 |
314 bool WebRtcTestBase::HasWebcamAvailableOnSystem( | 317 bool WebRtcTestBase::HasWebcamAvailableOnSystem( |
315 content::WebContents* tab_contents) const { | 318 content::WebContents* tab_contents) const { |
316 std::string result = | 319 std::string result = |
317 ExecuteJavascript("HasVideoSourceOnSystem();", tab_contents); | 320 ExecuteJavascript("HasVideoSourceOnSystem();", tab_contents); |
318 return result == "has-video-source"; | 321 return result == "has-video-source"; |
319 } | 322 } |
OLD | NEW |