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

Unified 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 side-by-side diff with in-line comments
Download patch
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 790aa574bd2901674ed7bb6582a760cda3ef85b6..2953503275b8bf45feaa354813335f81df216740 100644
--- a/chrome/browser/media/webrtc_browsertest_base.cc
+++ b/chrome/browser/media/webrtc_browsertest_base.cc
@@ -7,15 +7,18 @@
#include "base/lazy_instance.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#include "chrome/browser/infobars/infobar_responder.h"
+#include "chrome/browser/chrome_notification_types.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"
@@ -109,22 +112,30 @@
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)
- ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
+ ->SetView(mock_bubble_view.get());
+ mock_bubble_view->SetBrowserTest(true);
GetUserMedia(tab_contents, constraints);
- EXPECT_TRUE(content::ExecuteScriptAndExtractString(
- tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
+ 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;
} else {
- 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;
+ 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);
+ }
}
void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
@@ -135,53 +146,87 @@
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)
- ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
+ ->SetView(mock_bubble_view.get());
+ mock_bubble_view->SetBrowserTest(true);
GetUserMedia(tab_contents, constraints);
- EXPECT_TRUE(content::ExecuteScriptAndExtractString(
- tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
+ 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);
} else {
- 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);
+ 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));
+ }
}
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)
- ->set_auto_response_for_test(PermissionBubbleManager::DISMISS);
+ ->SetView(mock_bubble_view.get());
+ mock_bubble_view->SetBrowserTest(true);
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(content::ExecuteScriptAndExtractString(
- tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
+ EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
+ kFailedWithPermissionDismissedError,
+ tab_contents));
+ PermissionBubbleManager::FromWebContents(tab_contents)->SetView(NULL);
} else {
- InfoBarResponder infobar_dismiss_responder(
- InfoBarService::FromWebContents(tab_contents),
- InfoBarResponder::DISMISS);
- GetUserMedia(tab_contents, kAudioVideoCallConstraints);
+ infobars::InfoBar* infobar =
+ GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints);
+ infobar->delegate()->InfoBarDismissed();
+ CloseInfoBarInTab(tab_contents, infobar);
// A dismiss should be treated like a deny.
- EXPECT_TRUE(content::ExecuteScriptAndExtractString(
- tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
- }
- EXPECT_EQ(kFailedWithPermissionDismissedError, result);
+ EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
+ kFailedWithPermissionDismissedError,
+ tab_contents));
+ }
}
void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
const std::string& constraints) const {
- // Request user media: this will launch the media stream info bar or bubble.
+ // Request user media: this will launch the media stream info bar.
std::string result;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(
tab_contents, "doGetUserMedia(" + constraints + ");", &result));
- EXPECT_TRUE(result == "request-callback-denied" ||
- result == "request-callback-granted");
+ 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();
}
content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
@@ -213,9 +258,49 @@
const GURL& url) const {
content::WebContents* tab_contents =
browser()->tab_strip_model()->GetActiveWebContents();
- ui_test_utils::NavigateToURL(browser(), url);
- GetUserMediaAndAccept(tab_contents);
+ 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);
+ }
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(

Powered by Google App Engine
This is Rietveld 408576698