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

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

Issue 10821086: Fix bug in SpdySession (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix sleevi comments. Created 8 years, 4 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
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('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 (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/spdy/spdy_session.h" 5 #include "net/spdy/spdy_session.h"
6 6
7 #include "net/base/host_cache.h" 7 #include "net/base/host_cache.h"
8 #include "net/base/ip_endpoint.h" 8 #include "net/base/ip_endpoint.h"
9 #include "net/base/net_log_unittest.h" 9 #include "net/base/net_log_unittest.h"
10 #include "net/spdy/spdy_io_buffer.h" 10 #include "net/spdy/spdy_io_buffer.h"
11 #include "net/spdy/spdy_session_pool.h" 11 #include "net/spdy/spdy_session_pool.h"
12 #include "net/spdy/spdy_stream.h" 12 #include "net/spdy/spdy_stream.h"
13 #include "net/spdy/spdy_test_util_spdy2.h" 13 #include "net/spdy/spdy_test_util_spdy2.h"
14 #include "testing/platform_test.h" 14 #include "testing/platform_test.h"
15 15
16 using namespace net::test_spdy2; 16 using namespace net::test_spdy2;
17 17
18 namespace net {
19
18 namespace { 20 namespace {
19 21
20 base::TimeTicks the_near_future() { 22 base::TimeTicks the_near_future() {
21 return base::TimeTicks::Now() + 23 return base::TimeTicks::Now() +
22 base::TimeDelta::FromSeconds(301); 24 base::TimeDelta::FromSeconds(301);
23 } 25 }
24 26
27 class ClosingDelegate : public SpdyStream::Delegate {
28 public:
29 ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
30
31 // SpdyStream::Delegate implementation:
32 virtual bool OnSendHeadersComplete(int status) OVERRIDE {
33 return true;
34 }
35 virtual int OnSendBody() OVERRIDE {
36 return OK;
37 }
38 virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE {
39 return OK;
40 }
41 virtual int OnResponseReceived(const SpdyHeaderBlock& response,
42 base::Time response_time,
43 int status) OVERRIDE {
44 return OK;
45 }
46 virtual void OnDataReceived(const char* data, int length) OVERRIDE {}
47 virtual void OnDataSent(int length) OVERRIDE {}
48 virtual void OnClose(int status) OVERRIDE {
49 stream_->Close();
50 }
51 private:
52 SpdyStream* stream_;
53 };
54
25 } // namespace 55 } // namespace
26 56
27 namespace net {
28
29 // TODO(cbentzel): Expose compression setter/getter in public SpdySession 57 // TODO(cbentzel): Expose compression setter/getter in public SpdySession
30 // interface rather than going through all these contortions. 58 // interface rather than going through all these contortions.
31 class SpdySessionSpdy2Test : public PlatformTest { 59 class SpdySessionSpdy2Test : public PlatformTest {
32 protected: 60 protected:
33 virtual void SetUp() { 61 virtual void SetUp() {
34 SpdySession::set_default_protocol(kProtoSPDY2); 62 SpdySession::set_default_protocol(kProtoSPDY2);
35 } 63 }
36 64
37 private: 65 private:
38 SpdyTestStateHelper spdy_state_; 66 SpdyTestStateHelper spdy_state_;
(...skipping 1340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 data.RunFor(1); 1407 data.RunFor(1);
1380 1408
1381 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1409 EXPECT_EQ(0u, spdy_stream1->stream_id());
1382 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1410 EXPECT_EQ(1u, spdy_stream2->stream_id());
1383 1411
1384 spdy_stream1 = NULL; 1412 spdy_stream1 = NULL;
1385 spdy_stream2->Cancel(); 1413 spdy_stream2->Cancel();
1386 spdy_stream2 = NULL; 1414 spdy_stream2 = NULL;
1387 } 1415 }
1388 1416
1417 TEST_F(SpdySessionSpdy2Test, CloseSessionWithTwoCreatedStreams) {
1418 // Test that if a sesion is closed with two created streams pending,
1419 // it does not crash. http://crbug.com/139518
1420 MockConnect connect_data(SYNCHRONOUS, OK);
1421 SpdySessionDependencies session_deps;
1422 session_deps.host_resolver->set_synchronous_mode(true);
1423
1424 // No actual data will be sent.
1425 MockWrite writes[] = {
1426 MockWrite(ASYNC, 0, 1) // EOF
1427 };
1428
1429 MockRead reads[] = {
1430 MockRead(ASYNC, 0, 0) // EOF
1431 };
1432 DeterministicSocketData data(reads, arraysize(reads),
1433 writes, arraysize(writes));
1434 data.set_connect_data(connect_data);
1435 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1436
1437 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1438 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1439
1440 scoped_refptr<HttpNetworkSession> http_session(
1441 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1442
1443 const std::string kTestHost("www.foo.com");
1444 const int kTestPort = 80;
1445 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1446 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1447
1448 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1449
1450 // Create a session.
1451 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1452 scoped_refptr<SpdySession> session =
1453 spdy_session_pool->Get(pair, BoundNetLog());
1454 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1455
1456 scoped_refptr<TransportSocketParams> transport_params(
1457 new TransportSocketParams(test_host_port_pair,
1458 MEDIUM,
1459 false,
1460 false,
1461 OnHostResolutionCallback()));
1462 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1463 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1464 transport_params, MEDIUM, CompletionCallback(),
1465 http_session->GetTransportSocketPool(
1466 HttpNetworkSession::NORMAL_SOCKET_POOL),
1467 BoundNetLog()));
1468 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1469
1470 scoped_refptr<SpdyStream> spdy_stream1;
1471 TestCompletionCallback callback1;
1472 GURL url1("http://www.google.com");
1473 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1474 BoundNetLog(), callback1.callback()));
1475 EXPECT_EQ(0u, spdy_stream1->stream_id());
1476
1477 scoped_refptr<SpdyStream> spdy_stream2;
1478 TestCompletionCallback callback2;
1479 GURL url2("http://www.google.com");
1480 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1481 BoundNetLog(), callback2.callback()));
1482 EXPECT_EQ(0u, spdy_stream2->stream_id());
1483
1484 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1485 (*headers)["method"] = "GET";
1486 (*headers)["scheme"] = url1.scheme();
1487 (*headers)["host"] = url1.host();
1488 (*headers)["url"] = url1.path();
1489 (*headers)["version"] = "HTTP/1.1";
1490 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1491 *headers2 = *headers;
1492
1493 spdy_stream1->set_spdy_headers(headers.Pass());
1494 EXPECT_TRUE(spdy_stream1->HasUrl());
1495 ClosingDelegate delegate1(spdy_stream1.get());
1496 spdy_stream1->SetDelegate(&delegate1);
1497
1498 spdy_stream2->set_spdy_headers(headers2.Pass());
1499 EXPECT_TRUE(spdy_stream2->HasUrl());
1500 ClosingDelegate delegate2(spdy_stream2.get());
1501 spdy_stream2->SetDelegate(&delegate2);
1502
1503 spdy_stream1->SendRequest(false);
1504 spdy_stream2->SendRequest(false);
1505
1506 // Ensure that the streams have not yet been activated and assigned an id.
1507 EXPECT_EQ(0u, spdy_stream1->stream_id());
1508 EXPECT_EQ(0u, spdy_stream2->stream_id());
1509
1510 // Ensure we don't crash while closing the session.
1511 session->CloseSessionOnError(ERR_ABORTED, true, "");
1512
1513 EXPECT_TRUE(spdy_stream1->closed());
1514 EXPECT_TRUE(spdy_stream2->closed());
1515
1516 spdy_stream1 = NULL;
1517 spdy_stream2 = NULL;
1518 }
1519
1389 } // namespace net 1520 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698