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

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

Issue 1357773002: WKWebView: Implemented recoverable SSL interstitials. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lock_coloring
Patch Set: Merged with parent CL Created 5 years, 3 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_verification_cache_unittest.cc
diff --git a/ios/web/net/cert_verification_cache_unittest.cc b/ios/web/net/cert_verification_cache_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3142a5e422f9a57bf4e7812256ba51ee9099d7ef
--- /dev/null
+++ b/ios/web/net/cert_verification_cache_unittest.cc
@@ -0,0 +1,77 @@
+// 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_verification_cache.h"
+
+#include "net/base/test_data_directory.h"
+#include "net/test/cert_test_util.h"
+#include "testing/platform_test.h"
+
+namespace {
+// Test cert filenames.
+const char kCertFileName1[] = "ok_cert.pem";
+const char kCertFileName2[] = "expired_cert.pem";
+// Test hostnames.
+const char kHostName1[] = "www.example.com";
+const char kHostName2[] = "www.chromium.org";
+// Test values.
+const int kValue1 = 5;
+const int kValue2 = 6;
+} // namespace
+
+// Test fixture to test CertVerificationCache class.
+class CertVerificationCacheTest : public PlatformTest {
+ protected:
+ // Loads cert with the given |file_name|.
+ scoped_refptr<net::X509Certificate> GetCert(const std::string& file_name) {
+ return net::ImportCertFromFile(net::GetTestCertsDirectory(), file_name);
+ }
+
+ web::CertVerificationCache<int> cache_;
+};
+
+// Tests basic cache interactions.
+TEST_F(CertVerificationCacheTest, Basic) {
+ // Cache miss because it is empty.
+ int value;
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
+
+ // Insert first cert.
+ cache_.set(GetCert(kCertFileName1), kHostName1, kValue1);
+
+ // Cache miss because hostname/cert mismatch.
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), "", &value));
+
+ // Cahe hit.
+ EXPECT_TRUE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
+ EXPECT_EQ(kValue1, value);
+
+ // Insert second cert.
+ cache_.set(GetCert(kCertFileName2), kHostName2, kValue2);
+
+ // Cache miss because hostname/cert mismatch.
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
+
+ // Cahe hits.
+ EXPECT_TRUE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
+ EXPECT_EQ(kValue1, value);
+ EXPECT_TRUE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
+ EXPECT_EQ(kValue2, value);
+
+ // Clear cache.
+ cache_.reset();
+
+ // Cache miss because it is empty.
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName1, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName1), kHostName2, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName1, &value));
+ EXPECT_FALSE(cache_.get(GetCert(kCertFileName2), kHostName2, &value));
+}

Powered by Google App Engine
This is Rietveld 408576698