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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/certificate_selector_browsertest.cc
diff --git a/chrome/browser/ui/views/certificate_selector_browsertest.cc b/chrome/browser/ui/views/certificate_selector_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f433774d91f8308a421eac1dd8eb474f65406e75
--- /dev/null
+++ b/chrome/browser/ui/views/certificate_selector_browsertest.cc
@@ -0,0 +1,92 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/views/certificate_selector.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/interactive_test_utils.h"
+#include "content/public/test/browser_test_utils.h"
+#include "net/base/test_data_directory.h"
+#include "net/cert/x509_certificate.h"
+#include "net/test/cert_test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+class CertificateSelectorTest : public InProcessBrowserTest {
+ public:
+ void SetUpInProcessBrowserTestFixture() override {
+ client_1_ =
+ net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_1.pem");
+ ASSERT_TRUE(client_1_);
+
+ client_2_ =
+ net::ImportCertFromFile(net::GetTestCertsDirectory(), "client_2.pem");
+ ASSERT_TRUE(client_2_);
+ }
+
+ void SetUpOnMainThread() override {
+ ASSERT_TRUE(content::WaitForLoadStop(
+ browser()->tab_strip_model()->GetActiveWebContents()));
+
+ net::CertificateList certificates;
+ certificates.push_back(client_1_);
+ certificates.push_back(client_2_);
+
+ selector_ = new chrome::CertificateSelector(
+ browser()->tab_strip_model()->GetActiveWebContents(), certificates,
+ base::Bind(&CertificateSelectorTest::OnCertificateSelected,
+ base::Unretained(this)));
+ selector_->Init(base::ASCIIToUTF16("some arbitrary text"));
+ }
+
+ void TearDownOnMainThread() override { EXPECT_TRUE(callback_called_); }
+
+ void OnCertificateSelected(
+ const scoped_refptr<net::X509Certificate>& selected_cert) {
+ EXPECT_FALSE(callback_called_);
+ callback_called_ = true;
+ selected_cert_ = selected_cert;
+ }
+
+ protected:
+ scoped_refptr<net::X509Certificate> client_1_;
+ scoped_refptr<net::X509Certificate> client_2_;
+ scoped_refptr<net::X509Certificate> selected_cert_;
+
+ // Will be set to true if the callback passed to the selector is called.
+ bool callback_called_ = false;
+
+ private:
+ // The selector will be deleted when a cert is selected or the tab is closed.
+ chrome::CertificateSelector* selector_ = nullptr;
+};
+
+IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, Escape) {
+ EXPECT_FALSE(callback_called_);
+
+ EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_ESCAPE, false,
+ false, false, false));
+
+ EXPECT_TRUE(callback_called_);
+ EXPECT_FALSE(selected_cert_.get());
+}
+
+IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, SelectDefault) {
+ EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
+ false, false, false));
+
+ EXPECT_EQ(client_1_.get(), selected_cert_.get());
+}
+
+IN_PROC_BROWSER_TEST_F(CertificateSelectorTest, SelectSecond) {
+ EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false,
+ false, false, false));
+ EXPECT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_RETURN, false,
+ false, false, false));
+
+ EXPECT_EQ(client_2_.get(), selected_cert_.get());
+}

Powered by Google App Engine
This is Rietveld 408576698