OLD | NEW |
---|---|
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 | |
53 private: | 79 private: |
54 content::WebContents* LoadTestPageInBrowser(Browser* browser) { | 80 content::WebContents* LoadTestPageInBrowser(Browser* browser) { |
55 EXPECT_TRUE(test_server()->Start()); | 81 EXPECT_TRUE(test_server()->Start()); |
56 | 82 |
57 const char kMainWebrtcTestHtmlPage[] = | 83 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(); | 84 return browser->tab_strip_model()->GetActiveWebContents(); |
62 } | 85 } |
63 | 86 |
87 // Dummy callback for when we deny the current request directly. | |
88 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | |
89 content::MediaStreamRequestResult result, | |
90 scoped_ptr<content::MediaStreamUI> ui) {} | |
91 | |
64 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest); | 92 DISALLOW_COPY_AND_ASSIGN(MediaStreamInfoBarTest); |
65 }; | 93 }; |
66 | 94 |
67 | |
68 // Actual tests --------------------------------------------------------------- | 95 // Actual tests --------------------------------------------------------------- |
69 | 96 |
70 // Failing on ChromiumOS Debug and Win Aura, so disabling on both. | 97 // Failing on ChromiumOS Debug and Win Aura, so disabling on both. |
71 // See http://crbug.com/263333. | 98 // See http://crbug.com/263333. |
72 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA) | 99 #if (defined(OS_CHROMEOS) && !defined(NDEBUG)) || defined(USE_AURA) |
73 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia | 100 #define MAYBE_TestAllowingUserMedia DISABLED_TestAllowingUserMedia |
74 #else | 101 #else |
75 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia | 102 #define MAYBE_TestAllowingUserMedia TestAllowingUserMedia |
76 #endif | 103 #endif |
77 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAllowingUserMedia) { | 104 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAllowingUserMedia) { |
(...skipping 29 matching lines...) Expand all Loading... | |
107 MAYBE_TestAcceptThenDenyWhichShouldBeSticky) { | 134 MAYBE_TestAcceptThenDenyWhichShouldBeSticky) { |
108 #if defined(OS_WIN) && defined(USE_ASH) | 135 #if defined(OS_WIN) && defined(USE_ASH) |
109 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 136 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
110 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 137 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
111 return; | 138 return; |
112 #endif | 139 #endif |
113 | 140 |
114 content::WebContents* tab_contents = LoadTestPageInTab(); | 141 content::WebContents* tab_contents = LoadTestPageInTab(); |
115 | 142 |
116 GetUserMediaAndAccept(tab_contents); | 143 GetUserMediaAndAccept(tab_contents); |
117 GetUserMediaAndDeny(tab_contents); | 144 DenyRequest(tab_contents, content::MEDIA_DEVICE_PERMISSION_DENIED); |
118 | 145 |
119 // Should fail with permission denied right away with no infobar popping up. | 146 // Should fail with permission denied right away with no infobar popping up. |
120 GetUserMedia(tab_contents, kAudioVideoCallConstraints); | 147 GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
121 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 148 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
122 kFailedWithPermissionDeniedError, | 149 kFailedWithPermissionDeniedError, |
123 tab_contents)); | 150 tab_contents)); |
124 InfoBarService* infobar_service = | 151 InfoBarService* infobar_service = |
125 InfoBarService::FromWebContents(tab_contents); | 152 InfoBarService::FromWebContents(tab_contents); |
126 EXPECT_EQ(0u, infobar_service->infobar_count()); | 153 EXPECT_EQ(0u, infobar_service->infobar_count()); |
127 } | 154 } |
128 | 155 |
129 // Failing on Win Aura, so disabling on that. | 156 // Failing on Win Aura, so disabling on that. |
130 // See http://crbug.com/263333. | 157 // See http://crbug.com/263333. |
131 #if defined(USE_AURA) | 158 #if defined(USE_AURA) |
132 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky | 159 #define MAYBE_TestAcceptIsNotSticky DISABLED_TestAcceptIsNotSticky |
133 #else | 160 #else |
134 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky | 161 #define MAYBE_TestAcceptIsNotSticky TestAcceptIsNotSticky |
135 #endif | 162 #endif |
136 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAcceptIsNotSticky) { | 163 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, MAYBE_TestAcceptIsNotSticky) { |
137 content::WebContents* tab_contents = LoadTestPageInTab(); | 164 content::WebContents* tab_contents = LoadTestPageInTab(); |
138 | 165 |
139 // If accept were sticky the second call would hang because it hangs if an | 166 // If accept were sticky the second call would hang because it hangs if an |
140 // infobar does not pop up. | 167 // infobar does not pop up. |
141 GetUserMediaAndAccept(tab_contents); | 168 GetUserMediaAndAccept(tab_contents); |
169 | |
170 // Because http request permissions are sticky per navigation, we need to | |
171 // navigate away from the current page in order to verify that the granted | |
172 // permissions are not permanently sticky. | |
173 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), | |
174 GURL("about:blank"), 1); | |
175 | |
176 // Now navigate back to our test page. | |
177 ui_test_utils::NavigateToURL(browser(), test_page_url()); | |
178 tab_contents = browser()->tab_strip_model()->GetActiveWebContents(); | |
179 | |
142 GetUserMediaAndAccept(tab_contents); | 180 GetUserMediaAndAccept(tab_contents); |
143 } | 181 } |
144 | 182 |
183 // Test that accepting one getUserMedia request will not require a second | |
184 // prompt when issuing a second getUserMedia request. | |
185 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, | |
186 TestAcceptIsStickyPerNavigation) { | |
187 content::WebContents* tab_contents = LoadTestPageInTab(); | |
188 | |
189 GetUserMediaAndAccept(tab_contents); | |
190 | |
191 // Before issuing the second gUM request, make sure we first stop the tracks | |
192 // we started with the first request. If they're still running the permissions | |
193 // will be active for other reasons and we won't be testing the temporary | |
194 // stickiness properly. | |
195 std::string result; | |
196 bool ok = content::ExecuteScriptAndExtractString( | |
197 tab_contents, "stopLocalStream()", &result); | |
198 ASSERT_TRUE(ok); | |
199 EXPECT_TRUE(result.compare("ok-stopped") == 0); | |
200 | |
201 // Now no media tracks are running, so let's issue the second request. | |
202 GetUserMedia(tab_contents, kAudioVideoCallConstraints); | |
203 } | |
204 | |
perkj_chrome
2014/05/02 07:14:37
Test first gum for audio only. Then gum with audio
| |
145 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) { | 205 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, TestDismissIsNotSticky) { |
146 content::WebContents* tab_contents = LoadTestPageInTab(); | 206 content::WebContents* tab_contents = LoadTestPageInTab(); |
147 | 207 |
148 // If dismiss were sticky the second call would hang because it hangs if an | 208 // If dismiss were sticky the second call would hang because it hangs if an |
149 // infobar does not pop up. | 209 // infobar does not pop up. |
150 GetUserMediaAndDismiss(tab_contents); | 210 GetUserMediaAndDismiss(tab_contents); |
151 GetUserMediaAndDismiss(tab_contents); | 211 GetUserMediaAndDismiss(tab_contents); |
152 } | 212 } |
153 | 213 |
154 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, | 214 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, | 257 IN_PROC_BROWSER_TEST_F(MediaStreamInfoBarTest, |
198 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics) { | 258 MAYBE_DenyingCameraDoesNotCauseStickyDenyForMics) { |
199 content::WebContents* tab_contents = LoadTestPageInTab(); | 259 content::WebContents* tab_contents = LoadTestPageInTab(); |
200 | 260 |
201 // If camera blocking also blocked mics, the second call here would hang. | 261 // If camera blocking also blocked mics, the second call here would hang. |
202 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 262 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
203 kVideoOnlyCallConstraints); | 263 kVideoOnlyCallConstraints); |
204 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, | 264 GetUserMediaWithSpecificConstraintsAndAccept(tab_contents, |
205 kAudioOnlyCallConstraints); | 265 kAudioOnlyCallConstraints); |
206 } | 266 } |
OLD | NEW |