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

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

Issue 2898573002: Refactor client cert private key handling. (Closed)
Patch Set: rebase on https://codereview.chromium.org/2899083006/ Created 3 years, 7 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 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 net::ClientCertIdentityList certificates;
89 certificates.push_back(client_1_); 90 certificates.push_back(
90 certificates.push_back(client_2_); 91 base::MakeUnique<net::FakeClientCertIdentity>(client_1_));
92 certificates.push_back(
93 base::MakeUnique<net::FakeClientCertIdentity>(client_2_));
91 94
92 selector_ = new TestCertificateSelector( 95 selector_ = new TestCertificateSelector(
93 certificates, browser()->tab_strip_model()->GetActiveWebContents()); 96 std::move(certificates),
97 browser()->tab_strip_model()->GetActiveWebContents());
94 selector_->Init(); 98 selector_->Init();
95 selector_->Show(); 99 selector_->Show();
96 } 100 }
97 101
98 protected: 102 protected:
99 scoped_refptr<net::X509Certificate> client_1_; 103 scoped_refptr<net::X509Certificate> client_1_;
100 scoped_refptr<net::X509Certificate> client_2_; 104 scoped_refptr<net::X509Certificate> client_2_;
101 105
102 // The selector will be owned by the Views hierarchy and will at latest be 106 // The selector will be owned by the Views hierarchy and will at latest be
103 // deleted during the browser shutdown. 107 // deleted during the browser shutdown.
(...skipping 17 matching lines...) Expand all
121 model->GetText(1, IDS_CERT_SELECTOR_SUBJECT_COLUMN)); 125 model->GetText(1, IDS_CERT_SELECTOR_SUBJECT_COLUMN));
122 EXPECT_EQ(base::UTF8ToUTF16("E CA"), 126 EXPECT_EQ(base::UTF8ToUTF16("E CA"),
123 model->GetText(1, IDS_CERT_SELECTOR_ISSUER_COLUMN)); 127 model->GetText(1, IDS_CERT_SELECTOR_ISSUER_COLUMN));
124 EXPECT_EQ(base::string16(), 128 EXPECT_EQ(base::string16(),
125 model->GetText(1, IDS_CERT_SELECTOR_PROVIDER_COLUMN)); 129 model->GetText(1, IDS_CERT_SELECTOR_PROVIDER_COLUMN));
126 EXPECT_EQ(base::UTF8ToUTF16("1002"), 130 EXPECT_EQ(base::UTF8ToUTF16("1002"),
127 model->GetText(1, IDS_CERT_SELECTOR_SERIAL_COLUMN)); 131 model->GetText(1, IDS_CERT_SELECTOR_SERIAL_COLUMN));
128 } 132 }
129 133
130 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) { 134 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) {
131 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 135 ASSERT_TRUE(selector_->GetSelectedCert());
136 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()->certificate());
132 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, 137 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
133 false, false, false)); 138 false, false, false));
134 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()); 139 ASSERT_TRUE(selector_->GetSelectedCert());
140 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()->certificate());
135 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false, 141 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false,
136 false, false, false)); 142 false, false, false));
137 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 143 ASSERT_TRUE(selector_->GetSelectedCert());
144 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()->certificate());
138 } 145 }
139 146
140 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) { 147 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) {
141 bool accepted = false; 148 bool accepted = false;
142 bool canceled = false; 149 bool canceled = false;
143 selector_->TrackState(&accepted, &canceled); 150 selector_->TrackState(&accepted, &canceled);
144 151
145 base::RunLoop loop; 152 base::RunLoop loop;
146 selector_->set_on_destroy(loop.QuitClosure()); 153 selector_->set_on_destroy(loop.QuitClosure());
147 154
148 // Simulate double clicking on an entry in the certificate list. 155 // Simulate double clicking on an entry in the certificate list.
149 selector_->OnDoubleClick(); 156 selector_->OnDoubleClick();
150 157
151 // Wait for the dialog to be closed and destroyed. 158 // Wait for the dialog to be closed and destroyed.
152 loop.Run(); 159 loop.Run();
153 160
154 // Closing the dialog through a double click must call only the Accept() 161 // Closing the dialog through a double click must call only the Accept()
155 // function and not Cancel(). 162 // function and not Cancel().
156 EXPECT_TRUE(accepted); 163 EXPECT_TRUE(accepted);
157 EXPECT_FALSE(canceled); 164 EXPECT_FALSE(canceled);
158 } 165 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698