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..67ef9702723e6ce7de52882cc328118544e4fb99 |
--- /dev/null |
+++ b/chrome/browser/net/certificate_error_reporter_unittest.cc |
@@ -0,0 +1,50 @@ |
+// 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 chrome_browser_net { |
+ |
+const std::string kHostname = "test.mail.google.com"; |
Ryan Sleevi
2015/03/06 19:23:13
You should put all of these (including the test) i
estark
2015/03/06 19:52:06
If I put the test in an unnamed namespace, I can't
estark
2015/03/06 20:10:02
Done, except for the test for above reason.
Ryan Sleevi
2015/03/06 21:32:46
Ah, right, because the test is friended you can't.
|
+ |
+static SSLInfo GetSSLInfo() { |
Ryan Sleevi
2015/03/06 19:23:13
/static/ is not needed here (and perversely, undes
estark
2015/03/06 20:10:02
Done.
|
+ 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"; |
+ return info; |
+} |
+ |
+static 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; |
+} |
+ |
+// Test that a built report has the correct data. |
+TEST(CertificateErrorReporterTest, ReportIsBuiltCorrectly) { |
Ryan Sleevi
2015/03/06 19:23:13
This test is mostly testing the implementation det
estark
2015/03/06 19:28:18
I had a question about writing those kinds of test
|
+ SSLInfo info = GetSSLInfo(); |
+ CertLoggerRequest request; |
+ CertificateErrorReporter::BuildReport(kHostname, info, request); |
+ |
+ EXPECT_EQ(request.hostname(), kHostname); |
+ 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 |