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

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

Issue 1132203002: Switch media stream permissions to use IsOriginSecure() instead of SchemeIsSecure(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Run `git cl format` again. 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
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
81 } // namespace 116 } // namespace
82 117
83 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { 118 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) {
84 // The handler gets set for each test method, but that's fine since this 119 // The handler gets set for each test method, but that's fine since this
85 // set operation is idempotent. 120 // set operation is idempotent.
86 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler); 121 logging::SetLogMessageHandler(&JavascriptErrorDetectingLogHandler);
87 hit_javascript_errors_.Get() = false; 122 hit_javascript_errors_.Get() = false;
88 123
89 EnablePixelOutput(); 124 EnablePixelOutput();
90 } 125 }
(...skipping 11 matching lines...) Expand all
102 return GetUserMediaWithSpecificConstraintsAndAccept( 137 return GetUserMediaWithSpecificConstraintsAndAccept(
103 tab_contents, kAudioVideoCallConstraints); 138 tab_contents, kAudioVideoCallConstraints);
104 } 139 }
105 140
106 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( 141 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
107 content::WebContents* tab_contents, 142 content::WebContents* tab_contents,
108 const std::string& constraints) const { 143 const std::string& constraints) const {
109 std::string result; 144 std::string result;
110 PermissionBubbleManager::FromWebContents(tab_contents) 145 PermissionBubbleManager::FromWebContents(tab_contents)
111 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 146 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
147 PermissionRequestObserver permissionRequestObserver(tab_contents);
112 GetUserMedia(tab_contents, constraints); 148 GetUserMedia(tab_contents, constraints);
149 EXPECT_TRUE(permissionRequestObserver.request_shown());
113 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 150 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
114 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 151 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
115 return kOkGotStream == result; 152 return kOkGotStream == result;
116 } 153 }
117 154
118 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { 155 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
119 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 156 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
120 kAudioVideoCallConstraints); 157 kAudioVideoCallConstraints);
121 } 158 }
122 159
123 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( 160 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
124 content::WebContents* tab_contents, 161 content::WebContents* tab_contents,
125 const std::string& constraints) const { 162 const std::string& constraints) const {
126 std::string result; 163 std::string result;
127 PermissionBubbleManager::FromWebContents(tab_contents) 164 PermissionBubbleManager::FromWebContents(tab_contents)
128 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 165 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
166 PermissionRequestObserver permissionRequestObserver(tab_contents);
129 GetUserMedia(tab_contents, constraints); 167 GetUserMedia(tab_contents, constraints);
168 EXPECT_TRUE(permissionRequestObserver.request_shown());
130 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 169 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
131 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 170 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
132 EXPECT_EQ(kFailedWithPermissionDeniedError, result); 171 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
133 } 172 }
134 173
135 void WebRtcTestBase::GetUserMediaAndDismiss( 174 void WebRtcTestBase::GetUserMediaAndDismiss(
136 content::WebContents* tab_contents) const { 175 content::WebContents* tab_contents) const {
137 std::string result; 176 std::string result;
138 PermissionBubbleManager::FromWebContents(tab_contents) 177 PermissionBubbleManager::FromWebContents(tab_contents)
139 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); 178 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS);
179 PermissionRequestObserver permissionRequestObserver(tab_contents);
140 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 180 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
181 EXPECT_TRUE(permissionRequestObserver.request_shown());
141 // A dismiss should be treated like a deny. 182 // A dismiss should be treated like a deny.
142 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 183 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
143 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 184 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
144 EXPECT_EQ(kFailedWithPermissionDismissedError, result); 185 EXPECT_EQ(kFailedWithPermissionDismissedError, result);
145 } 186 }
146 187
188 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.
189 content::WebContents* tab_contents) const {
190 std::string result;
191 // Try to deny, to sanity check that auto-accept is overriding.
192 PermissionBubbleManager::FromWebContents(tab_contents)
193 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
194 PermissionRequestObserver permissionRequestObserver(tab_contents);
195 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
196 EXPECT_FALSE(permissionRequestObserver.request_shown());
197 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
198 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
199 EXPECT_EQ(kOkGotStream, result);
200 }
201
202 void WebRtcTestBase::GetUserMediaAndExpectAutoDenyWithoutPrompt(
203 content::WebContents* tab_contents) const {
204 std::string result;
205 // Try to accept, to sanity check that auto-deny is overriding.
206 PermissionBubbleManager::FromWebContents(tab_contents)
207 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
208 PermissionRequestObserver permissionRequestObserver(tab_contents);
209 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
210 EXPECT_FALSE(permissionRequestObserver.request_shown());
211 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
212 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
213 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
214 }
215
147 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 216 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
148 const std::string& constraints) const { 217 const std::string& constraints) const {
149 // Request user media: this will launch the media stream info bar or bubble. 218 // Request user media: this will launch the media stream info bar or bubble.
150 std::string result; 219 std::string result;
151 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 220 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
152 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); 221 tab_contents, "doGetUserMedia(" + constraints + ");", &result));
153 EXPECT_TRUE(result == "request-callback-denied" || 222 EXPECT_TRUE(result == "request-callback-denied" ||
154 result == "request-callback-granted"); 223 result == "request-callback-granted");
155 } 224 }
156 225
157 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( 226 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
158 const GURL& url) const { 227 const GURL& url) const {
159 return OpenPageAndGetUserMediaInNewTabWithConstraints( 228 return OpenPageAndGetUserMediaInNewTabWithConstraints(
160 url, kAudioVideoCallConstraints); 229 url, kAudioVideoCallConstraints);
161 } 230 }
162 231
163 content::WebContents* 232 content::WebContents*
164 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 233 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
165 const GURL& url, 234 const GURL& url,
166 const std::string& constraints) const { 235 const std::string& constraints) const {
167 chrome::AddTabAt(browser(), GURL(), -1, true); 236 chrome::AddTabAt(browser(), GURL(), -1, true);
168 ui_test_utils::NavigateToURL(browser(), url); 237 ui_test_utils::NavigateToURL(browser(), url);
169 content::WebContents* new_tab = 238 content::WebContents* new_tab =
170 browser()->tab_strip_model()->GetActiveWebContents(); 239 browser()->tab_strip_model()->GetActiveWebContents();
171 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( 240 // Accept if necessary, but don't expect a prompt (because auto-accept is also
172 new_tab, constraints)); 241 // okay).
242 PermissionBubbleManager::FromWebContents(new_tab)
243 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
244 GetUserMedia(new_tab, constraints);
245 std::string result;
246 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
247 new_tab->GetMainFrame(), "obtainGetUserMediaResult();", &result));
248 EXPECT_EQ(kOkGotStream, result);
173 return new_tab; 249 return new_tab;
174 } 250 }
175 251
176 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 252 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
177 const std::string& test_page) const { 253 const std::string& test_page) const {
178 return OpenPageAndGetUserMediaInNewTab( 254 return OpenPageAndGetUserMediaInNewTab(
179 embedded_test_server()->GetURL(test_page)); 255 embedded_test_server()->GetURL(test_page));
180 } 256 }
181 257
182 void WebRtcTestBase::CloseLastLocalStream( 258 void WebRtcTestBase::CloseLastLocalStream(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 #endif 387 #endif
312 } 388 }
313 389
314 bool WebRtcTestBase::OnWin8() const { 390 bool WebRtcTestBase::OnWin8() const {
315 #if defined(OS_WIN) 391 #if defined(OS_WIN)
316 return base::win::GetVersion() > base::win::VERSION_WIN7; 392 return base::win::GetVersion() > base::win::VERSION_WIN7;
317 #else 393 #else
318 return false; 394 return false;
319 #endif 395 #endif
320 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698