| OLD | NEW |
| (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 namespace { |
| 20 |
| 21 class CertificateSelectorTest : public InProcessBrowserTest { |
| 22 public: |
| 23 void SetUpInProcessBrowserTestFixture() override { |
| 24 client_1_ = |
| 25 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_1.pem"); |
| 26 ASSERT_NE(nullptr, client_1_); |
| 27 |
| 28 client_2_ = |
| 29 net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_2.pem"); |
| 30 ASSERT_NE(nullptr, client_2_); |
| 31 } |
| 32 |
| 33 void SetUpOnMainThread() override { |
| 34 ASSERT_TRUE(content::WaitForLoadStop( |
| 35 browser()->tab_strip_model()->GetActiveWebContents())); |
| 36 |
| 37 net::CertificateList certificates; |
| 38 certificates.push_back(client_1_); |
| 39 certificates.push_back(client_2_); |
| 40 |
| 41 selector_ = new chrome::CertificateSelector( |
| 42 certificates, browser()->tab_strip_model()->GetActiveWebContents()); |
| 43 selector_->Init(base::ASCIIToUTF16("some arbitrary text")); |
| 44 } |
| 45 |
| 46 void TearDownOnMainThread() override { |
| 47 selector_->Close(); |
| 48 selector_ = nullptr; |
| 49 } |
| 50 |
| 51 protected: |
| 52 scoped_refptr<net::X509Certificate> client_1_; |
| 53 scoped_refptr<net::X509Certificate> client_2_; |
| 54 |
| 55 // The selector will be deleted when the browser is shutdown. |
| 56 chrome::CertificateSelector* selector_ = nullptr; |
| 57 }; |
| 58 |
| 59 } // namespace |
| 60 |
| 61 IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, GetSelectedCert) { |
| 62 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); |
| 63 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, |
| 64 false, false, false)); |
| 65 EXPECT_EQ(client_2_.get(), selector_->GetSelectedCert()); |
| 66 EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_UP, false, |
| 67 false, false, false)); |
| 68 EXPECT_EQ(client_1_.get(), selector_->GetSelectedCert()); |
| 69 } |
| OLD | NEW |