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

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

Powered by Google App Engine
This is Rietveld 408576698