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

Side by Side Diff: net/quic/crypto/quic_compressed_certs_cache_test.cc

Issue 2193073003: Move shared files in net/quic/ into net/quic/core/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: io_thread_unittest.cc Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "net/quic/crypto/quic_compressed_certs_cache.h"
6
7 #include "base/logging.h"
8 #include "base/macros.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "net/quic/crypto/cert_compressor.h"
11 #include "net/quic/test_tools/crypto_test_utils.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using std::string;
15 using std::vector;
16
17 namespace net {
18
19 namespace test {
20
21 namespace {
22
23 class QuicCompressedCertsCacheTest : public testing::Test {
24 public:
25 QuicCompressedCertsCacheTest()
26 : certs_cache_(QuicCompressedCertsCache::kQuicCompressedCertsCacheSize) {}
27
28 protected:
29 QuicCompressedCertsCache certs_cache_;
30 };
31
32 TEST_F(QuicCompressedCertsCacheTest, CacheHit) {
33 vector<string> certs = {"leaf cert", "intermediate cert", "root cert"};
34 scoped_refptr<ProofSource::Chain> chain(new ProofSource::Chain(certs));
35 string common_certs = "common certs";
36 string cached_certs = "cached certs";
37 string compressed = "compressed cert";
38
39 certs_cache_.Insert(chain, common_certs, cached_certs, compressed);
40
41 const string* cached_value =
42 certs_cache_.GetCompressedCert(chain, common_certs, cached_certs);
43 ASSERT_NE(nullptr, cached_value);
44 EXPECT_EQ(*cached_value, compressed);
45 }
46
47 TEST_F(QuicCompressedCertsCacheTest, CacheMiss) {
48 vector<string> certs = {"leaf cert", "intermediate cert", "root cert"};
49 scoped_refptr<ProofSource::Chain> chain(new ProofSource::Chain(certs));
50 string common_certs = "common certs";
51 string cached_certs = "cached certs";
52 string compressed = "compressed cert";
53
54 certs_cache_.Insert(chain, common_certs, cached_certs, compressed);
55
56 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert(
57 chain, "mismatched common certs", cached_certs));
58 EXPECT_EQ(nullptr, certs_cache_.GetCompressedCert(chain, common_certs,
59 "mismatched cached certs"));
60 scoped_refptr<ProofSource::Chain> chain2(new ProofSource::Chain(certs));
61 EXPECT_EQ(nullptr,
62 certs_cache_.GetCompressedCert(chain2, common_certs, cached_certs));
63 }
64
65 TEST_F(QuicCompressedCertsCacheTest, CacheMissDueToEviction) {
66 // Test cache returns a miss when a queried uncompressed certs was cached but
67 // then evicted.
68 vector<string> certs = {"leaf cert", "intermediate cert", "root cert"};
69 scoped_refptr<ProofSource::Chain> chain(new ProofSource::Chain(certs));
70
71 string common_certs = "common certs";
72 string cached_certs = "cached certs";
73 string compressed = "compressed cert";
74 certs_cache_.Insert(chain, common_certs, cached_certs, compressed);
75
76 // Insert another kQuicCompressedCertsCacheSize certs to evict the first
77 // cached cert.
78 for (unsigned int i = 0;
79 i < QuicCompressedCertsCache::kQuicCompressedCertsCacheSize; i++) {
80 EXPECT_EQ(certs_cache_.Size(), i + 1);
81 certs_cache_.Insert(chain, base::IntToString(i), "", base::IntToString(i));
82 }
83 EXPECT_EQ(certs_cache_.MaxSize(), certs_cache_.Size());
84
85 EXPECT_EQ(nullptr,
86 certs_cache_.GetCompressedCert(chain, common_certs, cached_certs));
87 }
88
89 } // namespace
90 } // namespace test
91 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/quic_compressed_certs_cache.cc ('k') | net/quic/crypto/quic_crypto_client_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698