| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "base/command_line.h" | |
| 6 #include "base/files/file_util.h" | |
| 7 #include "base/macros.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_factory.h" | |
| 11 #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_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/browser/ui/website_settings/permission_bubble_manager.h" | |
| 19 #include "chrome/common/chrome_switches.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/content_settings/core/browser/host_content_settings_map.h" | |
| 24 #include "components/content_settings/core/common/content_settings_types.h" | |
| 25 #include "content/public/browser/notification_service.h" | |
| 26 #include "content/public/common/content_switches.h" | |
| 27 #include "content/public/common/media_stream_request.h" | |
| 28 #include "content/public/common/origin_util.h" | |
| 29 #include "content/public/test/browser_test_utils.h" | |
| 30 #include "media/base/media_switches.h" | |
| 31 #include "net/dns/mock_host_resolver.h" | |
| 32 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 33 | |
| 34 // MediaStreamPermissionTest --------------------------------------------------- | |
| 35 | |
| 36 class MediaStreamPermissionTest : public WebRtcTestBase { | |
| 37 public: | |
| 38 MediaStreamPermissionTest() {} | |
| 39 ~MediaStreamPermissionTest() override {} | |
| 40 | |
| 41 // InProcessBrowserTest: | |
| 42 void SetUpCommandLine(base::CommandLine* command_line) override { | |
| 43 // This test expects to run with fake devices but real UI. | |
| 44 command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream); | |
| 45 EXPECT_FALSE(command_line->HasSwitch(switches::kUseFakeUIForMediaStream)) | |
| 46 << "Since this test tests the UI we want the real UI!"; | |
| 47 } | |
| 48 | |
| 49 protected: | |
| 50 content::WebContents* LoadTestPageInTab() { | |
| 51 return LoadTestPageInBrowser(browser()); | |
| 52 } | |
| 53 | |
| 54 content::WebContents* LoadTestPageInIncognitoTab() { | |
| 55 return LoadTestPageInBrowser(CreateIncognitoBrowser()); | |
| 56 } | |
| 57 | |
| 58 // Returns the URL of the main test page. | |
| 59 GURL test_page_url() const { | |
| 60 const char kMainWebrtcTestHtmlPage[] = "/webrtc/webrtc_jsep01_test.html"; | |
| 61 return embedded_test_server()->GetURL(kMainWebrtcTestHtmlPage); | |
| 62 } | |
| 63 | |
| 64 private: | |
| 65 content::WebContents* LoadTestPageInBrowser(Browser* browser) { | |
| 66 EXPECT_TRUE(embedded_test_server()->Start()); | |
| 67 | |
| 68 // Uses the default server. | |
| 69 GURL url = test_page_url(); | |
| 70 | |
| 71 EXPECT_TRUE(content::IsOriginSecure(url)); | |
| 72 | |
| 73 ui_test_utils::NavigateToURL(browser, url); | |
| 74 return browser->tab_strip_model()->GetActiveWebContents(); | |
| 75 } | |
| 76 | |
| 77 // Dummy callback for when we deny the current request directly. | |
| 78 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | |
| 79 content::MediaStreamRequestResult result, | |
| 80 scoped_ptr<content::MediaStreamUI> ui) {} | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(MediaStreamPermissionTest); | |
| 83 }; | |
| 84 | |
| 85 // Actual tests --------------------------------------------------------------- | |
| 86 | |
| 87 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestAllowingUserMedia) { | |
| 88 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 89 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | |
| 90 } | |
| 91 | |
| 92 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDenyingUserMedia) { | |
| 93 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 94 GetUserMediaAndDeny(tab_contents); | |
| 95 } | |
| 96 | |
| 97 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissingRequest) { | |
| 98 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 99 GetUserMediaAndDismiss(tab_contents); | |
| 100 } | |
| 101 | |
| 102 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 103 TestDenyingUserMediaIncognito) { | |
| 104 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); | |
| 105 GetUserMediaAndDeny(tab_contents); | |
| 106 } | |
| 107 | |
| 108 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 109 TestSecureOriginDenyIsSticky) { | |
| 110 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 111 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 112 | |
| 113 GetUserMediaAndDeny(tab_contents); | |
| 114 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
| 115 } | |
| 116 | |
| 117 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 118 TestSecureOriginAcceptIsSticky) { | |
| 119 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 120 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
| 121 | |
| 122 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | |
| 123 GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents); | |
| 124 } | |
| 125 | |
| 126 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { | |
| 127 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 128 | |
| 129 GetUserMediaAndDismiss(tab_contents); | |
| 130 GetUserMediaAndDismiss(tab_contents); | |
| 131 } | |
| 132 | |
| 133 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 134 TestDenyingThenClearingStickyException) { | |
| 135 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 136 | |
| 137 GetUserMediaAndDeny(tab_contents); | |
| 138 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
| 139 | |
| 140 HostContentSettingsMap* settings_map = | |
| 141 HostContentSettingsMapFactory::GetForProfile(browser()->profile()); | |
| 142 | |
| 143 settings_map->ClearSettingsForOneType(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC); | |
| 144 settings_map->ClearSettingsForOneType( | |
| 145 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA); | |
| 146 | |
| 147 GetUserMediaAndDeny(tab_contents); | |
| 148 } | |
| 149 | |
| 150 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 151 DenyingMicDoesNotCauseStickyDenyForCameras) { | |
| 152 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 153 | |
| 154 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | |
| 155 kAudioOnlyCallConstraints); | |
| 156 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | |
| 157 tab_contents, kVideoOnlyCallConstraints)); | |
| 158 } | |
| 159 | |
| 160 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
| 161 DenyingCameraDoesNotCauseStickyDenyForMics) { | |
| 162 content::WebContents* tab_contents = LoadTestPageInTab(); | |
| 163 | |
| 164 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | |
| 165 kVideoOnlyCallConstraints); | |
| 166 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | |
| 167 tab_contents, kAudioOnlyCallConstraints)); | |
| 168 } | |
| OLD | NEW |