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

Unified Diff: ios/web/net/cert_host_pair_unittest.cc

Issue 1357773002: WKWebView: Implemented recoverable SSL interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_coloring
Patch Set: Addressed review comments Created 5 years, 2 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: ios/web/net/cert_host_pair_unittest.cc
diff --git a/ios/web/net/cert_host_pair_unittest.cc b/ios/web/net/cert_host_pair_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d09572e7e3c26f916d4918c40c8cf25aab06c130
--- /dev/null
+++ b/ios/web/net/cert_host_pair_unittest.cc
@@ -0,0 +1,76 @@
+// 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 "ios/web/net/cert_host_pair.h"
+
+#include "net/base/test_data_directory.h"
+#include "net/test/cert_test_util.h"
+#include "testing/platform_test.h"
+
+namespace web {
+
+namespace {
+// Test cert filenames.
Ryan Sleevi 2015/10/28 21:28:50 newline between 13/14
Eugene But (OOO till 7-30) 2015/10/29 00:39:14 Done.
+const char kCertFileName1[] = "ok_cert.pem";
+const char kCertFileName2[] = "expired_cert.pem";
+// Test hostnames.
Ryan Sleevi 2015/10/28 21:28:50 newline between 16/17
Eugene But (OOO till 7-30) 2015/10/29 00:39:14 Done.
+const char kHostName1[] = "www.example.com";
+const char kHostName2[] = "www.chromium.test";
+} // namespace
Ryan Sleevi 2015/10/28 21:28:50 newline between 19/20
Eugene But (OOO till 7-30) 2015/10/29 00:39:14 Done.
+
+// Test fixture to test CertHostPair struct.
+class CertHostPairTest : public PlatformTest {
+ protected:
+ // Loads cert with the given |file_name|.
+ scoped_refptr<net::X509Certificate> GetCert(
+ const std::string& file_name) const {
+ return net::ImportCertFromFile(net::GetTestCertsDirectory(), file_name);
Ryan Sleevi 2015/10/28 21:28:50 Is there a reason you used the fixture here rather
Eugene But (OOO till 7-30) 2015/10/29 00:39:14 Moved to a static function. Fixture is indeed unne
+ }
+};
+
+// Tests constructions.
+TEST_F(CertHostPairTest, Construction) {
+ scoped_refptr<net::X509Certificate> cert = GetCert(kCertFileName1);
Ryan Sleevi 2015/10/28 21:28:50 BUG/SAFETY: Each of these tests has a BUG in that
Eugene But (OOO till 7-30) 2015/10/29 00:39:14 Done.
+ CertHostPair pair(cert, kHostName1);
+ EXPECT_EQ(cert, pair.cert);
+ EXPECT_EQ(std::string(kHostName1), pair.host);
+}
+
+// Tests comparision with different certs and hosts.
+TEST_F(CertHostPairTest, ComparisonWithDifferentCertsAndHosts) {
+ CertHostPair pair1(GetCert(kCertFileName1), kHostName1);
+ CertHostPair pair2(GetCert(kCertFileName2), kHostName2);
+
+ EXPECT_TRUE(pair2 < pair1);
+ EXPECT_FALSE(pair1 < pair2);
+}
+
+// Tests comparision with same cert.
+TEST_F(CertHostPairTest, ComparisonWithSameCert) {
+ CertHostPair pair1(GetCert(kCertFileName1), kHostName1);
+ CertHostPair pair2(GetCert(kCertFileName1), kHostName2);
+
+ EXPECT_TRUE(pair2 < pair1);
+ EXPECT_FALSE(pair1 < pair2);
+}
+
+// Tests comparision with same host.
+TEST_F(CertHostPairTest, ComparisonWithSameHost) {
+ CertHostPair pair1(GetCert(kCertFileName1), kHostName1);
+ CertHostPair pair2(GetCert(kCertFileName2), kHostName1);
+
+ EXPECT_TRUE(pair1 < pair2);
+ EXPECT_FALSE(pair2 < pair1);
+}
+
+// Tests comparision with same cert and host.
+TEST_F(CertHostPairTest, ComparisonWithSameCertAndHost) {
+ CertHostPair pair1(GetCert(kCertFileName1), kHostName1);
+ CertHostPair pair2(GetCert(kCertFileName1), kHostName1);
+
+ EXPECT_FALSE(pair1 < pair2);
+ EXPECT_FALSE(pair2 < pair1);
+}
+
+} // namespace web

Powered by Google App Engine
This is Rietveld 408576698