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