| 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/priority_payload_decoder.h" | 5 #include "net/http2/decoder/payload_decoders/priority_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 30 matching lines...) Expand all Loading... |
| 50 void OnFrameSizeError(const Http2FrameHeader& header) override { | 49 void OnFrameSizeError(const Http2FrameHeader& header) override { |
| 51 VLOG(1) << "OnFrameSizeError: " << header; | 50 VLOG(1) << "OnFrameSizeError: " << header; |
| 52 FrameError(header)->OnFrameSizeError(header); | 51 FrameError(header)->OnFrameSizeError(header); |
| 53 } | 52 } |
| 54 }; | 53 }; |
| 55 | 54 |
| 56 class PriorityPayloadDecoderTest | 55 class PriorityPayloadDecoderTest |
| 57 : public AbstractPayloadDecoderTest<PriorityPayloadDecoder, | 56 : public AbstractPayloadDecoderTest<PriorityPayloadDecoder, |
| 58 PriorityPayloadDecoderPeer, | 57 PriorityPayloadDecoderPeer, |
| 59 Listener> { | 58 Listener> { |
| 60 public: | |
| 61 static bool ApproveSizeForWrongSize(size_t size) { | |
| 62 return size != Http2PriorityFields::EncodedSize(); | |
| 63 } | |
| 64 | |
| 65 protected: | 59 protected: |
| 66 Http2PriorityFields RandPriorityFields() { | 60 Http2PriorityFields RandPriorityFields() { |
| 67 Http2PriorityFields fields; | 61 Http2PriorityFields fields; |
| 68 test::Randomize(&fields, RandomPtr()); | 62 test::Randomize(&fields, RandomPtr()); |
| 69 return fields; | 63 return fields; |
| 70 } | 64 } |
| 71 }; | 65 }; |
| 72 | 66 |
| 73 // Confirm we get an error if the payload is not the correct size to hold | 67 // Confirm we get an error if the payload is not the correct size to hold |
| 74 // exactly one Http2PriorityFields. | 68 // exactly one Http2PriorityFields. |
| 75 TEST_F(PriorityPayloadDecoderTest, WrongSize) { | 69 TEST_F(PriorityPayloadDecoderTest, WrongSize) { |
| 70 auto approve_size = [](size_t size) { |
| 71 return size != Http2PriorityFields::EncodedSize(); |
| 72 }; |
| 76 Http2FrameBuilder fb; | 73 Http2FrameBuilder fb; |
| 77 fb.Append(RandPriorityFields()); | 74 fb.Append(RandPriorityFields()); |
| 78 fb.Append(RandPriorityFields()); | 75 fb.Append(RandPriorityFields()); |
| 79 EXPECT_TRUE(VerifyDetectsFrameSizeError( | 76 EXPECT_TRUE(VerifyDetectsFrameSizeError(0, fb.buffer(), approve_size)); |
| 80 0, fb.buffer(), | |
| 81 base::Bind(&PriorityPayloadDecoderTest::ApproveSizeForWrongSize))); | |
| 82 } | 77 } |
| 83 | 78 |
| 84 TEST_F(PriorityPayloadDecoderTest, VariousPayloads) { | 79 TEST_F(PriorityPayloadDecoderTest, VariousPayloads) { |
| 85 for (int n = 0; n < 100; ++n) { | 80 for (int n = 0; n < 100; ++n) { |
| 86 Http2PriorityFields fields = RandPriorityFields(); | 81 Http2PriorityFields fields = RandPriorityFields(); |
| 87 Http2FrameBuilder fb; | 82 Http2FrameBuilder fb; |
| 88 fb.Append(fields); | 83 fb.Append(fields); |
| 89 Http2FrameHeader header(fb.size(), Http2FrameType::PRIORITY, RandFlags(), | 84 Http2FrameHeader header(fb.size(), Http2FrameType::PRIORITY, RandFlags(), |
| 90 RandStreamId()); | 85 RandStreamId()); |
| 91 set_frame_header(header); | 86 set_frame_header(header); |
| 92 FrameParts expected(header); | 87 FrameParts expected(header); |
| 93 expected.opt_priority = fields; | 88 expected.opt_priority = fields; |
| 94 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); | 89 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); |
| 95 } | 90 } |
| 96 } | 91 } |
| 97 | 92 |
| 98 } // namespace | 93 } // namespace |
| 99 } // namespace test | 94 } // namespace test |
| 100 } // namespace net | 95 } // namespace net |
| OLD | NEW |