| 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 "net/ssl/ssl_client_session_cache.h" | 5 #include "net/ssl/ssl_client_session_cache.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/histogram_tester.h" |
| 10 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "base/trace_event/memory_allocator_dump.h" | 13 #include "base/trace_event/memory_allocator_dump.h" |
| 13 #include "base/trace_event/process_memory_dump.h" | 14 #include "base/trace_event/process_memory_dump.h" |
| 14 #include "base/trace_event/trace_event_argument.h" | 15 #include "base/trace_event/trace_event_argument.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "third_party/boringssl/src/include/openssl/ssl.h" | 17 #include "third_party/boringssl/src/include/openssl/ssl.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 EXPECT_EQ(nullptr, cache.Lookup("key1").get()); | 81 EXPECT_EQ(nullptr, cache.Lookup("key1").get()); |
| 81 EXPECT_EQ(nullptr, cache.Lookup("key2").get()); | 82 EXPECT_EQ(nullptr, cache.Lookup("key2").get()); |
| 82 EXPECT_EQ(nullptr, cache.Lookup("key3").get()); | 83 EXPECT_EQ(nullptr, cache.Lookup("key3").get()); |
| 83 EXPECT_EQ(0u, cache.size()); | 84 EXPECT_EQ(0u, cache.size()); |
| 84 | 85 |
| 85 EXPECT_EQ(1u, session1->references); | 86 EXPECT_EQ(1u, session1->references); |
| 86 EXPECT_EQ(1u, session2->references); | 87 EXPECT_EQ(1u, session2->references); |
| 87 EXPECT_EQ(1u, session3->references); | 88 EXPECT_EQ(1u, session3->references); |
| 88 } | 89 } |
| 89 | 90 |
| 91 // Test that pairs of calls to Lookup/DecrementLookupCount appropriately log to |
| 92 // UMA. |
| 93 TEST(SSLClientSessionCacheTest, LookupCountUMA) { |
| 94 const char kLookupCountHistogram[] = "Net.SSLSessionConcurrentLookupCount"; |
| 95 base::HistogramTester histograms; |
| 96 |
| 97 SSLClientSessionCache::Config config; |
| 98 SSLClientSessionCache cache(config); |
| 99 |
| 100 bssl::UniquePtr<SSL_SESSION> session1(SSL_SESSION_new()); |
| 101 bssl::UniquePtr<SSL_SESSION> session2(SSL_SESSION_new()); |
| 102 cache.Insert("key1", session1.get()); |
| 103 cache.Insert("key2", session2.get()); |
| 104 histograms.ExpectTotalCount(kLookupCountHistogram, 0); |
| 105 |
| 106 // Test that multiple lookups of the same key are grouped, but that only the |
| 107 // number of concurrent uses is logged, not the total number of uses before |
| 108 // the count returns to 0. |
| 109 EXPECT_EQ(session1.get(), cache.Lookup("key1").get()); |
| 110 EXPECT_EQ(session1.get(), cache.Lookup("key1").get()); |
| 111 cache.DecrementLookupCount("key1", true); |
| 112 EXPECT_EQ(session1.get(), cache.Lookup("key1").get()); |
| 113 cache.DecrementLookupCount("key1", true); |
| 114 cache.DecrementLookupCount("key1", true); |
| 115 histograms.ExpectBucketCount(kLookupCountHistogram, 2, 1); |
| 116 |
| 117 // Test that independent keys are logged separately. |
| 118 EXPECT_EQ(session1.get(), cache.Lookup("key1").get()); |
| 119 EXPECT_EQ(session2.get(), cache.Lookup("key2").get()); |
| 120 cache.DecrementLookupCount("key1", true); |
| 121 cache.DecrementLookupCount("key2", true); |
| 122 histograms.ExpectBucketCount(kLookupCountHistogram, 1, 2); |
| 123 |
| 124 histograms.ExpectTotalCount(kLookupCountHistogram, 3); |
| 125 |
| 126 // Check that nothing gets logged if false is passed into |
| 127 // DecrementLookupCount. |
| 128 EXPECT_EQ(session1.get(), cache.Lookup("key1").get()); |
| 129 cache.DecrementLookupCount("key1", false); |
| 130 histograms.ExpectTotalCount(kLookupCountHistogram, 3); |
| 131 |
| 132 EXPECT_EQ(2u, cache.size()); |
| 133 } |
| 134 |
| 90 // Test that a session may be inserted at two different keys. This should never | 135 // Test that a session may be inserted at two different keys. This should never |
| 91 // be necessary, but the API doesn't prohibit it. | 136 // be necessary, but the API doesn't prohibit it. |
| 92 TEST(SSLClientSessionCacheTest, DoubleInsert) { | 137 TEST(SSLClientSessionCacheTest, DoubleInsert) { |
| 93 SSLClientSessionCache::Config config; | 138 SSLClientSessionCache::Config config; |
| 94 SSLClientSessionCache cache(config); | 139 SSLClientSessionCache cache(config); |
| 95 | 140 |
| 96 bssl::UniquePtr<SSL_SESSION> session(SSL_SESSION_new()); | 141 bssl::UniquePtr<SSL_SESSION> session(SSL_SESSION_new()); |
| 97 EXPECT_EQ(1u, session->references); | 142 EXPECT_EQ(1u, session->references); |
| 98 | 143 |
| 99 EXPECT_EQ(nullptr, cache.Lookup("key1").get()); | 144 EXPECT_EQ(nullptr, cache.Lookup("key1").get()); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 std::unique_ptr<base::Value> raw_attrs = | 377 std::unique_ptr<base::Value> raw_attrs = |
| 333 dump->attributes_for_testing()->ToBaseValue(); | 378 dump->attributes_for_testing()->ToBaseValue(); |
| 334 base::DictionaryValue* attrs; | 379 base::DictionaryValue* attrs; |
| 335 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); | 380 ASSERT_TRUE(raw_attrs->GetAsDictionary(&attrs)); |
| 336 ASSERT_TRUE(attrs->HasKey("cert_count")); | 381 ASSERT_TRUE(attrs->HasKey("cert_count")); |
| 337 ASSERT_TRUE(attrs->HasKey("serialized_cert_size")); | 382 ASSERT_TRUE(attrs->HasKey("serialized_cert_size")); |
| 338 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); | 383 ASSERT_TRUE(attrs->HasKey(base::trace_event::MemoryAllocatorDump::kNameSize)); |
| 339 } | 384 } |
| 340 | 385 |
| 341 } // namespace net | 386 } // namespace net |
| OLD | NEW |