Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: chrome/browser/ui/views/certificate_selector_browsertest.cc

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: removed no longer needed forward declaration Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/certificate_selector.h" 5 #include "chrome/browser/ui/views/certificate_selector.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
15 #include "chrome/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/interactive_test_utils.h" 16 #include "chrome/test/base/interactive_test_utils.h"
17 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
18 #include "net/cert/x509_certificate.h" 18 #include "net/cert/x509_certificate.h"
19 #include "net/ssl/client_cert_identity_test_util.h"
19 #include "net/test/cert_test_util.h" 20 #include "net/test/cert_test_util.h"
20 #include "net/test/test_data_directory.h" 21 #include "net/test/test_data_directory.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/models/table_model.h" 23 #include "ui/base/models/table_model.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 25
25 namespace { 26 namespace {
26 27
27 class TestCertificateSelector : public chrome::CertificateSelector { 28 class TestCertificateSelector : public chrome::CertificateSelector {
28 public: 29 public:
29 TestCertificateSelector(const net::CertificateList& certificates, 30 TestCertificateSelector(net::ClientCertIdentityList certificates,
30 content::WebContents* web_contents) 31 content::WebContents* web_contents)
31 : CertificateSelector(certificates, web_contents) {} 32 : CertificateSelector(std::move(certificates), web_contents) {}
32 33
33 ~TestCertificateSelector() override { 34 ~TestCertificateSelector() override {
34 if (!on_destroy_.is_null()) 35 if (!on_destroy_.is_null())
35 on_destroy_.Run(); 36 on_destroy_.Run();
36 } 37 }
37 38
38 void Init() { 39 void Init() {
39 InitWithText(base::MakeUnique<views::Label>( 40 InitWithText(base::MakeUnique<views::Label>(
40 base::ASCIIToUTF16("some arbitrary text"))); 41 base::ASCIIToUTF16("some arbitrary text")));
41 } 42 }
42 43
43 bool Accept() override { 44 void AcceptCertificate(
45 std::unique_ptr<net::ClientCertIdentity> identity) override {
44 if (accepted_) 46 if (accepted_)
45 *accepted_ = true; 47 *accepted_ = true;
46 return CertificateSelector::Accept();
47 } 48 }
48 49
49 bool Cancel() override { 50 bool Cancel() override {
50 if (canceled_) 51 if (canceled_)
51 *canceled_ = true; 52 *canceled_ = true;
52 return CertificateSelector::Cancel(); 53 return CertificateSelector::Cancel();
53 } 54 }
54 55
55 void TrackState(bool* accepted, bool* canceled) { 56 void TrackState(bool* accepted, bool* canceled) {
56 accepted_ = accepted; 57 accepted_ = accepted;
(...skipping 21 matching lines...) Expand all
78 79
79 client_2_ = 80 client_2_ =
80 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_2.pem"); 81 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_2.pem");
81 ASSERT_TRUE(client_2_); 82 ASSERT_TRUE(client_2_);
82 } 83 }
83 84
84 void SetUpOnMainThread() override { 85 void SetUpOnMainThread() override {
85 ASSERT_TRUE(content::WaitForLoadStop( 86 ASSERT_TRUE(content::WaitForLoadStop(
86 browser()->tab_strip_model()->GetActiveWebContents())); 87 browser()->tab_strip_model()->GetActiveWebContents()));
87 88
88 net::CertificateList certificates;
89 certificates.push_back(client_1_);
90 certificates.push_back(client_2_);
91
92 selector_ = new TestCertificateSelector( 89 selector_ = new TestCertificateSelector(
93 certificates, browser()->tab_strip_model()->GetActiveWebContents()); 90 net::FakeClientCertIdentityListFromCertificateList(
91 {client_1_, client_2_}),
92 browser()->tab_strip_model()->GetActiveWebContents());
94 selector_->Init(); 93 selector_->Init();
95 selector_->Show(); 94 selector_->Show();
96 } 95 }
97 96
98 protected: 97 protected:
99 scoped_refptr<net::X509Certificate> client_1_; 98 scoped_refptr<net::X509Certificate> client_1_;
100 scoped_refptr<net::X509Certificate> client_2_; 99 scoped_refptr<net::X509Certificate> client_2_;
101 100
102 // The selector will be owned by the Views hierarchy and will at latest be 101 // The selector will be owned by the Views hierarchy and will at latest be
103 // deleted during the browser shutdown. 102 // deleted during the browser shutdown.
(...skipping 17 matching lines...) Expand all
121 model->GetText(1, IDS_CERT_SELECTOR_SUBJECT_COLUMN)); 120 model->GetText(1, IDS_CERT_SELECTOR_SUBJECT_COLUMN));
122 EXPECT_EQ(base::UTF8ToUTF16("E CA"), 121 EXPECT_EQ(base::UTF8ToUTF16("E CA"),
123 model->GetText(1, IDS_CERT_SELECTOR_ISSUER_COLUMN)); 122 model->GetText(1, IDS_CERT_SELECTOR_ISSUER_COLUMN));
124 EXPECT_EQ(base::string16(), 123 EXPECT_EQ(base::string16(),
125 model->GetText(1, IDS_CERT_SELECTOR_PROVIDER_COLUMN)); 124 model->GetText(1, IDS_CERT_SELECTOR_PROVIDER_COLUMN));
126 EXPECT_EQ(base::UTF8ToUTF16("1002"), 125 EXPECT_EQ(base::UTF8ToUTF16("1002"),
127 model->GetText(1, IDS_CERT_SELECTOR_SERIAL_COLUMN)); 126 model->GetText(1, IDS_CERT_SELECTOR_SERIAL_COLUMN));
128 } 127 }
129 128
130 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) { 129 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) {
131 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 130 ASSERT_TRUE(selector_->GetSelectedCert());
131 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()->certificate());
132 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, 132 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
133 false, false, false)); 133 false, false, false));
134 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()); 134 ASSERT_TRUE(selector_->GetSelectedCert());
135 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()->certificate());
135 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false, 136 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false,
136 false, false, false)); 137 false, false, false));
137 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 138 ASSERT_TRUE(selector_->GetSelectedCert());
139 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()->certificate());
138 } 140 }
139 141
140 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) { 142 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) {
141 bool accepted = false; 143 bool accepted = false;
142 bool canceled = false; 144 bool canceled = false;
143 selector_->TrackState(&accepted, &canceled); 145 selector_->TrackState(&accepted, &canceled);
144 146
145 base::RunLoop loop; 147 base::RunLoop loop;
146 selector_->set_on_destroy(loop.QuitClosure()); 148 selector_->set_on_destroy(loop.QuitClosure());
147 149
148 // Simulate double clicking on an entry in the certificate list. 150 // Simulate double clicking on an entry in the certificate list.
149 selector_->OnDoubleClick(); 151 selector_->OnDoubleClick();
150 152
151 // Wait for the dialog to be closed and destroyed. 153 // Wait for the dialog to be closed and destroyed.
152 loop.Run(); 154 loop.Run();
153 155
154 // Closing the dialog through a double click must call only the Accept() 156 // Closing the dialog through a double click must call only the Accept()
155 // function and not Cancel(). 157 // function and not Cancel().
156 EXPECT_TRUE(accepted); 158 EXPECT_TRUE(accepted);
157 EXPECT_FALSE(canceled); 159 EXPECT_FALSE(canceled);
158 } 160 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/certificate_selector.cc ('k') | chrome/browser/ui/views/platform_keys_certificate_selector_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698