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

Side by Side Diff: net/spdy/spdy_network_transaction_spdy2_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 SpdyNetworkTransactionSpdy2TestTypes { 32 enum SpdyNetworkTransactionSpdy2TestTypes {
33 SPDYNPN, 33 SPDYNPN,
34 SPDYNOSSL, 34 SPDYNOSSL,
35 SPDYSSL, 35 SPDYSSL,
36 }; 36 };
37 class SpdyNetworkTransactionSpdy2Test 37 class SpdyNetworkTransactionSpdy2Test
38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy2TestTypes> { 38 : public ::testing::TestWithParam<SpdyNetworkTransactionSpdy2TestTypes> {
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::kProtoSPDY2); 42 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY2);
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 SpdyNetworkTransactionSpdy2TestTypes test_type) 65 SpdyNetworkTransactionSpdy2TestTypes 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 SpdyNetworkTransactionSpdy2Test, 533 SpdyNetworkTransactionSpdy2Test,
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(SpdyNetworkTransactionSpdy2Test, FourGetsWithMaxConcurrentPriority) { 1052 TEST_P(SpdyNetworkTransactionSpdy2Test, 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 2367 matching lines...) Expand 10 before | Expand all | Expand 10 after
3437 TransactionHelperResult out = helper.output(); 3430 TransactionHelperResult out = helper.output();
3438 EXPECT_EQ(OK, out.rv); 3431 EXPECT_EQ(OK, out.rv);
3439 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 3432 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
3440 EXPECT_EQ("hello!", out.response_data); 3433 EXPECT_EQ("hello!", out.response_data);
3441 } 3434 }
3442 3435
3443 // In this test, we enable compression, but get a uncompressed SynReply from 3436 // In this test, we enable compression, but get a uncompressed SynReply from
3444 // the server. Verify that teardown is all clean. 3437 // the server. Verify that teardown is all clean.
3445 TEST_P(SpdyNetworkTransactionSpdy2Test, DecompressFailureOnSynReply) { 3438 TEST_P(SpdyNetworkTransactionSpdy2Test, DecompressFailureOnSynReply) {
3446 // For this test, we turn on the normal compression. 3439 // For this test, we turn on the normal compression.
3447 EnableCompression(true); 3440 spdy::SpdyFramer::set_enable_compression_default(true);
3448 3441
3449 scoped_ptr<spdy::SpdyFrame> compressed( 3442 scoped_ptr<spdy::SpdyFrame> compressed(
3450 ConstructSpdyGet(NULL, 0, true, 1, LOWEST)); 3443 ConstructSpdyGet(NULL, 0, true, 1, LOWEST));
3451 scoped_ptr<spdy::SpdyFrame> rst( 3444 scoped_ptr<spdy::SpdyFrame> rst(
3452 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR)); 3445 ConstructSpdyRstStream(1, spdy::PROTOCOL_ERROR));
3453 MockWrite writes[] = { 3446 MockWrite writes[] = {
3454 CreateMockWrite(*compressed), 3447 CreateMockWrite(*compressed),
3455 }; 3448 };
3456 3449
3457 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 3450 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
3458 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); 3451 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true));
3459 MockRead reads[] = { 3452 MockRead reads[] = {
3460 CreateMockRead(*resp), 3453 CreateMockRead(*resp),
3461 }; 3454 };
3462 3455
3463 scoped_ptr<DelayedSocketData> data( 3456 scoped_ptr<DelayedSocketData> data(
3464 new DelayedSocketData(1, reads, arraysize(reads), 3457 new DelayedSocketData(1, reads, arraysize(reads),
3465 writes, arraysize(writes))); 3458 writes, arraysize(writes)));
3466 NormalSpdyTransactionHelper helper(CreateGetRequest(), 3459 NormalSpdyTransactionHelper helper(CreateGetRequest(),
3467 BoundNetLog(), GetParam()); 3460 BoundNetLog(), GetParam());
3468 helper.RunToCompletion(data.get()); 3461 helper.RunToCompletion(data.get());
3469 TransactionHelperResult out = helper.output(); 3462 TransactionHelperResult out = helper.output();
3470 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); 3463 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv);
3471 data->Reset(); 3464 data->Reset();
3472
3473 EnableCompression(false);
3474 } 3465 }
3475 3466
3476 // Test that the NetLog contains good data for a simple GET request. 3467 // Test that the NetLog contains good data for a simple GET request.
3477 TEST_P(SpdyNetworkTransactionSpdy2Test, NetLog) { 3468 TEST_P(SpdyNetworkTransactionSpdy2Test, NetLog) {
3478 static const char* const kExtraHeaders[] = { 3469 static const char* const kExtraHeaders[] = {
3479 "user-agent", "Chrome", 3470 "user-agent", "Chrome",
3480 }; 3471 };
3481 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1, 3472 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(kExtraHeaders, 1, false, 1,
3482 LOWEST)); 3473 LOWEST));
3483 MockWrite writes[] = { CreateMockWrite(*req) }; 3474 MockWrite writes[] = { CreateMockWrite(*req) };
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after
5503 << " Write index: " 5494 << " Write index: "
5504 << data->write_index(); 5495 << data->write_index();
5505 5496
5506 // Verify the SYN_REPLY. 5497 // Verify the SYN_REPLY.
5507 HttpResponseInfo response = *trans->GetResponseInfo(); 5498 HttpResponseInfo response = *trans->GetResponseInfo();
5508 EXPECT_TRUE(response.headers != NULL); 5499 EXPECT_TRUE(response.headers != NULL);
5509 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5500 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5510 } 5501 }
5511 5502
5512 } // namespace net 5503 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_spdy21_unittest.cc ('k') | net/spdy/spdy_network_transaction_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698