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

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: Fix incorrect test code that I accidentally committed. 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
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(
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
147 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 230 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
148 const std::string& constraints) const { 231 const std::string& constraints) const {
149 // Request user media: this will launch the media stream info bar or bubble. 232 // Request user media: this will launch the media stream info bar or bubble.
150 std::string result; 233 std::string result;
151 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 234 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
152 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); 235 tab_contents, "doGetUserMedia(" + constraints + ");", &result));
153 EXPECT_TRUE(result == "request-callback-denied" || 236 EXPECT_TRUE(result == "request-callback-denied" ||
154 result == "request-callback-granted"); 237 result == "request-callback-granted");
155 } 238 }
156 239
157 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( 240 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
158 const GURL& url) const { 241 const GURL& url) const {
159 return OpenPageAndGetUserMediaInNewTabWithConstraints( 242 return OpenPageAndGetUserMediaInNewTabWithConstraints(
160 url, kAudioVideoCallConstraints); 243 url, kAudioVideoCallConstraints);
161 } 244 }
162 245
163 content::WebContents* 246 content::WebContents*
164 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 247 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
165 const GURL& url, 248 const GURL& url,
166 const std::string& constraints) const { 249 const std::string& constraints) const {
167 chrome::AddTabAt(browser(), GURL(), -1, true); 250 chrome::AddTabAt(browser(), GURL(), -1, true);
168 ui_test_utils::NavigateToURL(browser(), url); 251 ui_test_utils::NavigateToURL(browser(), url);
169 content::WebContents* new_tab = 252 content::WebContents* new_tab =
170 browser()->tab_strip_model()->GetActiveWebContents(); 253 browser()->tab_strip_model()->GetActiveWebContents();
171 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( 254 // Accept if necessary, but don't expect a prompt (because auto-accept is also
172 new_tab, constraints)); 255 // okay).
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);
173 return new_tab; 263 return new_tab;
174 } 264 }
175 265
176 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 266 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
177 const std::string& test_page) const { 267 const std::string& test_page) const {
178 return OpenPageAndGetUserMediaInNewTab( 268 return OpenPageAndGetUserMediaInNewTab(
179 embedded_test_server()->GetURL(test_page)); 269 embedded_test_server()->GetURL(test_page));
180 } 270 }
181 271
182 void WebRtcTestBase::CloseLastLocalStream( 272 void WebRtcTestBase::CloseLastLocalStream(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 #endif 401 #endif
312 } 402 }
313 403
314 bool WebRtcTestBase::OnWin8() const { 404 bool WebRtcTestBase::OnWin8() const {
315 #if defined(OS_WIN) 405 #if defined(OS_WIN)
316 return base::win::GetVersion() > base::win::VERSION_WIN7; 406 return base::win::GetVersion() > base::win::VERSION_WIN7;
317 #else 407 #else
318 return false; 408 return false;
319 #endif 409 #endif
320 } 410 }
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