Roll src/third_party/WebKit eac3800:0237a66 (svn 202606:202607)
[chromium-blink-merge.git] / net / quic / quic_sent_entropy_manager_test.cc
blob167e56b456b9da73f6a4ccf580084bd5dd79378f
1 // Copyright 2013 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.
5 #include "net/quic/quic_sent_entropy_manager.h"
7 #include <algorithm>
8 #include <vector>
10 #include "testing/gmock/include/gmock/gmock.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using std::make_pair;
14 using std::pair;
16 namespace net {
17 namespace test {
18 namespace {
20 class QuicSentEntropyManagerTest : public ::testing::Test {
21 protected:
22 QuicSentEntropyManager entropy_manager_;
25 TEST_F(QuicSentEntropyManagerTest, SentEntropyHash) {
26 EXPECT_EQ(0, entropy_manager_.GetCumulativeEntropy(0));
28 QuicPacketEntropyHash entropies[4] = {12, 1, 33, 3};
29 for (size_t i = 0; i < arraysize(entropies); ++i) {
30 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]);
33 QuicPacketEntropyHash hash = 0;
34 for (size_t i = 0; i < arraysize(entropies); ++i) {
35 hash ^= entropies[i];
36 EXPECT_EQ(hash, entropy_manager_.GetCumulativeEntropy(i + 1));
40 TEST_F(QuicSentEntropyManagerTest, IsValidEntropy) {
41 QuicPacketEntropyHash entropies[10] =
42 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
43 for (size_t i = 0; i < arraysize(entropies); ++i) {
44 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]);
47 PacketNumberQueue missing_packets;
48 missing_packets.Add(1);
49 missing_packets.Add(4);
50 missing_packets.Add(7, 9);
52 QuicPacketEntropyHash entropy_hash = 0;
53 for (size_t i = 0; i < arraysize(entropies); ++i) {
54 if (!missing_packets.Contains(i + 1)) {
55 entropy_hash ^= entropies[i];
59 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets,
60 entropy_hash));
63 TEST_F(QuicSentEntropyManagerTest, ClearEntropiesBefore) {
64 QuicPacketEntropyHash entropies[10] =
65 {12, 1, 33, 3, 32, 100, 28, 42, 22, 255};
67 for (size_t i = 0; i < arraysize(entropies); ++i) {
68 entropy_manager_.RecordPacketEntropyHash(i + 1, entropies[i]);
71 // Discard the first 5 entropies and ensure IsValidEntropy and EntropyHash
72 // still return correct results.
73 entropy_manager_.ClearEntropyBefore(5);
75 PacketNumberQueue missing_packets;
76 missing_packets.Add(7, 9);
78 QuicPacketEntropyHash entropy_hash = 0;
79 for (size_t i = 0; i < arraysize(entropies); ++i) {
80 if (!missing_packets.Contains(i + 1)) {
81 entropy_hash ^= entropies[i];
84 EXPECT_TRUE(entropy_manager_.IsValidEntropy(10, missing_packets,
85 entropy_hash));
87 entropy_hash = 0;
88 for (size_t i = 0; i < arraysize(entropies); ++i) {
89 entropy_hash ^= entropies[i];
91 EXPECT_EQ(entropy_hash, entropy_manager_.GetCumulativeEntropy(10));
94 } // namespace
95 } // namespace test
96 } // namespace net