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

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: Complete 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"
(...skipping 1368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 data.RunFor(1); 1379 data.RunFor(1);
1380 1380
1381 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1381 EXPECT_EQ(0u, spdy_stream1->stream_id());
1382 EXPECT_EQ(1u, spdy_stream2->stream_id()); 1382 EXPECT_EQ(1u, spdy_stream2->stream_id());
1383 1383
1384 spdy_stream1 = NULL; 1384 spdy_stream1 = NULL;
1385 spdy_stream2->Cancel(); 1385 spdy_stream2->Cancel();
1386 spdy_stream2 = NULL; 1386 spdy_stream2 = NULL;
1387 } 1387 }
1388 1388
1389 namespace {
Ryan Sleevi 2012/07/30 06:36:15 drive by nit: According to http://www.chromium.or
Ryan Hamilton 2012/07/30 16:21:13 Done. I had thought it made more sense to put the
1390
1391 class ClosingDelegate : public SpdyStream::Delegate {
1392 public:
1393 ClosingDelegate(SpdyStream* stream) : stream_(stream) {}
1394
1395 virtual bool OnSendHeadersComplete(int status) {
Ryan Sleevi 2012/07/30 06:36:15 comment nit: // SpdyStream::Delegate implementatio
Ryan Hamilton 2012/07/30 16:21:13 Done.
1396 return false;
1397 }
1398 virtual int OnSendBody() {
1399 return OK;
1400 }
1401 virtual int OnSendBodyComplete(int status, bool* eof) {
1402 return OK;
1403 }
1404 virtual int OnResponseReceived(const SpdyHeaderBlock& response,
1405 base::Time response_time,
1406 int status) {
1407 return OK;
1408 }
1409 virtual void OnDataReceived(const char* data, int length) {}
1410 virtual void OnDataSent(int length) {}
1411 virtual void OnClose(int status) {
1412 stream_->Close();
1413 }
1414 private:
1415 SpdyStream* stream_;
1416 };
1417
1418 } // namespace
1419
1420 TEST_F(SpdySessionSpdy2Test, CloseSessionWithTwoCreatedStreams) {
Ryan Sleevi 2012/07/30 06:36:15 minor nit: Comment about what the test tests ;-)
Ryan Hamilton 2012/07/30 16:21:13 Done.
1421 MockConnect connect_data(SYNCHRONOUS, OK);
1422 // Request 1, at HIGHEST priority, will be cancelled before it writes data.
1423 // Request 2, at LOWEST priority, will be a full request and will be id 1.
Ryan Sleevi 2012/07/30 06:36:15 BUG? I don't see where you test ID EQ 1 (see below
Ryan Hamilton 2012/07/30 16:21:13 Sorry, I copied this test from the previous test a
1424 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1425 MockWrite writes[] = {
1426 CreateMockWrite(*req2, 0),
1427 };
1428
1429 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1));
1430 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(1, true));
1431 MockRead reads[] = {
1432 CreateMockRead(*resp2, 1),
1433 CreateMockRead(*body2, 2),
1434 MockRead(ASYNC, 0, 3) // EOF
1435 };
1436
1437 SpdySessionDependencies session_deps;
1438 session_deps.host_resolver->set_synchronous_mode(true);
1439
1440 DeterministicSocketData data(reads, arraysize(reads),
1441 writes, arraysize(writes));
1442 data.set_connect_data(connect_data);
1443 session_deps.deterministic_socket_factory->AddSocketDataProvider(&data);
1444
1445 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1446 session_deps.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1447
1448 scoped_refptr<HttpNetworkSession> http_session(
1449 SpdySessionDependencies::SpdyCreateSessionDeterministic(&session_deps));
1450
1451 const std::string kTestHost("www.foo.com");
1452 const int kTestPort = 80;
1453 HostPortPair test_host_port_pair(kTestHost, kTestPort);
1454 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
1455
1456 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
1457
1458 // Create a session.
1459 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1460 scoped_refptr<SpdySession> session =
1461 spdy_session_pool->Get(pair, BoundNetLog());
1462 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
1463
1464 scoped_refptr<TransportSocketParams> transport_params(
1465 new TransportSocketParams(test_host_port_pair,
1466 MEDIUM,
1467 false,
1468 false,
1469 OnHostResolutionCallback()));
1470 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle);
1471 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(),
1472 transport_params, MEDIUM, CompletionCallback(),
1473 http_session->GetTransportSocketPool(
1474 HttpNetworkSession::NORMAL_SOCKET_POOL),
1475 BoundNetLog()));
1476 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK));
1477
1478 scoped_refptr<SpdyStream> spdy_stream1;
1479 TestCompletionCallback callback1;
1480 GURL url1("http://www.google.com");
1481 EXPECT_EQ(OK, session->CreateStream(url1, HIGHEST, &spdy_stream1,
1482 BoundNetLog(), callback1.callback()));
1483 EXPECT_EQ(0u, spdy_stream1->stream_id());
1484
1485 scoped_refptr<SpdyStream> spdy_stream2;
1486 TestCompletionCallback callback2;
1487 GURL url2("http://www.google.com");
1488 EXPECT_EQ(OK, session->CreateStream(url2, LOWEST, &spdy_stream2,
1489 BoundNetLog(), callback2.callback()));
1490 EXPECT_EQ(0u, spdy_stream2->stream_id());
Ryan Sleevi 2012/07/30 06:36:15 BUG? - Comment suggests it should be EQ 1
Ryan Hamilton 2012/07/30 16:21:13 No, the comment was bogus :<
1491
1492 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock);
1493 (*headers)["method"] = "GET";
1494 (*headers)["scheme"] = url1.scheme();
1495 (*headers)["host"] = url1.host();
1496 (*headers)["url"] = url1.path();
1497 (*headers)["version"] = "HTTP/1.1";
1498 scoped_ptr<SpdyHeaderBlock> headers2(new SpdyHeaderBlock);
1499 *headers2 = *headers;
1500
1501 spdy_stream1->set_spdy_headers(headers.Pass());
1502 EXPECT_TRUE(spdy_stream1->HasUrl());
1503 ClosingDelegate delegate1(spdy_stream1.get());
1504 spdy_stream1->SetDelegate(&delegate1);
1505
1506 spdy_stream2->set_spdy_headers(headers2.Pass());
1507 EXPECT_TRUE(spdy_stream2->HasUrl());
1508 ClosingDelegate delegate2(spdy_stream2.get());
1509 spdy_stream2->SetDelegate(&delegate2);
1510
1511 spdy_stream1->SendRequest(false);
1512 spdy_stream2->SendRequest(false);
1513
1514 EXPECT_EQ(0u, spdy_stream1->stream_id());
1515 EXPECT_EQ(0u, spdy_stream2->stream_id());
1516
1517 session->CloseSessionOnError(ERR_ABORTED, true, "");
1518
1519 EXPECT_EQ(0u, spdy_stream1->stream_id());
1520 EXPECT_EQ(0u, spdy_stream2->stream_id());
Ryan Sleevi 2012/07/30 06:36:15 Seems like the EXPECT_EQ here and on lines 1514-15
Ryan Hamilton 2012/07/30 16:21:13 I've revised this and added a comment that explain
1521
1522 spdy_stream1 = NULL;
1523 spdy_stream2 = NULL;
1524 }
1525
1389 } // namespace net 1526 } // 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