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

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

Issue 2521573006: Server push cancellation: change the ownership of ServerPushDelegate to HttpNetworkSession. (Closed)
Patch Set: address comments Created 4 years 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
« net/spdy/spdy_session.cc ('K') | « net/spdy/spdy_session_pool.cc ('k') | no next file » | 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 <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 UnstallStreamSend(stream, delta_window_size); 116 UnstallStreamSend(stream, delta_window_size);
117 UnstallSessionSend(delta_window_size); 117 UnstallSessionSend(delta_window_size);
118 } 118 }
119 119
120 protected: 120 protected:
121 SpdySessionTest() 121 SpdySessionTest()
122 : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( 122 : old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group(
123 HttpNetworkSession::NORMAL_SOCKET_POOL)), 123 HttpNetworkSession::NORMAL_SOCKET_POOL)),
124 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( 124 old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool(
125 HttpNetworkSession::NORMAL_SOCKET_POOL)), 125 HttpNetworkSession::NORMAL_SOCKET_POOL)),
126 test_push_delegate_(nullptr),
126 spdy_session_pool_(nullptr), 127 spdy_session_pool_(nullptr),
127 test_url_(kDefaultUrl), 128 test_url_(kDefaultUrl),
128 test_server_(test_url_), 129 test_server_(test_url_),
129 key_(HostPortPair::FromURL(test_url_), 130 key_(HostPortPair::FromURL(test_url_),
130 ProxyServer::Direct(), 131 ProxyServer::Direct(),
131 PRIVACY_MODE_DISABLED), 132 PRIVACY_MODE_DISABLED),
132 ssl_(SYNCHRONOUS, OK) {} 133 ssl_(SYNCHRONOUS, OK) {}
133 134
134 ~SpdySessionTest() override { 135 ~SpdySessionTest() override {
135 // Important to restore the per-pool limit first, since the pool limit must 136 // Important to restore the per-pool limit first, since the pool limit must
136 // always be greater than group limit, and the tests reduce both limits. 137 // always be greater than group limit, and the tests reduce both limits.
137 ClientSocketPoolManager::set_max_sockets_per_pool( 138 ClientSocketPoolManager::set_max_sockets_per_pool(
138 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); 139 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_);
139 ClientSocketPoolManager::set_max_sockets_per_group( 140 ClientSocketPoolManager::set_max_sockets_per_group(
140 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); 141 HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_);
141 } 142 }
142 143
143 void SetUp() override { 144 void SetUp() override {
144 g_time_delta = base::TimeDelta(); 145 g_time_delta = base::TimeDelta();
145 g_time_now = base::TimeTicks::Now(); 146 g_time_now = base::TimeTicks::Now();
146 session_deps_.net_log = log_.bound().net_log(); 147 session_deps_.net_log = log_.bound().net_log();
147 } 148 }
148 149
149 void CreateNetworkSession() { 150 void CreateNetworkSession() {
150 DCHECK(!http_session_); 151 DCHECK(!http_session_);
151 DCHECK(!spdy_session_pool_); 152 DCHECK(!spdy_session_pool_);
152 http_session_ = 153 http_session_ =
153 SpdySessionDependencies::SpdyCreateSession(&session_deps_); 154 SpdySessionDependencies::SpdyCreateSession(&session_deps_);
155 std::unique_ptr<TestServerPushDelegate> test_push_delegate(
156 new TestServerPushDelegate());
157 test_push_delegate_ = test_push_delegate.get();
158 http_session_->SetServerPushDelegate(std::move(test_push_delegate));
154 spdy_session_pool_ = http_session_->spdy_session_pool(); 159 spdy_session_pool_ = http_session_->spdy_session_pool();
155 } 160 }
156 161
157 void CreateInsecureSpdySession() { 162 void CreateInsecureSpdySession() {
158 DCHECK(!session_); 163 DCHECK(!session_);
159 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_, 164 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_,
160 log_.bound()); 165 log_.bound());
161 } 166 }
162 167
163 void AddSSLSocketData() { 168 void AddSSLSocketData() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 207
203 // Original socket limits. Some tests set these. Safest to always restore 208 // Original socket limits. Some tests set these. Safest to always restore
204 // them once each test has been run. 209 // them once each test has been run.
205 int old_max_group_sockets_; 210 int old_max_group_sockets_;
206 int old_max_pool_sockets_; 211 int old_max_pool_sockets_;
207 212
208 SpdyTestUtil spdy_util_; 213 SpdyTestUtil spdy_util_;
209 SpdySessionDependencies session_deps_; 214 SpdySessionDependencies session_deps_;
210 std::unique_ptr<HttpNetworkSession> http_session_; 215 std::unique_ptr<HttpNetworkSession> http_session_;
211 base::WeakPtr<SpdySession> session_; 216 base::WeakPtr<SpdySession> session_;
212 TestServerPushDelegate test_push_delegate_; 217 TestServerPushDelegate* test_push_delegate_;
213 SpdySessionPool* spdy_session_pool_; 218 SpdySessionPool* spdy_session_pool_;
214 const GURL test_url_; 219 const GURL test_url_;
215 const url::SchemeHostPort test_server_; 220 const url::SchemeHostPort test_server_;
216 SpdySessionKey key_; 221 SpdySessionKey key_;
217 SSLSocketDataProvider ssl_; 222 SSLSocketDataProvider ssl_;
218 BoundTestNetLog log_; 223 BoundTestNetLog log_;
219 }; 224 };
220 225
221 // Try to create a SPDY session that will fail during 226 // Try to create a SPDY session that will fail during
222 // initialization. Nothing should blow up. 227 // initialization. Nothing should blow up.
(...skipping 1080 matching lines...) Expand 10 before | Expand all | Expand 10 after
1303 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF 1308 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1304 }; 1309 };
1305 1310
1306 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1311 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1307 session_deps_.socket_factory->AddSocketDataProvider(&data); 1312 session_deps_.socket_factory->AddSocketDataProvider(&data);
1308 1313
1309 AddSSLSocketData(); 1314 AddSSLSocketData();
1310 1315
1311 CreateNetworkSession(); 1316 CreateNetworkSession();
1312 CreateSecureSpdySession(); 1317 CreateSecureSpdySession();
1313 session_->set_push_delegate(&test_push_delegate_);
1314 1318
1315 // Process the principal request, and the first push stream request & body. 1319 // Process the principal request, and the first push stream request & body.
1316 base::WeakPtr<SpdyStream> spdy_stream = 1320 base::WeakPtr<SpdyStream> spdy_stream =
1317 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, 1321 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1318 test_url_, MEDIUM, NetLogWithSource()); 1322 test_url_, MEDIUM, NetLogWithSource());
1319 test::StreamDelegateDoNothing delegate(spdy_stream); 1323 test::StreamDelegateDoNothing delegate(spdy_stream);
1320 spdy_stream->SetDelegate(&delegate); 1324 spdy_stream->SetDelegate(&delegate);
1321 1325
1322 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 1326 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1323 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 1327 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
(...skipping 27 matching lines...) Expand all
1351 EXPECT_TRUE(session_); 1355 EXPECT_TRUE(session_);
1352 1356
1353 // Read and process EOF. 1357 // Read and process EOF.
1354 data.Resume(); 1358 data.Resume();
1355 base::RunLoop().RunUntilIdle(); 1359 base::RunLoop().RunUntilIdle();
1356 1360
1357 // Cancel the first push after session goes away. Verify the test doesn't 1361 // Cancel the first push after session goes away. Verify the test doesn't
1358 // crash. 1362 // crash.
1359 EXPECT_FALSE(session_); 1363 EXPECT_FALSE(session_);
1360 EXPECT_TRUE( 1364 EXPECT_TRUE(
1361 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat"))); 1365 test_push_delegate_->CancelPush(GURL("https://www.example.org/a.dat")));
1362 1366
1363 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); 1367 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1364 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", 1368 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1365 6, 1); 1369 6, 1);
1366 } 1370 }
1367 1371
1368 TEST_F(SpdySessionTest, CancelPushAfterExpired) { 1372 TEST_F(SpdySessionTest, CancelPushAfterExpired) {
1369 base::HistogramTester histogram_tester; 1373 base::HistogramTester histogram_tester;
1370 session_deps_.host_resolver->set_synchronous_mode(true); 1374 session_deps_.host_resolver->set_synchronous_mode(true);
1371 session_deps_.time_func = TheNearFuture; 1375 session_deps_.time_func = TheNearFuture;
(...skipping 17 matching lines...) Expand all
1389 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF 1393 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1390 }; 1394 };
1391 1395
1392 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1396 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1393 session_deps_.socket_factory->AddSocketDataProvider(&data); 1397 session_deps_.socket_factory->AddSocketDataProvider(&data);
1394 1398
1395 AddSSLSocketData(); 1399 AddSSLSocketData();
1396 1400
1397 CreateNetworkSession(); 1401 CreateNetworkSession();
1398 CreateSecureSpdySession(); 1402 CreateSecureSpdySession();
1399 session_->set_push_delegate(&test_push_delegate_);
1400 1403
1401 // Process the principal request, and the first push stream request & body. 1404 // Process the principal request, and the first push stream request & body.
1402 base::WeakPtr<SpdyStream> spdy_stream = 1405 base::WeakPtr<SpdyStream> spdy_stream =
1403 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, 1406 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1404 test_url_, MEDIUM, NetLogWithSource()); 1407 test_url_, MEDIUM, NetLogWithSource());
1405 test::StreamDelegateDoNothing delegate(spdy_stream); 1408 test::StreamDelegateDoNothing delegate(spdy_stream);
1406 spdy_stream->SetDelegate(&delegate); 1409 spdy_stream->SetDelegate(&delegate);
1407 1410
1408 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 1411 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1409 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 1412 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
(...skipping 16 matching lines...) Expand all
1426 data.Resume(); 1429 data.Resume();
1427 base::RunLoop().RunUntilIdle(); 1430 base::RunLoop().RunUntilIdle();
1428 1431
1429 // Verify that the second pushed stream evicted the first pushed stream. 1432 // Verify that the second pushed stream evicted the first pushed stream.
1430 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1433 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1431 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url( 1434 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(
1432 GURL("https://www.example.org/0.dat"))); 1435 GURL("https://www.example.org/0.dat")));
1433 1436
1434 // Cancel the first push after its expiration. 1437 // Cancel the first push after its expiration.
1435 EXPECT_TRUE( 1438 EXPECT_TRUE(
1436 test_push_delegate_.CancelPush(GURL("https://www.example.org/a.dat"))); 1439 test_push_delegate_->CancelPush(GURL("https://www.example.org/a.dat")));
1437 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1440 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1438 EXPECT_TRUE(session_); 1441 EXPECT_TRUE(session_);
1439 1442
1440 // Verify that the session window reclaimed the evicted stream body. 1443 // Verify that the session window reclaimed the evicted stream body.
1441 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); 1444 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1442 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); 1445 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1443 EXPECT_TRUE(session_); 1446 EXPECT_TRUE(session_);
1444 1447
1445 // Read and process EOF. 1448 // Read and process EOF.
1446 data.Resume(); 1449 data.Resume();
(...skipping 29 matching lines...) Expand all
1476 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF 1479 MockRead(ASYNC, ERR_IO_PENDING, 6), MockRead(ASYNC, 0, 7) // EOF
1477 }; 1480 };
1478 1481
1479 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); 1482 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes));
1480 session_deps_.socket_factory->AddSocketDataProvider(&data); 1483 session_deps_.socket_factory->AddSocketDataProvider(&data);
1481 1484
1482 AddSSLSocketData(); 1485 AddSSLSocketData();
1483 1486
1484 CreateNetworkSession(); 1487 CreateNetworkSession();
1485 CreateSecureSpdySession(); 1488 CreateSecureSpdySession();
1486 session_->set_push_delegate(&test_push_delegate_);
1487 1489
1488 // Process the principal request, and the first push stream request & body. 1490 // Process the principal request, and the first push stream request & body.
1489 base::WeakPtr<SpdyStream> spdy_stream = 1491 base::WeakPtr<SpdyStream> spdy_stream =
1490 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, 1492 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_,
1491 test_url_, MEDIUM, NetLogWithSource()); 1493 test_url_, MEDIUM, NetLogWithSource());
1492 test::StreamDelegateDoNothing delegate(spdy_stream); 1494 test::StreamDelegateDoNothing delegate(spdy_stream);
1493 spdy_stream->SetDelegate(&delegate); 1495 spdy_stream->SetDelegate(&delegate);
1494 1496
1495 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); 1497 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl));
1496 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); 1498 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND);
(...skipping 20 matching lines...) Expand all
1517 GURL pushed_url("https://www.example.org/0.dat"); 1519 GURL pushed_url("https://www.example.org/0.dat");
1518 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams()); 1520 EXPECT_EQ(1u, session_->num_unclaimed_pushed_streams());
1519 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); 1521 EXPECT_EQ(1u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1520 1522
1521 // Verify that the session window reclaimed the evicted stream body. 1523 // Verify that the session window reclaimed the evicted stream body.
1522 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_); 1524 EXPECT_EQ(kDefaultInitialWindowSize, session_->session_recv_window_size_);
1523 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_); 1525 EXPECT_EQ(kUploadDataSize, session_->session_unacked_recv_window_bytes_);
1524 1526
1525 EXPECT_TRUE(session_); 1527 EXPECT_TRUE(session_);
1526 // Cancel the push before it's claimed. 1528 // Cancel the push before it's claimed.
1527 EXPECT_TRUE(test_push_delegate_.CancelPush(pushed_url)); 1529 EXPECT_TRUE(test_push_delegate_->CancelPush(pushed_url));
1528 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams()); 1530 EXPECT_EQ(0u, session_->num_unclaimed_pushed_streams());
1529 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url)); 1531 EXPECT_EQ(0u, session_->count_unclaimed_pushed_streams_for_url(pushed_url));
1530 1532
1531 // Read and process EOF. 1533 // Read and process EOF.
1532 data.Resume(); 1534 data.Resume();
1533 base::RunLoop().RunUntilIdle(); 1535 base::RunLoop().RunUntilIdle();
1534 EXPECT_FALSE(session_); 1536 EXPECT_FALSE(session_);
1535 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1); 1537 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedBytes", 6, 1);
1536 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes", 1538 histogram_tester.ExpectBucketCount("Net.SpdySession.PushedAndUnclaimedBytes",
1537 6, 1); 1539 6, 1);
(...skipping 4345 matching lines...) Expand 10 before | Expand all | Expand 10 after
5883 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5885 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5884 "spdy_pooling.pem"); 5886 "spdy_pooling.pem");
5885 ssl_info.is_issued_by_known_root = true; 5887 ssl_info.is_issued_by_known_root = true;
5886 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5888 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5887 5889
5888 EXPECT_TRUE(SpdySession::CanPool( 5890 EXPECT_TRUE(SpdySession::CanPool(
5889 &tss, ssl_info, "www.example.org", "mail.example.org")); 5891 &tss, ssl_info, "www.example.org", "mail.example.org"));
5890 } 5892 }
5891 5893
5892 } // namespace net 5894 } // namespace net
OLDNEW
« net/spdy/spdy_session.cc ('K') | « net/spdy/spdy_session_pool.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698