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
3 // found in the LICENSE file.
5 #include "base/command_line.h"
6 #include "base/file_util.h"
7 #include "base/path_service.h"
8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/media/webrtc_browsertest_base.h"
14 #include "chrome/browser/media/webrtc_browsertest_common.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_tabstrip.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_switches.h"
20 #include "chrome/common/content_settings_types.h"
21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/test_switches.h"
23 #include "chrome/test/base/ui_test_utils.h"
24 #include "chrome/test/ui/ui_test.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/test/browser_test_utils.h"
27 #include "net/test/spawned_test_server/spawned_test_server.h"
30 // MediaStreamInfoBarTest -----------------------------------------------------
32 class MediaStreamInfoBarTest
: public WebRtcTestBase
{
34 MediaStreamInfoBarTest() {}
35 virtual ~MediaStreamInfoBarTest() {}
37 // InProcessBrowserTest:
38 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
39 // This test expects to run with fake devices but real UI.
40 command_line
->AppendSwitch(switches::kUseFakeDeviceForMediaStream
);
41 EXPECT_FALSE(command_line
->HasSwitch(switches::kUseFakeUIForMediaStream
))
42 << "Since this test tests the UI we want the real UI!";
46 content::WebContents
* LoadTestPageInTab() {
47 return LoadTestPageInBrowser(browser());
50 content::WebContents
* LoadTestPageInIncognitoTab() {
51 return LoadTestPageInBrowser(CreateIncognitoBrowser());
55 content::WebContents
* LoadTestPageInBrowser(Browser
* browser
) {
56 EXPECT_TRUE(test_server()->Start());
58 const char kMainWebrtcTestHtmlPage
[] =
59 "files/webrtc/webrtc_jsep01_test.html";
60 ui_test_utils::NavigateToURL(
61 browser
, test_server()->GetURL(kMainWebrtcTestHtmlPage
));
62 return browser
->tab_strip_model()->GetActiveWebContents();
65 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest
);
69 // Actual tests ---------------------------------------------------------------
71 // Failing on ChromiumOS Debug and Win Aura, so disabling on both.
72 // See http://crbug.com/263333.
73 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA)
74 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia
76 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia
78 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, MAYBE_TestAllowingUserMedia
) {
79 content::WebContents
* tab_contents
= LoadTestPageInTab();
80 GetUserMediaAndAccept(tab_contents
);
83 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, TestDenyingUserMedia
) {
84 content::WebContents
* tab_contents
= LoadTestPageInTab();
85 GetUserMediaAndDeny(tab_contents
);
88 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, TestDismissingInfobar
) {
89 content::WebContents
* tab_contents
= LoadTestPageInTab();
90 GetUserMediaAndDismiss(tab_contents
);
93 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, TestDenyingUserMediaIncognito
) {
94 content::WebContents
* tab_contents
= LoadTestPageInIncognitoTab();
95 GetUserMediaAndDeny(tab_contents
);
98 // Failing on ChromiumOS Debug and Win Aura, so disabling on Aura.
99 // See http://crbug.com/263333.
100 #if defined(USE_AURA)
101 #define MAYBE_TestAcceptThenDenyWhichShouldBeSticky \
102 DISABLED_TestAcceptThenDenyWhichShouldBeSticky
104 #define MAYBE_TestAcceptThenDenyWhichShouldBeSticky \
105 TestAcceptThenDenyWhichShouldBeSticky
107 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
,
108 MAYBE_TestAcceptThenDenyWhichShouldBeSticky
) {
109 #if defined(OS_WIN) && defined(USE_ASH)
110 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
111 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests
))
115 content::WebContents
* tab_contents
= LoadTestPageInTab();
117 GetUserMediaAndAccept(tab_contents
);
118 GetUserMediaAndDeny(tab_contents
);
120 // Should fail with permission denied right away with no infobar popping up.
121 GetUserMedia(tab_contents
, kAudioVideoCallConstraints
);
122 EXPECT_TRUE(PollingWaitUntil("obtainGetUserMediaResult()",
123 kFailedWithPermissionDeniedError
,
125 InfoBarService
* infobar_service
=
126 InfoBarService::FromWebContents(tab_contents
);
127 EXPECT_EQ(0u, infobar_service
->infobar_count());
130 // Failing on Win Aura, so disabling on that.
131 // See http://crbug.com/263333.
132 #if defined(USE_AURA)
133 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky
135 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky
137 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, MAYBE_TestAcceptIsNotSticky
) {
138 content::WebContents
* tab_contents
= LoadTestPageInTab();
140 // If accept were sticky the second call would hang because it hangs if an
141 // infobar does not pop up.
142 GetUserMediaAndAccept(tab_contents
);
143 GetUserMediaAndAccept(tab_contents
);
146 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
, TestDismissIsNotSticky
) {
147 content::WebContents
* tab_contents
= LoadTestPageInTab();
149 // If dismiss were sticky the second call would hang because it hangs if an
150 // infobar does not pop up.
151 GetUserMediaAndDismiss(tab_contents
);
152 GetUserMediaAndDismiss(tab_contents
);
155 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
,
156 TestDenyingThenClearingStickyException
) {
157 content::WebContents
* tab_contents
= LoadTestPageInTab();
159 GetUserMediaAndDeny(tab_contents
);
161 HostContentSettingsMap
* settings_map
=
162 browser()->profile()->GetHostContentSettingsMap();
164 settings_map
->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC
);
165 settings_map
->ClearSettingsForOneType(
166 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA
);
168 // If an infobar is not launched now, this will hang.
169 GetUserMediaAndDeny(tab_contents
);
172 // Times out on win debug builds; http://crbug.com/295723 .
173 #if defined(OS_WIN) && !defined(NDEBUG)
174 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
175 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras
177 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
178 DenyingMicDoesNotCauseStickyDenyForCameras
180 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
,
181 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras
) {
182 content::WebContents
* tab_contents
= LoadTestPageInTab();
184 // If mic blocking also blocked cameras, the second call here would hang.
185 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents
,
186 kAudioOnlyCallConstraints
);
187 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents
,
188 kVideoOnlyCallConstraints
);
191 #if defined(OS_CHROMEOS) && !defined(NDEBUG)
192 #define MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics \
193 DISABLED_DenyingCameraDoesNotCauseStickyDenyForMics
195 #define MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics \
196 DenyingCameraDoesNotCauseStickyDenyForMics
198 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest
,
199 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics
) {
200 content::WebContents
* tab_contents
= LoadTestPageInTab();
202 // If camera blocking also blocked mics, the second call here would hang.
203 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents
,
204 kVideoOnlyCallConstraints
);
205 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents
,
206 kAudioOnlyCallConstraints
);