[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / media / chrome_media_stream_infobar_browsertest.cc
blobe0833408c04cb4024a54dfa6ffb6a397417c4c60
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_service.h"
12 #include "chrome/browser/media/webrtc_browsertest_base.h"
13 #include "chrome/browser/media/webrtc_browsertest_common.h"
14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_tabstrip.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/content_settings_types.h"
20 #include "chrome/test/base/in_process_browser_test.h"
21 #include "chrome/test/base/test_switches.h"
22 #include "chrome/test/base/ui_test_utils.h"
23 #include "components/infobars/core/infobar.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/test/browser_test_utils.h"
26 #include "net/test/spawned_test_server/spawned_test_server.h"
29 // MediaStreamInfoBarTest -----------------------------------------------------
31 class MediaStreamInfoBarTest : public WebRtcTestBase {
32 public:
33 MediaStreamInfoBarTest() {}
34 virtual ~MediaStreamInfoBarTest() {}
36 // InProcessBrowserTest:
37 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
38 // This test expects to run with fake devices but real UI.
39 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
40 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream))
41 << "Since this test tests the UI we want the real UI!";
44 protected:
45 content::WebContents* LoadTestPageInTab() {
46 return LoadTestPageInBrowser(browser());
49 content::WebContents* LoadTestPageInIncognitoTab() {
50 return LoadTestPageInBrowser(CreateIncognitoBrowser());
53 private:
54 content::WebContents* LoadTestPageInBrowser(Browser* browser) {
55 EXPECT_TRUE(test_server()->Start());
57 const char kMainWebrtcTestHtmlPage[] =
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();
64 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest);
68 // Actual tests ---------------------------------------------------------------
70 // Failing on ChromiumOS Debug and Win Aura, so disabling on both.
71 // See http://crbug.com/263333.
72 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA)
73 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia
74 #else
75 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia
76 #endif
77 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAllowingUserMedia) {
78 content::WebContents* tab_contents = LoadTestPageInTab();
79 GetUserMediaAndAccept(tab_contents);
82 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDenyingUserMedia) {
83 content::WebContents* tab_contents = LoadTestPageInTab();
84 GetUserMediaAndDeny(tab_contents);
87 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissingInfobar) {
88 content::WebContents* tab_contents = LoadTestPageInTab();
89 GetUserMediaAndDismiss(tab_contents);
92 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDenyingUserMediaIncognito) {
93 content::WebContents* tab_contents = LoadTestPageInIncognitoTab();
94 GetUserMediaAndDeny(tab_contents);
97 // Failing on ChromiumOS Debug and Win Aura, so disabling on Aura.
98 // See http://crbug.com/263333.
99 #if defined(USE_AURA)
100 #define MAYBE_TestAcceptThenDenyWhichShouldBeSticky \
101 DISABLED_TestAcceptThenDenyWhichShouldBeSticky
102 #else
103 #define MAYBE_TestAcceptThenDenyWhichShouldBeSticky \
104 TestAcceptThenDenyWhichShouldBeSticky
105 #endif
106 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
107 MAYBE_TestAcceptThenDenyWhichShouldBeSticky) {
108 #if defined(OS_WIN) && defined(USE_ASH)
109 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
110 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
111 return;
112 #endif
114 content::WebContents* tab_contents = LoadTestPageInTab();
116 GetUserMediaAndAccept(tab_contents);
117 GetUserMediaAndDeny(tab_contents);
119 // Should fail with permission denied right away with no infobar popping up.
120 GetUserMedia(tab_contents, kAudioVideoCallConstraints);
121 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()",
122 kFailedWithPermissionDeniedError,
123 tab_contents));
124 InfoBarService* infobar_service =
125 InfoBarService::FromWebContents(tab_contents);
126 EXPECT_EQ(0u, infobar_service->infobar_count());
129 // Failing on Win Aura, so disabling on that.
130 // See http://crbug.com/263333.
131 #if defined(USE_AURA)
132 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky
133 #else
134 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky
135 #endif
136 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAcceptIsNotSticky) {
137 content::WebContents* tab_contents = LoadTestPageInTab();
139 // If accept were sticky the second call would hang because it hangs if an
140 // infobar does not pop up.
141 GetUserMediaAndAccept(tab_contents);
142 GetUserMediaAndAccept(tab_contents);
145 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) {
146 content::WebContents* tab_contents = LoadTestPageInTab();
148 // If dismiss were sticky the second call would hang because it hangs if an
149 // infobar does not pop up.
150 GetUserMediaAndDismiss(tab_contents);
151 GetUserMediaAndDismiss(tab_contents);
154 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
155 TestDenyingThenClearingStickyException) {
156 content::WebContents* tab_contents = LoadTestPageInTab();
158 GetUserMediaAndDeny(tab_contents);
160 HostContentSettingsMap* settings_map =
161 browser()->profile()->GetHostContentSettingsMap();
163 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
164 settings_map->ClearSettingsForOneType(
165 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
167 // If an infobar is not launched now, this will hang.
168 GetUserMediaAndDeny(tab_contents);
171 // Times out on win debug builds; http://crbug.com/295723 .
172 #if defined(OS_WIN) && !defined(NDEBUG)
173 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
174 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras
175 #else
176 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \
177 DenyingMicDoesNotCauseStickyDenyForCameras
178 #endif
179 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
180 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) {
181 content::WebContents* tab_contents = LoadTestPageInTab();
183 // If mic blocking also blocked cameras, the second call here would hang.
184 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
185 kAudioOnlyCallConstraints);
186 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
187 kVideoOnlyCallConstraints);
190 #if defined(OS_CHROMEOS) && !defined(NDEBUG)
191 #define MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics \
192 DISABLED_DenyingCameraDoesNotCauseStickyDenyForMics
193 #else
194 #define MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics \
195 DenyingCameraDoesNotCauseStickyDenyForMics
196 #endif
197 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest,
198 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics) {
199 content::WebContents* tab_contents = LoadTestPageInTab();
201 // If camera blocking also blocked mics, the second call here would hang.
202 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents,
203 kVideoOnlyCallConstraints);
204 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents,
205 kAudioOnlyCallConstraints);