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 14100b9d72f2cdc6b099bab02668c11e48abe014..3a0650a3568ee379d34393d6ca5b7426b21e7bce 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_; |
mmenke
2015/02/17 19:50:14
DISALLOW_COPY_AND_ASSIGN? And include the relevan
davidben
2015/02/18 22:31:44
Done.
|
+}; |
+ |
+} // namespace |
+ |
class WorkerTest : public ContentBrowserTest { |
public: |
WorkerTest() {} |
@@ -102,14 +128,76 @@ IN_PROC_BROWSER_TEST_F(WorkerTest, WorkerHttpAuth) { |
NavigateAndWaitForAuth(url); |
} |
-// Make sure that auth dialog is displayed from shared worker context. |
+// Make sure that HTTP auth dialog is displayed from shared worker context. |
// http://crbug.com/33344 |
+// |
+// TODO(davidben): HTTP 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. |
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, |