| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/webui/ssl_client_certificate_selector_webui_browsert
est.h" | 5 #include "chrome/browser/ui/webui/ssl_client_certificate_selector_webui_browsert
est.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ssl/ssl_client_auth_requestor_mock.h" |
| 8 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/webui/chrome_web_ui.h" | 11 #include "chrome/browser/ui/webui/chrome_web_ui.h" |
| 10 #include "chrome/browser/ui/webui/ssl_client_certificate_selector_webui.h" | 12 #include "chrome/browser/ui/webui/ssl_client_certificate_selector_webui.h" |
| 11 #include "chrome/test/base/test_html_dialog_observer.h" | 13 #include "chrome/test/base/test_html_dialog_observer.h" |
| 12 #include "content/browser/ssl/ssl_client_auth_handler_mock.h" | |
| 13 #include "net/url_request/url_request.h" | 14 #include "net/url_request/url_request.h" |
| 14 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 15 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
| 16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 19 |
| 19 SSLClientCertificateSelectorUITest::SSLClientCertificateSelectorUITest() : | 20 SSLClientCertificateSelectorUITest::SSLClientCertificateSelectorUITest() : |
| 20 io_loop_finished_event_(false, false), url_request_(NULL) {} | 21 io_loop_finished_event_(false, false), url_request_(NULL) {} |
| 21 | 22 |
| 22 SSLClientCertificateSelectorUITest::~SSLClientCertificateSelectorUITest() {} | 23 SSLClientCertificateSelectorUITest::~SSLClientCertificateSelectorUITest() {} |
| 23 | 24 |
| 24 void SSLClientCertificateSelectorUITest::ShowSSLClientCertificateSelector() { | 25 void SSLClientCertificateSelectorUITest::ShowSSLClientCertificateSelector() { |
| 25 cert_request_info_ = new net::SSLCertRequestInfo; | 26 cert_request_info_ = new net::SSLCertRequestInfo; |
| 26 | 27 |
| 27 url_request_context_getter_ = browser()->profile()->GetRequestContext(); | 28 url_request_context_getter_ = browser()->profile()->GetRequestContext(); |
| 28 | 29 |
| 29 content::BrowserThread::PostTask( | 30 content::BrowserThread::PostTask( |
| 30 content::BrowserThread::IO, FROM_HERE, | 31 content::BrowserThread::IO, FROM_HERE, |
| 31 base::Bind(&SSLClientCertificateSelectorUITest::SetUpOnIOThread, this)); | 32 base::Bind(&SSLClientCertificateSelectorUITest::SetUpOnIOThread, this)); |
| 32 io_loop_finished_event_.Wait(); | 33 io_loop_finished_event_.Wait(); |
| 33 | 34 |
| 34 // The TestHtmlDialogObserver will catch our dialog when it gets created. | 35 // The TestHtmlDialogObserver will catch our dialog when it gets created. |
| 35 TestHtmlDialogObserver dialog_observer(this); | 36 TestHtmlDialogObserver dialog_observer(this); |
| 36 | 37 |
| 37 // Show the SSL client certificate selector. | 38 // Show the SSL client certificate selector. |
| 38 SSLClientCertificateSelectorWebUI::ShowDialog( | 39 SSLClientCertificateSelectorWebUI::ShowDialog( |
| 39 browser()->GetSelectedTabContentsWrapper(), | 40 browser()->GetSelectedTabContentsWrapper(), |
| 40 cert_request_info_, | 41 auth_requestor_->http_network_session_, |
| 41 auth_handler_ | 42 auth_requestor_->cert_request_info_, |
| 42 ); | 43 base::Bind(&SSLClientAuthRequestorMock::CertificateSelected, |
| 44 auth_requestor_)); |
| 43 | 45 |
| 44 EXPECT_CALL(*auth_handler_, CertificateSelectedNoNotify(::testing::_)); | 46 EXPECT_CALL(*auth_requestor_, CertificateSelected(::testing::_)); |
| 45 | 47 |
| 46 // Tell the test which WebUI instance we are dealing with and complete | 48 // Tell the test which WebUI instance we are dealing with and complete |
| 47 // initialization of this test. | 49 // initialization of this test. |
| 48 content::WebUI* webui = dialog_observer.GetWebUI(); | 50 content::WebUI* webui = dialog_observer.GetWebUI(); |
| 49 SetWebUIInstance(webui); | 51 SetWebUIInstance(webui); |
| 50 } | 52 } |
| 51 | 53 |
| 52 void SSLClientCertificateSelectorUITest::CleanUpOnMainThread() { | 54 void SSLClientCertificateSelectorUITest::CleanUpOnMainThread() { |
| 53 content::BrowserThread::PostTask( | 55 content::BrowserThread::PostTask( |
| 54 content::BrowserThread::IO, FROM_HERE, | 56 content::BrowserThread::IO, FROM_HERE, |
| 55 base::Bind(&SSLClientCertificateSelectorUITest::CleanUpOnIOThread, | 57 base::Bind(&SSLClientCertificateSelectorUITest::CleanUpOnIOThread, |
| 56 this)); | 58 this)); |
| 57 io_loop_finished_event_.Wait(); | 59 io_loop_finished_event_.Wait(); |
| 58 auth_handler_ = NULL; | 60 auth_requestor_ = NULL; |
| 59 WebUIBrowserTest::CleanUpOnMainThread(); | 61 WebUIBrowserTest::CleanUpOnMainThread(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 void SSLClientCertificateSelectorUITest::SetUpOnIOThread() { | 64 void SSLClientCertificateSelectorUITest::SetUpOnIOThread() { |
| 63 url_request_ = new net::URLRequest(GURL("https://example"), NULL); | 65 url_request_ = new net::URLRequest(GURL("https://example"), NULL); |
| 64 url_request_->set_context(url_request_context_getter_-> | 66 url_request_->set_context(url_request_context_getter_-> |
| 65 GetURLRequestContext()); | 67 GetURLRequestContext()); |
| 66 auth_handler_ = new testing::StrictMock<SSLClientAuthHandlerMock>( | 68 auth_requestor_ = new testing::StrictMock<SSLClientAuthRequestorMock>( |
| 67 url_request_, | 69 url_request_, |
| 68 cert_request_info_); | 70 cert_request_info_); |
| 69 io_loop_finished_event_.Signal(); | 71 io_loop_finished_event_.Signal(); |
| 70 } | 72 } |
| 71 | 73 |
| 72 void SSLClientCertificateSelectorUITest::CleanUpOnIOThread() { | 74 void SSLClientCertificateSelectorUITest::CleanUpOnIOThread() { |
| 73 delete url_request_; | 75 delete url_request_; |
| 74 url_request_ = NULL; | 76 url_request_ = NULL; |
| 75 io_loop_finished_event_.Signal(); | 77 io_loop_finished_event_.Signal(); |
| 76 } | 78 } |
| 77 | 79 |
| OLD | NEW |