| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/http2/decoder/payload_decoders/ping_payload_decoder.h" | 5 #include "net/http2/decoder/payload_decoders/ping_payload_decoder.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | |
| 10 #include "base/logging.h" | 9 #include "base/logging.h" |
| 11 #include "net/http2/decoder/frame_parts.h" | 10 #include "net/http2/decoder/frame_parts.h" |
| 12 #include "net/http2/decoder/frame_parts_collector.h" | 11 #include "net/http2/decoder/frame_parts_collector.h" |
| 13 #include "net/http2/decoder/http2_frame_decoder_listener.h" | 12 #include "net/http2/decoder/http2_frame_decoder_listener.h" |
| 14 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h" | 13 #include "net/http2/decoder/payload_decoders/payload_decoder_base_test_util.h" |
| 15 #include "net/http2/http2_constants.h" | 14 #include "net/http2/http2_constants.h" |
| 16 #include "net/http2/http2_structures_test_util.h" | 15 #include "net/http2/http2_structures_test_util.h" |
| 17 #include "net/http2/tools/http2_frame_builder.h" | 16 #include "net/http2/tools/http2_frame_builder.h" |
| 18 #include "net/http2/tools/http2_random.h" | 17 #include "net/http2/tools/http2_random.h" |
| 19 #include "net/http2/tools/random_decoder_test.h" | 18 #include "net/http2/tools/random_decoder_test.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 void OnFrameSizeError(const Http2FrameHeader& header) override { | 53 void OnFrameSizeError(const Http2FrameHeader& header) override { |
| 55 VLOG(1) << "OnFrameSizeError: " << header; | 54 VLOG(1) << "OnFrameSizeError: " << header; |
| 56 FrameError(header)->OnFrameSizeError(header); | 55 FrameError(header)->OnFrameSizeError(header); |
| 57 } | 56 } |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 class PingPayloadDecoderTest | 59 class PingPayloadDecoderTest |
| 61 : public AbstractPayloadDecoderTest<PingPayloadDecoder, | 60 : public AbstractPayloadDecoderTest<PingPayloadDecoder, |
| 62 PingPayloadDecoderPeer, | 61 PingPayloadDecoderPeer, |
| 63 Listener> { | 62 Listener> { |
| 64 public: | |
| 65 static bool ApproveSizeForWrongSize(size_t size) { | |
| 66 return size != Http2PingFields::EncodedSize(); | |
| 67 } | |
| 68 | |
| 69 protected: | 63 protected: |
| 70 Http2PingFields RandPingFields() { | 64 Http2PingFields RandPingFields() { |
| 71 Http2PingFields fields; | 65 Http2PingFields fields; |
| 72 test::Randomize(&fields, RandomPtr()); | 66 test::Randomize(&fields, RandomPtr()); |
| 73 return fields; | 67 return fields; |
| 74 } | 68 } |
| 75 }; | 69 }; |
| 76 | 70 |
| 77 // Confirm we get an error if the payload is not the correct size to hold | 71 // Confirm we get an error if the payload is not the correct size to hold |
| 78 // exactly one Http2PingFields. | 72 // exactly one Http2PingFields. |
| 79 TEST_F(PingPayloadDecoderTest, WrongSize) { | 73 TEST_F(PingPayloadDecoderTest, WrongSize) { |
| 74 auto approve_size = [](size_t size) { |
| 75 return size != Http2PingFields::EncodedSize(); |
| 76 }; |
| 80 Http2FrameBuilder fb; | 77 Http2FrameBuilder fb; |
| 81 fb.Append(RandPingFields()); | 78 fb.Append(RandPingFields()); |
| 82 fb.Append(RandPingFields()); | 79 fb.Append(RandPingFields()); |
| 83 fb.Append(RandPingFields()); | 80 fb.Append(RandPingFields()); |
| 84 EXPECT_TRUE(VerifyDetectsFrameSizeError( | 81 EXPECT_TRUE(VerifyDetectsFrameSizeError(0, fb.buffer(), approve_size)); |
| 85 0, fb.buffer(), | |
| 86 base::Bind(&PingPayloadDecoderTest::ApproveSizeForWrongSize))); | |
| 87 } | 82 } |
| 88 | 83 |
| 89 TEST_F(PingPayloadDecoderTest, Ping) { | 84 TEST_F(PingPayloadDecoderTest, Ping) { |
| 90 for (int n = 0; n < 100; ++n) { | 85 for (int n = 0; n < 100; ++n) { |
| 91 Http2PingFields fields = RandPingFields(); | 86 Http2PingFields fields = RandPingFields(); |
| 92 Http2FrameBuilder fb; | 87 Http2FrameBuilder fb; |
| 93 fb.Append(fields); | 88 fb.Append(fields); |
| 94 Http2FrameHeader header(fb.size(), Http2FrameType::PING, | 89 Http2FrameHeader header(fb.size(), Http2FrameType::PING, |
| 95 RandFlags() & ~Http2FrameFlag::FLAG_ACK, | 90 RandFlags() & ~Http2FrameFlag::FLAG_ACK, |
| 96 RandStreamId()); | 91 RandStreamId()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 113 set_frame_header(header); | 108 set_frame_header(header); |
| 114 FrameParts expected(header); | 109 FrameParts expected(header); |
| 115 expected.opt_ping = fields; | 110 expected.opt_ping = fields; |
| 116 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); | 111 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); |
| 117 } | 112 } |
| 118 } | 113 } |
| 119 | 114 |
| 120 } // namespace | 115 } // namespace |
| 121 } // namespace test | 116 } // namespace test |
| 122 } // namespace net | 117 } // namespace net |
| OLD | NEW |