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

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

Issue 932553002: Refactor SSLClientCertificateSelector for reuse with platformKeys API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_perms
Patch Set: Cleaned up includes. Fixed compilation. Created 5 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/files/file_path.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/browser/ui/views/certificate_selector.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "chrome/test/base/interactive_test_utils.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "net/base/test_data_directory.h"
15 #include "net/cert/x509_certificate.h"
16 #include "net/test/cert_test_util.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 class CertificateSelectorTest : public InProcessBrowserTest {
20 public:
21 void SetUpInProcessBrowserTestFixture() override {
22 client_1_ =
23 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_1.pem");
24 ASSERT_TRUE(client_1_);
25
26 client_2_ =
27 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_2.pem");
28 ASSERT_TRUE(client_2_);
29 }
30
31 void SetUpOnMainThread() override {
32 ASSERT_TRUE(content::WaitForLoadStop(
33 browser()->tab_strip_model()->GetActiveWebContents()));
34
35 net::CertificateList certificates;
36 certificates.push_back(client_1_);
37 certificates.push_back(client_2_);
38
39 selector_ = new chrome::CertificateSelector(
40 browser()->tab_strip_model()->GetActiveWebContents(), certificates,
41 base::Bind(&CertificateSelectorTest::OnCertificateSelected,
42 base::Unretained(this)));
43 selector_->Init(base::ASCIIToUTF16("some arbitrary text"));
44 }
45
46 void TearDownOnMainThread() override { EXPECT_TRUE(callback_called_); }
47
48 void OnCertificateSelected(
49 const scoped_refptr<net::X509Certificate>& selected_cert) {
50 EXPECT_FALSE(callback_called_);
51 callback_called_ = true;
52 selected_cert_ = selected_cert;
53 }
54
55 protected:
56 scoped_refptr<net::X509Certificate> client_1_;
57 scoped_refptr<net::X509Certificate> client_2_;
58 scoped_refptr<net::X509Certificate> selected_cert_;
59
60 // Will be set to true if the callback passed to the selector is called.
61 bool callback_called_ = false;
62
63 private:
64 // The selector will be deleted when a cert is selected or the tab is closed.
65 chrome::CertificateSelector* selector_ = nullptr;
66 };
67
68 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, Escape) {
69 EXPECT_FALSE(callback_called_);
70
71 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_ESCAPE, false,
72 false, false, false));
73
74 EXPECT_TRUE(callback_called_);
75 EXPECT_FALSE(selected_cert_.get());
76 }
77
78 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, SelectDefault) {
79 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
80 false, false, false));
81
82 EXPECT_EQ(client_1_.get(), selected_cert_.get());
83 }
84
85 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, SelectSecond) {
86 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
87 false, false, false));
88 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
89 false, false, false));
90
91 EXPECT_EQ(client_2_.get(), selected_cert_.get());
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698