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

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

Issue 1686903002: [Abandoned] Rename PermissionBubbleManager to PermissionRequestManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tests compile Created 4 years, 8 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/media/webrtc_browsertest_common.h" 14 #include "chrome/browser/media/webrtc_browsertest_common.h"
15 #include "chrome/browser/permissions/permission_request_manager.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
19 #include "chrome/test/base/ui_test_utils.h" 19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/test/browser_test_utils.h" 20 #include "content/public/test/browser_test_utils.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 22
23 #if defined(OS_WIN) 23 #if defined(OS_WIN)
24 // For fine-grained suppression. 24 // For fine-grained suppression.
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #endif 26 #endif
27 27
28 const char WebRtcTestBase::kAudioVideoCallConstraints[] = 28 const char WebRtcTestBase::kAudioVideoCallConstraints[] =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 (severity == logging::LOG_INFO && contains_uncaught)) { 78 (severity == logging::LOG_INFO && contains_uncaught)) {
79 hit_javascript_errors_.Get() = true; 79 hit_javascript_errors_.Get() = true;
80 } 80 }
81 81
82 return false; 82 return false;
83 } 83 }
84 84
85 // PermissionRequestObserver --------------------------------------------------- 85 // PermissionRequestObserver ---------------------------------------------------
86 86
87 // Used to observe the creation of permission prompt without responding. 87 // Used to observe the creation of permission prompt without responding.
88 class PermissionRequestObserver : public PermissionBubbleManager::Observer { 88 class PermissionRequestObserver : public PermissionRequestManager::Observer {
89 public: 89 public:
90 explicit PermissionRequestObserver(content::WebContents* web_contents) 90 explicit PermissionRequestObserver(content::WebContents* web_contents)
91 : bubble_manager_(PermissionBubbleManager::FromWebContents(web_contents)), 91 : request_manager_(
92 PermissionRequestManager::FromWebContents(web_contents)),
92 request_shown_(false), 93 request_shown_(false),
93 message_loop_runner_(new content::MessageLoopRunner) { 94 message_loop_runner_(new content::MessageLoopRunner) {
94 bubble_manager_->AddObserver(this); 95 request_manager_->AddObserver(this);
95 } 96 }
96 ~PermissionRequestObserver() override { 97 ~PermissionRequestObserver() override {
97 // Safe to remove twice if it happens. 98 // Safe to remove twice if it happens.
98 bubble_manager_->RemoveObserver(this); 99 request_manager_->RemoveObserver(this);
99 } 100 }
100 101
101 void Wait() { message_loop_runner_->Run(); } 102 void Wait() { message_loop_runner_->Run(); }
102 103
103 bool request_shown() const { return request_shown_; } 104 bool request_shown() const { return request_shown_; }
104 105
105 private: 106 private:
106 // PermissionBubbleManager::Observer 107 // PermissionRequestManager::Observer
107 void OnBubbleAdded() override { 108 void OnBubbleAdded() override {
108 request_shown_ = true; 109 request_shown_ = true;
109 bubble_manager_->RemoveObserver(this); 110 request_manager_->RemoveObserver(this);
110 message_loop_runner_->Quit(); 111 message_loop_runner_->Quit();
111 } 112 }
112 113
113 PermissionBubbleManager* bubble_manager_; 114 PermissionRequestManager* request_manager_;
114 bool request_shown_; 115 bool request_shown_;
115 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; 116 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
116 117
117 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver); 118 DISALLOW_COPY_AND_ASSIGN(PermissionRequestObserver);
118 }; 119 };
119 120
120 } // namespace 121 } // namespace
121 122
122 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) { 123 WebRtcTestBase::WebRtcTestBase(): detect_errors_in_javascript_(false) {
123 // The handler gets set for each test method, but that's fine since this 124 // The handler gets set for each test method, but that's fine since this
(...skipping 15 matching lines...) Expand all
139 bool WebRtcTestBase::GetUserMediaAndAccept( 140 bool WebRtcTestBase::GetUserMediaAndAccept(
140 content::WebContents* tab_contents) const { 141 content::WebContents* tab_contents) const {
141 return GetUserMediaWithSpecificConstraintsAndAccept( 142 return GetUserMediaWithSpecificConstraintsAndAccept(
142 tab_contents, kAudioVideoCallConstraints); 143 tab_contents, kAudioVideoCallConstraints);
143 } 144 }
144 145
145 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( 146 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
146 content::WebContents* tab_contents, 147 content::WebContents* tab_contents,
147 const std::string& constraints) const { 148 const std::string& constraints) const {
148 std::string result; 149 std::string result;
149 PermissionBubbleManager::FromWebContents(tab_contents) 150 PermissionRequestManager::FromWebContents(tab_contents)
150 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 151 ->set_auto_response_for_test(PermissionRequestManager::ACCEPT_ALL);
151 PermissionRequestObserver permissionRequestObserver(tab_contents); 152 PermissionRequestObserver permissionRequestObserver(tab_contents);
152 GetUserMedia(tab_contents, constraints); 153 GetUserMedia(tab_contents, constraints);
153 EXPECT_TRUE(permissionRequestObserver.request_shown()); 154 EXPECT_TRUE(permissionRequestObserver.request_shown());
154 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 155 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
155 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 156 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
156 return kOkGotStream == result; 157 return kOkGotStream == result;
157 } 158 }
158 159
159 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAcceptIfPrompted( 160 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAcceptIfPrompted(
160 content::WebContents* tab_contents, 161 content::WebContents* tab_contents,
161 const std::string& constraints) const { 162 const std::string& constraints) const {
162 std::string result; 163 std::string result;
163 PermissionBubbleManager::FromWebContents(tab_contents) 164 PermissionRequestManager::FromWebContents(tab_contents)
164 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 165 ->set_auto_response_for_test(PermissionRequestManager::ACCEPT_ALL);
165 GetUserMedia(tab_contents, constraints); 166 GetUserMedia(tab_contents, constraints);
166 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 167 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
167 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 168 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
168 return kOkGotStream == result; 169 return kOkGotStream == result;
169 } 170 }
170 171
171 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { 172 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) {
172 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 173 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
173 kAudioVideoCallConstraints); 174 kAudioVideoCallConstraints);
174 } 175 }
175 176
176 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( 177 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
177 content::WebContents* tab_contents, 178 content::WebContents* tab_contents,
178 const std::string& constraints) const { 179 const std::string& constraints) const {
179 std::string result; 180 std::string result;
180 PermissionBubbleManager::FromWebContents(tab_contents) 181 PermissionRequestManager::FromWebContents(tab_contents)
181 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 182 ->set_auto_response_for_test(PermissionRequestManager::DENY_ALL);
182 PermissionRequestObserver permissionRequestObserver(tab_contents); 183 PermissionRequestObserver permissionRequestObserver(tab_contents);
183 GetUserMedia(tab_contents, constraints); 184 GetUserMedia(tab_contents, constraints);
184 EXPECT_TRUE(permissionRequestObserver.request_shown()); 185 EXPECT_TRUE(permissionRequestObserver.request_shown());
185 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 186 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
186 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 187 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
187 EXPECT_EQ(kFailedWithPermissionDeniedError, result); 188 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
188 } 189 }
189 190
190 void WebRtcTestBase::GetUserMediaAndDismiss( 191 void WebRtcTestBase::GetUserMediaAndDismiss(
191 content::WebContents* tab_contents) const { 192 content::WebContents* tab_contents) const {
192 std::string result; 193 std::string result;
193 PermissionBubbleManager::FromWebContents(tab_contents) 194 PermissionRequestManager::FromWebContents(tab_contents)
194 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); 195 ->set_auto_response_for_test(PermissionRequestManager::DISMISS);
195 PermissionRequestObserver permissionRequestObserver(tab_contents); 196 PermissionRequestObserver permissionRequestObserver(tab_contents);
196 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 197 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
197 EXPECT_TRUE(permissionRequestObserver.request_shown()); 198 EXPECT_TRUE(permissionRequestObserver.request_shown());
198 // A dismiss should be treated like a deny. 199 // A dismiss should be treated like a deny.
199 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 200 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
200 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 201 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
201 EXPECT_EQ(kFailedWithPermissionDismissedError, result); 202 EXPECT_EQ(kFailedWithPermissionDismissedError, result);
202 } 203 }
203 204
204 void WebRtcTestBase::GetUserMediaAndExpectAutoAcceptWithoutPrompt( 205 void WebRtcTestBase::GetUserMediaAndExpectAutoAcceptWithoutPrompt(
205 content::WebContents* tab_contents) const { 206 content::WebContents* tab_contents) const {
206 std::string result; 207 std::string result;
207 // We issue a GetUserMedia() request. We expect that the origin already has a 208 // We issue a GetUserMedia() request. We expect that the origin already has a
208 // sticky "accept" permission (e.g. because the caller previously called 209 // sticky "accept" permission (e.g. because the caller previously called
209 // GetUserMediaAndAccept()), and therefore the GetUserMedia() request 210 // GetUserMediaAndAccept()), and therefore the GetUserMedia() request
210 // automatically succeeds without a prompt. 211 // automatically succeeds without a prompt.
211 // If the caller made a mistake, a prompt may show up instead. For this case, 212 // If the caller made a mistake, a prompt may show up instead. For this case,
212 // we set an auto-response to avoid leaving the prompt hanging. The choice of 213 // we set an auto-response to avoid leaving the prompt hanging. The choice of
213 // DENY_ALL makes sure that the response to the prompt doesn't accidentally 214 // DENY_ALL makes sure that the response to the prompt doesn't accidentally
214 // result in a newly granted media stream permission. 215 // result in a newly granted media stream permission.
215 PermissionBubbleManager::FromWebContents(tab_contents) 216 PermissionRequestManager::FromWebContents(tab_contents)
216 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 217 ->set_auto_response_for_test(PermissionRequestManager::DENY_ALL);
217 PermissionRequestObserver permissionRequestObserver(tab_contents); 218 PermissionRequestObserver permissionRequestObserver(tab_contents);
218 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 219 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
219 EXPECT_FALSE(permissionRequestObserver.request_shown()); 220 EXPECT_FALSE(permissionRequestObserver.request_shown());
220 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 221 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
221 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 222 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
222 EXPECT_EQ(kOkGotStream, result); 223 EXPECT_EQ(kOkGotStream, result);
223 } 224 }
224 225
225 void WebRtcTestBase::GetUserMediaAndExpectAutoDenyWithoutPrompt( 226 void WebRtcTestBase::GetUserMediaAndExpectAutoDenyWithoutPrompt(
226 content::WebContents* tab_contents) const { 227 content::WebContents* tab_contents) const {
227 std::string result; 228 std::string result;
228 // We issue a GetUserMedia() request. We expect that the origin already has a 229 // We issue a GetUserMedia() request. We expect that the origin already has a
229 // sticky "deny" permission (e.g. because the caller previously called 230 // sticky "deny" permission (e.g. because the caller previously called
230 // GetUserMediaAndDeny()), and therefore the GetUserMedia() request 231 // GetUserMediaAndDeny()), and therefore the GetUserMedia() request
231 // automatically succeeds without a prompt. 232 // automatically succeeds without a prompt.
232 // If the caller made a mistake, a prompt may show up instead. For this case, 233 // If the caller made a mistake, a prompt may show up instead. For this case,
233 // we set an auto-response to avoid leaving the prompt hanging. The choice of 234 // we set an auto-response to avoid leaving the prompt hanging. The choice of
234 // ACCEPT_ALL makes sure that the response to the prompt doesn't accidentally 235 // ACCEPT_ALL makes sure that the response to the prompt doesn't accidentally
235 // result in a newly granted media stream permission. 236 // result in a newly granted media stream permission.
236 PermissionBubbleManager::FromWebContents(tab_contents) 237 PermissionRequestManager::FromWebContents(tab_contents)
237 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 238 ->set_auto_response_for_test(PermissionRequestManager::ACCEPT_ALL);
238 PermissionRequestObserver permissionRequestObserver(tab_contents); 239 PermissionRequestObserver permissionRequestObserver(tab_contents);
239 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 240 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
240 EXPECT_FALSE(permissionRequestObserver.request_shown()); 241 EXPECT_FALSE(permissionRequestObserver.request_shown());
241 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 242 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
242 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 243 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
243 EXPECT_EQ(kFailedWithPermissionDeniedError, result); 244 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
244 } 245 }
245 246
246 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 247 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents,
247 const std::string& constraints) const { 248 const std::string& constraints) const {
(...skipping 14 matching lines...) Expand all
262 content::WebContents* 263 content::WebContents*
263 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 264 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
264 const GURL& url, 265 const GURL& url,
265 const std::string& constraints) const { 266 const std::string& constraints) const {
266 chrome::AddTabAt(browser(), GURL(), -1, true); 267 chrome::AddTabAt(browser(), GURL(), -1, true);
267 ui_test_utils::NavigateToURL(browser(), url); 268 ui_test_utils::NavigateToURL(browser(), url);
268 content::WebContents* new_tab = 269 content::WebContents* new_tab =
269 browser()->tab_strip_model()->GetActiveWebContents(); 270 browser()->tab_strip_model()->GetActiveWebContents();
270 // Accept if necessary, but don't expect a prompt (because auto-accept is also 271 // Accept if necessary, but don't expect a prompt (because auto-accept is also
271 // okay). 272 // okay).
272 PermissionBubbleManager::FromWebContents(new_tab) 273 PermissionRequestManager::FromWebContents(new_tab)
273 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 274 ->set_auto_response_for_test(PermissionRequestManager::ACCEPT_ALL);
274 GetUserMedia(new_tab, constraints); 275 GetUserMedia(new_tab, constraints);
275 std::string result; 276 std::string result;
276 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 277 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
277 new_tab->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 278 new_tab->GetMainFrame(), "obtainGetUserMediaResult();", &result));
278 EXPECT_EQ(kOkGotStream, result); 279 EXPECT_EQ(kOkGotStream, result);
279 return new_tab; 280 return new_tab;
280 } 281 }
281 282
282 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 283 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
283 const std::string& test_page) const { 284 const std::string& test_page) const {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 #endif 439 #endif
439 } 440 }
440 441
441 bool WebRtcTestBase::OnWin8() const { 442 bool WebRtcTestBase::OnWin8() const {
442 #if defined(OS_WIN) 443 #if defined(OS_WIN)
443 return base::win::GetVersion() > base::win::VERSION_WIN7; 444 return base::win::GetVersion() > base::win::VERSION_WIN7;
444 #else 445 #else
445 return false; 446 return false;
446 #endif 447 #endif
447 } 448 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698