| 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/files/file_util.h" | 6 #include "base/files/file_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/media/media_stream_devices_controller.h" | 9 #include "chrome/browser/media/media_stream_devices_controller.h" |
| 10 #include "chrome/browser/media/webrtc_browsertest_base.h" | 10 #include "chrome/browser/media/webrtc_browsertest_base.h" |
| 11 #include "chrome/browser/media/webrtc_browsertest_common.h" | 11 #include "chrome/browser/media/webrtc_browsertest_common.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" | 14 #include "chrome/browser/ui/browser_tabstrip.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| 17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/test_switches.h" | 19 #include "chrome/test/base/test_switches.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "components/content_settings/core/browser/host_content_settings_map.h" | 21 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 22 #include "components/content_settings/core/common/content_settings_types.h" | 22 #include "components/content_settings/core/common/content_settings_types.h" |
| 23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
| 24 #include "content/public/common/media_stream_request.h" | 24 #include "content/public/common/media_stream_request.h" |
| 25 #include "content/public/common/origin_util.h" | |
| 26 #include "content/public/test/browser_test_utils.h" | 25 #include "content/public/test/browser_test_utils.h" |
| 27 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 28 #include "net/dns/mock_host_resolver.h" | |
| 29 #include "net/test/spawned_test_server/spawned_test_server.h" | 27 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 30 | 28 |
| 31 // MediaStreamPermissionTest --------------------------------------------------- | 29 // MediaStreamPermissionTest --------------------------------------------------- |
| 32 | 30 |
| 33 class MediaStreamPermissionTest : public WebRtcTestBase { | 31 class MediaStreamPermissionTest : public WebRtcTestBase { |
| 34 public: | 32 public: |
| 35 // The default test server is localhost, which is considered secure: | 33 MediaStreamPermissionTest() {} |
| 36 // http://www.w3.org/TR/powerful-features/#is-origin-trustworthy | |
| 37 MediaStreamPermissionTest() : use_secure_origin_for_test_page_(true) {} | |
| 38 ~MediaStreamPermissionTest() override {} | 34 ~MediaStreamPermissionTest() override {} |
| 39 | 35 |
| 40 // InProcessBrowserTest: | 36 // InProcessBrowserTest: |
| 41 void SetUpCommandLine(base::CommandLine* command_line) override { | 37 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 42 // This test expects to run with fake devices but real UI. | 38 // This test expects to run with fake devices but real UI. |
| 43 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | 39 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 44 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) | 40 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) |
| 45 << "Since this test tests the UI we want the real UI!"; | 41 << "Since this test tests the UI we want the real UI!"; |
| 46 } | 42 } |
| 47 | 43 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 64 // Executes stopLocalStream() in the test page, which frees up an already | 60 // Executes stopLocalStream() in the test page, which frees up an already |
| 65 // acquired mediastream. | 61 // acquired mediastream. |
| 66 bool StopLocalStream(content::WebContents* tab_contents) { | 62 bool StopLocalStream(content::WebContents* tab_contents) { |
| 67 std::string result; | 63 std::string result; |
| 68 bool ok = content::ExecuteScriptAndExtractString( | 64 bool ok = content::ExecuteScriptAndExtractString( |
| 69 tab_contents, "stopLocalStream()", &result); | 65 tab_contents, "stopLocalStream()", &result); |
| 70 DCHECK(ok); | 66 DCHECK(ok); |
| 71 return result.compare("ok-stopped") == 0; | 67 return result.compare("ok-stopped") == 0; |
| 72 } | 68 } |
| 73 | 69 |
| 74 void useNonSecureOriginForTestPage() { | |
| 75 use_secure_origin_for_test_page_ = false; | |
| 76 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 77 } | |
| 78 | |
| 79 private: | 70 private: |
| 80 bool use_secure_origin_for_test_page_; | |
| 81 | |
| 82 content::WebContents* LoadTestPageInBrowser(Browser* browser) { | 71 content::WebContents* LoadTestPageInBrowser(Browser* browser) { |
| 83 EXPECT_TRUE(test_server()->Start()); | 72 EXPECT_TRUE(test_server()->Start()); |
| 84 | 73 |
| 85 GURL url; | 74 ui_test_utils::NavigateToURL(browser, test_page_url()); |
| 86 | |
| 87 if (use_secure_origin_for_test_page_) { | |
| 88 // Uses the default server. | |
| 89 url = test_page_url(); | |
| 90 } else { | |
| 91 static const char kFoo[] = "not-secure.example.com"; | |
| 92 GURL::Replacements replacements; | |
| 93 replacements.SetSchemeStr(url::kHttpScheme); | |
| 94 replacements.SetHostStr(kFoo); | |
| 95 url = test_page_url().ReplaceComponents(replacements); | |
| 96 } | |
| 97 | |
| 98 EXPECT_EQ(use_secure_origin_for_test_page_, content::IsOriginSecure(url)); | |
| 99 | |
| 100 ui_test_utils::NavigateToURL(browser, url); | |
| 101 return browser->tab_strip_model()->GetActiveWebContents(); | 75 return browser->tab_strip_model()->GetActiveWebContents(); |
| 102 } | 76 } |
| 103 | 77 |
| 104 // Dummy callback for when we deny the current request directly. | 78 // Dummy callback for when we deny the current request directly. |
| 105 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | 79 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, |
| 106 content::MediaStreamRequestResult result, | 80 content::MediaStreamRequestResult result, |
| 107 scoped_ptr<content::MediaStreamUI> ui) {} | 81 scoped_ptr<content::MediaStreamUI> ui) {} |
| 108 | 82 |
| 109 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); | 83 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); |
| 110 }; | 84 }; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 126 GetUserMediaAndDismiss(tab_contents); | 100 GetUserMediaAndDismiss(tab_contents); |
| 127 } | 101 } |
| 128 | 102 |
| 129 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 103 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 130 TestDenyingUserMediaIncognito) { | 104 TestDenyingUserMediaIncognito) { |
| 131 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); | 105 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); |
| 132 GetUserMediaAndDeny(tab_contents); | 106 GetUserMediaAndDeny(tab_contents); |
| 133 } | 107 } |
| 134 | 108 |
| 135 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 109 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 136 TestNonSecureOriginAcceptThenDenyIsSticky) { | 110 TestAcceptThenDenyWhichShouldBeSticky) { |
| 137 #if defined(OS_WIN) && defined(USE_ASH) | 111 #if defined(OS_WIN) && defined(USE_ASH) |
| 138 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 112 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 139 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 113 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 140 switches::kAshBrowserTests)) | 114 switches::kAshBrowserTests)) |
| 141 return; | 115 return; |
| 142 #endif | 116 #endif |
| 143 | 117 |
| 144 useNonSecureOriginForTestPage(); | |
| 145 content::WebContents* tab_contents = LoadTestPageInTab(); | 118 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 146 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 147 | 119 |
| 148 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 120 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| 149 GetUserMediaAndDeny(tab_contents); | 121 GetUserMediaAndDeny(tab_contents); |
| 150 | 122 |
| 151 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | 123 // Should fail with permission denied, instead of hanging. |
| 124 GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| 125 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| 126 kFailedWithPermissionDeniedError, |
| 127 tab_contents)); |
| 152 } | 128 } |
| 153 | 129 |
| 154 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 130 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAcceptIsNotSticky) { |
| 155 TestNonSecureOriginDenyIsSticky) { | |
| 156 useNonSecureOriginForTestPage(); | |
| 157 content::WebContents* tab_contents = LoadTestPageInTab(); | 131 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 158 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 159 | 132 |
| 160 GetUserMediaAndDeny(tab_contents); | 133 // If accept were sticky the second call would hang because it hangs if a |
| 161 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | 134 // bubble does not pop up. |
| 162 } | |
| 163 | |
| 164 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 165 TestSecureOriginDenyIsSticky) { | |
| 166 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 167 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 168 | |
| 169 GetUserMediaAndDeny(tab_contents); | |
| 170 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
| 171 } | |
| 172 | |
| 173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 174 TestNonSecureOriginAcceptIsNotSticky) { | |
| 175 useNonSecureOriginForTestPage(); | |
| 176 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 177 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 178 | |
| 179 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 135 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| 180 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 136 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| 181 } | 137 } |
| 182 | 138 |
| 183 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 184 TestSecureOriginAcceptIsSticky) { | |
| 185 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 186 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 187 | |
| 188 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | |
| 189 GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents); | |
| 190 } | |
| 191 | |
| 192 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { | 139 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { |
| 193 content::WebContents* tab_contents = LoadTestPageInTab(); | 140 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 194 | 141 |
| 142 // If dismiss were sticky the second call would hang because it hangs if a |
| 143 // bubble does not pop up. |
| 195 GetUserMediaAndDismiss(tab_contents); | 144 GetUserMediaAndDismiss(tab_contents); |
| 196 GetUserMediaAndDismiss(tab_contents); | 145 GetUserMediaAndDismiss(tab_contents); |
| 197 } | 146 } |
| 198 | 147 |
| 199 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 148 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 200 TestDenyingThenClearingStickyException) { | 149 TestDenyingThenClearingStickyException) { |
| 201 content::WebContents* tab_contents = LoadTestPageInTab(); | 150 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 202 | 151 |
| 203 GetUserMediaAndDeny(tab_contents); | 152 GetUserMediaAndDeny(tab_contents); |
| 204 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
| 205 | 153 |
| 206 HostContentSettingsMap* settings_map = | 154 HostContentSettingsMap* settings_map = |
| 207 browser()->profile()->GetHostContentSettingsMap(); | 155 browser()->profile()->GetHostContentSettingsMap(); |
| 208 | 156 |
| 209 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 157 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 210 settings_map->ClearSettingsForOneType( | 158 settings_map->ClearSettingsForOneType( |
| 211 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 159 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 212 | 160 |
| 161 // If a bubble is not launched now, this will hang. |
| 213 GetUserMediaAndDeny(tab_contents); | 162 GetUserMediaAndDeny(tab_contents); |
| 214 } | 163 } |
| 215 | 164 |
| 165 // Times out on win debug builds; http://crbug.com/295723 . |
| 166 #if defined(OS_WIN) && !defined(NDEBUG) |
| 167 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| 168 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras |
| 169 #else |
| 170 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| 171 DenyingMicDoesNotCauseStickyDenyForCameras |
| 172 #endif |
| 216 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 217 DenyingMicDoesNotCauseStickyDenyForCameras) { | 174 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { |
| 218 content::WebContents* tab_contents = LoadTestPageInTab(); | 175 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 219 | 176 |
| 177 // If mic blocking also blocked cameras, the second call here would hang. |
| 220 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 178 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| 221 kAudioOnlyCallConstraints); | 179 kAudioOnlyCallConstraints); |
| 222 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | 180 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| 223 tab_contents, kVideoOnlyCallConstraints)); | 181 tab_contents, kVideoOnlyCallConstraints)); |
| 224 } | 182 } |
| 225 | 183 |
| 226 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 184 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 227 DenyingCameraDoesNotCauseStickyDenyForMics) { | 185 DenyingCameraDoesNotCauseStickyDenyForMics) { |
| 228 content::WebContents* tab_contents = LoadTestPageInTab(); | 186 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 229 | 187 |
| 188 // If camera blocking also blocked mics, the second call here would hang. |
| 230 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 189 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| 231 kVideoOnlyCallConstraints); | 190 kVideoOnlyCallConstraints); |
| 232 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | 191 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| 233 tab_contents, kAudioOnlyCallConstraints)); | 192 tab_contents, kAudioOnlyCallConstraints)); |
| 234 } | 193 } |
| OLD | NEW |