Chromium Code Reviews| 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" | |
| 25 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 26 #include "media/base/media_switches.h" | 27 #include "media/base/media_switches.h" |
| 28 #include "net/dns/mock_host_resolver.h" | |
| 27 #include "net/test/spawned_test_server/spawned_test_server.h" | 29 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 28 | 30 |
| 29 // MediaStreamPermissionTest --------------------------------------------------- | 31 // MediaStreamPermissionTest --------------------------------------------------- |
| 30 | 32 |
| 31 class MediaStreamPermissionTest : public WebRtcTestBase { | 33 class MediaStreamPermissionTest : public WebRtcTestBase { |
| 32 public: | 34 public: |
| 33 MediaStreamPermissionTest() {} | 35 // The default test server is localhost, which is considered secure: |
| 36 // https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-p owerful-new-features | |
| 37 MediaStreamPermissionTest() : use_secure_origin_for_test_page_(true) {} | |
| 34 ~MediaStreamPermissionTest() override {} | 38 ~MediaStreamPermissionTest() override {} |
| 35 | 39 |
| 36 // InProcessBrowserTest: | 40 // InProcessBrowserTest: |
| 37 void SetUpCommandLine(base::CommandLine* command_line) override { | 41 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 38 // This test expects to run with fake devices but real UI. | 42 // This test expects to run with fake devices but real UI. |
| 39 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | 43 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); |
| 40 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) | 44 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) |
| 41 << "Since this test tests the UI we want the real UI!"; | 45 << "Since this test tests the UI we want the real UI!"; |
| 42 } | 46 } |
| 43 | 47 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 60 // Executes stopLocalStream() in the test page, which frees up an already | 64 // Executes stopLocalStream() in the test page, which frees up an already |
| 61 // acquired mediastream. | 65 // acquired mediastream. |
| 62 bool StopLocalStream(content::WebContents* tab_contents) { | 66 bool StopLocalStream(content::WebContents* tab_contents) { |
| 63 std::string result; | 67 std::string result; |
| 64 bool ok = content::ExecuteScriptAndExtractString( | 68 bool ok = content::ExecuteScriptAndExtractString( |
| 65 tab_contents, "stopLocalStream()", &result); | 69 tab_contents, "stopLocalStream()", &result); |
| 66 DCHECK(ok); | 70 DCHECK(ok); |
| 67 return result.compare("ok-stopped") == 0; | 71 return result.compare("ok-stopped") == 0; |
| 68 } | 72 } |
| 69 | 73 |
| 74 void useNonSecureOriginForTestPage() { | |
| 75 use_secure_origin_for_test_page_ = false; | |
| 76 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 77 } | |
| 78 | |
| 70 private: | 79 private: |
| 80 bool use_secure_origin_for_test_page_; | |
| 81 | |
| 71 content::WebContents* LoadTestPageInBrowser(Browser* browser) { | 82 content::WebContents* LoadTestPageInBrowser(Browser* browser) { |
| 72 EXPECT_TRUE(test_server()->Start()); | 83 EXPECT_TRUE(test_server()->Start()); |
| 73 | 84 |
| 74 ui_test_utils::NavigateToURL(browser, test_page_url()); | 85 GURL 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); | |
| 75 return browser->tab_strip_model()->GetActiveWebContents(); | 101 return browser->tab_strip_model()->GetActiveWebContents(); |
| 76 } | 102 } |
| 77 | 103 |
| 78 // Dummy callback for when we deny the current request directly. | 104 // Dummy callback for when we deny the current request directly. |
| 79 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | 105 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, |
| 80 content::MediaStreamRequestResult result, | 106 content::MediaStreamRequestResult result, |
| 81 scoped_ptr<content::MediaStreamUI> ui) {} | 107 scoped_ptr<content::MediaStreamUI> ui) {} |
| 82 | 108 |
| 83 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); | 109 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); |
| 84 }; | 110 }; |
| 85 | 111 |
| 86 // Actual tests --------------------------------------------------------------- | 112 // Actual tests --------------------------------------------------------------- |
| 87 | 113 |
| 88 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAllowingUserMedia) { | 114 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAllowingUserMedia) { |
| 89 content::WebContents* tab_contents = LoadTestPageInTab(); | 115 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 90 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 116 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_SHOWN)); |
| 91 } | 117 } |
| 92 | 118 |
| 93 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDenyingUserMedia) { | 119 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDenyingUserMedia) { |
| 94 content::WebContents* tab_contents = LoadTestPageInTab(); | 120 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 95 GetUserMediaAndDeny(tab_contents); | 121 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 96 } | 122 } |
| 97 | 123 |
| 98 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissingRequest) { | 124 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissingRequest) { |
| 99 content::WebContents* tab_contents = LoadTestPageInTab(); | 125 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 100 GetUserMediaAndDismiss(tab_contents); | 126 GetUserMediaAndDismiss(tab_contents, EXPECT_PROMPT_SHOWN); |
| 101 } | 127 } |
| 102 | 128 |
| 103 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 129 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 104 TestDenyingUserMediaIncognito) { | 130 TestDenyingUserMediaIncognito) { |
| 105 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); | 131 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); |
| 106 GetUserMediaAndDeny(tab_contents); | 132 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 107 } | 133 } |
| 108 | 134 |
| 109 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 135 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 110 TestAcceptThenDenyWhichShouldBeSticky) { | 136 TestNonSecureOriginAcceptThenDenyIsSticky) { |
| 111 #if defined(OS_WIN) && defined(USE_ASH) | 137 #if defined(OS_WIN) && defined(USE_ASH) |
| 112 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 138 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 113 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 139 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 114 switches::kAshBrowserTests)) | 140 switches::kAshBrowserTests)) |
| 115 return; | 141 return; |
| 116 #endif | 142 #endif |
| 117 | 143 |
| 144 useNonSecureOriginForTestPage(); | |
| 118 content::WebContents* tab_contents = LoadTestPageInTab(); | 145 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 146 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 119 | 147 |
| 120 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 148 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_SHOWN)); |
| 121 GetUserMediaAndDeny(tab_contents); | 149 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 122 | 150 |
| 123 // Should fail with permission denied, instead of hanging. | 151 GetUserMedia(tab_contents, kAudioVideoCallConstraints, |
| 124 GetUserMedia(tab_contents, kAudioVideoCallConstraints); | 152 EXPECT_PROMPT_NOT_SHOWN); |
| 125 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", | 153 EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| 126 kFailedWithPermissionDeniedError, | 154 kFailedWithPermissionDeniedError, |
| 127 tab_contents)); | 155 tab_contents)); |
| 128 } | 156 } |
| 129 | 157 |
| 130 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAcceptIsNotSticky) { | 158 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 159 TestNonSecureOriginDenyIsSticky) { | |
| 160 useNonSecureOriginForTestPage(); | |
| 131 content::WebContents* tab_contents = LoadTestPageInTab(); | 161 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 162 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 132 | 163 |
| 133 // If accept were sticky the second call would hang because it hangs if a | 164 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 134 // bubble does not pop up. | 165 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_NOT_SHOWN)); |
|
felt
2015/08/04 13:42:26
This seems weird. The name of the method is GetUse
lgarron
2015/08/04 18:02:41
Hmm, I didn't want to create 2 (or 3) methods for
lgarron
2015/08/04 20:15:44
After poking around a bit, I found that just addin
| |
| 135 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 166 } |
| 136 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 167 |
| 168 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 169 TestSecureOriginDenyIsSticky) { | |
| 170 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 171 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 172 | |
| 173 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); | |
| 174 EXPECT_FALSE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_NOT_SHOWN)); | |
| 175 } | |
| 176 | |
| 177 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 178 TestNonSecureOriginAcceptIsNotSticky) { | |
| 179 useNonSecureOriginForTestPage(); | |
| 180 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 181 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 182 | |
| 183 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_SHOWN)); | |
| 184 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_SHOWN)); | |
| 185 } | |
| 186 | |
| 187 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 188 TestSecureOriginAcceptIsSticky) { | |
| 189 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 190 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 191 | |
| 192 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_SHOWN)); | |
| 193 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_NOT_SHOWN)); | |
| 137 } | 194 } |
| 138 | 195 |
| 139 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { | 196 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { |
| 140 content::WebContents* tab_contents = LoadTestPageInTab(); | 197 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 141 | 198 |
| 142 // If dismiss were sticky the second call would hang because it hangs if a | 199 GetUserMediaAndDismiss(tab_contents, EXPECT_PROMPT_SHOWN); |
| 143 // bubble does not pop up. | 200 GetUserMediaAndDismiss(tab_contents, EXPECT_PROMPT_SHOWN); |
| 144 GetUserMediaAndDismiss(tab_contents); | |
| 145 GetUserMediaAndDismiss(tab_contents); | |
| 146 } | 201 } |
| 147 | 202 |
| 148 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 203 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 149 TestDenyingThenClearingStickyException) { | 204 TestDenyingThenClearingStickyException) { |
| 150 content::WebContents* tab_contents = LoadTestPageInTab(); | 205 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 151 | 206 |
| 152 GetUserMediaAndDeny(tab_contents); | 207 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 208 GetUserMediaAndAccept(tab_contents, EXPECT_PROMPT_NOT_SHOWN); | |
| 153 | 209 |
| 154 HostContentSettingsMap* settings_map = | 210 HostContentSettingsMap* settings_map = |
| 155 browser()->profile()->GetHostContentSettingsMap(); | 211 browser()->profile()->GetHostContentSettingsMap(); |
| 156 | 212 |
| 157 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | 213 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); |
| 158 settings_map->ClearSettingsForOneType( | 214 settings_map->ClearSettingsForOneType( |
| 159 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | 215 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| 160 | 216 |
| 161 // If a bubble is not launched now, this will hang. | 217 GetUserMediaAndDeny(tab_contents, EXPECT_PROMPT_SHOWN); |
| 162 GetUserMediaAndDeny(tab_contents); | |
| 163 } | 218 } |
| 164 | 219 |
| 165 // Times out on win debug builds; http://crbug.com/295723 . | 220 // Times out on win debug builds; http://crbug.com/295723 . |
| 166 #if defined(OS_WIN) && !defined(NDEBUG) | 221 #if defined(OS_WIN) && !defined(NDEBUG) |
| 167 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ | 222 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| 168 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras | 223 DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras |
| 169 #else | 224 #else |
| 170 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ | 225 #define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| 171 DenyingMicDoesNotCauseStickyDenyForCameras | 226 DenyingMicDoesNotCauseStickyDenyForCameras |
| 172 #endif | 227 #endif |
| 173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 228 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 174 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { | 229 MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { |
| 175 content::WebContents* tab_contents = LoadTestPageInTab(); | 230 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 176 | 231 |
| 177 // If mic blocking also blocked cameras, the second call here would hang. | 232 GetUserMediaWithSpecificConstraintsAndDeny( |
| 178 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 233 tab_contents, kAudioOnlyCallConstraints, EXPECT_PROMPT_SHOWN); |
| 179 kAudioOnlyCallConstraints); | |
| 180 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | 234 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| 181 tab_contents, kVideoOnlyCallConstraints)); | 235 tab_contents, kVideoOnlyCallConstraints, EXPECT_PROMPT_SHOWN)); |
| 182 } | 236 } |
| 183 | 237 |
| 184 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 238 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| 185 DenyingCameraDoesNotCauseStickyDenyForMics) { | 239 DenyingCameraDoesNotCauseStickyDenyForMics) { |
| 186 content::WebContents* tab_contents = LoadTestPageInTab(); | 240 content::WebContents* tab_contents = LoadTestPageInTab(); |
| 187 | 241 |
| 188 // If camera blocking also blocked mics, the second call here would hang. | 242 GetUserMediaWithSpecificConstraintsAndDeny( |
| 189 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 243 tab_contents, kVideoOnlyCallConstraints, EXPECT_PROMPT_SHOWN); |
| 190 kVideoOnlyCallConstraints); | |
| 191 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | 244 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| 192 tab_contents, kAudioOnlyCallConstraints)); | 245 tab_contents, kAudioOnlyCallConstraints, EXPECT_PROMPT_SHOWN)); |
| 193 } | 246 } |
| OLD | NEW |