Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Side by Side Diff: net/http2/decoder/payload_decoders/rst_stream_payload_decoder_test.cc

Issue 2572343002: Use std::function instead of base::Callback in net/http2/. (Closed)
Patch Set: Rebase. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/rst_stream_payload_decoder.h" 5 #include "net/http2/decoder/payload_decoders/rst_stream_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_constants_test_util.h" 15 #include "net/http2/http2_constants_test_util.h"
17 #include "net/http2/http2_structures_test_util.h" 16 #include "net/http2/http2_structures_test_util.h"
18 #include "net/http2/tools/http2_frame_builder.h" 17 #include "net/http2/tools/http2_frame_builder.h"
19 #include "net/http2/tools/http2_random.h" 18 #include "net/http2/tools/http2_random.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 void OnFrameSizeError(const Http2FrameHeader& header) override { 50 void OnFrameSizeError(const Http2FrameHeader& header) override {
52 VLOG(1) << "OnFrameSizeError: " << header; 51 VLOG(1) << "OnFrameSizeError: " << header;
53 FrameError(header)->OnFrameSizeError(header); 52 FrameError(header)->OnFrameSizeError(header);
54 } 53 }
55 }; 54 };
56 55
57 class RstStreamPayloadDecoderTest 56 class RstStreamPayloadDecoderTest
58 : public AbstractPayloadDecoderTest<RstStreamPayloadDecoder, 57 : public AbstractPayloadDecoderTest<RstStreamPayloadDecoder,
59 RstStreamPayloadDecoderPeer, 58 RstStreamPayloadDecoderPeer,
60 Listener> { 59 Listener> {
61 public:
62 static bool ApproveSizeForWrongSize(size_t size) {
63 return size != Http2RstStreamFields::EncodedSize();
64 }
65
66 protected: 60 protected:
67 Http2RstStreamFields RandRstStreamFields() { 61 Http2RstStreamFields RandRstStreamFields() {
68 Http2RstStreamFields fields; 62 Http2RstStreamFields fields;
69 test::Randomize(&fields, RandomPtr()); 63 test::Randomize(&fields, RandomPtr());
70 return fields; 64 return fields;
71 } 65 }
72 }; 66 };
73 67
74 // Confirm we get an error if the payload is not the correct size to hold 68 // Confirm we get an error if the payload is not the correct size to hold
75 // exactly one Http2RstStreamFields. 69 // exactly one Http2RstStreamFields.
76 TEST_F(RstStreamPayloadDecoderTest, WrongSize) { 70 TEST_F(RstStreamPayloadDecoderTest, WrongSize) {
71 auto approve_size = [](size_t size) {
72 return size != Http2RstStreamFields::EncodedSize();
73 };
77 Http2FrameBuilder fb; 74 Http2FrameBuilder fb;
78 fb.Append(RandRstStreamFields()); 75 fb.Append(RandRstStreamFields());
79 fb.Append(RandRstStreamFields()); 76 fb.Append(RandRstStreamFields());
80 fb.Append(RandRstStreamFields()); 77 fb.Append(RandRstStreamFields());
81 EXPECT_TRUE(VerifyDetectsFrameSizeError( 78 EXPECT_TRUE(VerifyDetectsFrameSizeError(0, fb.buffer(), approve_size));
82 0, fb.buffer(),
83 base::Bind(&RstStreamPayloadDecoderTest::ApproveSizeForWrongSize)));
84 } 79 }
85 80
86 TEST_F(RstStreamPayloadDecoderTest, AllErrors) { 81 TEST_F(RstStreamPayloadDecoderTest, AllErrors) {
87 for (auto error_code : AllHttp2ErrorCodes()) { 82 for (auto error_code : AllHttp2ErrorCodes()) {
88 Http2RstStreamFields fields{error_code}; 83 Http2RstStreamFields fields{error_code};
89 Http2FrameBuilder fb; 84 Http2FrameBuilder fb;
90 fb.Append(fields); 85 fb.Append(fields);
91 Http2FrameHeader header(fb.size(), Http2FrameType::RST_STREAM, RandFlags(), 86 Http2FrameHeader header(fb.size(), Http2FrameType::RST_STREAM, RandFlags(),
92 RandStreamId()); 87 RandStreamId());
93 set_frame_header(header); 88 set_frame_header(header);
94 FrameParts expected(header); 89 FrameParts expected(header);
95 expected.opt_rst_stream_error_code = error_code; 90 expected.opt_rst_stream_error_code = error_code;
96 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected)); 91 EXPECT_TRUE(DecodePayloadAndValidateSeveralWays(fb.buffer(), expected));
97 } 92 }
98 } 93 }
99 94
100 } // namespace 95 } // namespace
101 } // namespace test 96 } // namespace test
102 } // namespace net 97 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698