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

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

Issue 9817014: Created a new class SpdyTestStateHelper to serve as a helper to manage the state of a number of SPD… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add TODO Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 21 matching lines...) Expand all
32 enum SpdyNetworkTransactionSpdy21TestTypes { 32 enum SpdyNetworkTransactionSpdy21TestTypes {
33 SPDYNPN, 33 SPDYNPN,
34 SPDYNOSSL, 34 SPDYNOSSL,
35 SPDYSSL, 35 SPDYSSL,
36 }; 36 };
37 class SpdyNetworkTransactionSpdy21Test 37 class SpdyNetworkTransactionSpdy21Test
38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy21TestTypes> { 38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy21TestTypes> {
39 protected: 39 protected:
40 40
41 virtual void SetUp() { 41 virtual void SetUp() {
42 // By default, all tests turn off compression.
43 EnableCompression(false);
44 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY21); 42 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY21);
45 google_get_request_initialized_ = false; 43 google_get_request_initialized_ = false;
46 google_post_request_initialized_ = false; 44 google_post_request_initialized_ = false;
47 google_chunked_post_request_initialized_ = false; 45 google_chunked_post_request_initialized_ = false;
48 } 46 }
49 47
50 virtual void TearDown() { 48 virtual void TearDown() {
51 // Empty the current queue. 49 // Empty the current queue.
52 MessageLoop::current()->RunAllPending(); 50 MessageLoop::current()->RunAllPending();
53 } 51 }
54 52
55 struct TransactionHelperResult { 53 struct TransactionHelperResult {
56 int rv; 54 int rv;
57 std::string status_line; 55 std::string status_line;
58 std::string response_data; 56 std::string response_data;
59 HttpResponseInfo response_info; 57 HttpResponseInfo response_info;
60 }; 58 };
61 59
62 void EnableCompression(bool enabled) {
63 spdy::SpdyFramer::set_enable_compression_default(enabled);
64 }
65
66 // A helper class that handles all the initial npn/ssl setup. 60 // A helper class that handles all the initial npn/ssl setup.
67 class NormalSpdyTransactionHelper { 61 class NormalSpdyTransactionHelper {
68 public: 62 public:
69 NormalSpdyTransactionHelper(const HttpRequestInfo& request, 63 NormalSpdyTransactionHelper(const HttpRequestInfo& request,
70 const BoundNetLog& log, 64 const BoundNetLog& log,
71 SpdyNetworkTransactionSpdy21TestTypes test_type) 65 SpdyNetworkTransactionSpdy21TestTypes test_type)
72 : request_(request), 66 : request_(request),
73 session_deps_(new SpdySessionDependencies()), 67 session_deps_(new SpdySessionDependencies()),
74 session_(SpdySessionDependencies::SpdyCreateSession( 68 session_(SpdySessionDependencies::SpdyCreateSession(
75 session_deps_.get())), 69 session_deps_.get())),
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 } 516 }
523 517
524 private: 518 private:
525 bool google_get_request_initialized_; 519 bool google_get_request_initialized_;
526 bool google_post_request_initialized_; 520 bool google_post_request_initialized_;
527 bool google_chunked_post_request_initialized_; 521 bool google_chunked_post_request_initialized_;
528 HttpRequestInfo google_get_request_; 522 HttpRequestInfo google_get_request_;
529 HttpRequestInfo google_post_request_; 523 HttpRequestInfo google_post_request_;
530 HttpRequestInfo google_chunked_post_request_; 524 HttpRequestInfo google_chunked_post_request_;
531 HttpRequestInfo google_get_push_request_; 525 HttpRequestInfo google_get_push_request_;
526 SpdyTestStateHelper spdy_state_;
532 }; 527 };
533 528
534 //----------------------------------------------------------------------------- 529 //-----------------------------------------------------------------------------
535 // All tests are run with three different connection types: SPDY after NPN 530 // All tests are run with three different connection types: SPDY after NPN
536 // negotiation, SPDY without SSL, and SPDY with SSL. 531 // negotiation, SPDY without SSL, and SPDY with SSL.
537 INSTANTIATE_TEST_CASE_P(Spdy, 532 INSTANTIATE_TEST_CASE_P(Spdy,
538 SpdyNetworkTransactionSpdy21Test, 533 SpdyNetworkTransactionSpdy21Test,
539 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); 534 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN));
540 535
541 536
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 } 1043 }
1049 EXPECT_EQ(OK, out.rv); 1044 EXPECT_EQ(OK, out.rv);
1050 } 1045 }
1051 1046
1052 // Similar to ThreeGetsWithMaxConcurrent above, however this test adds 1047 // Similar to ThreeGetsWithMaxConcurrent above, however this test adds
1053 // a fourth transaction. The third and fourth transactions have 1048 // a fourth transaction. The third and fourth transactions have
1054 // different data ("hello!" vs "hello!hello!") and because of the 1049 // different data ("hello!" vs "hello!hello!") and because of the
1055 // user specified priority, we expect to see them inverted in 1050 // user specified priority, we expect to see them inverted in
1056 // the response from the server. 1051 // the response from the server.
1057 TEST_P(SpdyNetworkTransactionSpdy21Test, FourGetsWithMaxConcurrentPriority) { 1052 TEST_P(SpdyNetworkTransactionSpdy21Test, FourGetsWithMaxConcurrentPriority) {
1058 SpdySession::set_enable_ping_based_connection_checking(false);
1059
1060 // Construct the request. 1053 // Construct the request.
1061 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 1054 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1062 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 1055 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
1063 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false)); 1056 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false));
1064 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true)); 1057 scoped_ptr<spdy::SpdyFrame> fbody(ConstructSpdyBodyFrame(1, true));
1065 1058
1066 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST)); 1059 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 3, LOWEST));
1067 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3)); 1060 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 3));
1068 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false)); 1061 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(3, false));
1069 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true)); 1062 scoped_ptr<spdy::SpdyFrame> fbody2(ConstructSpdyBodyFrame(3, true));
(...skipping 2731 matching lines...) Expand 10 before | Expand all | Expand 10 after
3801 TransactionHelperResult out = helper.output(); 3794 TransactionHelperResult out = helper.output();
3802 EXPECT_EQ(OK, out.rv); 3795 EXPECT_EQ(OK, out.rv);
3803 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3796 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3804 EXPECT_EQ("hello!", out.response_data); 3797 EXPECT_EQ("hello!", out.response_data);
3805 } 3798 }
3806 3799
3807 // In this test, we enable compression, but get a uncompressed SynReply from 3800 // In this test, we enable compression, but get a uncompressed SynReply from
3808 // the server. Verify that teardown is all clean. 3801 // the server. Verify that teardown is all clean.
3809 TEST_P(SpdyNetworkTransactionSpdy21Test, DecompressFailureOnSynReply) { 3802 TEST_P(SpdyNetworkTransactionSpdy21Test, DecompressFailureOnSynReply) {
3810 // For this test, we turn on the normal compression. 3803 // For this test, we turn on the normal compression.
3811 EnableCompression(true); 3804 spdy::SpdyFramer::set_enable_compression_default(true);
3812 3805
3813 scoped_ptr<spdy::SpdyFrame> compressed( 3806 scoped_ptr<spdy::SpdyFrame> compressed(
3814 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); 3807 ConstructSpdyGet(NULL, 0, true, 1, LOWEST));
3815 scoped_ptr<spdy::SpdyFrame> rst( 3808 scoped_ptr<spdy::SpdyFrame> rst(
3816 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR)); 3809 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR));
3817 MockWrite writes[] = { 3810 MockWrite writes[] = {
3818 CreateMockWrite(*compressed), 3811 CreateMockWrite(*compressed),
3819 }; 3812 };
3820 3813
3821 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 3814 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
3822 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); 3815 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true));
3823 MockRead reads[] = { 3816 MockRead reads[] = {
3824 CreateMockRead(*resp), 3817 CreateMockRead(*resp),
3825 }; 3818 };
3826 3819
3827 scoped_ptr<DelayedSocketData> data( 3820 scoped_ptr<DelayedSocketData> data(
3828 new DelayedSocketData(1, reads, arraysize(reads), 3821 new DelayedSocketData(1, reads, arraysize(reads),
3829 writes, arraysize(writes))); 3822 writes, arraysize(writes)));
3830 NormalSpdyTransactionHelper helper(CreateGetRequest(), 3823 NormalSpdyTransactionHelper helper(CreateGetRequest(),
3831 BoundNetLog(), GetParam()); 3824 BoundNetLog(), GetParam());
3832 helper.RunToCompletion(data.get()); 3825 helper.RunToCompletion(data.get());
3833 TransactionHelperResult out = helper.output(); 3826 TransactionHelperResult out = helper.output();
3834 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 3827 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
3835 data->Reset(); 3828 data->Reset();
3836
3837 EnableCompression(false);
3838 } 3829 }
3839 3830
3840 // Test that the NetLog contains good data for a simple GET request. 3831 // Test that the NetLog contains good data for a simple GET request.
3841 TEST_P(SpdyNetworkTransactionSpdy21Test, NetLog) { 3832 TEST_P(SpdyNetworkTransactionSpdy21Test, NetLog) {
3842 static const char* const kExtraHeaders[] = { 3833 static const char* const kExtraHeaders[] = {
3843 "user-agent", "Chrome", 3834 "user-agent", "Chrome",
3844 }; 3835 };
3845 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1, 3836 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1,
3846 LOWEST)); 3837 LOWEST));
3847 MockWrite writes[] = { CreateMockWrite(*req) }; 3838 MockWrite writes[] = { CreateMockWrite(*req) };
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after
5867 << " Write index: " 5858 << " Write index: "
5868 << data->write_index(); 5859 << data->write_index();
5869 5860
5870 // Verify the SYN_REPLY. 5861 // Verify the SYN_REPLY.
5871 HttpResponseInfo response = *trans->GetResponseInfo(); 5862 HttpResponseInfo response = *trans->GetResponseInfo();
5872 EXPECT_TRUE(response.headers != NULL); 5863 EXPECT_TRUE(response.headers != NULL);
5873 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5864 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5874 } 5865 }
5875 5866
5876 } // namespace net 5867 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_stream_spdy3_unittest.cc ('k') | net/spdy/spdy_network_transaction_spdy2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698