Chromium Code Reviews| Index: chrome/browser/net/certificate_error_reporter_unittest.cc |
| diff --git a/chrome/browser/net/certificate_error_reporter_unittest.cc b/chrome/browser/net/certificate_error_reporter_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d684265363f151c157c75a325c7e27a170f57fe6 |
| --- /dev/null |
| +++ b/chrome/browser/net/certificate_error_reporter_unittest.cc |
| @@ -0,0 +1,54 @@ |
| +// 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 "chrome/browser/net/certificate_error_reporter.h" |
| + |
| +#include "base/files/file_util.h" |
| +#include "chrome/browser/net/cert_logger.pb.h" |
| +#include "content/public/test/test_browser_thread.h" |
| +#include "net/base/test_data_directory.h" |
| +#include "net/test/cert_test_util.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using content::BrowserThread; |
| +using net::SSLInfo; |
| + |
| +namespace { |
| + |
| +const std::string kHostname = "test.mail.google.com"; |
|
Ryan Sleevi
2015/03/06 21:32:47
s/std::string kHostname/const char kHostname[]/
(
estark
2015/03/07 00:38:50
Done.
|
| + |
| +SSLInfo GetSSLInfo() { |
| + SSLInfo info; |
| + info.cert = net::ImportCertFromFile(net::GetTestCertsDirectory(), |
| + "test_mail_google_com.pem"); |
| + info.is_issued_by_known_root = true; |
| + info.pinning_failure_log = "dummy failure log"; |
|
Ryan Sleevi
2015/03/06 21:32:47
Should this be a constant (line 26 vs 51)
estark
2015/03/07 00:38:50
Done.
|
| + return info; |
| +} |
| + |
| +std::string GetPEMEncodedChain() { |
| + base::FilePath cert_path = |
| + net::GetTestCertsDirectory().AppendASCII("test_mail_google_com.pem"); |
| + std::string cert_data; |
| + EXPECT_TRUE(base::ReadFileToString(cert_path, &cert_data)); |
| + return cert_data; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace chrome_browser_net { |
| + |
| +// Test that a built report has the correct data. |
| +TEST(CertificateErrorReporterTest, ReportIsBuiltCorrectly) { |
| + SSLInfo info = GetSSLInfo(); |
| + CertLoggerRequest request; |
| + CertificateErrorReporter::BuildReport(kHostname, info, request); |
| + |
| + EXPECT_EQ(request.hostname(), kHostname); |
|
Ryan Sleevi
2015/03/06 21:32:47
You only use this constant once. Were you intendin
estark
2015/03/07 00:38:50
Yes, and I am now.
|
| + EXPECT_EQ(request.cert_chain(), GetPEMEncodedChain()); |
| + EXPECT_EQ(request.pin().size(), 1); |
| + EXPECT_EQ(request.pin().Get(0), "dummy failure log"); |
| +} |
| + |
| +} // namespace chrome_browser_net |