Chromium Code Reviews| Index: chrome/browser/media/chrome_media_stream_infobar_browsertest.cc |
| diff --git a/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc b/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc |
| index 395641f798ea678eadebd92ae54eed87460aa915..2808ae2135144d9ff71398fc9ed7c7318d0de06e 100644 |
| --- a/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc |
| +++ b/chrome/browser/media/chrome_media_stream_infobar_browsertest.cc |
| @@ -22,15 +22,19 @@ |
| #include "components/content_settings/core/common/content_settings_types.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/common/media_stream_request.h" |
| +#include "content/public/common/origin_util.h" |
| #include "content/public/test/browser_test_utils.h" |
| #include "media/base/media_switches.h" |
| +#include "net/dns/mock_host_resolver.h" |
| #include "net/test/spawned_test_server/spawned_test_server.h" |
| // MediaStreamPermissionTest --------------------------------------------------- |
| class MediaStreamPermissionTest : public WebRtcTestBase { |
| public: |
| - MediaStreamPermissionTest() {} |
| + // The default test server is localhost, which is considered secure: |
| + // https://www.chromium.org/Home/chromium-security/prefer-secure-origins-for-powerful-new-features |
|
raymes
2015/08/05 02:31:05
nit: should this be broken across lines to fit in
lgarron
2015/08/06 22:10:09
Splitting a URL breaks highlighting/copying/auto-l
|
| + MediaStreamPermissionTest() : use_secure_origin_for_test_page_(true) {} |
| ~MediaStreamPermissionTest() override {} |
| // InProcessBrowserTest: |
| @@ -67,11 +71,33 @@ class MediaStreamPermissionTest : public WebRtcTestBase { |
| return result.compare("ok-stopped") == 0; |
| } |
| + void useNonSecureOriginForTestPage() { |
| + use_secure_origin_for_test_page_ = false; |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + } |
| + |
| private: |
| + bool use_secure_origin_for_test_page_; |
| + |
| content::WebContents* LoadTestPageInBrowser(Browser* browser) { |
| EXPECT_TRUE(test_server()->Start()); |
| - ui_test_utils::NavigateToURL(browser, test_page_url()); |
| + GURL url; |
| + |
| + if (use_secure_origin_for_test_page_) { |
| + // Uses the default server. |
| + url = test_page_url(); |
| + } else { |
| + static const char kFoo[] = "not-secure.example.com"; |
| + GURL::Replacements replacements; |
| + replacements.SetSchemeStr(url::kHttpScheme); |
| + replacements.SetHostStr(kFoo); |
| + url = test_page_url().ReplaceComponents(replacements); |
| + } |
| + |
| + EXPECT_EQ(use_secure_origin_for_test_page_, content::IsOriginSecure(url)); |
| + |
| + ui_test_utils::NavigateToURL(browser, url); |
| return browser->tab_strip_model()->GetActiveWebContents(); |
| } |
| @@ -107,7 +133,7 @@ IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| } |
| IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| - TestAcceptThenDenyWhichShouldBeSticky) { |
| + TestNonSecureOriginAcceptThenDenyIsSticky) { |
| #if defined(OS_WIN) && defined(USE_ASH) |
| // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| @@ -115,32 +141,57 @@ IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| return; |
| #endif |
| + useNonSecureOriginForTestPage(); |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| + EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
| EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| GetUserMediaAndDeny(tab_contents); |
| - // Should fail with permission denied, instead of hanging. |
| - GetUserMedia(tab_contents, kAudioVideoCallConstraints); |
| - EXPECT_TRUE(test::PollingWaitUntil("obtainGetUserMediaResult()", |
| - kFailedWithPermissionDeniedError, |
| - tab_contents)); |
| + GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| + TestNonSecureOriginDenyIsSticky) { |
| + useNonSecureOriginForTestPage(); |
| + content::WebContents* tab_contents = LoadTestPageInTab(); |
| + EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
| + |
| + GetUserMediaAndDeny(tab_contents); |
| + GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| + TestSecureOriginDenyIsSticky) { |
| + content::WebContents* tab_contents = LoadTestPageInTab(); |
| + EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
| + |
| + GetUserMediaAndDeny(tab_contents); |
| + GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); |
| } |
| -IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAcceptIsNotSticky) { |
| +IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| + TestNonSecureOriginAcceptIsNotSticky) { |
| + useNonSecureOriginForTestPage(); |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| + EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
| - // If accept were sticky the second call would hang because it hangs if a |
| - // bubble does not pop up. |
| EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| } |
| +IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| + TestSecureOriginAcceptIsSticky) { |
| + content::WebContents* tab_contents = LoadTestPageInTab(); |
| + EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
| + |
| + EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
| + GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| - // If dismiss were sticky the second call would hang because it hangs if a |
| - // bubble does not pop up. |
| GetUserMediaAndDismiss(tab_contents); |
| GetUserMediaAndDismiss(tab_contents); |
| } |
| @@ -150,6 +201,7 @@ IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| GetUserMediaAndDeny(tab_contents); |
| + GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); |
| HostContentSettingsMap* settings_map = |
| browser()->profile()->GetHostContentSettingsMap(); |
| @@ -158,23 +210,13 @@ IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| settings_map->ClearSettingsForOneType( |
| CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); |
| - // If a bubble is not launched now, this will hang. |
| GetUserMediaAndDeny(tab_contents); |
| } |
| -// Times out on win debug builds; http://crbug.com/295723 . |
| -#if defined(OS_WIN) && !defined(NDEBUG) |
| -#define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| - DISABLED_DenyingMicDoesNotCauseStickyDenyForCameras |
| -#else |
| -#define MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras \ |
| - DenyingMicDoesNotCauseStickyDenyForCameras |
| -#endif |
| IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| - MAYBE_DenyingMicDoesNotCauseStickyDenyForCameras) { |
| + DenyingMicDoesNotCauseStickyDenyForCameras) { |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| - // If mic blocking also blocked cameras, the second call here would hang. |
| GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| kAudioOnlyCallConstraints); |
| EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
| @@ -185,7 +227,6 @@ IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
| DenyingCameraDoesNotCauseStickyDenyForMics) { |
| content::WebContents* tab_contents = LoadTestPageInTab(); |
| - // If camera blocking also blocked mics, the second call here would hang. |
| GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
| kVideoOnlyCallConstraints); |
| EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |