| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "content/browser/ssl/ssl_host_state.h" | 5 #include "content/browser/ssl/ssl_host_state.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 // Certificates for test data. They're obtained with: | 10 // Certificates for test data. They're obtained with: |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 0x63, 0xd6, 0x46, 0x81, 0x6f, 0x00, 0xd8, 0x72, 0x2f, 0x82, 0x37, 0x44, | 85 0x63, 0xd6, 0x46, 0x81, 0x6f, 0x00, 0xd8, 0x72, 0x2f, 0x82, 0x37, 0x44, |
| 86 0xc1 | 86 0xc1 |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 } // namespace | 89 } // namespace |
| 90 | 90 |
| 91 class SSLHostStateTest : public testing::Test { | 91 class SSLHostStateTest : public testing::Test { |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 TEST_F(SSLHostStateTest, DidHostRunInsecureContent) { | 94 TEST_F(SSLHostStateTest, DidHostRunInsecureContent) { |
| 95 SSLHostState state(NULL); | 95 SSLHostState state; |
| 96 | 96 |
| 97 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 42)); | 97 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 42)); |
| 98 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 98 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
| 99 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); | 99 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); |
| 100 | 100 |
| 101 state.HostRanInsecureContent("www.google.com", 42); | 101 state.HostRanInsecureContent("www.google.com", 42); |
| 102 | 102 |
| 103 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); | 103 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); |
| 104 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 104 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
| 105 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); | 105 EXPECT_FALSE(state.DidHostRunInsecureContent("example.com", 42)); |
| 106 | 106 |
| 107 state.HostRanInsecureContent("example.com", 42); | 107 state.HostRanInsecureContent("example.com", 42); |
| 108 | 108 |
| 109 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); | 109 EXPECT_TRUE(state.DidHostRunInsecureContent("www.google.com", 42)); |
| 110 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); | 110 EXPECT_FALSE(state.DidHostRunInsecureContent("www.google.com", 191)); |
| 111 EXPECT_TRUE(state.DidHostRunInsecureContent("example.com", 42)); | 111 EXPECT_TRUE(state.DidHostRunInsecureContent("example.com", 42)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST_F(SSLHostStateTest, QueryPolicy) { | 114 TEST_F(SSLHostStateTest, QueryPolicy) { |
| 115 scoped_refptr<net::X509Certificate> google_cert( | 115 scoped_refptr<net::X509Certificate> google_cert( |
| 116 net::X509Certificate::CreateFromBytes( | 116 net::X509Certificate::CreateFromBytes( |
| 117 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 117 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
| 118 | 118 |
| 119 SSLHostState state(NULL); | 119 SSLHostState state; |
| 120 | 120 |
| 121 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), | 121 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), |
| 122 net::CertPolicy::UNKNOWN); | 122 net::CertPolicy::UNKNOWN); |
| 123 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "google.com"), | 123 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "google.com"), |
| 124 net::CertPolicy::UNKNOWN); | 124 net::CertPolicy::UNKNOWN); |
| 125 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "example.com"), | 125 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "example.com"), |
| 126 net::CertPolicy::UNKNOWN); | 126 net::CertPolicy::UNKNOWN); |
| 127 | 127 |
| 128 state.AllowCertForHost(google_cert.get(), "www.google.com"); | 128 state.AllowCertForHost(google_cert.get(), "www.google.com"); |
| 129 | 129 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 145 | 145 |
| 146 state.DenyCertForHost(google_cert.get(), "example.com"); | 146 state.DenyCertForHost(google_cert.get(), "example.com"); |
| 147 | 147 |
| 148 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), | 148 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "www.google.com"), |
| 149 net::CertPolicy::ALLOWED); | 149 net::CertPolicy::ALLOWED); |
| 150 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "google.com"), | 150 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "google.com"), |
| 151 net::CertPolicy::UNKNOWN); | 151 net::CertPolicy::UNKNOWN); |
| 152 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "example.com"), | 152 EXPECT_EQ(state.QueryPolicy(google_cert.get(), "example.com"), |
| 153 net::CertPolicy::DENIED); | 153 net::CertPolicy::DENIED); |
| 154 } | 154 } |
| OLD | NEW |