Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Side by Side Diff: chrome/browser/media/webrtc_browsertest_base.cc

Issue 1175443002: Revert of Convert the WebRtcTestBase to use infobar and bubble autoresponders (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/infobars/infobar_responder.h" 10 #include "chrome/browser/chrome_notification_types.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/webrtc_browsertest_common.h" 13 #include "chrome/browser/media/webrtc_browsertest_common.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 15 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h"
16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 18 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
17 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/infobars/core/infobar.h" 20 #include "components/infobars/core/infobar.h"
21 #include "content/public/browser/notification_service.h"
19 #include "content/public/test/browser_test_utils.h" 22 #include "content/public/test/browser_test_utils.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 23 #include "net/test/embedded_test_server/embedded_test_server.h"
21 24
22 #if defined(OS_WIN) 25 #if defined(OS_WIN)
23 // For fine-grained suppression. 26 // For fine-grained suppression.
24 #include "base/win/windows_version.h" 27 #include "base/win/windows_version.h"
25 #endif 28 #endif
26 29
27 const char WebRtcTestBase::kAudioVideoCallConstraints[] = 30 const char WebRtcTestBase::kAudioVideoCallConstraints[] =
28 "{audio: true, video: true}"; 31 "{audio: true, video: true}";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 105
103 bool WebRtcTestBase::GetUserMediaAndAccept( 106 bool WebRtcTestBase::GetUserMediaAndAccept(
104 content::WebContents* tab_contents) const { 107 content::WebContents* tab_contents) const {
105 return GetUserMediaWithSpecificConstraintsAndAccept( 108 return GetUserMediaWithSpecificConstraintsAndAccept(
106 tab_contents, kAudioVideoCallConstraints); 109 tab_contents, kAudioVideoCallConstraints);
107 } 110 }
108 111
109 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( 112 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
110 content::WebContents* tab_contents, 113 content::WebContents* tab_contents,
111 const std::string& constraints) const { 114 const std::string& constraints) const {
112 std::string result;
113 if (PermissionBubbleManager::Enabled()) { 115 if (PermissionBubbleManager::Enabled()) {
116 scoped_ptr<MockPermissionBubbleView> mock_bubble_view(
117 new MockPermissionBubbleView());
114 PermissionBubbleManager::FromWebContents(tab_contents) 118 PermissionBubbleManager::FromWebContents(tab_contents)
115 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 119 ->SetView(mock_bubble_view.get());
120 mock_bubble_view->SetBrowserTest(true);
116 GetUserMedia(tab_contents, constraints); 121 GetUserMedia(tab_contents, constraints);
117 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 122 if (!mock_bubble_view->IsVisible())
118 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 123 content::RunMessageLoop();
124 mock_bubble_view->Accept();
125 // Wait for WebRTC to call the success callback, then remove the view.
126 const bool result = test::PollingWaitUntil("obtainGetUserMediaResult()",
127 kOkGotStream, tab_contents);
128 PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL);
129 return result;
119 } else { 130 } else {
120 InfoBarResponder infobar_accept_responder( 131 infobars::InfoBar* infobar =
121 InfoBarService::FromWebContents(tab_contents), 132 GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
122 InfoBarResponder::ACCEPT); 133 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept();
123 GetUserMedia(tab_contents, constraints); 134 CloseInfoBarInTab(tab_contents, infobar);
124 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 135 // Wait for WebRTC to call the success callback.
125 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 136 return test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream,
137 tab_contents);
126 } 138 }
127 return kOkGotStream == result;
128 } 139 }
129 140
130 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { 141 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
131 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 142 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
132 kAudioVideoCallConstraints); 143 kAudioVideoCallConstraints);
133 } 144 }
134 145
135 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( 146 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
136 content::WebContents* tab_contents, 147 content::WebContents* tab_contents,
137 const std::string& constraints) const { 148 const std::string& constraints) const {
138 std::string result;
139 if (PermissionBubbleManager::Enabled()) { 149 if (PermissionBubbleManager::Enabled()) {
150 scoped_ptr<MockPermissionBubbleView> mock_bubble_view(
151 new MockPermissionBubbleView());
140 PermissionBubbleManager::FromWebContents(tab_contents) 152 PermissionBubbleManager::FromWebContents(tab_contents)
141 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 153 ->SetView(mock_bubble_view.get());
154 mock_bubble_view->SetBrowserTest(true);
142 GetUserMedia(tab_contents, constraints); 155 GetUserMedia(tab_contents, constraints);
143 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 156 if (!mock_bubble_view->IsVisible())
144 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 157 content::RunMessageLoop();
158 mock_bubble_view->Deny();
159 // Wait for WebRTC to call the fail callback, then remove the view.
160 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
161 kFailedWithPermissionDeniedError,
162 tab_contents));
163 PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL);
145 } else { 164 } else {
146 InfoBarResponder infobar_deny_responder( 165 infobars::InfoBar* infobar =
147 InfoBarService::FromWebContents(tab_contents), InfoBarResponder::DENY); 166 GetUserMediaAndWaitForInfoBar(tab_contents, constraints);
148 GetUserMedia(tab_contents, constraints); 167 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel();
149 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 168 CloseInfoBarInTab(tab_contents, infobar);
150 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 169 // Wait for WebRTC to call the fail callback.
170 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
171 kFailedWithPermissionDeniedError,
172 tab_contents));
151 } 173 }
152 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
153 } 174 }
154 175
155 void WebRtcTestBase::GetUserMediaAndDismiss( 176 void WebRtcTestBase::GetUserMediaAndDismiss(
156 content::WebContents* tab_contents) const { 177 content::WebContents* tab_contents) const {
157 std::string result;
158 if (PermissionBubbleManager::Enabled()) { 178 if (PermissionBubbleManager::Enabled()) {
179 scoped_ptr<MockPermissionBubbleView> mock_bubble_view(
180 new MockPermissionBubbleView());
159 PermissionBubbleManager::FromWebContents(tab_contents) 181 PermissionBubbleManager::FromWebContents(tab_contents)
160 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); 182 ->SetView(mock_bubble_view.get());
183 mock_bubble_view->SetBrowserTest(true);
161 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 184 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
185 if (!mock_bubble_view->IsVisible())
186 content::RunMessageLoop();
187 mock_bubble_view->Close();
162 // A dismiss should be treated like a deny. 188 // A dismiss should be treated like a deny.
163 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 189 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
164 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 190 kFailedWithPermissionDismissedError,
191 tab_contents));
192 PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL);
165 } else { 193 } else {
166 InfoBarResponder infobar_dismiss_responder( 194 infobars::InfoBar* infobar =
167 InfoBarService::FromWebContents(tab_contents), 195 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints);
168 InfoBarResponder::DISMISS); 196 infobar->delegate()->InfoBarDismissed();
169 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 197 CloseInfoBarInTab(tab_contents, infobar);
170 // A dismiss should be treated like a deny. 198 // A dismiss should be treated like a deny.
171 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 199 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
172 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 200 kFailedWithPermissionDismissedError,
201 tab_contents));
173 } 202 }
174 EXPECT_EQ(kFailedWithPermissionDismissedError, result);
175 } 203 }
176 204
177 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 205 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
178 const std::string& constraints) const { 206 const std::string& constraints) const {
179 // Request user media: this will launch the media stream info bar or bubble. 207 // Request user media: this will launch the media stream info bar.
180 std::string result; 208 std::string result;
181 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 209 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
182 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); 210 tab_contents, "doGetUserMedia(" + constraints + ");", &result));
183 EXPECT_TRUE(result == "request-callback-denied" || 211 EXPECT_EQ("ok-requested", result);
184 result == "request-callback-granted"); 212 }
213
214 infobars::InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar(
215 content::WebContents* tab_contents,
216 const std::string& constraints) const {
217 content::WindowedNotificationObserver infobar_added(
218 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
219 content::NotificationService::AllSources());
220
221 // Request user media: this will launch the media stream info bar.
222 GetUserMedia(tab_contents, constraints);
223
224 // Wait for the bar to pop up, then return it.
225 infobar_added.Wait();
226 content::Details<infobars::InfoBar::AddedDetails> details(
227 infobar_added.details());
228 EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate());
229 return details.ptr();
185 } 230 }
186 231
187 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( 232 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
188 const GURL& url) const { 233 const GURL& url) const {
189 return OpenPageAndGetUserMediaInNewTabWithConstraints( 234 return OpenPageAndGetUserMediaInNewTabWithConstraints(
190 url, kAudioVideoCallConstraints); 235 url, kAudioVideoCallConstraints);
191 } 236 }
192 237
193 content::WebContents* 238 content::WebContents*
194 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 239 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
(...skipping 11 matching lines...) Expand all
206 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 251 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
207 const std::string& test_page) const { 252 const std::string& test_page) const {
208 return OpenPageAndGetUserMediaInNewTab( 253 return OpenPageAndGetUserMediaInNewTab(
209 embedded_test_server()->GetURL(test_page)); 254 embedded_test_server()->GetURL(test_page));
210 } 255 }
211 256
212 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( 257 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia(
213 const GURL& url) const { 258 const GURL& url) const {
214 content::WebContents* tab_contents = 259 content::WebContents* tab_contents =
215 browser()->tab_strip_model()->GetActiveWebContents(); 260 browser()->tab_strip_model()->GetActiveWebContents();
216 ui_test_utils::NavigateToURL(browser(), url); 261 if (PermissionBubbleManager::Enabled()) {
217 GetUserMediaAndAccept(tab_contents); 262 scoped_ptr<MockPermissionBubbleView> mock_bubble_view(
263 new MockPermissionBubbleView());
264 PermissionBubbleManager::FromWebContents(tab_contents)
265 ->SetView(mock_bubble_view.get());
266 mock_bubble_view->SetBrowserTest(true);
267 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url,
268 1);
269 if (!mock_bubble_view->IsVisible())
270 content::RunMessageLoop();
271 mock_bubble_view->Accept();
272 // Wait to make sure the callback is fired before deleting the bubble view.
273 test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream,
274 tab_contents);
275 PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL);
276 } else {
277 content::WindowedNotificationObserver nav(
278 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
279 content::NotificationService::AllSources());
280 ui_test_utils::NavigateToURL(browser(), url);
281 nav.Wait();
282
283 content::Details<infobars::InfoBar::AddedDetails> details(nav.details());
284 infobars::InfoBar* infobar = details.ptr();
285 EXPECT_TRUE(infobar);
286 infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept();
287
288 CloseInfoBarInTab(tab_contents, infobar);
289 }
218 return tab_contents; 290 return tab_contents;
219 } 291 }
220 292
293 void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents,
294 infobars::InfoBar* infobar) const {
295 content::WindowedNotificationObserver infobar_removed(
296 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED,
297 content::NotificationService::AllSources());
298
299 InfoBarService* infobar_service =
300 InfoBarService::FromWebContents(tab_contents);
301 infobar_service->RemoveInfoBar(infobar);
302
303 infobar_removed.Wait();
304 }
305
221 void WebRtcTestBase::CloseLastLocalStream( 306 void WebRtcTestBase::CloseLastLocalStream(
222 content::WebContents* tab_contents) const { 307 content::WebContents* tab_contents) const {
223 EXPECT_EQ("ok-stopped", 308 EXPECT_EQ("ok-stopped",
224 ExecuteJavascript("stopLocalStream();", tab_contents)); 309 ExecuteJavascript("stopLocalStream();", tab_contents));
225 } 310 }
226 311
227 // Convenience method which executes the provided javascript in the context 312 // Convenience method which executes the provided javascript in the context
228 // of the provided web contents and returns what it evaluated to. 313 // of the provided web contents and returns what it evaluated to.
229 std::string WebRtcTestBase::ExecuteJavascript( 314 std::string WebRtcTestBase::ExecuteJavascript(
230 const std::string& javascript, 315 const std::string& javascript,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 #endif 435 #endif
351 } 436 }
352 437
353 bool WebRtcTestBase::OnWin8() const { 438 bool WebRtcTestBase::OnWin8() const {
354 #if defined(OS_WIN) 439 #if defined(OS_WIN)
355 return base::win::GetVersion() > base::win::VERSION_WIN7; 440 return base::win::GetVersion() > base::win::VERSION_WIN7;
356 #else 441 #else
357 return false; 442 return false;
358 #endif 443 #endif
359 } 444 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698