OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ios/web/net/cert_host_pair.h" | 5 #include "ios/web/net/cert_host_pair.h" |
6 | 6 |
7 #include "net/base/test_data_directory.h" | 7 #include "net/base/test_data_directory.h" |
8 #include "net/test/cert_test_util.h" | 8 #include "net/test/cert_test_util.h" |
9 #include "testing/platform_test.h" | 9 #include "testing/platform_test.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 // Test fixture to test CertHostPair struct. | 30 // Test fixture to test CertHostPair struct. |
31 typedef PlatformTest CertHostPairTest; | 31 typedef PlatformTest CertHostPairTest; |
32 | 32 |
33 // Tests constructions. | 33 // Tests constructions. |
34 TEST_F(CertHostPairTest, Construction) { | 34 TEST_F(CertHostPairTest, Construction) { |
35 scoped_refptr<net::X509Certificate> cert = GetCert(kCertFileName1); | 35 scoped_refptr<net::X509Certificate> cert = GetCert(kCertFileName1); |
36 ASSERT_TRUE(cert); | 36 ASSERT_TRUE(cert); |
37 CertHostPair pair(cert, kHostName1); | 37 CertHostPair pair(cert, kHostName1); |
38 EXPECT_EQ(cert, pair.cert); | 38 EXPECT_EQ(cert, pair.cert_); |
39 EXPECT_EQ(std::string(kHostName1), pair.host); | 39 EXPECT_EQ(std::string(kHostName1), pair.host_); |
40 } | 40 } |
41 | 41 |
42 // Tests comparision with different certs and hosts. | 42 // Tests comparision with different certs and hosts. |
43 TEST_F(CertHostPairTest, ComparisonWithDifferentCertsAndHosts) { | 43 TEST_F(CertHostPairTest, ComparisonWithDifferentCertsAndHosts) { |
44 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); | 44 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); |
45 ASSERT_TRUE(cert1); | 45 ASSERT_TRUE(cert1); |
46 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName2); | 46 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName2); |
47 ASSERT_TRUE(cert2); | 47 ASSERT_TRUE(cert2); |
48 CertHostPair pair1(cert1, kHostName1); | 48 CertHostPair pair1(cert1, kHostName1); |
49 CertHostPair pair2(cert2, kHostName2); | 49 CertHostPair pair2(cert2, kHostName2); |
50 | 50 |
51 EXPECT_TRUE(pair2 < pair1); | 51 EXPECT_FALSE(pair1 < pair1); |
52 EXPECT_FALSE(pair1 < pair2); | 52 EXPECT_FALSE(pair2 < pair2); |
| 53 EXPECT_TRUE((pair1 < pair2 && !(pair2 < pair1)) || |
| 54 (pair2 < pair1 && !(pair1 < pair2))); |
53 } | 55 } |
54 | 56 |
55 // Tests comparision with same cert. | 57 // Tests comparision with same cert. |
56 TEST_F(CertHostPairTest, ComparisonWithSameCert) { | 58 TEST_F(CertHostPairTest, ComparisonWithSameCert) { |
57 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); | 59 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); |
58 ASSERT_TRUE(cert1); | 60 ASSERT_TRUE(cert1); |
59 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName1); | 61 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName1); |
60 ASSERT_TRUE(cert2); | 62 ASSERT_TRUE(cert2); |
61 CertHostPair pair1(cert1, kHostName1); | 63 CertHostPair pair1(cert1, kHostName1); |
62 CertHostPair pair2(cert2, kHostName2); | 64 CertHostPair pair2(cert2, kHostName2); |
63 | 65 |
64 EXPECT_TRUE(pair2 < pair1); | 66 EXPECT_FALSE(pair1 < pair1); |
65 EXPECT_FALSE(pair1 < pair2); | 67 EXPECT_FALSE(pair2 < pair2); |
| 68 EXPECT_TRUE((pair1 < pair2 && !(pair2 < pair1)) || |
| 69 (pair2 < pair1 && !(pair1 < pair2))); |
66 } | 70 } |
67 | 71 |
68 // Tests comparision with same host. | 72 // Tests comparision with same host. |
69 TEST_F(CertHostPairTest, ComparisonWithSameHost) { | 73 TEST_F(CertHostPairTest, ComparisonWithSameHost) { |
70 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); | 74 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); |
71 ASSERT_TRUE(cert1); | 75 ASSERT_TRUE(cert1); |
72 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName2); | 76 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName2); |
73 ASSERT_TRUE(cert2); | 77 ASSERT_TRUE(cert2); |
74 CertHostPair pair1(cert1, kHostName1); | 78 CertHostPair pair1(cert1, kHostName1); |
75 CertHostPair pair2(cert2, kHostName1); | 79 CertHostPair pair2(cert2, kHostName1); |
76 | 80 |
77 EXPECT_TRUE(pair1 < pair2); | 81 EXPECT_FALSE(pair1 < pair1); |
78 EXPECT_FALSE(pair2 < pair1); | 82 EXPECT_FALSE(pair2 < pair2); |
| 83 EXPECT_TRUE((pair1 < pair2 && !(pair2 < pair1)) || |
| 84 (pair2 < pair1 && !(pair1 < pair2))); |
79 } | 85 } |
80 | 86 |
81 // Tests comparision with same cert and host. | 87 // Tests comparision with same cert and host. |
82 TEST_F(CertHostPairTest, ComparisonWithSameCertAndHost) { | 88 TEST_F(CertHostPairTest, ComparisonWithSameCertAndHost) { |
83 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); | 89 scoped_refptr<net::X509Certificate> cert1 = GetCert(kCertFileName1); |
84 ASSERT_TRUE(cert1); | 90 ASSERT_TRUE(cert1); |
85 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName1); | 91 scoped_refptr<net::X509Certificate> cert2 = GetCert(kCertFileName1); |
86 ASSERT_TRUE(cert2); | 92 ASSERT_TRUE(cert2); |
87 CertHostPair pair1(cert1, kHostName1); | 93 CertHostPair pair1(cert1, kHostName1); |
88 CertHostPair pair2(cert2, kHostName1); | 94 CertHostPair pair2(cert2, kHostName1); |
89 | 95 |
| 96 EXPECT_FALSE(pair1 < pair1); |
| 97 EXPECT_FALSE(pair2 < pair2); |
90 EXPECT_FALSE(pair1 < pair2); | 98 EXPECT_FALSE(pair1 < pair2); |
91 EXPECT_FALSE(pair2 < pair1); | 99 EXPECT_FALSE(pair2 < pair1); |
92 } | 100 } |
93 | 101 |
94 } // namespace web | 102 } // namespace web |
OLD | NEW |