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

Side by Side Diff: net/spdy/spdy_stream_unittest.cc

Issue 1411383005: Initial implementation of RequestPriority-based HTTP/2 dependencies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final round of comments. Created 5 years, 1 month 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
« no previous file with comments | « net/spdy/spdy_session_unittest.cc ('k') | net/spdy/spdy_test_util_common.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 <cstddef> 5 #include <cstddef>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 16 matching lines...) Expand all
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc 29 // TODO(ukai): factor out common part with spdy_http_stream_unittest.cc
30 // 30 //
31 namespace net { 31 namespace net {
32 32
33 namespace test { 33 namespace test {
34 34
35 namespace { 35 namespace {
36 36
37 enum TestCase {
38 // Test using the SPDY/3.1 protocol.
39 kTestCaseSPDY31,
40
41 // Test using the HTTP/2 protocol, without specifying a stream
42 // dependency based on the RequestPriority.
43 kTestCaseHTTP2NoPriorityDependencies,
44
45 // Test using the HTTP/2 protocol, specifying a stream
46 // dependency based on the RequestPriority.
47 kTestCaseHTTP2PriorityDependencies
48 };
49
37 const char kStreamUrl[] = "http://www.example.org/"; 50 const char kStreamUrl[] = "http://www.example.org/";
38 const char kPostBody[] = "\0hello!\xff"; 51 const char kPostBody[] = "\0hello!\xff";
39 const size_t kPostBodyLength = arraysize(kPostBody); 52 const size_t kPostBodyLength = arraysize(kPostBody);
40 const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength); 53 const base::StringPiece kPostBodyStringPiece(kPostBody, kPostBodyLength);
41 54
55 } // namespace
56
42 class SpdyStreamTest : public ::testing::Test, 57 class SpdyStreamTest : public ::testing::Test,
43 public ::testing::WithParamInterface<NextProto> { 58 public ::testing::WithParamInterface<TestCase> {
44 protected: 59 protected:
45 // A function that takes a SpdyStream and the number of bytes which 60 // A function that takes a SpdyStream and the number of bytes which
46 // will unstall the next frame completely. 61 // will unstall the next frame completely.
47 typedef base::Callback<void(const base::WeakPtr<SpdyStream>&, int32)> 62 typedef base::Callback<void(const base::WeakPtr<SpdyStream>&, int32)>
48 UnstallFunction; 63 UnstallFunction;
49 64
50 SpdyStreamTest() 65 SpdyStreamTest()
51 : spdy_util_(GetParam()), 66 : spdy_util_(GetProtocol(), GetDependenciesFromPriority()),
52 session_deps_(GetParam()), 67 session_deps_(GetProtocol()),
53 offset_(0) {} 68 offset_(0) {
69 SpdySession::SetPriorityDependencyDefaultForTesting(
70 GetDependenciesFromPriority());
71 }
72
73 ~SpdyStreamTest() {
74 SpdySession::SetPriorityDependencyDefaultForTesting(false);
75 }
54 76
55 base::WeakPtr<SpdySession> CreateDefaultSpdySession() { 77 base::WeakPtr<SpdySession> CreateDefaultSpdySession() {
56 SpdySessionKey key(HostPortPair("www.example.org", 80), 78 SpdySessionKey key(HostPortPair("www.example.org", 80),
57 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); 79 ProxyServer::Direct(), PRIVACY_MODE_DISABLED);
58 return CreateInsecureSpdySession(session_.get(), key, BoundNetLog()); 80 return CreateInsecureSpdySession(session_.get(), key, BoundNetLog());
59 } 81 }
60 82
61 void TearDown() override { base::MessageLoop::current()->RunUntilIdle(); } 83 void TearDown() override { base::MessageLoop::current()->RunUntilIdle(); }
62 84
85 NextProto GetProtocol() const {
86 return GetParam() == kTestCaseSPDY31 ? kProtoSPDY31 : kProtoHTTP2;
87 }
88
89 bool GetDependenciesFromPriority() const {
90 return GetParam() == kTestCaseHTTP2PriorityDependencies;
91 }
92
63 void RunResumeAfterUnstallRequestResponseTest( 93 void RunResumeAfterUnstallRequestResponseTest(
64 const UnstallFunction& unstall_function); 94 const UnstallFunction& unstall_function);
65 95
66 void RunResumeAfterUnstallBidirectionalTest( 96 void RunResumeAfterUnstallBidirectionalTest(
67 const UnstallFunction& unstall_function); 97 const UnstallFunction& unstall_function);
68 98
69 // Add{Read,Write}() populates lists that are eventually passed to a 99 // Add{Read,Write}() populates lists that are eventually passed to a
70 // SocketData class. |frame| must live for the whole test. 100 // SocketData class. |frame| must live for the whole test.
71 101
72 void AddRead(const SpdyFrame& frame) { 102 void AddRead(const SpdyFrame& frame) {
(...skipping 28 matching lines...) Expand all
101 SpdySessionDependencies session_deps_; 131 SpdySessionDependencies session_deps_;
102 scoped_ptr<HttpNetworkSession> session_; 132 scoped_ptr<HttpNetworkSession> session_;
103 133
104 private: 134 private:
105 // Used by Add{Read,Write}() above. 135 // Used by Add{Read,Write}() above.
106 std::vector<MockWrite> writes_; 136 std::vector<MockWrite> writes_;
107 std::vector<MockRead> reads_; 137 std::vector<MockRead> reads_;
108 int offset_; 138 int offset_;
109 }; 139 };
110 140
111 INSTANTIATE_TEST_CASE_P(NextProto, 141 INSTANTIATE_TEST_CASE_P(ProtoPlusDepend,
112 SpdyStreamTest, 142 SpdyStreamTest,
113 testing::Values(kProtoSPDY31, 143 testing::Values(kTestCaseSPDY31,
114 kProtoHTTP2)); 144 kTestCaseHTTP2NoPriorityDependencies,
145 kTestCaseHTTP2PriorityDependencies));
115 146
116 TEST_P(SpdyStreamTest, SendDataAfterOpen) { 147 TEST_P(SpdyStreamTest, SendDataAfterOpen) {
117 GURL url(kStreamUrl); 148 GURL url(kStreamUrl);
118 149
119 session_ = 150 session_ =
120 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_); 151 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps_);
121 152
122 scoped_ptr<SpdyFrame> req( 153 scoped_ptr<SpdyFrame> req(
123 spdy_util_.ConstructSpdyPost( 154 spdy_util_.ConstructSpdyPost(
124 kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0)); 155 kStreamUrl, 1, kPostBodyLength, LOWEST, NULL, 0));
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 EXPECT_EQ(0, stream->raw_received_bytes()); 1151 EXPECT_EQ(0, stream->raw_received_bytes());
1121 data.RunFor(1); // REPLY 1152 data.RunFor(1); // REPLY
1122 EXPECT_EQ(reply_frame_len, stream->raw_received_bytes()); 1153 EXPECT_EQ(reply_frame_len, stream->raw_received_bytes());
1123 data.RunFor(1); // DATA 1154 data.RunFor(1); // DATA
1124 EXPECT_EQ(response_len, stream->raw_received_bytes()); 1155 EXPECT_EQ(response_len, stream->raw_received_bytes());
1125 data.RunFor(1); // FIN 1156 data.RunFor(1); // FIN
1126 1157
1127 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); 1158 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose());
1128 } 1159 }
1129 1160
1130 } // namespace
1131
1132 } // namespace test 1161 } // namespace test
1133 1162
1134 } // namespace net 1163 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_unittest.cc ('k') | net/spdy/spdy_test_util_common.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698