| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/infobars/infobar.h" | 9 #include "chrome/browser/infobars/infobar.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 void WebRtcTestBase::GetUserMediaAndAccept( | 32 void WebRtcTestBase::GetUserMediaAndAccept( |
| 33 content::WebContents* tab_contents) const { | 33 content::WebContents* tab_contents) const { |
| 34 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | 34 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, |
| 35 kAudioVideoCallConstraints); | 35 kAudioVideoCallConstraints); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( | 38 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( |
| 39 content::WebContents* tab_contents, | 39 content::WebContents* tab_contents, |
| 40 const std::string& constraints) const { | 40 const std::string& constraints) const { |
| 41 MediaStreamInfoBarDelegate* infobar = | 41 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| 42 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 42 infobar->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| 43 infobar->Accept(); | |
| 44 CloseInfoBarInTab(tab_contents, infobar); | 43 CloseInfoBarInTab(tab_contents, infobar); |
| 45 | 44 |
| 46 // Wait for WebRTC to call the success callback. | 45 // Wait for WebRTC to call the success callback. |
| 47 const char kOkGotStream[] = "ok-got-stream"; | 46 const char kOkGotStream[] = "ok-got-stream"; |
| 48 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, | 47 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", kOkGotStream, |
| 49 tab_contents)); | 48 tab_contents)); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { | 51 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { |
| 53 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 52 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| 54 kAudioVideoCallConstraints); | 53 kAudioVideoCallConstraints); |
| 55 } | 54 } |
| 56 | 55 |
| 57 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( | 56 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( |
| 58 content::WebContents* tab_contents, | 57 content::WebContents* tab_contents, |
| 59 const std::string& constraints) const { | 58 const std::string& constraints) const { |
| 60 MediaStreamInfoBarDelegate* infobar = | 59 InfoBar* infobar = GetUserMediaAndWaitForInfoBar(tab_contents, constraints); |
| 61 GetUserMediaAndWaitForInfoBar(tab_contents, constraints); | 60 infobar->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| 62 infobar->Cancel(); | |
| 63 CloseInfoBarInTab(tab_contents, infobar); | 61 CloseInfoBarInTab(tab_contents, infobar); |
| 64 | 62 |
| 65 // Wait for WebRTC to call the fail callback. | 63 // Wait for WebRTC to call the fail callback. |
| 66 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | 64 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
| 67 kFailedWithPermissionDeniedError, tab_contents)); | 65 kFailedWithPermissionDeniedError, tab_contents)); |
| 68 } | 66 } |
| 69 | 67 |
| 70 void WebRtcTestBase::GetUserMediaAndDismiss( | 68 void WebRtcTestBase::GetUserMediaAndDismiss( |
| 71 content::WebContents* tab_contents) const { | 69 content::WebContents* tab_contents) const { |
| 72 MediaStreamInfoBarDelegate* infobar = | 70 InfoBar* infobar = |
| 73 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); | 71 GetUserMediaAndWaitForInfoBar(tab_contents, kAudioVideoCallConstraints); |
| 74 infobar->InfoBarDismissed(); | 72 infobar->delegate()->InfoBarDismissed(); |
| 75 CloseInfoBarInTab(tab_contents, infobar); | 73 CloseInfoBarInTab(tab_contents, infobar); |
| 76 | 74 |
| 77 // A dismiss should be treated like a deny. | 75 // A dismiss should be treated like a deny. |
| 78 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", | 76 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()", |
| 79 kFailedWithPermissionDeniedError, tab_contents)); | 77 kFailedWithPermissionDeniedError, tab_contents)); |
| 80 } | 78 } |
| 81 | 79 |
| 82 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, | 80 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, |
| 83 const std::string& constraints) const { | 81 const std::string& constraints) const { |
| 84 // TODO(phoglund): temporary debugging measure for crbug.com/281268. | 82 // TODO(phoglund): temporary debugging measure for crbug.com/281268. |
| 85 std::string javascript = | 83 std::string javascript = |
| 86 "if (typeof(doGetUserMedia) != typeof(Function)) {\n" | 84 "if (typeof(doGetUserMedia) != typeof(Function)) {\n" |
| 87 " console.log('hitting weird js load bug: diagnosing...');\n" | 85 " console.log('hitting weird js load bug: diagnosing...');\n" |
| 88 " for (var v in window) {\n" | 86 " for (var v in window) {\n" |
| 89 " if (window.hasOwnProperty(v)) console.log(v);\n" | 87 " if (window.hasOwnProperty(v)) console.log(v);\n" |
| 90 " }\n" | 88 " }\n" |
| 91 " window.domAutomationController.send('failed!');\n" | 89 " window.domAutomationController.send('failed!');\n" |
| 92 "}\n" | 90 "}\n" |
| 93 "else\n" | 91 "else\n" |
| 94 " doGetUserMedia(" + constraints + ");"; | 92 " doGetUserMedia(" + constraints + ");"; |
| 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 std::string result; | 94 std::string result; |
| 97 EXPECT_TRUE(content::ExecuteScriptAndExtractString( | 95 EXPECT_TRUE(content::ExecuteScriptAndExtractString( |
| 98 tab_contents, javascript, &result)); | 96 tab_contents, javascript, &result)); |
| 99 EXPECT_EQ("ok-requested", result); | 97 EXPECT_EQ("ok-requested", result); |
| 100 } | 98 } |
| 101 | 99 |
| 102 MediaStreamInfoBarDelegate* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( | 100 InfoBar* WebRtcTestBase::GetUserMediaAndWaitForInfoBar( |
| 103 content::WebContents* tab_contents, | 101 content::WebContents* tab_contents, |
| 104 const std::string& constraints) const { | 102 const std::string& constraints) const { |
| 105 content::WindowedNotificationObserver infobar_added( | 103 content::WindowedNotificationObserver infobar_added( |
| 106 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 104 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 107 content::NotificationService::AllSources()); | 105 content::NotificationService::AllSources()); |
| 108 | 106 |
| 109 // Request user media: this will launch the media stream info bar. | 107 // Request user media: this will launch the media stream info bar. |
| 110 GetUserMedia(tab_contents, constraints); | 108 GetUserMedia(tab_contents, constraints); |
| 111 | 109 |
| 112 // Wait for the bar to pop up, then return it. | 110 // Wait for the bar to pop up, then return it. |
| 113 infobar_added.Wait(); | 111 infobar_added.Wait(); |
| 114 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); | 112 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); |
| 115 MediaStreamInfoBarDelegate* infobar = details->AsMediaStreamInfoBarDelegate(); | 113 EXPECT_TRUE(details->delegate()->AsMediaStreamInfoBarDelegate()); |
| 116 EXPECT_TRUE(infobar); | 114 return details.ptr(); |
| 117 return infobar; | |
| 118 } | 115 } |
| 119 | 116 |
| 120 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( | 117 content::WebContents* WebRtcTestBase::OpenPageAndAcceptUserMedia( |
| 121 const GURL& url) const { | 118 const GURL& url) const { |
| 122 content::WindowedNotificationObserver infobar_added( | 119 content::WindowedNotificationObserver infobar_added( |
| 123 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 120 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 124 content::NotificationService::AllSources()); | 121 content::NotificationService::AllSources()); |
| 125 | 122 |
| 126 ui_test_utils::NavigateToURL(browser(), url); | 123 ui_test_utils::NavigateToURL(browser(), url); |
| 127 | 124 |
| 128 infobar_added.Wait(); | 125 infobar_added.Wait(); |
| 129 | 126 |
| 130 content::WebContents* tab_contents = | 127 content::WebContents* tab_contents = |
| 131 browser()->tab_strip_model()->GetActiveWebContents(); | 128 browser()->tab_strip_model()->GetActiveWebContents(); |
| 132 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); | 129 content::Details<InfoBar::AddedDetails> details(infobar_added.details()); |
| 133 MediaStreamInfoBarDelegate* infobar = | 130 InfoBar* infobar = details.ptr(); |
| 134 details->AsMediaStreamInfoBarDelegate(); | |
| 135 EXPECT_TRUE(infobar); | 131 EXPECT_TRUE(infobar); |
| 136 infobar->Accept(); | 132 infobar->delegate()->AsMediaStreamInfoBarDelegate()->Accept(); |
| 137 | 133 |
| 138 CloseInfoBarInTab(tab_contents, infobar); | 134 CloseInfoBarInTab(tab_contents, infobar); |
| 139 return tab_contents; | 135 return tab_contents; |
| 140 } | 136 } |
| 141 | 137 |
| 142 void WebRtcTestBase::CloseInfoBarInTab( | 138 void WebRtcTestBase::CloseInfoBarInTab( |
| 143 content::WebContents* tab_contents, | 139 content::WebContents* tab_contents, |
| 144 MediaStreamInfoBarDelegate* infobar) const { | 140 InfoBar* infobar) const { |
| 145 content::WindowedNotificationObserver infobar_removed( | 141 content::WindowedNotificationObserver infobar_removed( |
| 146 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, | 142 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 147 content::NotificationService::AllSources()); | 143 content::NotificationService::AllSources()); |
| 148 | 144 |
| 149 InfoBarService* infobar_service = | 145 InfoBarService* infobar_service = |
| 150 InfoBarService::FromWebContents(tab_contents); | 146 InfoBarService::FromWebContents(tab_contents); |
| 151 infobar_service->RemoveInfoBar(infobar); | 147 infobar_service->RemoveInfoBar(infobar); |
| 152 | 148 |
| 153 infobar_removed.Wait(); | 149 infobar_removed.Wait(); |
| 154 } | 150 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 167 // The peer connection server lets our two tabs find each other and talk to | 163 // The peer connection server lets our two tabs find each other and talk to |
| 168 // each other (e.g. it is the application-specific "signaling solution"). | 164 // each other (e.g. it is the application-specific "signaling solution"). |
| 169 void WebRtcTestBase::ConnectToPeerConnectionServer( | 165 void WebRtcTestBase::ConnectToPeerConnectionServer( |
| 170 const std::string& peer_name, | 166 const std::string& peer_name, |
| 171 content::WebContents* tab_contents) const { | 167 content::WebContents* tab_contents) const { |
| 172 std::string javascript = base::StringPrintf( | 168 std::string javascript = base::StringPrintf( |
| 173 "connect('http://localhost:%s', '%s');", | 169 "connect('http://localhost:%s', '%s');", |
| 174 PeerConnectionServerRunner::kDefaultPort, peer_name.c_str()); | 170 PeerConnectionServerRunner::kDefaultPort, peer_name.c_str()); |
| 175 EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents)); | 171 EXPECT_EQ("ok-connected", ExecuteJavascript(javascript, tab_contents)); |
| 176 } | 172 } |
| OLD | NEW |