| 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/command_line.h" |
| 6 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 7 #include "base/logging.h" | 8 #include "base/logging.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 "build/build_config.h" | 14 #include "build/build_config.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/client_certificate_delegate.h" | 16 #include "content/public/browser/client_certificate_delegate.h" |
| 17 #include "content/public/common/content_features.h" |
| 16 #include "content/public/common/content_paths.h" | 18 #include "content/public/common/content_paths.h" |
| 19 #include "content/public/common/content_switches.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 20 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/content_browser_test.h" | 21 #include "content/public/test/content_browser_test.h" |
| 19 #include "content/public/test/content_browser_test_utils.h" | 22 #include "content/public/test/content_browser_test_utils.h" |
| 20 #include "content/public/test/test_utils.h" | 23 #include "content/public/test/test_utils.h" |
| 21 #include "content/shell/browser/shell.h" | 24 #include "content/shell/browser/shell.h" |
| 22 #include "content/shell/browser/shell_content_browser_client.h" | 25 #include "content/shell/browser/shell_content_browser_client.h" |
| 23 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" | 26 #include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
| 24 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
| 25 #include "net/ssl/ssl_server_config.h" | 28 #include "net/ssl/ssl_server_config.h" |
| 26 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 shell()->LoadURL(url); | 101 shell()->LoadURL(url); |
| 99 runner->Run(); | 102 runner->Run(); |
| 100 } | 103 } |
| 101 | 104 |
| 102 private: | 105 private: |
| 103 void OnSelectClientCertificate() { select_certificate_count_++; } | 106 void OnSelectClientCertificate() { select_certificate_count_++; } |
| 104 | 107 |
| 105 int select_certificate_count_; | 108 int select_certificate_count_; |
| 106 }; | 109 }; |
| 107 | 110 |
| 111 class WorkerFetchTest : public testing::WithParamInterface<bool>, |
| 112 public WorkerTest { |
| 113 public: |
| 114 ~WorkerFetchTest() override {} |
| 115 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 116 if (GetParam()) { |
| 117 command_line->AppendSwitchASCII(switches::kEnableFeatures, |
| 118 features::kOffMainThreadFetch.name); |
| 119 } else { |
| 120 command_line->AppendSwitchASCII(switches::kDisableFeatures, |
| 121 features::kOffMainThreadFetch.name); |
| 122 } |
| 123 } |
| 124 }; |
| 125 |
| 108 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { | 126 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { |
| 109 RunTest("single_worker.html", std::string()); | 127 RunTest("single_worker.html", std::string()); |
| 110 } | 128 } |
| 111 | 129 |
| 112 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { | 130 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { |
| 113 RunTest("multi_worker.html", std::string()); | 131 RunTest("multi_worker.html", std::string()); |
| 114 } | 132 } |
| 115 | 133 |
| 116 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleSharedWorker) { | 134 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleSharedWorker) { |
| 117 if (!SupportsSharedWorker()) | 135 if (!SupportsSharedWorker()) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 136 | 154 |
| 137 // Load a non-incognito tab and have it create a shared worker | 155 // Load a non-incognito tab and have it create a shared worker |
| 138 RunTest("incognito_worker.html", std::string()); | 156 RunTest("incognito_worker.html", std::string()); |
| 139 | 157 |
| 140 // Incognito worker should not share with non-incognito | 158 // Incognito worker should not share with non-incognito |
| 141 RunTest(CreateOffTheRecordBrowser(), "incognito_worker.html", std::string()); | 159 RunTest(CreateOffTheRecordBrowser(), "incognito_worker.html", std::string()); |
| 142 } | 160 } |
| 143 | 161 |
| 144 // Make sure that auth dialog is displayed from worker context. | 162 // Make sure that auth dialog is displayed from worker context. |
| 145 // http://crbug.com/33344 | 163 // http://crbug.com/33344 |
| 146 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { | 164 IN_PROC_BROWSER_TEST_P(WorkerFetchTest, WorkerHttpAuth) { |
| 147 ASSERT_TRUE(embedded_test_server()->Start()); | 165 ASSERT_TRUE(embedded_test_server()->Start()); |
| 148 GURL url = embedded_test_server()->GetURL("/workers/worker_auth.html"); | 166 GURL url = embedded_test_server()->GetURL("/workers/worker_auth.html"); |
| 149 | 167 |
| 150 NavigateAndWaitForAuth(url); | 168 NavigateAndWaitForAuth(url); |
| 151 } | 169 } |
| 152 | 170 |
| 153 // Make sure that HTTP auth dialog is displayed from shared worker context. | 171 // Make sure that HTTP auth dialog is displayed from shared worker context. |
| 154 // http://crbug.com/33344 | 172 // http://crbug.com/33344 |
| 155 // | 173 // |
| 156 // TODO(davidben): HTTP auth dialogs are no longer displayed on shared workers, | 174 // TODO(davidben): HTTP auth dialogs are no longer displayed on shared workers, |
| 157 // but this test only tests that the delegate is called. Move handling the | 175 // but this test only tests that the delegate is called. Move handling the |
| 158 // WebContentsless case from chrome/ to content/ and adjust the test | 176 // WebContentsless case from chrome/ to content/ and adjust the test |
| 159 // accordingly. | 177 // accordingly. |
| 160 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { | 178 IN_PROC_BROWSER_TEST_P(WorkerFetchTest, SharedWorkerHttpAuth) { |
| 161 if (!SupportsSharedWorker()) | 179 if (!SupportsSharedWorker()) |
| 162 return; | 180 return; |
| 163 | 181 |
| 164 ASSERT_TRUE(embedded_test_server()->Start()); | 182 ASSERT_TRUE(embedded_test_server()->Start()); |
| 165 GURL url = embedded_test_server()->GetURL("/workers/shared_worker_auth.html"); | 183 GURL url = embedded_test_server()->GetURL("/workers/shared_worker_auth.html"); |
| 166 NavigateAndWaitForAuth(url); | 184 NavigateAndWaitForAuth(url); |
| 167 } | 185 } |
| 168 | 186 |
| 169 // Tests that TLS client auth prompts for normal workers. | 187 // Tests that TLS client auth prompts for normal workers's importScripts. |
| 170 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerTlsClientAuth) { | 188 IN_PROC_BROWSER_TEST_P(WorkerFetchTest, WorkerTlsClientAuthImportScripts) { |
| 171 // Launch HTTPS server. | 189 // Launch HTTPS server. |
| 172 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 190 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 173 https_server.ServeFilesFromSourceDirectory("content/test/data"); | 191 https_server.ServeFilesFromSourceDirectory("content/test/data"); |
| 174 net::SSLServerConfig ssl_config; | 192 net::SSLServerConfig ssl_config; |
| 175 ssl_config.client_cert_type = | 193 ssl_config.client_cert_type = |
| 176 net::SSLServerConfig::ClientCertType::REQUIRE_CLIENT_CERT; | 194 net::SSLServerConfig::ClientCertType::REQUIRE_CLIENT_CERT; |
| 177 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); | 195 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); |
| 178 ASSERT_TRUE(https_server.Start()); | 196 ASSERT_TRUE(https_server.Start()); |
| 179 | 197 |
| 180 RunTest("worker_tls_client_auth.html", | 198 RunTest("worker_tls_client_auth.html", |
| 181 "url=" + net::EscapeQueryParamValue(https_server.GetURL("/").spec(), | 199 "test=import&url=" + net::EscapeQueryParamValue( |
| 182 true)); | 200 https_server.GetURL("/").spec(), true)); |
| 201 EXPECT_EQ(1, select_certificate_count()); |
| 202 } |
| 203 |
| 204 // Tests that TLS client auth prompts for normal workers's fetch() call. |
| 205 IN_PROC_BROWSER_TEST_P(WorkerFetchTest, WorkerTlsClientAuthFetch) { |
| 206 // Launch HTTPS server. |
| 207 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 208 https_server.ServeFilesFromSourceDirectory("content/test/data"); |
| 209 net::SSLServerConfig ssl_config; |
| 210 ssl_config.client_cert_type = |
| 211 net::SSLServerConfig::ClientCertType::REQUIRE_CLIENT_CERT; |
| 212 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); |
| 213 ASSERT_TRUE(https_server.Start()); |
| 214 |
| 215 RunTest("worker_tls_client_auth.html", |
| 216 "test=fetch&url=" + net::EscapeQueryParamValue( |
| 217 https_server.GetURL("/").spec(), true)); |
| 183 EXPECT_EQ(1, select_certificate_count()); | 218 EXPECT_EQ(1, select_certificate_count()); |
| 184 } | 219 } |
| 185 | 220 |
| 186 // Tests that TLS client auth does not prompt for a shared worker; shared | 221 // Tests that TLS client auth does not prompt for a shared worker; shared |
| 187 // workers are not associated with a WebContents. | 222 // workers are not associated with a WebContents. |
| 188 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerTlsClientAuth) { | 223 IN_PROC_BROWSER_TEST_P(WorkerFetchTest, |
| 224 SharedWorkerTlsClientAuthImportScripts) { |
| 189 if (!SupportsSharedWorker()) | 225 if (!SupportsSharedWorker()) |
| 190 return; | 226 return; |
| 191 | 227 |
| 192 // Launch HTTPS server. | 228 // Launch HTTPS server. |
| 193 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); | 229 net::EmbeddedTestServer https_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 194 https_server.ServeFilesFromSourceDirectory("content/test/data"); | 230 https_server.ServeFilesFromSourceDirectory("content/test/data"); |
| 195 net::SSLServerConfig ssl_config; | 231 net::SSLServerConfig ssl_config; |
| 196 ssl_config.client_cert_type = | 232 ssl_config.client_cert_type = |
| 197 net::SSLServerConfig::ClientCertType::REQUIRE_CLIENT_CERT; | 233 net::SSLServerConfig::ClientCertType::REQUIRE_CLIENT_CERT; |
| 198 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); | 234 https_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); |
| 199 ASSERT_TRUE(https_server.Start()); | 235 ASSERT_TRUE(https_server.Start()); |
| 200 | 236 |
| 201 RunTest("worker_tls_client_auth.html", | 237 RunTest( |
| 202 "shared=true&url=" + net::EscapeQueryParamValue( | 238 "worker_tls_client_auth.html", |
| 203 https_server.GetURL("/").spec(), true)); | 239 "test=import&shared=true&url=" + |
| 240 net::EscapeQueryParamValue(https_server.GetURL("/").spec(), true)); |
| 204 EXPECT_EQ(0, select_certificate_count()); | 241 EXPECT_EQ(0, select_certificate_count()); |
| 205 } | 242 } |
| 206 | 243 |
| 207 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { | 244 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { |
| 208 if (!SupportsSharedWorker()) | 245 if (!SupportsSharedWorker()) |
| 209 return; | 246 return; |
| 210 | 247 |
| 211 // Launch WebSocket server. | 248 // Launch WebSocket server. |
| 212 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, | 249 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |
| 213 net::SpawnedTestServer::kLocalhost, | 250 net::SpawnedTestServer::kLocalhost, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 237 } | 274 } |
| 238 | 275 |
| 239 IN_PROC_BROWSER_TEST_F(WorkerTest, | 276 IN_PROC_BROWSER_TEST_F(WorkerTest, |
| 240 PassMessagePortToSharedWorkerDontWaitForConnect) { | 277 PassMessagePortToSharedWorkerDontWaitForConnect) { |
| 241 if (!SupportsSharedWorker()) | 278 if (!SupportsSharedWorker()) |
| 242 return; | 279 return; |
| 243 | 280 |
| 244 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); | 281 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); |
| 245 } | 282 } |
| 246 | 283 |
| 284 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 285 WorkerFetchTest, |
| 286 ::testing::Values(true, false)); |
| 287 |
| 247 } // namespace content | 288 } // namespace content |
| OLD | NEW |