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

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: Initialize use_secure_origin_for_test_page_ in only one place. 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 }
91 126
92 WebRtcTestBase::~WebRtcTestBase() { 127 WebRtcTestBase::~WebRtcTestBase() {
93 if (detect_errors_in_javascript_) { 128 if (detect_errors_in_javascript_) {
94 EXPECT_FALSE(hit_javascript_errors_.Get()) 129 EXPECT_FALSE(hit_javascript_errors_.Get())
95 << "Encountered javascript errors during test execution (Search " 130 << "Encountered javascript errors during test execution (Search "
96 << "for Uncaught or ERROR:CONSOLE in the test output)."; 131 << "for Uncaught or ERROR:CONSOLE in the test output).";
97 } 132 }
98 } 133 }
99 134
100 bool WebRtcTestBase::GetUserMediaAndAccept( 135 bool WebRtcTestBase::GetUserMediaAndAccept(
101 content::WebContents* tab_contents) const { 136 content::WebContents* tab_contents,
137 ExpectedPromptBehaviour expected_prompt_behaviour) const {
102 return GetUserMediaWithSpecificConstraintsAndAccept( 138 return GetUserMediaWithSpecificConstraintsAndAccept(
103 tab_contents, kAudioVideoCallConstraints); 139 tab_contents, kAudioVideoCallConstraints, expected_prompt_behaviour);
104 } 140 }
105 141
106 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept( 142 bool WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndAccept(
107 content::WebContents* tab_contents, 143 content::WebContents* tab_contents,
108 const std::string& constraints) const { 144 const std::string& constraints,
145 ExpectedPromptBehaviour expected_prompt_behaviour) const {
109 std::string result; 146 std::string result;
110 PermissionBubbleManager::FromWebContents(tab_contents) 147 PermissionBubbleManager::FromWebContents(tab_contents)
111 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL); 148 ->set_auto_response_for_test(PermissionBubbleManager::ACCEPT_ALL);
112 GetUserMedia(tab_contents, constraints); 149 PermissionRequestObserver permissionRequestObserver(tab_contents);
150 GetUserMedia(tab_contents, constraints, expected_prompt_behaviour);
113 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 151 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
114 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 152 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
115 return kOkGotStream == result; 153 return kOkGotStream == result;
116 } 154 }
117 155
118 void WebRtcTestBase::GetUserMediaAndDeny(content::WebContents* tab_contents) { 156 void WebRtcTestBase::GetUserMediaAndDeny(
119 return GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 157 content::WebContents* tab_contents,
120 kAudioVideoCallConstraints); 158 ExpectedPromptBehaviour expected_prompt_behaviour) {
159 return GetUserMediaWithSpecificConstraintsAndDeny(
160 tab_contents, kAudioVideoCallConstraints, expected_prompt_behaviour);
121 } 161 }
122 162
123 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny( 163 void WebRtcTestBase::GetUserMediaWithSpecificConstraintsAndDeny(
124 content::WebContents* tab_contents, 164 content::WebContents* tab_contents,
125 const std::string& constraints) const { 165 const std::string& constraints,
166 ExpectedPromptBehaviour expected_prompt_behaviour) const {
126 std::string result; 167 std::string result;
127 PermissionBubbleManager::FromWebContents(tab_contents) 168 PermissionBubbleManager::FromWebContents(tab_contents)
128 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL); 169 ->set_auto_response_for_test(PermissionBubbleManager::DENY_ALL);
129 GetUserMedia(tab_contents, constraints); 170 PermissionRequestObserver permissionRequestObserver(tab_contents);
171 GetUserMedia(tab_contents, constraints, expected_prompt_behaviour);
130 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 172 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
131 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 173 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
132 EXPECT_EQ(kFailedWithPermissionDeniedError, result); 174 EXPECT_EQ(kFailedWithPermissionDeniedError, result);
133 } 175 }
134 176
135 void WebRtcTestBase::GetUserMediaAndDismiss( 177 void WebRtcTestBase::GetUserMediaAndDismiss(
136 content::WebContents* tab_contents) const { 178 content::WebContents* tab_contents,
179 ExpectedPromptBehaviour expected_prompt_behaviour) const {
137 std::string result; 180 std::string result;
138 PermissionBubbleManager::FromWebContents(tab_contents) 181 PermissionBubbleManager::FromWebContents(tab_contents)
139 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS); 182 ->set_auto_response_for_test(PermissionBubbleManager::DISMISS);
140 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 183 GetUserMedia(tab_contents, kAudioVideoCallConstraints,
184 expected_prompt_behaviour);
141 // A dismiss should be treated like a deny. 185 // A dismiss should be treated like a deny.
142 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 186 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
143 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result)); 187 tab_contents->GetMainFrame(), "obtainGetUserMediaResult();", &result));
144 EXPECT_EQ(kFailedWithPermissionDismissedError, result); 188 EXPECT_EQ(kFailedWithPermissionDismissedError, result);
145 } 189 }
146 190
147 void WebRtcTestBase::GetUserMedia(content::WebContents* tab_contents, 191 void WebRtcTestBase::GetUserMedia(
148 const std::string& constraints) const { 192 content::WebContents* tab_contents,
193 const std::string& constraints,
194 ExpectedPromptBehaviour expected_prompt_behaviour) const {
195 PermissionRequestObserver permissionRequestObserver(tab_contents);
149 // Request user media: this will launch the media stream info bar or bubble. 196 // Request user media: this will launch the media stream info bar or bubble.
150 std::string result; 197 std::string result;
151 EXPECT_TRUE(content::ExecuteScriptAndExtractString( 198 EXPECT_TRUE(content::ExecuteScriptAndExtractString(
152 tab_contents, "doGetUserMedia(" + constraints + ");", &result)); 199 tab_contents, "doGetUserMedia(" + constraints + ");", &result));
153 EXPECT_TRUE(result == "request-callback-denied" || 200 EXPECT_TRUE(result == "request-callback-denied" ||
154 result == "request-callback-granted"); 201 result == "request-callback-granted");
202 switch (expected_prompt_behaviour) {
203 case IGNORE_PROMPT_BEHAVIOUR:
204 // Nothing
205 break;
206 case EXPECT_PROMPT_SHOWN:
207 EXPECT_TRUE(permissionRequestObserver.request_shown());
208 break;
209 case EXPECT_PROMPT_NOT_SHOWN:
210 EXPECT_FALSE(permissionRequestObserver.request_shown());
211 break;
212 }
155 } 213 }
156 214
157 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab( 215 content::WebContents* WebRtcTestBase::OpenPageAndGetUserMediaInNewTab(
158 const GURL& url) const { 216 const GURL& url) const {
159 return OpenPageAndGetUserMediaInNewTabWithConstraints( 217 return OpenPageAndGetUserMediaInNewTabWithConstraints(
160 url, kAudioVideoCallConstraints); 218 url, kAudioVideoCallConstraints);
161 } 219 }
162 220
163 content::WebContents* 221 content::WebContents*
164 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints( 222 WebRtcTestBase::OpenPageAndGetUserMediaInNewTabWithConstraints(
165 const GURL& url, 223 const GURL& url,
166 const std::string& constraints) const { 224 const std::string& constraints) const {
167 chrome::AddTabAt(browser(), GURL(), -1, true); 225 chrome::AddTabAt(browser(), GURL(), -1, true);
168 ui_test_utils::NavigateToURL(browser(), url); 226 ui_test_utils::NavigateToURL(browser(), url);
169 content::WebContents* new_tab = 227 content::WebContents* new_tab =
170 browser()->tab_strip_model()->GetActiveWebContents(); 228 browser()->tab_strip_model()->GetActiveWebContents();
171 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( 229 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept(
172 new_tab, constraints)); 230 new_tab, constraints, IGNORE_PROMPT_BEHAVIOUR));
173 return new_tab; 231 return new_tab;
174 } 232 }
175 233
176 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab( 234 content::WebContents* WebRtcTestBase::OpenTestPageAndGetUserMediaInNewTab(
177 const std::string& test_page) const { 235 const std::string& test_page) const {
178 return OpenPageAndGetUserMediaInNewTab( 236 return OpenPageAndGetUserMediaInNewTab(
179 embedded_test_server()->GetURL(test_page)); 237 embedded_test_server()->GetURL(test_page));
180 } 238 }
181 239
182 void WebRtcTestBase::CloseLastLocalStream( 240 void WebRtcTestBase::CloseLastLocalStream(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 #endif 369 #endif
312 } 370 }
313 371
314 bool WebRtcTestBase::OnWin8() const { 372 bool WebRtcTestBase::OnWin8() const {
315 #if defined(OS_WIN) 373 #if defined(OS_WIN)
316 return base::win::GetVersion() > base::win::VERSION_WIN7; 374 return base::win::GetVersion() > base::win::VERSION_WIN7;
317 #else 375 #else
318 return false; 376 return false;
319 #endif 377 #endif
320 } 378 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698