OLD | NEW |
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" |
14 #include "content/public/common/content_paths.h" | 15 #include "content/public/common/content_paths.h" |
15 #include "content/public/test/browser_test_utils.h" | 16 #include "content/public/test/browser_test_utils.h" |
16 #include "content/public/test/content_browser_test.h" | 17 #include "content/public/test/content_browser_test.h" |
17 #include "content/public/test/content_browser_test_utils.h" | 18 #include "content/public/test/content_browser_test_utils.h" |
18 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
19 #include "content/shell/browser/shell.h" | 20 #include "content/shell/browser/shell.h" |
20 #include "content/shell/browser/shell_content_browser_client.h" | 21 #include "content/shell/browser/shell_content_browser_client.h" |
21 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 22 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
| 23 #include "net/base/escape.h" |
22 #include "net/base/test_data_directory.h" | 24 #include "net/base/test_data_directory.h" |
23 #include "net/test/spawned_test_server/spawned_test_server.h" | 25 #include "net/test/spawned_test_server/spawned_test_server.h" |
24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
25 | 27 |
26 namespace content { | 28 namespace content { |
27 | 29 |
| 30 namespace { |
| 31 |
| 32 bool SupportsSharedWorker() { |
| 33 #if defined(OS_ANDROID) |
| 34 // SharedWorkers are not enabled on Android. https://crbug.com/154571 |
| 35 // |
| 36 // TODO(davidben): Move other SharedWorker exclusions from |
| 37 // build/android/pylib/gtest/filter/ inline. |
| 38 return false; |
| 39 #else |
| 40 return true; |
| 41 #endif |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
28 class WorkerTest : public ContentBrowserTest { | 46 class WorkerTest : public ContentBrowserTest { |
29 public: | 47 public: |
30 WorkerTest() {} | 48 WorkerTest() : select_certificate_count_(0) {} |
| 49 |
| 50 void SetUpOnMainThread() override { |
| 51 ShellContentBrowserClient::Get()->set_select_client_certificate_callback( |
| 52 base::Bind(&WorkerTest::OnSelectClientCertificate, |
| 53 base::Unretained(this))); |
| 54 } |
| 55 |
| 56 void TearDownOnMainThread() override { |
| 57 ShellContentBrowserClient::Get()->set_select_client_certificate_callback( |
| 58 base::Closure()); |
| 59 } |
| 60 |
| 61 int select_certificate_count() const { return select_certificate_count_; } |
31 | 62 |
32 GURL GetTestURL(const std::string& test_case, const std::string& query) { | 63 GURL GetTestURL(const std::string& test_case, const std::string& query) { |
33 base::FilePath test_file_path = GetTestFilePath( | 64 base::FilePath test_file_path = GetTestFilePath( |
34 "workers", test_case.c_str()); | 65 "workers", test_case.c_str()); |
35 return GetFileUrlWithQuery(test_file_path, query); | 66 return GetFileUrlWithQuery(test_file_path, query); |
36 } | 67 } |
37 | 68 |
38 void RunTest(Shell* window, | 69 void RunTest(Shell* window, |
39 const std::string& test_case, | 70 const std::string& test_case, |
40 const std::string& query) { | 71 const std::string& query) { |
(...skipping 16 matching lines...) Expand all Loading... |
57 void NavigateAndWaitForAuth(const GURL& url) { | 88 void NavigateAndWaitForAuth(const GURL& url) { |
58 ShellContentBrowserClient* browser_client = | 89 ShellContentBrowserClient* browser_client = |
59 ShellContentBrowserClient::Get(); | 90 ShellContentBrowserClient::Get(); |
60 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); | 91 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); |
61 browser_client->resource_dispatcher_host_delegate()-> | 92 browser_client->resource_dispatcher_host_delegate()-> |
62 set_login_request_callback( | 93 set_login_request_callback( |
63 base::Bind(&QuitUIMessageLoop, runner->QuitClosure())); | 94 base::Bind(&QuitUIMessageLoop, runner->QuitClosure())); |
64 shell()->LoadURL(url); | 95 shell()->LoadURL(url); |
65 runner->Run(); | 96 runner->Run(); |
66 } | 97 } |
| 98 |
| 99 private: |
| 100 void OnSelectClientCertificate() { select_certificate_count_++; } |
| 101 |
| 102 int select_certificate_count_; |
67 }; | 103 }; |
68 | 104 |
69 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { | 105 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { |
70 RunTest("single_worker.html", std::string()); | 106 RunTest("single_worker.html", std::string()); |
71 } | 107 } |
72 | 108 |
73 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { | 109 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { |
74 RunTest("multi_worker.html", std::string()); | 110 RunTest("multi_worker.html", std::string()); |
75 } | 111 } |
76 | 112 |
(...skipping 18 matching lines...) Expand all Loading... |
95 | 131 |
96 // Make sure that auth dialog is displayed from worker context. | 132 // Make sure that auth dialog is displayed from worker context. |
97 // http://crbug.com/33344 | 133 // http://crbug.com/33344 |
98 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { | 134 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { |
99 ASSERT_TRUE(test_server()->Start()); | 135 ASSERT_TRUE(test_server()->Start()); |
100 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); | 136 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); |
101 | 137 |
102 NavigateAndWaitForAuth(url); | 138 NavigateAndWaitForAuth(url); |
103 } | 139 } |
104 | 140 |
105 // Make sure that auth dialog is displayed from shared worker context. | 141 // Make sure that HTTP auth dialog is displayed from shared worker context. |
106 // http://crbug.com/33344 | 142 // http://crbug.com/33344 |
| 143 // |
| 144 // TODO(davidben): HTTP auth dialogs are no longer displayed on shared workers, |
| 145 // but this test only tests that the delegate is called. Move handling the |
| 146 // WebContentsless case from chrome/ to content/ and adjust the test |
| 147 // accordingly. |
107 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { | 148 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { |
108 ASSERT_TRUE(test_server()->Start()); | 149 ASSERT_TRUE(test_server()->Start()); |
109 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); | 150 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); |
110 NavigateAndWaitForAuth(url); | 151 NavigateAndWaitForAuth(url); |
111 } | 152 } |
112 | 153 |
| 154 // Tests that TLS client auth prompts for normal workers. |
| 155 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerTlsClientAuth) { |
| 156 // Launch HTTPS server. |
| 157 net::SpawnedTestServer::SSLOptions ssl_options; |
| 158 ssl_options.request_client_certificate = true; |
| 159 net::SpawnedTestServer https_server( |
| 160 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 161 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 162 ASSERT_TRUE(https_server.Start()); |
| 163 |
| 164 RunTest("worker_tls_client_auth.html", |
| 165 "url=" + |
| 166 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); |
| 167 EXPECT_EQ(1, select_certificate_count()); |
| 168 } |
| 169 |
| 170 // Tests that TLS client auth does not prompt for a shared worker; shared |
| 171 // workers are not associated with a WebContents. |
| 172 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerTlsClientAuth) { |
| 173 if (!SupportsSharedWorker()) |
| 174 return; |
| 175 |
| 176 // Launch HTTPS server. |
| 177 net::SpawnedTestServer::SSLOptions ssl_options; |
| 178 ssl_options.request_client_certificate = true; |
| 179 net::SpawnedTestServer https_server( |
| 180 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 181 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
| 182 ASSERT_TRUE(https_server.Start()); |
| 183 |
| 184 RunTest("worker_tls_client_auth.html", |
| 185 "shared=true&url=" + |
| 186 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); |
| 187 EXPECT_EQ(0, select_certificate_count()); |
| 188 } |
| 189 |
113 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { | 190 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { |
114 // Launch WebSocket server. | 191 // Launch WebSocket server. |
115 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, | 192 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |
116 net::SpawnedTestServer::kLocalhost, | 193 net::SpawnedTestServer::kLocalhost, |
117 net::GetWebSocketTestDataDirectory()); | 194 net::GetWebSocketTestDataDirectory()); |
118 ASSERT_TRUE(ws_server.Start()); | 195 ASSERT_TRUE(ws_server.Start()); |
119 | 196 |
120 // Generate test URL. | 197 // Generate test URL. |
121 GURL::Replacements replacements; | 198 GURL::Replacements replacements; |
122 replacements.SetSchemeStr("http"); | 199 replacements.SetSchemeStr("http"); |
(...skipping 12 matching lines...) Expand all Loading... |
135 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) { | 212 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) { |
136 RunTest("pass_messageport_to_sharedworker.html", ""); | 213 RunTest("pass_messageport_to_sharedworker.html", ""); |
137 } | 214 } |
138 | 215 |
139 IN_PROC_BROWSER_TEST_F(WorkerTest, | 216 IN_PROC_BROWSER_TEST_F(WorkerTest, |
140 PassMessagePortToSharedWorkerDontWaitForConnect) { | 217 PassMessagePortToSharedWorkerDontWaitForConnect) { |
141 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); | 218 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); |
142 } | 219 } |
143 | 220 |
144 } // namespace content | 221 } // namespace content |
OLD | NEW |