Index: content/browser/shared_worker/worker_browsertest.cc |
diff --git a/content/browser/shared_worker/worker_browsertest.cc b/content/browser/shared_worker/worker_browsertest.cc |
index ce39df5788c24189d49063644097d9e54da44f0b..ebe8963bd0a8a36fe01f79bd867856b880333a8a 100644 |
--- a/content/browser/shared_worker/worker_browsertest.cc |
+++ b/content/browser/shared_worker/worker_browsertest.cc |
@@ -11,6 +11,8 @@ |
#include "base/sys_info.h" |
#include "base/test/test_timeouts.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/client_certificate_delegate.h" |
+#include "content/public/common/content_client.h" |
#include "content/public/common/content_paths.h" |
#include "content/public/test/browser_test_utils.h" |
#include "content/public/test/content_browser_test.h" |
@@ -19,12 +21,36 @@ |
#include "content/shell/browser/shell.h" |
#include "content/shell/browser/shell_content_browser_client.h" |
#include "content/shell/browser/shell_resource_dispatcher_host_delegate.h" |
+#include "content/test/test_content_browser_client.h" |
+#include "net/base/escape.h" |
#include "net/base/test_data_directory.h" |
#include "net/test/spawned_test_server/spawned_test_server.h" |
#include "url/gurl.h" |
namespace content { |
+namespace { |
+ |
+class SelectCertificateContentBrowserClient : public TestContentBrowserClient { |
+ public: |
+ SelectCertificateContentBrowserClient() : select_certificate_count_(0) {} |
+ |
+ int select_certificate_count() const { return select_certificate_count_; } |
+ |
+ void SelectClientCertificate( |
+ WebContents* web_contents, |
+ net::SSLCertRequestInfo* cert_request_info, |
+ scoped_ptr<ClientCertificateDelegate> delegate) override { |
+ select_certificate_count_++; |
+ delegate->CancelCertificateSelection(); |
+ } |
+ |
+ private: |
+ int select_certificate_count_; |
+}; |
+ |
+} // namespace |
+ |
class WorkerTest : public ContentBrowserTest { |
public: |
WorkerTest() {} |
@@ -104,12 +130,74 @@ IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { |
// Make sure that auth dialog is displayed from shared worker context. |
// http://crbug.com/33344 |
+// |
+// TODO(davidben): Auth dialogs are no longer displayed on shared workers, but |
+// this test only tests that the delegate is called. Move handling the |
+// WebContentsless case from chrome/ to content/ and adjust the test |
+// accordingly. |
mmenke
2015/02/10 17:19:10
In this CL, you're actually doing that moving, no?
davidben
2015/02/10 20:28:49
This CL's about client auth, but this is HTTP auth
|
IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerHttpAuth) { |
ASSERT_TRUE(test_server()->Start()); |
GURL url = test_server()->GetURL("files/workers/shared_worker_auth.html"); |
NavigateAndWaitForAuth(url); |
} |
+// Tests that TLS client auth prompts for normal workers. |
+IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerTlsClientAuth) { |
+ // Launch HTTPS server. |
+ net::SpawnedTestServer::SSLOptions ssl_options; |
+ ssl_options.request_client_certificate = true; |
+ net::SpawnedTestServer https_server( |
+ net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
+ base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
+ ASSERT_TRUE(https_server.Start()); |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ SelectCertificateContentBrowserClient client; |
+ ContentBrowserClient* old_client = SetBrowserClientForTesting(&client); |
+ |
+ GURL url = test_server()->GetURL( |
+ "files/workers/worker_tls_client_auth.html?url=" + |
+ net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); |
+ |
+ const base::string16 expected_title = base::ASCIIToUTF16("OK"); |
+ TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
+ NavigateToURL(shell(), url); |
+ base::string16 final_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, final_title); |
+ EXPECT_EQ(1, client.select_certificate_count()); |
+ |
+ SetBrowserClientForTesting(old_client); |
+} |
+ |
+// Tests that TLS client auth does not prompt for a shared worker; shared |
+// workers are not associated with a WebContents. |
+IN_PROC_BROWSER_TEST_F(WorkerTest, SharedWorkerTlsClientAuth) { |
+ // Launch HTTPS server. |
+ net::SpawnedTestServer::SSLOptions ssl_options; |
+ ssl_options.request_client_certificate = true; |
+ net::SpawnedTestServer https_server( |
+ net::SpawnedTestServer::TYPE_HTTPS, ssl_options, |
+ base::FilePath(FILE_PATH_LITERAL("content/test/data"))); |
+ ASSERT_TRUE(https_server.Start()); |
+ ASSERT_TRUE(test_server()->Start()); |
+ |
+ SelectCertificateContentBrowserClient client; |
+ ContentBrowserClient* old_client = SetBrowserClientForTesting(&client); |
+ |
+ GURL url = test_server()->GetURL( |
+ "files/workers/worker_tls_client_auth.html?shared=true;url=" + |
+ net::EscapeQueryParamValue(https_server.GetURL("").spec(), true)); |
+ |
+ const base::string16 expected_title = base::ASCIIToUTF16("OK"); |
+ TitleWatcher title_watcher(shell()->web_contents(), expected_title); |
+ NavigateToURL(shell(), url); |
+ base::string16 final_title = title_watcher.WaitAndGetTitle(); |
+ EXPECT_EQ(expected_title, final_title); |
+ EXPECT_EQ(0, client.select_certificate_count()); |
+ |
+ SetBrowserClientForTesting(old_client); |
+} |
+ |
IN_PROC_BROWSER_TEST_F(WorkerTest, WebSocketSharedWorker) { |
// Launch WebSocket server. |
net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |