Chromium Code Reviews| 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 |
| 28 class WorkerTest : public ContentBrowserTest { | 30 class WorkerTest : public ContentBrowserTest { |
| 29 public: | 31 public: |
| 30 WorkerTest() {} | 32 WorkerTest() : select_certificate_count_(0) {} |
| 33 | |
| 34 void SetUpOnMainThread() override { | |
| 35 ShellContentBrowserClient::Get()->set_select_client_certificate_callback( | |
| 36 base::Bind(&WorkerTest::OnSelectClientCertificate, | |
| 37 base::Unretained(this))); | |
| 38 } | |
| 39 | |
| 40 void TearDownOnMainThread() override { | |
| 41 ShellContentBrowserClient::Get()->set_select_client_certificate_callback( | |
| 42 base::Callback<void()>()); | |
|
mmenke
2015/03/09 18:30:27
base::Closure? Or could just use a WeakPtrFactory
davidben
2015/03/10 02:07:57
Done. (I think I prefer base::Closure. Setting it
| |
| 43 } | |
| 44 | |
| 45 int select_certificate_count() const { return select_certificate_count_; } | |
| 31 | 46 |
| 32 GURL GetTestURL(const std::string& test_case, const std::string& query) { | 47 GURL GetTestURL(const std::string& test_case, const std::string& query) { |
| 33 base::FilePath test_file_path = GetTestFilePath( | 48 base::FilePath test_file_path = GetTestFilePath( |
| 34 "workers", test_case.c_str()); | 49 "workers", test_case.c_str()); |
| 35 return GetFileUrlWithQuery(test_file_path, query); | 50 return GetFileUrlWithQuery(test_file_path, query); |
| 36 } | 51 } |
| 37 | 52 |
| 38 void RunTest(Shell* window, | 53 void RunTest(Shell* window, |
| 39 const std::string& test_case, | 54 const std::string& test_case, |
| 40 const std::string& query) { | 55 const std::string& query) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 57 void NavigateAndWaitForAuth(const GURL& url) { | 72 void NavigateAndWaitForAuth(const GURL& url) { |
| 58 ShellContentBrowserClient* browser_client = | 73 ShellContentBrowserClient* browser_client = |
| 59 ShellContentBrowserClient::Get(); | 74 ShellContentBrowserClient::Get(); |
| 60 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); | 75 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner(); |
| 61 browser_client->resource_dispatcher_host_delegate()-> | 76 browser_client->resource_dispatcher_host_delegate()-> |
| 62 set_login_request_callback( | 77 set_login_request_callback( |
| 63 base::Bind(&QuitUIMessageLoop, runner->QuitClosure())); | 78 base::Bind(&QuitUIMessageLoop, runner->QuitClosure())); |
| 64 shell()->LoadURL(url); | 79 shell()->LoadURL(url); |
| 65 runner->Run(); | 80 runner->Run(); |
| 66 } | 81 } |
| 82 | |
| 83 private: | |
| 84 void OnSelectClientCertificate() { | |
| 85 select_certificate_count_++; | |
| 86 } | |
| 87 | |
| 88 int select_certificate_count_; | |
| 67 }; | 89 }; |
| 68 | 90 |
| 69 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { | 91 IN_PROC_BROWSER_TEST_F(WorkerTest, SingleWorker) { |
| 70 RunTest("single_worker.html", std::string()); | 92 RunTest("single_worker.html", std::string()); |
| 71 } | 93 } |
| 72 | 94 |
| 73 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { | 95 IN_PROC_BROWSER_TEST_F(WorkerTest, MultipleWorkers) { |
| 74 RunTest("multi_worker.html", std::string()); | 96 RunTest("multi_worker.html", std::string()); |
| 75 } | 97 } |
| 76 | 98 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 95 | 117 |
| 96 // Make sure that auth dialog is displayed from worker context. | 118 // Make sure that auth dialog is displayed from worker context. |
| 97 // http://crbug.com/33344 | 119 // http://crbug.com/33344 |
| 98 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { | 120 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { |
| 99 ASSERT_TRUE(test_server()->Start()); | 121 ASSERT_TRUE(test_server()->Start()); |
| 100 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); | 122 GURL url = test_server()->GetURL("files/workers/worker_auth.html"); |
| 101 | 123 |
| 102 NavigateAndWaitForAuth(url); | 124 NavigateAndWaitForAuth(url); |
| 103 } | 125 } |
| 104 | 126 |
| 105 // Make sure that auth dialog is displayed from shared worker context. | 127 // Make sure that HTTP auth dialog is displayed from shared worker context. |
| 106 // http://crbug.com/33344 | 128 // http://crbug.com/33344 |
| 129 // | |
| 130 // TODO(davidben): HTTP auth dialogs are no longer displayed on shared workers, | |
| 131 // but this test only tests that the delegate is called. Move handling the | |
| 132 // WebContentsless case from chrome/ to content/ and adjust the test | |
| 133 // accordingly. | |
| 107 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { | 134 IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { |
| 108 ASSERT_TRUE(test_server()->Start()); | 135 ASSERT_TRUE(test_server()->Start()); |
| 109 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); | 136 GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); |
| 110 NavigateAndWaitForAuth(url); | 137 NavigateAndWaitForAuth(url); |
| 111 } | 138 } |
| 112 | 139 |
| 140 // Tests that TLS client auth prompts for normal workers. | |
| 141 IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerTlsClientAuth) { | |
| 142 // Launch HTTPS server. | |
| 143 net::SpawnedTestServer::SSLOptions ssl_options; | |
| 144 ssl_options.request_client_certificate = true; | |
| 145 net::SpawnedTestServer https_server( | |
| 146 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
| 147 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
| 148 ASSERT_TRUE(https_server.Start()); | |
| 149 | |
| 150 RunTest("worker_tls_client_auth.html", | |
| 151 "url=" + | |
| 152 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); | |
| 153 EXPECT_EQ(1, select_certificate_count()); | |
| 154 } | |
| 155 | |
| 156 // Tests that TLS client auth does not prompt for a shared worker; shared | |
| 157 // workers are not associated with a WebContents. | |
| 158 #if defined(OS_ANDROID) | |
| 159 // SharedWorkers are not enabled on Android. https://crbug.com/154571 | |
| 160 #define MAYBE_SharedWorkerTlsClientAuth DISABLED_SharedWorkerTlsClientAuth | |
| 161 #else | |
| 162 #define MAYBE_SharedWorkerTlsClientAuth SharedWorkerTlsClientAuth | |
| 163 #endif | |
|
mmenke
2015/03/09 18:30:27
Should this be disabled via the same mechanism as
davidben
2015/03/10 02:07:57
So, I really don't like this out-of-band thing. :-
mmenke
2015/03/10 02:10:54
SGTM.
| |
| 164 IN_PROC_BROWSER_TEST_F(WorkerTest, MAYBE_SharedWorkerTlsClientAuth) { | |
| 165 // Launch HTTPS server. | |
| 166 net::SpawnedTestServer::SSLOptions ssl_options; | |
| 167 ssl_options.request_client_certificate = true; | |
| 168 net::SpawnedTestServer https_server( | |
| 169 net::SpawnedTestServer::TYPE_HTTPS, ssl_options, | |
| 170 base::FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
| 171 ASSERT_TRUE(https_server.Start()); | |
| 172 | |
| 173 RunTest("worker_tls_client_auth.html", | |
| 174 "shared=true&url=" + | |
| 175 net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); | |
| 176 EXPECT_EQ(0, select_certificate_count()); | |
| 177 } | |
| 178 | |
| 113 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { | 179 IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { |
| 114 // Launch WebSocket server. | 180 // Launch WebSocket server. |
| 115 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, | 181 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |
| 116 net::SpawnedTestServer::kLocalhost, | 182 net::SpawnedTestServer::kLocalhost, |
| 117 net::GetWebSocketTestDataDirectory()); | 183 net::GetWebSocketTestDataDirectory()); |
| 118 ASSERT_TRUE(ws_server.Start()); | 184 ASSERT_TRUE(ws_server.Start()); |
| 119 | 185 |
| 120 // Generate test URL. | 186 // Generate test URL. |
| 121 GURL::Replacements replacements; | 187 GURL::Replacements replacements; |
| 122 replacements.SetSchemeStr("http"); | 188 replacements.SetSchemeStr("http"); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 135 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) { | 201 IN_PROC_BROWSER_TEST_F(WorkerTest, PassMessagePortToSharedWorker) { |
| 136 RunTest("pass_messageport_to_sharedworker.html", ""); | 202 RunTest("pass_messageport_to_sharedworker.html", ""); |
| 137 } | 203 } |
| 138 | 204 |
| 139 IN_PROC_BROWSER_TEST_F(WorkerTest, | 205 IN_PROC_BROWSER_TEST_F(WorkerTest, |
| 140 PassMessagePortToSharedWorkerDontWaitForConnect) { | 206 PassMessagePortToSharedWorkerDontWaitForConnect) { |
| 141 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); | 207 RunTest("pass_messageport_to_sharedworker_dont_wait_for_connect.html", ""); |
| 142 } | 208 } |
| 143 | 209 |
| 144 } // namespace content | 210 } // namespace content |
| OLD | NEW |