Chromium Code Reviews| 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 "ios/web/net/cert_host_pair.h" | |
| 6 | |
| 7 #include "net/base/test_data_directory.h" | |
| 8 #include "net/test/cert_test_util.h" | |
| 9 #include "testing/platform_test.h" | |
| 10 | |
| 11 namespace web { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Test cert filenames. | |
| 16 const char kCertFileName1[] = "ok_cert.pem"; | |
| 17 const char kCertFileName2[] = "expired_cert.pem"; | |
| 18 | |
| 19 // Test hostnames. | |
| 20 const char kHostName1[] = "www.example.com"; | |
| 21 const char kHostName2[] = "www.chromium.test"; | |
| 22 | |
| 23 // Loads cert with the given |file_name|. | |
| 24 scoped_refptr<net::X509Certificate> GetCert(const std::string& file_name) { | |
| 25 return net::ImportCertFromFile(net::GetTestCertsDirectory(), file_name); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 // Test fixture to test CertHostPair struct. | |
| 31 typedef PlatformTest CertHostPairTest; | |
| 32 | |
| 33 // Tests constructions. | |
| 34 TEST_F(CertHostPairTest, Construction) { | |
| 35 scoped_refptr<net::X509Certificate> cert = GetCert(kCertFileName1); | |
| 36 ASSERT_TRUE(cert); | |
| 37 CertHostPair pair(cert, kHostName1); | |
| 38 EXPECT_EQ(cert, pair.cert); | |
| 39 EXPECT_EQ(std::string(kHostName1), pair.host); | |
| 40 } | |
| 41 | |
| 42 // Tests comparision with different certs and hosts. | |
| 43 TEST_F(CertHostPairTest, ComparisonWithDifferentCertsAndHosts) { | |
| 44 ASSERT_TRUE(GetCert(kCertFileName1)); | |
| 45 ASSERT_TRUE(GetCert(kCertFileName2)); | |
|
Ryan Sleevi
2015/10/29 22:37:27
I was more trying to suggest you should follow lin
Eugene But (OOO till 7-30)
2015/10/30 01:40:55
Done.
| |
| 46 CertHostPair pair1(GetCert(kCertFileName1), kHostName1); | |
| 47 CertHostPair pair2(GetCert(kCertFileName2), kHostName2); | |
| 48 | |
| 49 EXPECT_TRUE(pair2 < pair1); | |
| 50 EXPECT_FALSE(pair1 < pair2); | |
| 51 } | |
| 52 | |
| 53 // Tests comparision with same cert. | |
| 54 TEST_F(CertHostPairTest, ComparisonWithSameCert) { | |
| 55 ASSERT_TRUE(GetCert(kCertFileName1)); | |
| 56 CertHostPair pair1(GetCert(kCertFileName1), kHostName1); | |
| 57 CertHostPair pair2(GetCert(kCertFileName1), kHostName2); | |
| 58 | |
| 59 EXPECT_TRUE(pair2 < pair1); | |
| 60 EXPECT_FALSE(pair1 < pair2); | |
| 61 } | |
| 62 | |
| 63 // Tests comparision with same host. | |
| 64 TEST_F(CertHostPairTest, ComparisonWithSameHost) { | |
| 65 ASSERT_TRUE(GetCert(kCertFileName1)); | |
| 66 ASSERT_TRUE(GetCert(kCertFileName2)); | |
| 67 CertHostPair pair1(GetCert(kCertFileName1), kHostName1); | |
| 68 CertHostPair pair2(GetCert(kCertFileName2), kHostName1); | |
| 69 | |
| 70 EXPECT_TRUE(pair1 < pair2); | |
| 71 EXPECT_FALSE(pair2 < pair1); | |
| 72 } | |
| 73 | |
| 74 // Tests comparision with same cert and host. | |
| 75 TEST_F(CertHostPairTest, ComparisonWithSameCertAndHost) { | |
| 76 ASSERT_TRUE(GetCert(kCertFileName1)); | |
| 77 CertHostPair pair1(GetCert(kCertFileName1), kHostName1); | |
| 78 CertHostPair pair2(GetCert(kCertFileName1), kHostName1); | |
| 79 | |
| 80 EXPECT_FALSE(pair1 < pair2); | |
| 81 EXPECT_FALSE(pair2 < pair1); | |
| 82 } | |
| 83 | |
| 84 } // namespace web | |
| OLD | NEW |