Chromium Code Reviews| Index: chrome/browser/media/webrtc_browsertest_base.cc |
| diff --git a/chrome/browser/media/webrtc_browsertest_base.cc b/chrome/browser/media/webrtc_browsertest_base.cc |
| index 2953503275b8bf45feaa354813335f81df216740..790aa574bd2901674ed7bb6582a760cda3ef85b6 100644 |
| --- a/chrome/browser/media/webrtc_browsertest_base.cc |
| +++ b/chrome/browser/media/webrtc_browsertest_base.cc |
| @@ -7,18 +7,15 @@ |
| #include "base/lazy_instance.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| -#include "chrome/browser/chrome_notification_types.h" |
| +#include "chrome/browser/infobars/infobar_responder.h" |
| #include "chrome/browser/infobars/infobar_service.h" |
| -#include "chrome/browser/media/media_stream_infobar_delegate.h" |
| #include "chrome/browser/media/webrtc_browsertest_common.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_tabstrip.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| -#include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" |
| #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "components/infobars/core/infobar.h" |
| -#include "content/public/browser/notification_service.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| @@ -112,30 +109,22 @@ bool WebRtcTestBase::GetUserMediaAndAccept( |
| bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
| content::WebContents* tab_contents, |
| const std::string& constraints) const { |
| + std::string result; |
| if (PermissionBubbleManager::Enabled()) { |
| - scoped_ptr<MockPermissionBubbleView> mock_bubble_view( |
| - new MockPermissionBubbleView()); |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| - ->SetView(mock_bubble_view.get()); |
| - mock_bubble_view->SetBrowserTest(true); |
| + ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); |
|
phoglund_chromium
2015/06/08 21:14:57
Nice! We used to have to poll here because the tes
|
| GetUserMedia(tab_contents, constraints); |
| - if (!mock_bubble_view->IsVisible()) |
| - content::RunMessageLoop(); |
| - mock_bubble_view->Accept(); |
| - // Wait for WebRTC to call the success callback, then remove the view. |
| - const bool result = test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kOkGotStream, tab_contents); |
| - PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL); |
| - return result; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } else { |
| - infobars::InfoBar* infobar = |
| - GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| - infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| - CloseInfoBarInTab(tab_contents, infobar); |
| - // Wait for WebRTC to call the success callback. |
| - return test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
| - tab_contents); |
| + InfoBarResponder infobar_accept_responder( |
| + InfoBarService::FromWebContents(tab_contents), |
| + InfoBarResponder::ACCEPT); |
| + GetUserMedia(tab_contents, constraints); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } |
| + return kOkGotStream == result; |
| } |
| void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
| @@ -146,87 +135,53 @@ void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
| void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
| content::WebContents* tab_contents, |
| const std::string& constraints) const { |
| + std::string result; |
| if (PermissionBubbleManager::Enabled()) { |
| - scoped_ptr<MockPermissionBubbleView> mock_bubble_view( |
| - new MockPermissionBubbleView()); |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| - ->SetView(mock_bubble_view.get()); |
| - mock_bubble_view->SetBrowserTest(true); |
| + ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); |
| GetUserMedia(tab_contents, constraints); |
| - if (!mock_bubble_view->IsVisible()) |
| - content::RunMessageLoop(); |
| - mock_bubble_view->Deny(); |
| - // Wait for WebRTC to call the fail callback, then remove the view. |
| - EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kFailedWithPermissionDeniedError, |
| - tab_contents)); |
| - PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } else { |
| - infobars::InfoBar* infobar = |
| - GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| - infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| - CloseInfoBarInTab(tab_contents, infobar); |
| - // Wait for WebRTC to call the fail callback. |
| - EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kFailedWithPermissionDeniedError, |
| - tab_contents)); |
| + InfoBarResponder infobar_deny_responder( |
| + InfoBarService::FromWebContents(tab_contents), InfoBarResponder::DENY); |
| + GetUserMedia(tab_contents, constraints); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } |
| + EXPECT_EQ(kFailedWithPermissionDeniedError, result); |
| } |
| void WebRtcTestBase::GetUserMediaAndDismiss( |
| content::WebContents* tab_contents) const { |
| + std::string result; |
| if (PermissionBubbleManager::Enabled()) { |
| - scoped_ptr<MockPermissionBubbleView> mock_bubble_view( |
| - new MockPermissionBubbleView()); |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| - ->SetView(mock_bubble_view.get()); |
| - mock_bubble_view->SetBrowserTest(true); |
| + ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); |
| GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| - if (!mock_bubble_view->IsVisible()) |
| - content::RunMessageLoop(); |
| - mock_bubble_view->Close(); |
| // A dismiss should be treated like a deny. |
| - EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kFailedWithPermissionDismissedError, |
| - tab_contents)); |
| - PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } else { |
| - infobars::InfoBar* infobar = |
| - GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
| - infobar->delegate()->InfoBarDismissed(); |
| - CloseInfoBarInTab(tab_contents, infobar); |
| + InfoBarResponder infobar_dismiss_responder( |
| + InfoBarService::FromWebContents(tab_contents), |
| + InfoBarResponder::DISMISS); |
| + GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| // A dismiss should be treated like a deny. |
| - EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kFailedWithPermissionDismissedError, |
| - tab_contents)); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| } |
| + EXPECT_EQ(kFailedWithPermissionDismissedError, result); |
| } |
| void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
| const std::string& constraints) const { |
| - // Request user media: this will launch the media stream info bar. |
| + // Request user media: this will launch the media stream info bar or bubble. |
| std::string result; |
| EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| tab_contents, "doGetUserMedia(" + constraints + ");", &result)); |
| - EXPECT_EQ("ok-requested", result); |
| -} |
| - |
| -infobars::InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( |
| - content::WebContents* tab_contents, |
| - const std::string& constraints) const { |
| - content::WindowedNotificationObserver infobar_added( |
| - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| - content::NotificationService::AllSources()); |
| - |
| - // Request user media: this will launch the media stream info bar. |
| - GetUserMedia(tab_contents, constraints); |
| - |
| - // Wait for the bar to pop up, then return it. |
| - infobar_added.Wait(); |
| - content::Details<infobars::InfoBar::AddedDetails> details( |
| - infobar_added.details()); |
| - EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); |
| - return details.ptr(); |
| + EXPECT_TRUE(result == "request-callback-denied" || |
| + result == "request-callback-granted"); |
| } |
| content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( |
| @@ -258,51 +213,11 @@ content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( |
| const GURL& url) const { |
| content::WebContents* tab_contents = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - if (PermissionBubbleManager::Enabled()) { |
| - scoped_ptr<MockPermissionBubbleView> mock_bubble_view( |
| - new MockPermissionBubbleView()); |
| - PermissionBubbleManager::FromWebContents(tab_contents) |
| - ->SetView(mock_bubble_view.get()); |
| - mock_bubble_view->SetBrowserTest(true); |
| - ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, |
| - 1); |
| - if (!mock_bubble_view->IsVisible()) |
| - content::RunMessageLoop(); |
| - mock_bubble_view->Accept(); |
| - // Wait to make sure the callback is fired before deleting the bubble view. |
| - test::PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
| - tab_contents); |
| - PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL); |
| - } else { |
| - content::WindowedNotificationObserver nav( |
| - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| - content::NotificationService::AllSources()); |
| - ui_test_utils::NavigateToURL(browser(), url); |
| - nav.Wait(); |
| - |
| - content::Details<infobars::InfoBar::AddedDetails> details(nav.details()); |
| - infobars::InfoBar* infobar = details.ptr(); |
| - EXPECT_TRUE(infobar); |
| - infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept(); |
| - |
| - CloseInfoBarInTab(tab_contents, infobar); |
| - } |
| + ui_test_utils::NavigateToURL(browser(), url); |
| + GetUserMediaAndAccept(tab_contents); |
| return tab_contents; |
| } |
| -void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents, |
| - infobars::InfoBar* infobar) const { |
| - content::WindowedNotificationObserver infobar_removed( |
| - chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| - content::NotificationService::AllSources()); |
| - |
| - InfoBarService* infobar_service = |
| - InfoBarService::FromWebContents(tab_contents); |
| - infobar_service->RemoveInfoBar(infobar); |
| - |
| - infobar_removed.Wait(); |
| -} |
| - |
| void WebRtcTestBase::CloseLastLocalStream( |
| content::WebContents* tab_contents) const { |
| EXPECT_EQ("ok-stopped", |