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

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

Powered by Google App Engine
This is Rietveld 408576698