Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / ssl / ssl_client_certificate_selector_test.cc
blob41c6035c3aa36ad58d5aa53be3a17aec2897ae9f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ssl/ssl_client_certificate_selector_test.h"
7 #include "base/bind.h"
8 #include "base/files/file_path.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/browser_test_utils.h"
15 #include "net/base/request_priority.h"
16 #include "net/base/test_data_directory.h"
17 #include "net/cert/x509_certificate.h"
18 #include "net/http/http_transaction_factory.h"
19 #include "net/ssl/ssl_cert_request_info.h"
20 #include "net/test/cert_test_util.h"
21 #include "net/url_request/url_request.h"
22 #include "net/url_request/url_request_context.h"
23 #include "net/url_request/url_request_context_getter.h"
25 using ::testing::Mock;
26 using ::testing::StrictMock;
27 using content::BrowserThread;
29 SSLClientCertificateSelectorTestBase::SSLClientCertificateSelectorTestBase()
30 : io_loop_finished_event_(false, false) {
33 SSLClientCertificateSelectorTestBase::~SSLClientCertificateSelectorTestBase() {
36 void SSLClientCertificateSelectorTestBase::SetUpInProcessBrowserTestFixture() {
37 base::FilePath certs_dir = net::GetTestCertsDirectory();
39 mit_davidben_cert_ = net::ImportCertFromFile(certs_dir, "mit.davidben.der");
40 ASSERT_TRUE(mit_davidben_cert_.get());
42 foaf_me_chromium_test_cert_ = net::ImportCertFromFile(
43 certs_dir, "foaf.me.chromium-test-cert.der");
44 ASSERT_TRUE(foaf_me_chromium_test_cert_.get());
46 cert_request_info_ = new net::SSLCertRequestInfo;
47 cert_request_info_->host_and_port = net::HostPortPair("foo", 123);
48 cert_request_info_->client_certs.push_back(mit_davidben_cert_);
49 cert_request_info_->client_certs.push_back(foaf_me_chromium_test_cert_);
52 void SSLClientCertificateSelectorTestBase::SetUpOnMainThread() {
53 url_request_context_getter_ = browser()->profile()->GetRequestContext();
55 BrowserThread::PostTask(
56 BrowserThread::IO,
57 FROM_HERE,
58 base::Bind(&SSLClientCertificateSelectorTestBase::SetUpOnIOThread,
59 this));
61 io_loop_finished_event_.Wait();
63 content::WaitForLoadStop(
64 browser()->tab_strip_model()->GetActiveWebContents());
67 // Have to release our reference to the auth handler during the test to allow
68 // it to be destroyed while the Browser and its IO thread still exist.
69 void SSLClientCertificateSelectorTestBase::TearDownOnMainThread() {
70 BrowserThread::PostTask(
71 BrowserThread::IO,
72 FROM_HERE,
73 base::Bind(&SSLClientCertificateSelectorTestBase::TearDownOnIOThread,
74 this));
76 io_loop_finished_event_.Wait();
78 auth_requestor_ = NULL;
81 void SSLClientCertificateSelectorTestBase::SetUpOnIOThread() {
82 url_request_ = MakeURLRequest(url_request_context_getter_.get()).release();
84 auth_requestor_ = new StrictMock<SSLClientAuthRequestorMock>(
85 url_request_, cert_request_info_.get());
87 io_loop_finished_event_.Signal();
90 void SSLClientCertificateSelectorTestBase::TearDownOnIOThread() {
91 delete url_request_;
93 io_loop_finished_event_.Signal();
96 scoped_ptr<net::URLRequest>
97 SSLClientCertificateSelectorTestBase::MakeURLRequest(
98 net::URLRequestContextGetter* context_getter) {
99 scoped_ptr<net::URLRequest> request =
100 context_getter->GetURLRequestContext()->CreateRequest(
101 GURL("https://example"), net::DEFAULT_PRIORITY, NULL);
102 return request.Pass();