QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 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/third_party/quiche/src/spdy/core/spdy_protocol_test_utils.h" |
| 6 | |
| 7 | #include <cstdint> |
| 8 | |
| 9 | #include "net/third_party/quiche/src/spdy/platform/api/spdy_string_piece.h" |
| 10 | |
| 11 | namespace spdy { |
| 12 | namespace test { |
| 13 | |
| 14 | // TODO(jamessynge): Where it makes sense in these functions, it would be nice |
| 15 | // to make use of the existing gMock matchers here, instead of rolling our own. |
| 16 | |
| 17 | ::testing::AssertionResult VerifySpdyFrameWithHeaderBlockIREquals( |
| 18 | const SpdyFrameWithHeaderBlockIR& expected, |
| 19 | const SpdyFrameWithHeaderBlockIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 20 | SPDY_VLOG(1) << "VerifySpdyFrameWithHeaderBlockIREquals"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 21 | VERIFY_TRUE(actual.header_block() == expected.header_block()); |
| 22 | return ::testing::AssertionSuccess(); |
| 23 | } |
| 24 | |
| 25 | ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyAltSvcIR& expected, |
| 26 | const SpdyAltSvcIR& actual) { |
| 27 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 28 | VERIFY_EQ(expected.origin(), actual.origin()); |
| 29 | VERIFY_THAT(actual.altsvc_vector(), |
| 30 | ::testing::ContainerEq(expected.altsvc_vector())); |
| 31 | return ::testing::AssertionSuccess(); |
| 32 | } |
| 33 | |
| 34 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
danzh | 8f3a576 | 2019-06-25 13:43:51 -0700 | [diff] [blame] | 35 | const SpdyContinuationIR& /*expected*/, |
| 36 | const SpdyContinuationIR& /*actual*/) { |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 37 | return ::testing::AssertionFailure() |
| 38 | << "VerifySpdyFrameIREquals SpdyContinuationIR not yet implemented"; |
| 39 | } |
| 40 | |
| 41 | ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyDataIR& expected, |
| 42 | const SpdyDataIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 43 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyDataIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 44 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 45 | VERIFY_EQ(expected.fin(), actual.fin()); |
| 46 | VERIFY_EQ(expected.data_len(), actual.data_len()); |
| 47 | if (expected.data() == nullptr) { |
| 48 | VERIFY_EQ(nullptr, actual.data()); |
| 49 | } else { |
| 50 | VERIFY_EQ(SpdyStringPiece(expected.data(), expected.data_len()), |
| 51 | SpdyStringPiece(actual.data(), actual.data_len())); |
| 52 | } |
| 53 | VERIFY_SUCCESS(VerifySpdyFrameWithPaddingIREquals(expected, actual)); |
| 54 | return ::testing::AssertionSuccess(); |
| 55 | } |
| 56 | |
| 57 | ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyGoAwayIR& expected, |
| 58 | const SpdyGoAwayIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 59 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyGoAwayIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 60 | VERIFY_EQ(expected.last_good_stream_id(), actual.last_good_stream_id()); |
| 61 | VERIFY_EQ(expected.error_code(), actual.error_code()); |
| 62 | VERIFY_EQ(expected.description(), actual.description()); |
| 63 | return ::testing::AssertionSuccess(); |
| 64 | } |
| 65 | |
| 66 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 67 | const SpdyHeadersIR& expected, |
| 68 | const SpdyHeadersIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 69 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyHeadersIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 70 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 71 | VERIFY_EQ(expected.fin(), actual.fin()); |
| 72 | VERIFY_SUCCESS(VerifySpdyFrameWithHeaderBlockIREquals(expected, actual)); |
| 73 | VERIFY_EQ(expected.has_priority(), actual.has_priority()); |
| 74 | if (expected.has_priority()) { |
| 75 | VERIFY_SUCCESS(VerifySpdyFrameWithPriorityIREquals(expected, actual)); |
| 76 | } |
| 77 | VERIFY_SUCCESS(VerifySpdyFrameWithPaddingIREquals(expected, actual)); |
| 78 | return ::testing::AssertionSuccess(); |
| 79 | } |
| 80 | |
| 81 | ::testing::AssertionResult VerifySpdyFrameIREquals(const SpdyPingIR& expected, |
| 82 | const SpdyPingIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 83 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyPingIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 84 | VERIFY_EQ(expected.id(), actual.id()); |
| 85 | VERIFY_EQ(expected.is_ack(), actual.is_ack()); |
| 86 | return ::testing::AssertionSuccess(); |
| 87 | } |
| 88 | |
| 89 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 90 | const SpdyPriorityIR& expected, |
| 91 | const SpdyPriorityIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 92 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyPriorityIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 93 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 94 | VERIFY_SUCCESS(VerifySpdyFrameWithPriorityIREquals(expected, actual)); |
| 95 | return ::testing::AssertionSuccess(); |
| 96 | } |
| 97 | |
| 98 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 99 | const SpdyPushPromiseIR& expected, |
| 100 | const SpdyPushPromiseIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 101 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyPushPromiseIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 102 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 103 | VERIFY_SUCCESS(VerifySpdyFrameWithPaddingIREquals(expected, actual)); |
| 104 | VERIFY_EQ(expected.promised_stream_id(), actual.promised_stream_id()); |
| 105 | VERIFY_SUCCESS(VerifySpdyFrameWithHeaderBlockIREquals(expected, actual)); |
| 106 | return ::testing::AssertionSuccess(); |
| 107 | } |
| 108 | |
| 109 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 110 | const SpdyRstStreamIR& expected, |
| 111 | const SpdyRstStreamIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 112 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyRstStreamIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 113 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 114 | VERIFY_EQ(expected.error_code(), actual.error_code()); |
| 115 | return ::testing::AssertionSuccess(); |
| 116 | } |
| 117 | |
| 118 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 119 | const SpdySettingsIR& expected, |
| 120 | const SpdySettingsIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 121 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdySettingsIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 122 | // Note, ignoring non-HTTP/2 fields such as clear_settings. |
| 123 | VERIFY_EQ(expected.is_ack(), actual.is_ack()); |
| 124 | |
| 125 | // Note, the following doesn't work because there isn't a comparator and |
| 126 | // formatter for SpdySettingsIR::Value. Fixable if we cared. |
| 127 | // |
| 128 | // VERIFY_THAT(actual.values(), ::testing::ContainerEq(actual.values())); |
| 129 | |
| 130 | VERIFY_EQ(expected.values().size(), actual.values().size()); |
| 131 | for (const auto& entry : expected.values()) { |
| 132 | const auto& param = entry.first; |
| 133 | auto actual_itr = actual.values().find(param); |
| 134 | VERIFY_TRUE(!(actual_itr == actual.values().end())) |
| 135 | << "actual doesn't contain param: " << param; |
| 136 | uint32_t expected_value = entry.second; |
| 137 | uint32_t actual_value = actual_itr->second; |
| 138 | VERIFY_EQ(expected_value, actual_value) |
| 139 | << "Values don't match for parameter: " << param; |
| 140 | } |
| 141 | |
| 142 | return ::testing::AssertionSuccess(); |
| 143 | } |
| 144 | |
| 145 | ::testing::AssertionResult VerifySpdyFrameIREquals( |
| 146 | const SpdyWindowUpdateIR& expected, |
| 147 | const SpdyWindowUpdateIR& actual) { |
QUICHE team | ded0351 | 2019-03-07 14:45:11 -0800 | [diff] [blame] | 148 | SPDY_VLOG(1) << "VerifySpdyFrameIREquals SpdyWindowUpdateIR"; |
QUICHE team | 82dee2f | 2019-01-18 12:35:12 -0500 | [diff] [blame] | 149 | VERIFY_EQ(expected.stream_id(), actual.stream_id()); |
| 150 | VERIFY_EQ(expected.delta(), actual.delta()); |
| 151 | return ::testing::AssertionSuccess(); |
| 152 | } |
| 153 | |
| 154 | } // namespace test |
| 155 | } // namespace spdy |