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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Executes stopLocalStream() in the test page, which frees up an already | 62 // Executes stopLocalStream() in the test page, which frees up an already |
63 // acquired mediastream. | 63 // acquired mediastream. |
64 bool StopLocalStream(content::WebContents* tab_contents) { | 64 bool StopLocalStream(content::WebContents* tab_contents) { |
65 std::string result; | 65 std::string result; |
66 bool ok = content::ExecuteScriptAndExtractString( | 66 bool ok = content::ExecuteScriptAndExtractString( |
67 tab_contents, "stopLocalStream()", &result); | 67 tab_contents, "stopLocalStream()", &result); |
68 DCHECK(ok); | 68 DCHECK(ok); |
69 return result.compare("ok-stopped") == 0; | 69 return result.compare("ok-stopped") == 0; |
70 } | 70 } |
71 | 71 |
72 void useNonSecureOriginForTestPage() { | |
73 use_secure_origin_for_test_page_ = false; | |
74 host_resolver()->AddRule("*", "127.0.0.1"); | |
75 } | |
76 | |
77 private: | 72 private: |
78 // The default test server is localhost, which is considered secure: | |
79 // http://www.w3.org/TR/powerful-features/#is-origin-trustworthy | |
80 bool use_secure_origin_for_test_page_ = true; | |
81 | |
82 content::WebContents* LoadTestPageInBrowser(Browser* browser) { | 73 content::WebContents* LoadTestPageInBrowser(Browser* browser) { |
83 EXPECT_TRUE(test_server()->Start()); | 74 EXPECT_TRUE(test_server()->Start()); |
84 | 75 |
85 GURL url; | 76 // Uses the default server. |
| 77 GURL url = test_page_url(); |
86 | 78 |
87 if (use_secure_origin_for_test_page_) { | 79 EXPECT_TRUE(content::IsOriginSecure(url)); |
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 | 80 |
100 ui_test_utils::NavigateToURL(browser, url); | 81 ui_test_utils::NavigateToURL(browser, url); |
101 return browser->tab_strip_model()->GetActiveWebContents(); | 82 return browser->tab_strip_model()->GetActiveWebContents(); |
102 } | 83 } |
103 | 84 |
104 // Dummy callback for when we deny the current request directly. | 85 // Dummy callback for when we deny the current request directly. |
105 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, | 86 static void OnMediaStreamResponse(const content::MediaStreamDevices& devices, |
106 content::MediaStreamRequestResult result, | 87 content::MediaStreamRequestResult result, |
107 scoped_ptr<content::MediaStreamUI> ui) {} | 88 scoped_ptr<content::MediaStreamUI> ui) {} |
108 | 89 |
(...skipping 17 matching lines...) Expand all Loading... |
126 GetUserMediaAndDismiss(tab_contents); | 107 GetUserMediaAndDismiss(tab_contents); |
127 } | 108 } |
128 | 109 |
129 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 110 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
130 TestDenyingUserMediaIncognito) { | 111 TestDenyingUserMediaIncognito) { |
131 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); | 112 content::WebContents* tab_contents = LoadTestPageInIncognitoTab(); |
132 GetUserMediaAndDeny(tab_contents); | 113 GetUserMediaAndDeny(tab_contents); |
133 } | 114 } |
134 | 115 |
135 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 116 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
136 TestNonSecureOriginAcceptThenDenyIsSticky) { | |
137 #if defined(OS_WIN) && defined(USE_ASH) | |
138 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | |
139 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
140 switches::kAshBrowserTests)) | |
141 return; | |
142 #endif | |
143 | |
144 useNonSecureOriginForTestPage(); | |
145 content::WebContents* tab_contents = LoadTestPageInTab(); | |
146 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
147 | |
148 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | |
149 GetUserMediaAndDeny(tab_contents); | |
150 | |
151 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
152 } | |
153 | |
154 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
155 TestNonSecureOriginDenyIsSticky) { | |
156 useNonSecureOriginForTestPage(); | |
157 content::WebContents* tab_contents = LoadTestPageInTab(); | |
158 EXPECT_FALSE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | |
159 | |
160 GetUserMediaAndDeny(tab_contents); | |
161 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | |
162 } | |
163 | |
164 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
165 TestSecureOriginDenyIsSticky) { | 117 TestSecureOriginDenyIsSticky) { |
166 content::WebContents* tab_contents = LoadTestPageInTab(); | 118 content::WebContents* tab_contents = LoadTestPageInTab(); |
167 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | 119 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
168 | 120 |
169 GetUserMediaAndDeny(tab_contents); | 121 GetUserMediaAndDeny(tab_contents); |
170 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); | 122 GetUserMediaAndExpectAutoDenyWithoutPrompt(tab_contents); |
171 } | 123 } |
172 | 124 |
173 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 125 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)); | |
180 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | |
181 } | |
182 | |
183 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | |
184 TestSecureOriginAcceptIsSticky) { | 126 TestSecureOriginAcceptIsSticky) { |
185 content::WebContents* tab_contents = LoadTestPageInTab(); | 127 content::WebContents* tab_contents = LoadTestPageInTab(); |
186 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); | 128 EXPECT_TRUE(content::IsOriginSecure(tab_contents->GetLastCommittedURL())); |
187 | 129 |
188 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); | 130 EXPECT_TRUE(GetUserMediaAndAccept(tab_contents)); |
189 GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents); | 131 GetUserMediaAndExpectAutoAcceptWithoutPrompt(tab_contents); |
190 } | 132 } |
191 | 133 |
192 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { | 134 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, TestDismissIsNotSticky) { |
193 content::WebContents* tab_contents = LoadTestPageInTab(); | 135 content::WebContents* tab_contents = LoadTestPageInTab(); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 | 167 |
226 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, | 168 IN_PROC_BROWSER_TEST_F(MediaStreamPermissionTest, |
227 DenyingCameraDoesNotCauseStickyDenyForMics) { | 169 DenyingCameraDoesNotCauseStickyDenyForMics) { |
228 content::WebContents* tab_contents = LoadTestPageInTab(); | 170 content::WebContents* tab_contents = LoadTestPageInTab(); |
229 | 171 |
230 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, | 172 GetUserMediaWithSpecificConstraintsAndDeny(tab_contents, |
231 kVideoOnlyCallConstraints); | 173 kVideoOnlyCallConstraints); |
232 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( | 174 EXPECT_TRUE(GetUserMediaWithSpecificConstraintsAndAccept( |
233 tab_contents, kAudioOnlyCallConstraints)); | 175 tab_contents, kAudioOnlyCallConstraints)); |
234 } | 176 } |
OLD | NEW |