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

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

Issue 341833004: [WebsiteSettings] Enable permission bubbles by default. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 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 | 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/media_stream_devices_controller.h"
13 #include "chrome/browser/media/webrtc_browsertest_base.h" 13 #include "chrome/browser/media/webrtc_browsertest_base.h"
14 #include "chrome/browser/media/webrtc_browsertest_common.h" 14 #include "chrome/browser/media/webrtc_browsertest_common.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_tabstrip.h" 17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
19 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.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/content_settings/core/common/content_settings_types.h" 24 #include "components/content_settings/core/common/content_settings_types.h"
24 #include "components/infobars/core/infobar.h" 25 #include "components/infobars/core/infobar.h"
25 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
26 #include "content/public/common/media_stream_request.h" 27 #include "content/public/common/media_stream_request.h"
27 #include "content/public/test/browser_test_utils.h" 28 #include "content/public/test/browser_test_utils.h"
28 #include "media/base/media_switches.h" 29 #include "media/base/media_switches.h"
29 #include "net/test/spawned_test_server/spawned_test_server.h" 30 #include "net/test/spawned_test_server/spawned_test_server.h"
30 31
31 32
32 // MediaStreamInfoBarTest ----------------------------------------------------- 33 class MockPermissionBubbleView : public PermissionBubbleView {
34 public:
35 MockPermissionBubbleView() : shown_(false) {}
36 virtual ~MockPermissionBubbleView() {}
33 37
34 class MediaStreamInfoBarTest : public WebRtcTestBase { 38 virtual void SetDelegate(Delegate* delegate) OVERRIDE {
39 }
40
41 virtual void Show(
42 const std::vector<PermissionBubbleRequest*>& requests,
43 const std::vector<bool>& accept_state,
44 bool customization_mode) OVERRIDE {
45 LOG(INFO) << "Showing view... " << requests[0]->GetMessageText();
46 shown_ = true;
47 }
48
49 virtual bool CanAcceptRequestUpdate() OVERRIDE {
50 return true;
51 }
52
53 virtual void Hide() OVERRIDE {
54 shown_ = false;
55 }
56
57 virtual bool IsVisible() OVERRIDE {
58 return shown_;
59 }
60
61 private:
62 bool shown_;
63 };
64
65 // MediaStreamBrowserTest -----------------------------------------------------
66
67 class MediaStreamBrowserTest : public WebRtcTestBase {
35 public: 68 public:
36 MediaStreamInfoBarTest() {} 69 MediaStreamBrowserTest() {}
37 virtual ~MediaStreamInfoBarTest() {} 70 virtual ~MediaStreamBrowserTest() {}
38 71
39 // InProcessBrowserTest: 72 // InProcessBrowserTest:
40 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 73 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
41 // This test expects to run with fake devices but real UI. 74 // This test expects to run with fake devices but real UI.
42 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); 75 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
43 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) 76 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream))
44 << "Since this test tests the UI we want the real UI!"; 77 << "Since this test tests the UI we want the real UI!";
45 } 78 }
46 79
47 protected: 80 protected:
(...skipping 22 matching lines...) Expand all
70 content::MEDIA_DEVICE_ACCESS, no_id, no_id, 103 content::MEDIA_DEVICE_ACCESS, no_id, no_id,
71 content::MEDIA_DEVICE_AUDIO_CAPTURE, 104 content::MEDIA_DEVICE_AUDIO_CAPTURE,
72 content::MEDIA_DEVICE_VIDEO_CAPTURE); 105 content::MEDIA_DEVICE_VIDEO_CAPTURE);
73 106
74 scoped_ptr<MediaStreamDevicesController> controller( 107 scoped_ptr<MediaStreamDevicesController> controller(
75 new MediaStreamDevicesController(tab_contents, request, 108 new MediaStreamDevicesController(tab_contents, request,
76 base::Bind(&OnMediaStreamResponse))); 109 base::Bind(&OnMediaStreamResponse)));
77 controller->Deny(true, result); 110 controller->Deny(true, result);
78 } 111 }
79 112
113 int GetBubblesQueueSize(PermissionBubbleManager* mgr) {
114 return static_cast<int>(mgr->requests_.size());
115 }
116
80 // Executes stopLocalStream() in the test page, which frees up an already 117 // Executes stopLocalStream() in the test page, which frees up an already
81 // acquired mediastream. 118 // acquired mediastream.
82 bool StopLocalStream(content::WebContents* tab_contents) { 119 bool StopLocalStream(content::WebContents* tab_contents) {
83 std::string result; 120 std::string result;
84 bool ok = content::ExecuteScriptAndExtractString( 121 bool ok = content::ExecuteScriptAndExtractString(
85 tab_contents, "stopLocalStream()", &result); 122 tab_contents, "stopLocalStream()", &result);
86 DCHECK(ok); 123 DCHECK(ok);
87 return result.compare("ok-stopped") == 0; 124 return result.compare("ok-stopped") == 0;
88 } 125 }
89 126
90 private: 127 private:
91 content::WebContents* LoadTestPageInBrowser(Browser* browser) { 128 content::WebContents* LoadTestPageInBrowser(Browser* browser) {
92 EXPECT_TRUE(test_server()->Start()); 129 EXPECT_TRUE(test_server()->Start());
93 130
94 ui_test_utils::NavigateToURL(browser, test_page_url()); 131 ui_test_utils::NavigateToURL(browser, test_page_url());
95 return browser->tab_strip_model()->GetActiveWebContents(); 132 return browser->tab_strip_model()->GetActiveWebContents();
96 } 133 }
97 134
98 // Dummy callback for when we deny the current request directly. 135 // Dummy callback for when we deny the current request directly.
99 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, 136 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices,
100 content::MediaStreamRequestResult result, 137 content::MediaStreamRequestResult result,
101 scoped_ptr<content::MediaStreamUI> ui) {} 138 scoped_ptr<content::MediaStreamUI> ui) {}
102 139
103 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest); 140 MockPermissionBubbleView mock_view_;
141
142 DISALLOW_COPY_AND_ASSIGN(MediaStreamBrowserTest);
104 }; 143 };
105 144
106 // Actual tests --------------------------------------------------------------- 145 // Actual tests ---------------------------------------------------------------
107 146
108 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestAllowingUserMedia) { 147 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestAllowingUserMedia) {
109 content::WebContents* tab_contents = LoadTestPageInTab(); 148 content::WebContents* tab_contents = LoadTestPageInTab();
110 GetUserMediaAndAccept(tab_contents); 149 GetUserMediaAndAccept(tab_contents);
111 } 150 }
112 151
113 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDenyingUserMedia) { 152 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestDenyingUserMedia) {
114 content::WebContents* tab_contents = LoadTestPageInTab(); 153 content::WebContents* tab_contents = LoadTestPageInTab();
115 GetUserMediaAndDeny(tab_contents); 154 GetUserMediaAndDeny(tab_contents);
116 } 155 }
117 156
118 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissingInfobar) { 157 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestDismissingPrompt) {
119 content::WebContents* tab_contents = LoadTestPageInTab(); 158 content::WebContents* tab_contents = LoadTestPageInTab();
120 GetUserMediaAndDismiss(tab_contents); 159 GetUserMediaAndDismiss(tab_contents);
121 } 160 }
122 161
123 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDenyingUserMediaIncognito) { 162 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestDenyingUserMediaIncognito) {
124 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); 163 content::WebContents* tab_contents = LoadTestPageInIncognitoTab();
125 GetUserMediaAndDeny(tab_contents); 164 GetUserMediaAndDeny(tab_contents);
126 } 165 }
127 166
128 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 167 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest,
129 TestAcceptThenDenyWhichShouldBeSticky) { 168 TestAcceptThenDenyWhichShouldBeSticky) {
130 #if defined(OS_WIN) && defined(USE_ASH) 169 #if defined(OS_WIN) && defined(USE_ASH)
131 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 170 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
132 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 171 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
133 return; 172 return;
134 #endif 173 #endif
135 174
136 content::WebContents* tab_contents = LoadTestPageInTab(); 175 content::WebContents* tab_contents = LoadTestPageInTab();
137 176
138 GetUserMediaAndAccept(tab_contents); 177 GetUserMediaAndAccept(tab_contents);
139 GetUserMediaAndDeny(tab_contents); 178 GetUserMediaAndDeny(tab_contents);
140 179
141 // Should fail with permission denied right away with no infobar popping up. 180 // Should fail with permission denied right away with no prompt popping up.
142 GetUserMedia(tab_contents, kAudioVideoCallConstraints); 181 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
143 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", 182 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
144 kFailedWithPermissionDeniedError, 183 kFailedWithPermissionDeniedError,
145 tab_contents)); 184 tab_contents));
146 InfoBarService* infobar_service = 185
147 InfoBarService::FromWebContents(tab_contents); 186 if (!PermissionBubbleManager::Enabled()) {
148 EXPECT_EQ(0u, infobar_service->infobar_count()); 187 InfoBarService* infobar_service =
188 InfoBarService::FromWebContents(tab_contents);
189 EXPECT_EQ(0u, infobar_service->infobar_count());
190 } else {
191 PermissionBubbleManager* manager =
192 PermissionBubbleManager::FromWebContents(tab_contents);
193 EXPECT_EQ(0, GetBubblesQueueSize(manager));
194 }
149 } 195 }
150 196
151 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestAcceptIsNotSticky) { 197 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestAcceptIsNotSticky) {
152 content::WebContents* tab_contents = LoadTestPageInTab(); 198 content::WebContents* tab_contents = LoadTestPageInTab();
153 199
154 // If accept were sticky the second call would hang because it hangs if an 200 // If accept were sticky the second call would hang because it hangs if a
155 // infobar does not pop up. 201 // prompt does not pop up.
156 GetUserMediaAndAccept(tab_contents); 202 GetUserMediaAndAccept(tab_contents);
157 GetUserMediaAndAccept(tab_contents); 203 GetUserMediaAndAccept(tab_contents);
158 } 204 }
159 205
160 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) { 206 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest, TestDismissIsNotSticky) {
161 content::WebContents* tab_contents = LoadTestPageInTab(); 207 content::WebContents* tab_contents = LoadTestPageInTab();
162 208
163 // If dismiss were sticky the second call would hang because it hangs if an 209 // If dismiss were sticky the second call would hang because it hangs if a
164 // infobar does not pop up. 210 // prompt does not pop up.
165 GetUserMediaAndDismiss(tab_contents); 211 GetUserMediaAndDismiss(tab_contents);
166 GetUserMediaAndDismiss(tab_contents); 212 GetUserMediaAndDismiss(tab_contents);
167 } 213 }
168 214
169 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 215 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest,
170 TestDenyingThenClearingStickyException) { 216 TestDenyingThenClearingStickyException) {
171 content::WebContents* tab_contents = LoadTestPageInTab(); 217 content::WebContents* tab_contents = LoadTestPageInTab();
172 218
173 GetUserMediaAndDeny(tab_contents); 219 GetUserMediaAndDeny(tab_contents);
174 220
175 HostContentSettingsMap* settings_map = 221 HostContentSettingsMap* settings_map =
176 browser()->profile()->GetHostContentSettingsMap(); 222 browser()->profile()->GetHostContentSettingsMap();
177 223
178 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); 224 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
179 settings_map->ClearSettingsForOneType( 225 settings_map->ClearSettingsForOneType(
180 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); 226 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
181 227
182 // If an infobar is not launched now, this will hang. 228 // If a prompt is not shown now, this will hang.
183 GetUserMediaAndDeny(tab_contents); 229 GetUserMediaAndDeny(tab_contents);
184 } 230 }
185 231
186 // Times out on win debug builds; http://crbug.com/295723 . 232 // Times out on win debug builds; http://crbug.com/295723 .
187 #if defined(OS_WIN) && !defined(NDEBUG) 233 #if defined(OS_WIN) && !defined(NDEBUG)
188 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ 234 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
189 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras 235 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras
190 #else 236 #else
191 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ 237 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
192 DenyingMicDoesNotCauseStickyDenyForCameras 238 DenyingMicDoesNotCauseStickyDenyForCameras
193 #endif 239 #endif
194 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 240 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest,
195 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { 241 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) {
196 content::WebContents* tab_contents = LoadTestPageInTab(); 242 content::WebContents* tab_contents = LoadTestPageInTab();
197 243
198 // If mic blocking also blocked cameras, the second call here would hang. 244 // If mic blocking also blocked cameras, the second call here would hang.
199 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 245 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
200 kAudioOnlyCallConstraints); 246 kAudioOnlyCallConstraints);
201 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, 247 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
202 kVideoOnlyCallConstraints); 248 kVideoOnlyCallConstraints);
203 } 249 }
204 250
205 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, 251 IN_PROC_BROWSER_TEST_F(MediaStreamBrowserTest,
206 DenyingCameraDoesNotCauseStickyDenyForMics) { 252 DenyingCameraDoesNotCauseStickyDenyForMics) {
207 content::WebContents* tab_contents = LoadTestPageInTab(); 253 content::WebContents* tab_contents = LoadTestPageInTab();
208 254
209 // If camera blocking also blocked mics, the second call here would hang. 255 // If camera blocking also blocked mics, the second call here would hang.
210 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, 256 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
211 kVideoOnlyCallConstraints); 257 kVideoOnlyCallConstraints);
212 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, 258 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
213 kAudioOnlyCallConstraints); 259 kAudioOnlyCallConstraints);
214 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698