Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: content/browser/shared_worker/worker_browsertest.cc

Issue 859213006: Cancel client auth requests when not promptable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@client-auth-cancel-1
Patch Set: extension test Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/sys_info.h" 11 #include "base/sys_info.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/client_certificate_delegate.h"
15 #include "content/public/common/content_client.h"
14 #include "content/public/common/content_paths.h" 16 #include "content/public/common/content_paths.h"
15 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/content_browser_test.h" 18 #include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h" 19 #include "content/public/test/content_browser_test_utils.h"
18 #include "content/public/test/test_utils.h" 20 #include "content/public/test/test_utils.h"
19 #include "content/shell/browser/shell.h" 21 #include "content/shell/browser/shell.h"
20 #include "content/shell/browser/shell_content_browser_client.h" 22 #include "content/shell/browser/shell_content_browser_client.h"
21 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" 23 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h"
24 #include "content/test/test_content_browser_client.h"
25 #include "net/base/escape.h"
22 #include "net/base/test_data_directory.h" 26 #include "net/base/test_data_directory.h"
23 #include "net/test/spawned_test_server/spawned_test_server.h" 27 #include "net/test/spawned_test_server/spawned_test_server.h"
24 #include "url/gurl.h" 28 #include "url/gurl.h"
25 29
26 namespace content { 30 namespace content {
27 31
32 namespace {
33
34 class SelectCertificateContentBrowserClient : public TestContentBrowserClient {
35 public:
36 SelectCertificateContentBrowserClient() : select_certificate_count_(0) {}
37
38 int select_certificate_count() const { return select_certificate_count_; }
39
40 void SelectClientCertificate(
41 WebContents* web_contents,
42 net::SSLCertRequestInfo* cert_request_info,
43 scoped_ptr<ClientCertificateDelegate> delegate) override {
44 select_certificate_count_++;
45 delegate->CancelCertificateSelection();
46 }
47
48 private:
49 int select_certificate_count_;
50 };
51
52 } // namespace
53
28 class WorkerTest : public ContentBrowserTest { 54 class WorkerTest : public ContentBrowserTest {
29 public: 55 public:
30 WorkerTest() {} 56 WorkerTest() {}
31 57
32 GURL GetTestURL(const std::string& test_case, const std::string& query) { 58 GURL GetTestURL(const std::string& test_case, const std::string& query) {
33 base::FilePath test_file_path = GetTestFilePath( 59 base::FilePath test_file_path = GetTestFilePath(
34 "workers", test_case.c_str()); 60 "workers", test_case.c_str());
35 return GetFileUrlWithQuery(test_file_path, query); 61 return GetFileUrlWithQuery(test_file_path, query);
36 } 62 }
37 63
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // http://crbug.com/33344 123 // http://crbug.com/33344
98 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { 124 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) {
99 ASSERT_TRUE(test_server()->Start()); 125 ASSERT_TRUE(test_server()->Start());
100 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); 126 GURL url = test_server()->GetURL("files/workers/worker_auth.html");
101 127
102 NavigateAndWaitForAuth(url); 128 NavigateAndWaitForAuth(url);
103 } 129 }
104 130
105 // Make sure that auth dialog is displayed from shared worker context. 131 // Make sure that auth dialog is displayed from shared worker context.
106 // http://crbug.com/33344 132 // http://crbug.com/33344
133 //
134 // TODO(davidben): Auth dialogs are no longer displayed on shared workers, but
135 // this test only tests that the delegate is called. Move handling the
136 // WebContentsless case from chrome/ to content/ and adjust the test
137 // accordingly.
mmenke 2015/02/10 17:19:10 In this CL, you're actually doing that moving, no?
davidben 2015/02/10 20:28:49 This CL's about client auth, but this is HTTP auth
107 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { 138 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) {
108 ASSERT_TRUE(test_server()->Start()); 139 ASSERT_TRUE(test_server()->Start());
109 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); 140 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html");
110 NavigateAndWaitForAuth(url); 141 NavigateAndWaitForAuth(url);
111 } 142 }
112 143
144 // Tests that TLS client auth prompts for normal workers.
145 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerTlsClientAuth) {
146 // Launch HTTPS server.
147 net::SpawnedTestServer::SSLOptions ssl_options;
148 ssl_options.request_client_certificate = true;
149 net::SpawnedTestServer https_server(
150 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
151 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
152 ASSERT_TRUE(https_server.Start());
153 ASSERT_TRUE(test_server()->Start());
154
155 SelectCertificateContentBrowserClient client;
156 ContentBrowserClient* old_client = SetBrowserClientForTesting(&client);
157
158 GURL url = test_server()->GetURL(
159 "files/workers/worker_tls_client_auth.html?url=" +
160 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true));
161
162 const base::string16 expected_title = base::ASCIIToUTF16("OK");
163 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
164 NavigateToURL(shell(), url);
165 base::string16 final_title = title_watcher.WaitAndGetTitle();
166 EXPECT_EQ(expected_title, final_title);
167 EXPECT_EQ(1, client.select_certificate_count());
168
169 SetBrowserClientForTesting(old_client);
170 }
171
172 // Tests that TLS client auth does not prompt for a shared worker; shared
173 // workers are not associated with a WebContents.
174 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerTlsClientAuth) {
175 // Launch HTTPS server.
176 net::SpawnedTestServer::SSLOptions ssl_options;
177 ssl_options.request_client_certificate = true;
178 net::SpawnedTestServer https_server(
179 net::SpawnedTestServer::TYPE_HTTPS, ssl_options,
180 base::FilePath(FILE_PATH_LITERAL("content/test/data")));
181 ASSERT_TRUE(https_server.Start());
182 ASSERT_TRUE(test_server()->Start());
183
184 SelectCertificateContentBrowserClient client;
185 ContentBrowserClient* old_client = SetBrowserClientForTesting(&client);
186
187 GURL url = test_server()->GetURL(
188 "files/workers/worker_tls_client_auth.html?shared=true;url=" +
189 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true));
190
191 const base::string16 expected_title = base::ASCIIToUTF16("OK");
192 TitleWatcher title_watcher(shell()->web_contents(), expected_title);
193 NavigateToURL(shell(), url);
194 base::string16 final_title = title_watcher.WaitAndGetTitle();
195 EXPECT_EQ(expected_title, final_title);
196 EXPECT_EQ(0, client.select_certificate_count());
197
198 SetBrowserClientForTesting(old_client);
199 }
200
113 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { 201 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) {
114 // Launch WebSocket server. 202 // Launch WebSocket server.
115 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, 203 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS,
116 net::SpawnedTestServer::kLocalhost, 204 net::SpawnedTestServer::kLocalhost,
117 net::GetWebSocketTestDataDirectory()); 205 net::GetWebSocketTestDataDirectory());
118 ASSERT_TRUE(ws_server.Start()); 206 ASSERT_TRUE(ws_server.Start());
119 207
120 // Generate test URL. 208 // Generate test URL.
121 std::string scheme("http"); 209 std::string scheme("http");
122 GURL::Replacements replacements; 210 GURL::Replacements replacements;
(...skipping 13 matching lines...) Expand all
136 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) { 224 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) {
137 RunTest("pass_messageport_to_sharedworker.html", ""); 225 RunTest("pass_messageport_to_sharedworker.html", "");
138 } 226 }
139 227
140 IN_PROC_BROWSER_TEST_F(WorkerTest, 228 IN_PROC_BROWSER_TEST_F(WorkerTest,
141 PassMessagePortToSharedWorkerDontWaitForConnect) { 229 PassMessagePortToSharedWorkerDontWaitForConnect) {
142 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); 230 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", "");
143 } 231 }
144 232
145 } // namespace content 233 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698