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

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

Issue 1918143005: Add a serial number column to the certificate selector dialog and fix its size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sleevi comments Created 4 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/test/base/in_process_browser_test.h" 15 #include "chrome/test/base/in_process_browser_test.h"
15 #include "chrome/test/base/interactive_test_utils.h" 16 #include "chrome/test/base/interactive_test_utils.h"
16 #include "content/public/test/browser_test_utils.h" 17 #include "content/public/test/browser_test_utils.h"
17 #include "net/base/test_data_directory.h" 18 #include "net/base/test_data_directory.h"
18 #include "net/cert/x509_certificate.h" 19 #include "net/cert/x509_certificate.h"
19 #include "net/test/cert_test_util.h" 20 #include "net/test/cert_test_util.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/base/models/table_model.h"
21 #include "ui/views/controls/label.h" 23 #include "ui/views/controls/label.h"
22 24
23 namespace { 25 namespace {
24 26
25 class TestCertificateSelector : public chrome::CertificateSelector { 27 class TestCertificateSelector : public chrome::CertificateSelector {
26 public: 28 public:
27 TestCertificateSelector(const net::CertificateList& certificates, 29 TestCertificateSelector(const net::CertificateList& certificates,
28 content::WebContents* web_contents) 30 content::WebContents* web_contents)
29 : CertificateSelector(certificates, web_contents) {} 31 : CertificateSelector(certificates, web_contents) {}
30 32
(...skipping 17 matching lines...) Expand all
48 if (canceled_) 50 if (canceled_)
49 *canceled_ = true; 51 *canceled_ = true;
50 return CertificateSelector::Cancel(); 52 return CertificateSelector::Cancel();
51 } 53 }
52 54
53 void TrackState(bool* accepted, bool* canceled) { 55 void TrackState(bool* accepted, bool* canceled) {
54 accepted_ = accepted; 56 accepted_ = accepted;
55 canceled_ = canceled; 57 canceled_ = canceled;
56 } 58 }
57 59
60 using chrome::CertificateSelector::table_model_for_testing;
61
58 void set_on_destroy(base::Closure on_destroy) { on_destroy_ = on_destroy; } 62 void set_on_destroy(base::Closure on_destroy) { on_destroy_ = on_destroy; }
59 63
60 private: 64 private:
61 bool* accepted_ = nullptr; 65 bool* accepted_ = nullptr;
62 bool* canceled_ = nullptr; 66 bool* canceled_ = nullptr;
63 base::Closure on_destroy_; 67 base::Closure on_destroy_;
64 68
65 DISALLOW_COPY_AND_ASSIGN(TestCertificateSelector); 69 DISALLOW_COPY_AND_ASSIGN(TestCertificateSelector);
66 }; 70 };
67 71
(...skipping 27 matching lines...) Expand all
95 scoped_refptr<net::X509Certificate> client_1_; 99 scoped_refptr<net::X509Certificate> client_1_;
96 scoped_refptr<net::X509Certificate> client_2_; 100 scoped_refptr<net::X509Certificate> client_2_;
97 101
98 // The selector will be owned by the Views hierarchy and will at latest be 102 // The selector will be owned by the Views hierarchy and will at latest be
99 // deleted during the browser shutdown. 103 // deleted during the browser shutdown.
100 TestCertificateSelector* selector_ = nullptr; 104 TestCertificateSelector* selector_ = nullptr;
101 }; 105 };
102 106
103 } // namespace 107 } // namespace
104 108
109 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetRowText) {
110 ui::TableModel* model = selector_->table_model_for_testing();
111 EXPECT_EQ(base::UTF8ToUTF16("Client Cert A"),
112 model->GetText(0, IDS_CERT_SELECTOR_SUBJECT_COLUMN));
113 EXPECT_EQ(base::UTF8ToUTF16("B CA"),
114 model->GetText(0, IDS_CERT_SELECTOR_ISSUER_COLUMN));
115 EXPECT_EQ(base::UTF8ToUTF16(""),
msw 2016/04/29 18:04:54 nit: use base::string16()
meacer 2016/04/29 21:50:53 Done.
116 model->GetText(0, IDS_CERT_SELECTOR_PROVIDER_COLUMN));
117 EXPECT_EQ(base::UTF8ToUTF16("1000"),
118 model->GetText(0, IDS_CERT_SELECTOR_SERIAL_COLUMN));
119
120 EXPECT_EQ(base::UTF8ToUTF16("Client Cert D"),
121 model->GetText(1, IDS_CERT_SELECTOR_SUBJECT_COLUMN));
122 EXPECT_EQ(base::UTF8ToUTF16("E CA"),
123 model->GetText(1, IDS_CERT_SELECTOR_ISSUER_COLUMN));
124 EXPECT_EQ(base::UTF8ToUTF16(""),
msw 2016/04/29 18:04:54 ditto
meacer 2016/04/29 21:50:53 Done.
125 model->GetText(1, IDS_CERT_SELECTOR_PROVIDER_COLUMN));
126 EXPECT_EQ(base::UTF8ToUTF16("1002"),
127 model->GetText(1, IDS_CERT_SELECTOR_SERIAL_COLUMN));
128 }
129
105 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) { 130 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) {
106 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 131 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert());
107 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, 132 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
108 false, false, false)); 133 false, false, false));
109 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()); 134 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert());
110 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false, 135 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false,
111 false, false, false)); 136 false, false, false));
112 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); 137 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert());
113 } 138 }
114 139
115 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) { 140 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, DoubleClick) {
116 bool accepted = false; 141 bool accepted = false;
117 bool canceled = false; 142 bool canceled = false;
118 selector_->TrackState(&accepted, &canceled); 143 selector_->TrackState(&accepted, &canceled);
119 144
120 base::RunLoop loop; 145 base::RunLoop loop;
121 selector_->set_on_destroy(loop.QuitClosure()); 146 selector_->set_on_destroy(loop.QuitClosure());
122 147
123 // Simulate double clicking on an entry in the certificate list. 148 // Simulate double clicking on an entry in the certificate list.
124 selector_->OnDoubleClick(); 149 selector_->OnDoubleClick();
125 150
126 // Wait for the dialog to be closed and destroyed. 151 // Wait for the dialog to be closed and destroyed.
127 loop.Run(); 152 loop.Run();
128 153
129 // Closing the dialog through a double click must call only the Accept() 154 // Closing the dialog through a double click must call only the Accept()
130 // function and not Cancel(). 155 // function and not Cancel().
131 EXPECT_TRUE(accepted); 156 EXPECT_TRUE(accepted);
132 EXPECT_FALSE(canceled); 157 EXPECT_FALSE(canceled);
133 } 158 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698