| 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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
| 8 #include "chrome/browser/infobars/infobar.h" | 8 #include "chrome/browser/infobars/infobar.h" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "chrome/browser/media/media_stream_infobar_delegate.h" | 10 #include "chrome/browser/media/media_stream_infobar_delegate.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } | 28 } |
| 29 | 29 |
| 30 void WebRtcTestBase::GetUserMediaAndAccept(content::WebContents* tab_contents) { | 30 void WebRtcTestBase::GetUserMediaAndAccept(content::WebContents* tab_contents) { |
| 31 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | 31 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, |
| 32 kAudioVideoCallConstraints); | 32 kAudioVideoCallConstraints); |
| 33 } | 33 } |
| 34 | 34 |
| 35 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 35 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
| 36 content::WebContents* tab_contents, | 36 content::WebContents* tab_contents, |
| 37 const std::string& constraints) { | 37 const std::string& constraints) { |
| 38 MediaStreamInfoBarDelegate* infobar = | 38 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| 39 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 39 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| 40 infobar->Accept(); | |
| 41 CloseInfoBarInTab(tab_contents, infobar); | 40 CloseInfoBarInTab(tab_contents, infobar); |
| 42 | 41 |
| 43 // Wait for WebRTC to call the success callback. | 42 // Wait for WebRTC to call the success callback. |
| 44 const char kOkGotStream[] = "ok-got-stream"; | 43 const char kOkGotStream[] = "ok-got-stream"; |
| 45 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, | 44 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
| 46 tab_contents)); | 45 tab_contents)); |
| 47 } | 46 } |
| 48 | 47 |
| 49 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | 48 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
| 50 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 49 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| 51 kAudioVideoCallConstraints); | 50 kAudioVideoCallConstraints); |
| 52 } | 51 } |
| 53 | 52 |
| 54 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | 53 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
| 55 content::WebContents* tab_contents, | 54 content::WebContents* tab_contents, |
| 56 const std::string& constraints) { | 55 const std::string& constraints) { |
| 57 MediaStreamInfoBarDelegate* infobar = | 56 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| 58 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 57 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 59 infobar->Cancel(); | |
| 60 CloseInfoBarInTab(tab_contents, infobar); | 58 CloseInfoBarInTab(tab_contents, infobar); |
| 61 | 59 |
| 62 // Wait for WebRTC to call the fail callback. | 60 // Wait for WebRTC to call the fail callback. |
| 63 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | 61 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
| 64 kFailedWithPermissionDeniedError, tab_contents)); | 62 kFailedWithPermissionDeniedError, tab_contents)); |
| 65 } | 63 } |
| 66 | 64 |
| 67 void WebRtcTestBase::GetUserMediaAndDismiss( | 65 void WebRtcTestBase::GetUserMediaAndDismiss( |
| 68 content::WebContents* tab_contents) { | 66 content::WebContents* tab_contents) { |
| 69 MediaStreamInfoBarDelegate* infobar = | 67 InfoBar* infobar = |
| 70 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); | 68 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
| 71 infobar->InfoBarDismissed(); | 69 infobar->delegate()->InfoBarDismissed(); |
| 72 CloseInfoBarInTab(tab_contents, infobar); | 70 CloseInfoBarInTab(tab_contents, infobar); |
| 73 | 71 |
| 74 // A dismiss should be treated like a deny. | 72 // A dismiss should be treated like a deny. |
| 75 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | 73 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
| 76 kFailedWithPermissionDeniedError, tab_contents)); | 74 kFailedWithPermissionDeniedError, tab_contents)); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, | 77 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
| 80 const std::string& constraints) { | 78 const std::string& constraints) { |
| 81 // Request user media: this will launch the media stream info bar. | 79 // Request user media: this will launch the media stream info bar. |
| 82 std::string result; | 80 std::string result; |
| 83 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 81 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 84 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); | 82 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); |
| 85 EXPECT_EQ("ok-requested", result); | 83 EXPECT_EQ("ok-requested", result); |
| 86 } | 84 } |
| 87 | 85 |
| 88 MediaStreamInfoBarDelegate* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( | 86 InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( |
| 89 content::WebContents* tab_contents, | 87 content::WebContents* tab_contents, |
| 90 const std::string& constraints) { | 88 const std::string& constraints) { |
| 91 content::WindowedNotificationObserver infobar_added( | 89 content::WindowedNotificationObserver infobar_added( |
| 92 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 90 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 93 content::NotificationService::AllSources()); | 91 content::NotificationService::AllSources()); |
| 94 | 92 |
| 95 // Request user media: this will launch the media stream info bar. | 93 // Request user media: this will launch the media stream info bar. |
| 96 GetUserMedia(tab_contents, constraints); | 94 GetUserMedia(tab_contents, constraints); |
| 97 | 95 |
| 98 // Wait for the bar to pop up, then return it. | 96 // Wait for the bar to pop up, then return it. |
| 99 infobar_added.Wait(); | 97 infobar_added.Wait(); |
| 100 content::Details<InfoBarAddedDetails> details(infobar_added.details()); | 98 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); |
| 101 MediaStreamInfoBarDelegate* infobar = details->AsMediaStreamInfoBarDelegate(); | 99 EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); |
| 102 EXPECT_TRUE(infobar); | 100 return details.ptr(); |
| 103 return infobar; | |
| 104 } | 101 } |
| 105 | 102 |
| 106 void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents, | 103 void WebRtcTestBase::CloseInfoBarInTab(content::WebContents* tab_contents, |
| 107 MediaStreamInfoBarDelegate* infobar) { | 104 InfoBar* infobar) { |
| 108 content::WindowedNotificationObserver infobar_removed( | 105 content::WindowedNotificationObserver infobar_removed( |
| 109 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 106 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 110 content::NotificationService::AllSources()); | 107 content::NotificationService::AllSources()); |
| 111 | 108 |
| 112 InfoBarService* infobar_service = | 109 InfoBarService* infobar_service = |
| 113 InfoBarService::FromWebContents(tab_contents); | 110 InfoBarService::FromWebContents(tab_contents); |
| 114 infobar_service->RemoveInfoBar(infobar); | 111 infobar_service->RemoveInfoBar(infobar); |
| 115 | 112 |
| 116 infobar_removed.Wait(); | 113 infobar_removed.Wait(); |
| 117 } | 114 } |
| OLD | NEW |