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

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

Issue 262763004: Per navigation sticky media permissions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
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/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 10 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/infobars/infobar_service.h" 11 #include "chrome/browser/infobars/infobar_service.h"
12 #include "chrome/browser/media/media_stream_devices_controller.h"
12 #include "chrome/browser/media/webrtc_browsertest_base.h" 13 #include "chrome/browser/media/webrtc_browsertest_base.h"
13 #include "chrome/browser/media/webrtc_browsertest_common.h" 14 #include "chrome/browser/media/webrtc_browsertest_common.h"
14 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.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/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/content_settings_types.h" 20 #include "chrome/common/content_settings_types.h"
20 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h" 22 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/ui_test_utils.h" 23 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/infobars/core/infobar.h" 24 #include "components/infobars/core/infobar.h"
24 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/common/media_stream_request.h"
25 #include "content/public/test/browser_test_utils.h" 27 #include "content/public/test/browser_test_utils.h"
26 #include "net/test/spawned_test_server/spawned_test_server.h" 28 #include "net/test/spawned_test_server/spawned_test_server.h"
27 29
28 30
29 // MediaStreamInfoBarTest ----------------------------------------------------- 31 // MediaStreamInfoBarTest -----------------------------------------------------
30 32
31 class MediaStreamInfoBarTest : public WebRtcTestBase { 33 class MediaStreamInfoBarTest : public WebRtcTestBase {
32 public: 34 public:
33 MediaStreamInfoBarTest() {} 35 MediaStreamInfoBarTest() {}
34 virtual ~MediaStreamInfoBarTest() {} 36 virtual ~MediaStreamInfoBarTest() {}
35 37
36 // InProcessBrowserTest: 38 // InProcessBrowserTest:
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
38 // This test expects to run with fake devices but real UI. 40 // This test expects to run with fake devices but real UI.
39 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); 41 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
40 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) 42 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream))
41 << "Since this test tests the UI we want the real UI!"; 43 << "Since this test tests the UI we want the real UI!";
42 } 44 }
43 45
44 protected: 46 protected:
45 content::WebContents* LoadTestPageInTab() { 47 content::WebContents* LoadTestPageInTab() {
46 return LoadTestPageInBrowser(browser()); 48 return LoadTestPageInBrowser(browser());
47 } 49 }
48 50
49 content::WebContents* LoadTestPageInIncognitoTab() { 51 content::WebContents* LoadTestPageInIncognitoTab() {
50 return LoadTestPageInBrowser(CreateIncognitoBrowser()); 52 return LoadTestPageInBrowser(CreateIncognitoBrowser());
51 } 53 }
52 54
55 // Returns the URL of the main test page.
56 GURL test_page_url() const {
57 const char kMainWebrtcTestHtmlPage[] =
58 "files/webrtc/webrtc_jsep01_test.html";
59 return test_server()->GetURL(kMainWebrtcTestHtmlPage);
60 }
61
62 // Denies getUserMedia requests (audio, video) for the test page.
63 // The deny setting is sticky.
64 void DenyRequest(content::WebContents* tab_contents,
65 content::MediaStreamRequestResult result) const {
66 const std::string no_id;
67 content::MediaStreamRequest request(
68 0, 0, 0, test_page_url().GetOrigin(), false,
69 content::MEDIA_DEVICE_ACCESS, no_id, no_id,
70 content::MEDIA_DEVICE_AUDIO_CAPTURE,
71 content::MEDIA_DEVICE_VIDEO_CAPTURE);
72
73 scoped_ptr<MediaStreamDevicesController> controller(
74 new MediaStreamDevicesController(tab_contents, request,
75 base::Bind(&OnMediaStreamResponse)));
76 controller->Deny(true, result);
77 }
78
79 // Executes stopLocalStream() in the test page, which frees up an already
80 // acquired mediastream.
81 bool StopLocalStream(content::WebContents* tab_contents) {
82 std::string result;
83 bool ok = content::ExecuteScriptAndExtractString(
84 tab_contents, "stopLocalStream()", &result);
perkj_chrome 2014/05/05 07:28:25 Do you know what this uses? Stop the tracks or sto
tommi (sloooow) - chröme 2014/05/05 08:02:54 I think it does the right thing but you can verify
85 DCHECK(ok);
86 return result.compare("ok-stopped") == 0;
87 }
88
53 private: 89 private:
54 content::WebContents* LoadTestPageInBrowser(Browser* browser) { 90 content::WebContents* LoadTestPageInBrowser(Browser* browser) {
55 EXPECT_TRUE(test_server()->Start()); 91 EXPECT_TRUE(test_server()->Start());
56 92
57 const char kMainWebrtcTestHtmlPage[] = 93 ui_test_utils::NavigateToURL(browser, test_page_url());
58 "files/webrtc/webrtc_jsep01_test.html";
59 ui_test_utils::NavigateToURL(
60 browser, test_server()->GetURL(kMainWebrtcTestHtmlPage));
61 return browser->tab_strip_model()->GetActiveWebContents(); 94 return browser->tab_strip_model()->GetActiveWebContents();
62 } 95 }
63 96
97 // Dummy callback for when we deny the current request directly.
98 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices,
99 content::MediaStreamRequestResult result,
100 scoped_ptr<content::MediaStreamUI> ui) {}
101
64 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest); 102 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest);
65 }; 103 };
66 104
67
68 // Actual tests --------------------------------------------------------------- 105 // Actual tests ---------------------------------------------------------------
69 106
70 // Failing on ChromiumOS Debug and Win Aura, so disabling on both. 107 // Failing on ChromiumOS Debug and Win Aura, so disabling on both.
71 // See http://crbug.com/263333. 108 // See http://crbug.com/263333.
72 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA) 109 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA)
73 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia 110 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia
74 #else 111 #else
75 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia 112 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia
76 #endif 113 #endif
77 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAllowingUserMedia) { 114 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAllowingUserMedia) {
(...skipping 29 matching lines...) Expand all
107 MAYBE_TestAcceptThenDenyWhichShouldBeSticky) { 144 MAYBE_TestAcceptThenDenyWhichShouldBeSticky) {
108 #if defined(OS_WIN) && defined(USE_ASH) 145 #if defined(OS_WIN) && defined(USE_ASH)
109 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 146 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
110 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 147 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
111 return; 148 return;
112 #endif 149 #endif
113 150
114 content::WebContents* tab_contents = LoadTestPageInTab(); 151 content::WebContents* tab_contents = LoadTestPageInTab();
115 152
116 GetUserMediaAndAccept(tab_contents); 153 GetUserMediaAndAccept(tab_contents);
117 GetUserMediaAndDeny(tab_contents); 154 DenyRequest(tab_contents, content::MEDIA_DEVICE_PERMISSION_DENIED);
118 155
119 // Should fail with permission denied right away with no infobar popping up. 156 // Should fail with permission denied right away with no infobar popping up.
120 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 157 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
121 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", 158 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
122 kFailedWithPermissionDeniedError, 159 kFailedWithPermissionDeniedError,
123 tab_contents)); 160 tab_contents));
124 InfoBarService* infobar_service = 161 InfoBarService* infobar_service =
125 InfoBarService::FromWebContents(tab_contents); 162 InfoBarService::FromWebContents(tab_contents);
126 EXPECT_EQ(0u, infobar_service->infobar_count()); 163 EXPECT_EQ(0u, infobar_service->infobar_count());
127 } 164 }
128 165
129 // Failing on Win Aura, so disabling on that. 166 // Failing on Win Aura, so disabling on that.
130 // See http://crbug.com/263333. 167 // See http://crbug.com/263333.
perkj_chrome 2014/05/05 07:28:25 Can this be enabled?
tommi (sloooow) - chröme 2014/05/05 08:02:54 I thought about it but decided to rather do that o
131 #if defined(USE_AURA) 168 #if defined(USE_AURA)
132 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky 169 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky
133 #else 170 #else
134 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky 171 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky
135 #endif 172 #endif
136 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAcceptIsNotSticky) { 173 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAcceptIsNotSticky) {
137 content::WebContents* tab_contents = LoadTestPageInTab(); 174 content::WebContents* tab_contents = LoadTestPageInTab();
138 175
139 // If accept were sticky the second call would hang because it hangs if an 176 // If accept were sticky the second call would hang because it hangs if an
140 // infobar does not pop up. 177 // infobar does not pop up.
141 GetUserMediaAndAccept(tab_contents); 178 GetUserMediaAndAccept(tab_contents);
179
180 // Because http request permissions are sticky per navigation, we need to
181 // navigate away from the current page in order to verify that the granted
182 // permissions are not permanently sticky.
183 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
184 GURL("about:blank"), 1);
185
186 // Now navigate back to our test page.
187 ui_test_utils::NavigateToURL(browser(), test_page_url());
188 tab_contents = browser()->tab_strip_model()->GetActiveWebContents();
189
142 GetUserMediaAndAccept(tab_contents); 190 GetUserMediaAndAccept(tab_contents);
143 } 191 }
144 192
193 // Test that accepting one getUserMedia request will not require a second
194 // prompt when issuing a second getUserMedia request.
195 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
196 TestAcceptIsStickyPerNavigation) {
197 content::WebContents* tab_contents = LoadTestPageInTab();
198
199 GetUserMediaAndAccept(tab_contents);
200
201 // Before issuing the second gUM request, make sure we first stop the tracks
202 // we started with the first request. If they're still running the permissions
203 // will be active for other reasons and we won't be testing the temporary
204 // stickiness properly.
205 EXPECT_TRUE(StopLocalStream(tab_contents));
206
207 // Now no media tracks are running, so let's issue the second request.
208 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
209 }
210
211 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
212 TestTwoAcceptsPlusStickyPerNavigation) {
213 content::WebContents* tab_contents = LoadTestPageInTab();
214
215 // First ask for audio only and approve.
216 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
217 kAudioOnlyCallConstraints);
218 EXPECT_TRUE(StopLocalStream(tab_contents));
219
220 // Next ask for video permissions.
221 // This will hang if the previous gUM call somehow gave video permissions.
222 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
223 kVideoOnlyCallConstraints);
224 EXPECT_TRUE(StopLocalStream(tab_contents));
225
226 // Now ask for both audio and video and expect the call to go through without
227 // showing any UI.
228 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
229 }
230
145 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) { 231 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) {
146 content::WebContents* tab_contents = LoadTestPageInTab(); 232 content::WebContents* tab_contents = LoadTestPageInTab();
147 233
148 // If dismiss were sticky the second call would hang because it hangs if an 234 // If dismiss were sticky the second call would hang because it hangs if an
149 // infobar does not pop up. 235 // infobar does not pop up.
150 GetUserMediaAndDismiss(tab_contents); 236 GetUserMediaAndDismiss(tab_contents);
151 GetUserMediaAndDismiss(tab_contents); 237 GetUserMediaAndDismiss(tab_contents);
152 } 238 }
153 239
154 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 240 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 283 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
198 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics) { 284 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics) {
199 content::WebContents* tab_contents = LoadTestPageInTab(); 285 content::WebContents* tab_contents = LoadTestPageInTab();
200 286
201 // If camera blocking also blocked mics, the second call here would hang. 287 // If camera blocking also blocked mics, the second call here would hang.
202 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 288 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
203 kVideoOnlyCallConstraints); 289 kVideoOnlyCallConstraints);
204 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, 290 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
205 kAudioOnlyCallConstraints); 291 kAudioOnlyCallConstraints);
206 } 292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698