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

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

Issue 1286363002: Switch media stream permissions to use IsOriginSecure() instead of SchemeIsSecure(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address nits. 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 | « no previous file | chrome/browser/media/chrome_webrtc_webcam_browsertest.cc » ('j') | 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/media/media_stream_devices_controller.h" 9 #include "chrome/browser/media/media_stream_devices_controller.h"
10 #include "chrome/browser/media/webrtc_browsertest_base.h" 10 #include "chrome/browser/media/webrtc_browsertest_base.h"
11 #include "chrome/browser/media/webrtc_browsertest_common.h" 11 #include "chrome/browser/media/webrtc_browsertest_common.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 14 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
17 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/in_process_browser_test.h" 18 #include "chrome/test/base/in_process_browser_test.h"
19 #include "chrome/test/base/test_switches.h" 19 #include "chrome/test/base/test_switches.h"
20 #include "chrome/test/base/ui_test_utils.h" 20 #include "chrome/test/base/ui_test_utils.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 21 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/content_settings/core/common/content_settings_types.h" 22 #include "components/content_settings/core/common/content_settings_types.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/common/media_stream_request.h" 24 #include "content/public/common/media_stream_request.h"
25 #include "content/public/common/origin_util.h"
25 #include "content/public/test/browser_test_utils.h" 26 #include "content/public/test/browser_test_utils.h"
26 #include "media/base/media_switches.h" 27 #include "media/base/media_switches.h"
28 #include "net/dns/mock_host_resolver.h"
27 #include "net/test/spawned_test_server/spawned_test_server.h" 29 #include "net/test/spawned_test_server/spawned_test_server.h"
28 30
29 // MediaStreamPermissionTest --------------------------------------------------- 31 // MediaStreamPermissionTest ---------------------------------------------------
30 32
31 class MediaStreamPermissionTest : public WebRtcTestBase { 33 class MediaStreamPermissionTest : public WebRtcTestBase {
32 public: 34 public:
33 MediaStreamPermissionTest() {} 35 MediaStreamPermissionTest() {}
34 ~MediaStreamPermissionTest() override {} 36 ~MediaStreamPermissionTest() override {}
35 37
36 // InProcessBrowserTest: 38 // InProcessBrowserTest:
(...skipping 23 matching lines...) Expand all
60 // Executes stopLocalStream() in the test page, which frees up an already 62 // Executes stopLocalStream() in the test page, which frees up an already
61 // acquired mediastream. 63 // acquired mediastream.
62 bool StopLocalStream(content::WebContents* tab_contents) { 64 bool StopLocalStream(content::WebContents* tab_contents) {
63 std::string result; 65 std::string result;
64 bool ok = content::ExecuteScriptAndExtractString( 66 bool ok = content::ExecuteScriptAndExtractString(
65 tab_contents, "stopLocalStream()", &result); 67 tab_contents, "stopLocalStream()", &result);
66 DCHECK(ok); 68 DCHECK(ok);
67 return result.compare("ok-stopped") == 0; 69 return result.compare("ok-stopped") == 0;
68 } 70 }
69 71
72 void useNonSecureOriginForTestPage() {
73 use_secure_origin_for_test_page_ = false;
74 host_resolver()->AddRule("*", "127.0.0.1");
75 }
76
70 private: 77 private:
78 // The default test server is localhost, which is considered secure:
79 // http://www.w3.org/TR/powerful-features/#is-origin-trustworthy
80 bool use_secure_origin_for_test_page_ = true;
81
71 content::WebContents* LoadTestPageInBrowser(Browser* browser) { 82 content::WebContents* LoadTestPageInBrowser(Browser* browser) {
72 EXPECT_TRUE(test_server()->Start()); 83 EXPECT_TRUE(test_server()->Start());
73 84
74 ui_test_utils::NavigateToURL(browser, test_page_url()); 85 GURL url;
86
87 if (use_secure_origin_for_test_page_) {
88 // Uses the default server.
89 url = test_page_url();
90 } else {
91 static const char kFoo[] = "not-secure.example.com";
92 GURL::Replacements replacements;
93 replacements.SetSchemeStr(url::kHttpScheme);
94 replacements.SetHostStr(kFoo);
95 url = test_page_url().ReplaceComponents(replacements);
96 }
97
98 EXPECT_EQ(use_secure_origin_for_test_page_, content::IsOriginSecure(url));
99
100 ui_test_utils::NavigateToURL(browser, url);
75 return browser->tab_strip_model()->GetActiveWebContents(); 101 return browser->tab_strip_model()->GetActiveWebContents();
76 } 102 }
77 103
78 // Dummy callback for when we deny the current request directly. 104 // Dummy callback for when we deny the current request directly.
79 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, 105 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices,
80 content::MediaStreamRequestResult result, 106 content::MediaStreamRequestResult result,
81 scoped_ptr<content::MediaStreamUI> ui) {} 107 scoped_ptr<content::MediaStreamUI> ui) {}
82 108
83 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); 109 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest);
84 }; 110 };
(...skipping 15 matching lines...) Expand all
100 GetUserMediaAndDismiss(tab_contents); 126 GetUserMediaAndDismiss(tab_contents);
101 } 127 }
102 128
103 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, 129 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
104 TestDenyingUserMediaIncognito) { 130 TestDenyingUserMediaIncognito) {
105 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); 131 content::WebContents* tab_contents = LoadTestPageInIncognitoTab();
106 GetUserMediaAndDeny(tab_contents); 132 GetUserMediaAndDeny(tab_contents);
107 } 133 }
108 134
109 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, 135 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
110 TestAcceptThenDenyWhichShouldBeSticky) { 136 TestNonSecureOriginAcceptThenDenyIsSticky) {
111 #if defined(OS_WIN) && defined(USE_ASH) 137 #if defined(OS_WIN) && defined(USE_ASH)
112 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 138 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
113 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 139 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
114 switches::kAshBrowserTests)) 140 switches::kAshBrowserTests))
115 return; 141 return;
116 #endif 142 #endif
117 143
144 useNonSecureOriginForTestPage();
118 content::WebContents* tab_contents = LoadTestPageInTab(); 145 content::WebContents* tab_contents = LoadTestPageInTab();
146 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL()));
119 147
120 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); 148 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents));
121 GetUserMediaAndDeny(tab_contents); 149 GetUserMediaAndDeny(tab_contents);
122 150
123 // Should fail with permission denied, instead of hanging. 151 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents);
124 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
125 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
126 kFailedWithPermissionDeniedError,
127 tab_contents));
128 } 152 }
129 153
130 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAcceptIsNotSticky) { 154 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
155 TestNonSecureOriginDenyIsSticky) {
156 useNonSecureOriginForTestPage();
131 content::WebContents* tab_contents = LoadTestPageInTab(); 157 content::WebContents* tab_contents = LoadTestPageInTab();
158 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL()));
132 159
133 // If accept were sticky the second call would hang because it hangs if a 160 GetUserMediaAndDeny(tab_contents);
134 // bubble does not pop up. 161 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents);
162 }
163
164 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
165 TestSecureOriginDenyIsSticky) {
166 content::WebContents* tab_contents = LoadTestPageInTab();
167 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL()));
168
169 GetUserMediaAndDeny(tab_contents);
170 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents);
171 }
172
173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
174 TestNonSecureOriginAcceptIsNotSticky) {
175 useNonSecureOriginForTestPage();
176 content::WebContents* tab_contents = LoadTestPageInTab();
177 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL()));
178
135 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); 179 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents));
136 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); 180 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents));
137 } 181 }
138 182
183 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
184 TestSecureOriginAcceptIsSticky) {
185 content::WebContents* tab_contents = LoadTestPageInTab();
186 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL()));
187
188 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents));
189 GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents);
190 }
191
139 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { 192 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) {
140 content::WebContents* tab_contents = LoadTestPageInTab(); 193 content::WebContents* tab_contents = LoadTestPageInTab();
141 194
142 // If dismiss were sticky the second call would hang because it hangs if a
143 // bubble does not pop up.
144 GetUserMediaAndDismiss(tab_contents); 195 GetUserMediaAndDismiss(tab_contents);
145 GetUserMediaAndDismiss(tab_contents); 196 GetUserMediaAndDismiss(tab_contents);
146 } 197 }
147 198
148 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, 199 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
149 TestDenyingThenClearingStickyException) { 200 TestDenyingThenClearingStickyException) {
150 content::WebContents* tab_contents = LoadTestPageInTab(); 201 content::WebContents* tab_contents = LoadTestPageInTab();
151 202
152 GetUserMediaAndDeny(tab_contents); 203 GetUserMediaAndDeny(tab_contents);
204 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents);
153 205
154 HostContentSettingsMap* settings_map = 206 HostContentSettingsMap* settings_map =
155 browser()->profile()->GetHostContentSettingsMap(); 207 browser()->profile()->GetHostContentSettingsMap();
156 208
157 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 209 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
158 settings_map->ClearSettingsForOneType( 210 settings_map->ClearSettingsForOneType(
159 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 211 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
160 212
161 // If a bubble is not launched now, this will hang.
162 GetUserMediaAndDeny(tab_contents); 213 GetUserMediaAndDeny(tab_contents);
163 } 214 }
164 215
165 // Times out on win debug builds; http://crbug.com/295723 .
166 #if defined(OS_WIN) && !defined(NDEBUG)
167 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
168 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras
169 #else
170 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
171 DenyingMicDoesNotCauseStickyDenyForCameras
172 #endif
173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, 216 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
174 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { 217 DenyingMicDoesNotCauseStickyDenyForCameras) {
175 content::WebContents* tab_contents = LoadTestPageInTab(); 218 content::WebContents* tab_contents = LoadTestPageInTab();
176 219
177 // If mic blocking also blocked cameras, the second call here would hang.
178 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 220 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
179 kAudioOnlyCallConstraints); 221 kAudioOnlyCallConstraints);
180 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( 222 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept(
181 tab_contents, kVideoOnlyCallConstraints)); 223 tab_contents, kVideoOnlyCallConstraints));
182 } 224 }
183 225
184 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, 226 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest,
185 DenyingCameraDoesNotCauseStickyDenyForMics) { 227 DenyingCameraDoesNotCauseStickyDenyForMics) {
186 content::WebContents* tab_contents = LoadTestPageInTab(); 228 content::WebContents* tab_contents = LoadTestPageInTab();
187 229
188 // If camera blocking also blocked mics, the second call here would hang.
189 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 230 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
190 kVideoOnlyCallConstraints); 231 kVideoOnlyCallConstraints);
191 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( 232 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept(
192 tab_contents, kAudioOnlyCallConstraints)); 233 tab_contents, kAudioOnlyCallConstraints));
193 } 234 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/media/chrome_webrtc_webcam_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698