| 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..f9722c41f2c740707e5e1fb7eb0143d1caa3980f 100644
|
| --- a/content/browser/shared_worker/worker_browsertest.cc
|
| +++ b/content/browser/shared_worker/worker_browsertest.cc
|
| @@ -5,12 +5,15 @@
|
| #include "base/bind.h"
|
| #include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| +#include "base/macros.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/strings/stringprintf.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #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 +22,37 @@
|
| #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_++;
|
| + }
|
| +
|
| + private:
|
| + int select_certificate_count_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SelectCertificateContentBrowserClient);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| class WorkerTest : public ContentBrowserTest {
|
| public:
|
| WorkerTest() {}
|
| @@ -102,14 +130,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,
|
|
|