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 52707ebe04de4348f6dd4b840977ad461d69447b..e3e460c7d1848268f01baae5d91e51df2cffac56 100644 |
| --- a/chrome/browser/media/webrtc_browsertest_base.cc |
| +++ b/chrome/browser/media/webrtc_browsertest_base.cc |
| @@ -78,6 +78,41 @@ bool JavascriptErrorDetectingLogHandler(int severity, |
| return false; |
| } |
| +// PermissionRequestObserver --------------------------------------------------- |
| + |
| +// Used to observe the creation of permission prompt without responding. |
| +class PermissionRequestObserver : public PermissionBubbleManager::Observer { |
| + public: |
| + explicit PermissionRequestObserver(content::WebContents* web_contents) |
| + : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), |
| + request_shown_(false), |
| + message_loop_runner_(new content::MessageLoopRunner) { |
| + bubble_manager_->AddObserver(this); |
| + } |
| + ~PermissionRequestObserver() override { |
| + // Safe to remove twice if it happens. |
| + bubble_manager_->RemoveObserver(this); |
| + } |
| + |
| + void Wait() { message_loop_runner_->Run(); } |
| + |
| + bool request_shown() { return request_shown_; } |
| + |
| + private: |
| + // PermissionBubbleManager::Observer |
| + void OnBubbleAdded() override { |
| + request_shown_ = true; |
| + bubble_manager_->RemoveObserver(this); |
| + message_loop_runner_->Quit(); |
| + } |
| + |
| + PermissionBubbleManager* bubble_manager_; |
| + bool request_shown_; |
| + scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); |
| +}; |
| + |
| } // namespace |
| WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { |
| @@ -109,7 +144,9 @@ bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
| std::string result; |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); |
| + PermissionRequestObserver permissionRequestObserver(tab_contents); |
| GetUserMedia(tab_contents, constraints); |
| + EXPECT_TRUE(permissionRequestObserver.request_shown()); |
| EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| return kOkGotStream == result; |
| @@ -126,7 +163,9 @@ void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
| std::string result; |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); |
| + PermissionRequestObserver permissionRequestObserver(tab_contents); |
| GetUserMedia(tab_contents, constraints); |
| + EXPECT_TRUE(permissionRequestObserver.request_shown()); |
| EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| EXPECT_EQ(kFailedWithPermissionDeniedError, result); |
| @@ -137,13 +176,43 @@ void WebRtcTestBase::GetUserMediaAndDismiss( |
| std::string result; |
| PermissionBubbleManager::FromWebContents(tab_contents) |
| ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); |
| + PermissionRequestObserver permissionRequestObserver(tab_contents); |
| GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| + EXPECT_TRUE(permissionRequestObserver.request_shown()); |
| // A dismiss should be treated like a deny. |
| EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| EXPECT_EQ(kFailedWithPermissionDismissedError, result); |
| } |
| +void WebRtcTestBase::GetUserMediaAndExpectAutoAcceptWithoutPrompt( |
|
felt
2015/08/06 18:40:13
This is kind of confusing, because you don't actua
lgarron
2015/08/06 22:10:09
Done.
|
| + content::WebContents* tab_contents) const { |
| + std::string result; |
| + // Try to deny, to sanity check that auto-accept is overriding. |
| + PermissionBubbleManager::FromWebContents(tab_contents) |
| + ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); |
| + PermissionRequestObserver permissionRequestObserver(tab_contents); |
| + GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| + EXPECT_FALSE(permissionRequestObserver.request_shown()); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| + EXPECT_EQ(kOkGotStream, result); |
| +} |
| + |
| +void WebRtcTestBase::GetUserMediaAndExpectAutoDenyWithoutPrompt( |
| + content::WebContents* tab_contents) const { |
| + std::string result; |
| + // Try to accept, to sanity check that auto-deny is overriding. |
| + PermissionBubbleManager::FromWebContents(tab_contents) |
| + ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); |
| + PermissionRequestObserver permissionRequestObserver(tab_contents); |
| + GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| + EXPECT_FALSE(permissionRequestObserver.request_shown()); |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| + EXPECT_EQ(kFailedWithPermissionDeniedError, result); |
| +} |
| + |
| 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. |
| @@ -168,8 +237,15 @@ WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( |
| ui_test_utils::NavigateToURL(browser(), url); |
| content::WebContents* new_tab = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| - EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| - new_tab, constraints)); |
| + // Accept if necessary, but don't expect a prompt (because auto-accept is also |
| + // okay). |
| + PermissionBubbleManager::FromWebContents(new_tab) |
| + ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); |
| + GetUserMedia(new_tab, constraints); |
| + std::string result; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| + new_tab->GetMainFrame(), "obtainGetUserMediaResult();", &result)); |
| + EXPECT_EQ(kOkGotStream, result); |
| return new_tab; |
| } |