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

Side by Side Diff: chrome/browser/media/webrtc_browsertest_base.cc

Issue 1276373004: Revert of Switch media stream permissions to use IsOriginSecure() instead of SchemeIsSecure(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/media/webrtc_browsertest_common.h" 10 #include "chrome/browser/media/webrtc_browsertest_common.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos; 72 bool contains_uncaught = str.find("\"Uncaught ") != std::string::npos;
73 if (severity == logging::LOG_ERROR || 73 if (severity == logging::LOG_ERROR ||
74 (severity == logging::LOG_INFO && contains_uncaught)) { 74 (severity == logging::LOG_INFO && contains_uncaught)) {
75 hit_javascript_errors_.Get() = true; 75 hit_javascript_errors_.Get() = true;
76 } 76 }
77 77
78 return false; 78 return false;
79 } 79 }
80 80
81 // PermissionRequestObserver ---------------------------------------------------
82
83 // Used to observe the creation of permission prompt without responding.
84 class PermissionRequestObserver : public PermissionBubbleManager::Observer {
85 public:
86 explicit PermissionRequestObserver(content::WebContents* web_contents)
87 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)),
88 request_shown_(false),
89 message_loop_runner_(new content::MessageLoopRunner) {
90 bubble_manager_->AddObserver(this);
91 }
92 ~PermissionRequestObserver() override {
93 // Safe to remove twice if it happens.
94 bubble_manager_->RemoveObserver(this);
95 }
96
97 void Wait() { message_loop_runner_->Run(); }
98
99 bool request_shown() { return request_shown_; }
100
101 private:
102 // PermissionBubbleManager::Observer
103 void OnBubbleAdded() override {
104 request_shown_ = true;
105 bubble_manager_->RemoveObserver(this);
106 message_loop_runner_->Quit();
107 }
108
109 PermissionBubbleManager* bubble_manager_;
110 bool request_shown_;
111 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
112
113 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
114 };
115
116 } // namespace 81 } // namespace
117 82
118 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { 83 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) {
119 // The handler gets set for each test method, but that's fine since this 84 // The handler gets set for each test method, but that's fine since this
120 // set operation is idempotent. 85 // set operation is idempotent.
121 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); 86 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler);
122 hit_javascript_errors_.Get() = false; 87 hit_javascript_errors_.Get() = false;
123 88
124 EnablePixelOutput(); 89 EnablePixelOutput();
125 } 90 }
(...skipping 11 matching lines...) Expand all
137 return GetUserMediaWithSpecificConstraintsAndAccept( 102 return GetUserMediaWithSpecificConstraintsAndAccept(
138 tab_contents, kAudioVideoCallConstraints); 103 tab_contents, kAudioVideoCallConstraints);
139 } 104 }
140 105
141 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( 106 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
142 content::WebContents* tab_contents, 107 content::WebContents* tab_contents,
143 const std::string& constraints) const { 108 const std::string& constraints) const {
144 std::string result; 109 std::string result;
145 PermissionBubbleManager::FromWebContents(tab_contents) 110 PermissionBubbleManager::FromWebContents(tab_contents)
146 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 111 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
147 PermissionRequestObserver permissionRequestObserver(tab_contents);
148 GetUserMedia(tab_contents, constraints); 112 GetUserMedia(tab_contents, constraints);
149 EXPECT_TRUE(permissionRequestObserver.request_shown());
150 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 113 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
151 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 114 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
152 return kOkGotStream == result; 115 return kOkGotStream == result;
153 } 116 }
154 117
155 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { 118 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
156 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 119 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
157 kAudioVideoCallConstraints); 120 kAudioVideoCallConstraints);
158 } 121 }
159 122
160 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( 123 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
161 content::WebContents* tab_contents, 124 content::WebContents* tab_contents,
162 const std::string& constraints) const { 125 const std::string& constraints) const {
163 std::string result; 126 std::string result;
164 PermissionBubbleManager::FromWebContents(tab_contents) 127 PermissionBubbleManager::FromWebContents(tab_contents)
165 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 128 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
166 PermissionRequestObserver permissionRequestObserver(tab_contents);
167 GetUserMedia(tab_contents, constraints); 129 GetUserMedia(tab_contents, constraints);
168 EXPECT_TRUE(permissionRequestObserver.request_shown());
169 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 130 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
170 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 131 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
171 EXPECT_EQ(kFailedWithPermissionDeniedError, result); 132 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
172 } 133 }
173 134
174 void WebRtcTestBase::GetUserMediaAndDismiss( 135 void WebRtcTestBase::GetUserMediaAndDismiss(
175 content::WebContents* tab_contents) const { 136 content::WebContents* tab_contents) const {
176 std::string result; 137 std::string result;
177 PermissionBubbleManager::FromWebContents(tab_contents) 138 PermissionBubbleManager::FromWebContents(tab_contents)
178 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); 139 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS);
179 PermissionRequestObserver permissionRequestObserver(tab_contents);
180 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 140 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
181 EXPECT_TRUE(permissionRequestObserver.request_shown());
182 // A dismiss should be treated like a deny. 141 // A dismiss should be treated like a deny.
183 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 142 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
184 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 143 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
185 EXPECT_EQ(kFailedWithPermissionDismissedError, result); 144 EXPECT_EQ(kFailedWithPermissionDismissedError, result);
186 } 145 }
187 146
188 void WebRtcTestBase::GetUserMediaAndExpectAutoAcceptWithoutPrompt(
189 content::WebContents* tab_contents) const {
190 std::string result;
191 // We issue a GetUserMedia() request. We expect that the origin already has a
192 // sticky "accept" permission (e.g. because the caller previously called
193 // GetUserMediaAndAccept()), and therefore the GetUserMedia() request
194 // automatically succeeds without a prompt.
195 // If the caller made a mistake, a prompt may show up instead. For this case,
196 // we set an auto-response to avoid leaving the prompt hanging. The choice of
197 // DENY_ALL makes sure that the response to the prompt doesn't accidentally
198 // result in a newly granted media stream permission.
199 PermissionBubbleManager::FromWebContents(tab_contents)
200 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
201 PermissionRequestObserver permissionRequestObserver(tab_contents);
202 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
203 EXPECT_FALSE(permissionRequestObserver.request_shown());
204 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
205 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
206 EXPECT_EQ(kOkGotStream, result);
207 }
208
209 void WebRtcTestBase::GetUserMediaAndExpectAutoDenyWithoutPrompt(
210 content::WebContents* tab_contents) const {
211 std::string result;
212 // We issue a GetUserMedia() request. We expect that the origin already has a
213 // sticky "deny" permission (e.g. because the caller previously called
214 // GetUserMediaAndDeny()), and therefore the GetUserMedia() request
215 // automatically succeeds without a prompt.
216 // If the caller made a mistake, a prompt may show up instead. For this case,
217 // we set an auto-response to avoid leaving the prompt hanging. The choice of
218 // ACCEPT_ALL makes sure that the response to the prompt doesn't accidentally
219 // result in a newly granted media stream permission.
220 PermissionBubbleManager::FromWebContents(tab_contents)
221 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
222 PermissionRequestObserver permissionRequestObserver(tab_contents);
223 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
224 EXPECT_FALSE(permissionRequestObserver.request_shown());
225 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
226 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
227 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
228 }
229
230 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 147 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
231 const std::string& constraints) const { 148 const std::string& constraints) const {
232 // Request user media: this will launch the media stream info bar or bubble. 149 // Request user media: this will launch the media stream info bar or bubble.
233 std::string result; 150 std::string result;
234 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 151 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
235 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); 152 tab_contents, "doGetUserMedia(" + constraints + ");", &result));
236 EXPECT_TRUE(result == "request-callback-denied" || 153 EXPECT_TRUE(result == "request-callback-denied" ||
237 result == "request-callback-granted"); 154 result == "request-callback-granted");
238 } 155 }
239 156
240 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( 157 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
241 const GURL& url) const { 158 const GURL& url) const {
242 return OpenPageAndGetUserMediaInNewTabWithConstraints( 159 return OpenPageAndGetUserMediaInNewTabWithConstraints(
243 url, kAudioVideoCallConstraints); 160 url, kAudioVideoCallConstraints);
244 } 161 }
245 162
246 content::WebContents* 163 content::WebContents*
247 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 164 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
248 const GURL& url, 165 const GURL& url,
249 const std::string& constraints) const { 166 const std::string& constraints) const {
250 chrome::AddTabAt(browser(), GURL(), -1, true); 167 chrome::AddTabAt(browser(), GURL(), -1, true);
251 ui_test_utils::NavigateToURL(browser(), url); 168 ui_test_utils::NavigateToURL(browser(), url);
252 content::WebContents* new_tab = 169 content::WebContents* new_tab =
253 browser()->tab_strip_model()->GetActiveWebContents(); 170 browser()->tab_strip_model()->GetActiveWebContents();
254 // Accept if necessary, but don't expect a prompt (because auto-accept is also 171 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept(
255 // okay). 172 new_tab, constraints));
256 PermissionBubbleManager::FromWebContents(new_tab)
257 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
258 GetUserMedia(new_tab, constraints);
259 std::string result;
260 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
261 new_tab->GetMainFrame(), "obtainGetUserMediaResult();", &result));
262 EXPECT_EQ(kOkGotStream, result);
263 return new_tab; 173 return new_tab;
264 } 174 }
265 175
266 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 176 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
267 const std::string& test_page) const { 177 const std::string& test_page) const {
268 return OpenPageAndGetUserMediaInNewTab( 178 return OpenPageAndGetUserMediaInNewTab(
269 embedded_test_server()->GetURL(test_page)); 179 embedded_test_server()->GetURL(test_page));
270 } 180 }
271 181
272 void WebRtcTestBase::CloseLastLocalStream( 182 void WebRtcTestBase::CloseLastLocalStream(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 #endif 311 #endif
402 } 312 }
403 313
404 bool WebRtcTestBase::OnWin8() const { 314 bool WebRtcTestBase::OnWin8() const {
405 #if defined(OS_WIN) 315 #if defined(OS_WIN)
406 return base::win::GetVersion() > base::win::VERSION_WIN7; 316 return base::win::GetVersion() > base::win::VERSION_WIN7;
407 #else 317 #else
408 return false; 318 return false;
409 #endif 319 #endif
410 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/media/webrtc_browsertest_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698