OLD | NEW |
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 <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/base64.h" | 11 #include "base/base64.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/test/histogram_tester.h" | 15 #include "base/test/histogram_tester.h" |
| 16 #include "base/test/scoped_feature_list.h" |
16 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
17 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
18 #include "net/base/ip_endpoint.h" | 19 #include "net/base/ip_endpoint.h" |
19 #include "net/base/proxy_delegate.h" | 20 #include "net/base/proxy_delegate.h" |
20 #include "net/base/request_priority.h" | 21 #include "net/base/request_priority.h" |
21 #include "net/base/test_data_stream.h" | 22 #include "net/base/test_data_stream.h" |
22 #include "net/base/test_proxy_delegate.h" | 23 #include "net/base/test_proxy_delegate.h" |
23 #include "net/cert/ct_policy_status.h" | 24 #include "net/cert/ct_policy_status.h" |
24 #include "net/log/net_log_event_type.h" | 25 #include "net/log/net_log_event_type.h" |
25 #include "net/log/net_log_source.h" | 26 #include "net/log/net_log_source.h" |
(...skipping 5393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5419 // Client id exceeding watermark. | 5420 // Client id exceeding watermark. |
5420 EXPECT_FALSE(session_->OnUnknownFrame(9, 0)); | 5421 EXPECT_FALSE(session_->OnUnknownFrame(9, 0)); |
5421 | 5422 |
5422 session_->last_accepted_push_stream_id_ = 6; | 5423 session_->last_accepted_push_stream_id_ = 6; |
5423 // Low server (even) ids are fine. | 5424 // Low server (even) ids are fine. |
5424 EXPECT_TRUE(session_->OnUnknownFrame(2, 0)); | 5425 EXPECT_TRUE(session_->OnUnknownFrame(2, 0)); |
5425 // Server id exceeding last accepted id. | 5426 // Server id exceeding last accepted id. |
5426 EXPECT_FALSE(session_->OnUnknownFrame(8, 0)); | 5427 EXPECT_FALSE(session_->OnUnknownFrame(8, 0)); |
5427 } | 5428 } |
5428 | 5429 |
| 5430 enum ReadIfReadySupport { |
| 5431 // ReadIfReady() field trial is enabled, but ReadyIfReady() is unimplemented. |
| 5432 READ_IF_READY_ENABLED_SUPPORTED, |
| 5433 // ReadIfReady() field trial is enabled, and ReadyIfReady() is implemented. |
| 5434 READ_IF_READY_ENABLED_NOT_SUPPORTED, |
| 5435 // ReadIfReady() field trial is disabled. |
| 5436 READ_IF_READY_DISABLED, |
| 5437 }; |
| 5438 |
| 5439 class SpdySessionReadyIfReadyTest |
| 5440 : public SpdySessionTest, |
| 5441 public testing::WithParamInterface<ReadIfReadySupport> { |
| 5442 public: |
| 5443 void SetUp() override { |
| 5444 if (GetParam() != READ_IF_READY_DISABLED) |
| 5445 scoped_feature_list_.InitAndEnableFeature(Socket::kReadIfReadyExperiment); |
| 5446 if (GetParam() == READ_IF_READY_ENABLED_SUPPORTED) |
| 5447 session_deps_.socket_factory->set_enable_read_if_ready(true); |
| 5448 SpdySessionTest::SetUp(); |
| 5449 } |
| 5450 |
| 5451 private: |
| 5452 base::test::ScopedFeatureList scoped_feature_list_; |
| 5453 }; |
| 5454 |
| 5455 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 5456 SpdySessionReadyIfReadyTest, |
| 5457 testing::Values(READ_IF_READY_ENABLED_SUPPORTED, |
| 5458 READ_IF_READY_ENABLED_NOT_SUPPORTED, |
| 5459 READ_IF_READY_DISABLED)); |
| 5460 |
| 5461 // Tests basic functionality of ReadIfReady() when it is enabled or disabled. |
| 5462 TEST_P(SpdySessionReadyIfReadyTest, ReadIfReady) { |
| 5463 SpdySerializedFrame req( |
| 5464 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, HIGHEST, true)); |
| 5465 MockWrite writes[] = { |
| 5466 CreateMockWrite(req, 0), |
| 5467 }; |
| 5468 |
| 5469 SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5470 SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5471 MockRead reads[] = { |
| 5472 CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 5473 MockRead(ASYNC, 0, 3) // EOF |
| 5474 }; |
| 5475 |
| 5476 session_deps_.host_resolver->set_synchronous_mode(true); |
| 5477 |
| 5478 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5479 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 5480 |
| 5481 AddSSLSocketData(); |
| 5482 |
| 5483 CreateNetworkSession(); |
| 5484 CreateSecureSpdySession(); |
| 5485 |
| 5486 base::WeakPtr<SpdyStream> spdy_stream = |
| 5487 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, session_, |
| 5488 test_url_, HIGHEST, NetLogWithSource()); |
| 5489 ASSERT_TRUE(spdy_stream); |
| 5490 EXPECT_EQ(0u, spdy_stream->stream_id()); |
| 5491 test::StreamDelegateDoNothing delegate(spdy_stream); |
| 5492 spdy_stream->SetDelegate(&delegate); |
| 5493 |
| 5494 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
| 5495 spdy_stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 5496 |
| 5497 base::RunLoop().RunUntilIdle(); |
| 5498 |
| 5499 EXPECT_FALSE(spdy_stream); |
| 5500 EXPECT_EQ(1u, delegate.stream_id()); |
| 5501 } |
| 5502 |
5429 class SendInitialSettingsOnNewSpdySessionTest : public SpdySessionTest { | 5503 class SendInitialSettingsOnNewSpdySessionTest : public SpdySessionTest { |
5430 protected: | 5504 protected: |
5431 void RunInitialSettingsTest(const SettingsMap expected_settings) { | 5505 void RunInitialSettingsTest(const SettingsMap expected_settings) { |
5432 session_deps_.host_resolver->set_synchronous_mode(true); | 5506 session_deps_.host_resolver->set_synchronous_mode(true); |
5433 | 5507 |
5434 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; | 5508 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; |
5435 | 5509 |
5436 SpdySerializedFrame settings_frame( | 5510 SpdySerializedFrame settings_frame( |
5437 spdy_util_.ConstructSpdySettings(expected_settings)); | 5511 spdy_util_.ConstructSpdySettings(expected_settings)); |
5438 MockWrite writes[] = {MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, | 5512 MockWrite writes[] = {MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6000 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 6074 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
6001 "spdy_pooling.pem"); | 6075 "spdy_pooling.pem"); |
6002 ssl_info.is_issued_by_known_root = true; | 6076 ssl_info.is_issued_by_known_root = true; |
6003 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 6077 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
6004 | 6078 |
6005 EXPECT_TRUE(SpdySession::CanPool( | 6079 EXPECT_TRUE(SpdySession::CanPool( |
6006 &tss, ssl_info, "www.example.org", "mail.example.org")); | 6080 &tss, ssl_info, "www.example.org", "mail.example.org")); |
6007 } | 6081 } |
6008 | 6082 |
6009 } // namespace net | 6083 } // namespace net |
OLD | NEW |