Chromium Code Reviews| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 GURL test_url_; | 212 GURL test_url_; |
| 213 HostPortPair test_host_port_pair_; | 213 HostPortPair test_host_port_pair_; |
| 214 SpdySessionKey key_; | 214 SpdySessionKey key_; |
| 215 }; | 215 }; |
| 216 | 216 |
| 217 INSTANTIATE_TEST_CASE_P( | 217 INSTANTIATE_TEST_CASE_P( |
| 218 NextProto, | 218 NextProto, |
| 219 SpdySessionTest, | 219 SpdySessionTest, |
| 220 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); | 220 testing::Values(kProtoSPDY2, kProtoSPDY3, kProtoSPDY31, kProtoSPDY4a2)); |
| 221 | 221 |
| 222 // TODO(akalin): Don't early-exit in the tests below for values > | |
| 223 // kProtoSPDY3. | |
| 224 | |
| 225 TEST_P(SpdySessionTest, GoAway) { | 222 TEST_P(SpdySessionTest, GoAway) { |
| 226 if (GetParam() > kProtoSPDY3) | |
| 227 return; | |
| 228 | |
| 229 session_deps_.host_resolver->set_synchronous_mode(true); | 223 session_deps_.host_resolver->set_synchronous_mode(true); |
| 230 | 224 |
| 231 MockConnect connect_data(SYNCHRONOUS, OK); | 225 MockConnect connect_data(SYNCHRONOUS, OK); |
| 232 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 226 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| 233 MockRead reads[] = { | 227 MockRead reads[] = { |
| 234 CreateMockRead(*goaway, 2), | 228 CreateMockRead(*goaway, 2), |
| 235 MockRead(ASYNC, 0, 3) // EOF | 229 MockRead(ASYNC, 0, 3) // EOF |
| 236 }; | 230 }; |
| 237 scoped_ptr<SpdyFrame> req1( | 231 scoped_ptr<SpdyFrame> req1( |
| 238 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 232 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 // Delete the first session. | 295 // Delete the first session. |
| 302 session = NULL; | 296 session = NULL; |
| 303 | 297 |
| 304 // Delete the second session. | 298 // Delete the second session. |
| 305 spdy_session_pool_->Remove(session2); | 299 spdy_session_pool_->Remove(session2); |
| 306 session2 = NULL; | 300 session2 = NULL; |
| 307 EXPECT_EQ(NULL, spdy_stream2.get()); | 301 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 308 } | 302 } |
| 309 | 303 |
| 310 TEST_P(SpdySessionTest, ClientPing) { | 304 TEST_P(SpdySessionTest, ClientPing) { |
| 311 if (GetParam() > kProtoSPDY3) | |
| 312 return; | |
| 313 | |
| 314 session_deps_.enable_ping = true; | 305 session_deps_.enable_ping = true; |
| 315 session_deps_.host_resolver->set_synchronous_mode(true); | 306 session_deps_.host_resolver->set_synchronous_mode(true); |
| 316 | 307 |
| 317 MockConnect connect_data(SYNCHRONOUS, OK); | 308 MockConnect connect_data(SYNCHRONOUS, OK); |
| 318 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); | 309 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); |
| 319 MockRead reads[] = { | 310 MockRead reads[] = { |
| 320 CreateMockRead(*read_ping), | 311 CreateMockRead(*read_ping), |
| 321 MockRead(SYNCHRONOUS, 0, 0) // EOF | 312 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 322 }; | 313 }; |
| 323 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); | 314 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 EXPECT_FALSE(session->check_ping_status_pending()); | 351 EXPECT_FALSE(session->check_ping_status_pending()); |
| 361 EXPECT_GE(session->last_activity_time(), before_ping_time); | 352 EXPECT_GE(session->last_activity_time(), before_ping_time); |
| 362 | 353 |
| 363 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); | 354 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); |
| 364 | 355 |
| 365 // Delete the first session. | 356 // Delete the first session. |
| 366 session = NULL; | 357 session = NULL; |
| 367 } | 358 } |
| 368 | 359 |
| 369 TEST_P(SpdySessionTest, ServerPing) { | 360 TEST_P(SpdySessionTest, ServerPing) { |
| 370 if (GetParam() > kProtoSPDY3) | |
| 371 return; | |
| 372 | |
| 373 session_deps_.host_resolver->set_synchronous_mode(true); | 361 session_deps_.host_resolver->set_synchronous_mode(true); |
| 374 | 362 |
| 375 MockConnect connect_data(SYNCHRONOUS, OK); | 363 MockConnect connect_data(SYNCHRONOUS, OK); |
| 376 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(2)); | 364 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(2)); |
| 377 MockRead reads[] = { | 365 MockRead reads[] = { |
| 378 CreateMockRead(*read_ping), | 366 CreateMockRead(*read_ping), |
| 379 MockRead(SYNCHRONOUS, 0, 0) // EOF | 367 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 380 }; | 368 }; |
| 381 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(2)); | 369 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(2)); |
| 382 MockWrite writes[] = { | 370 MockWrite writes[] = { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 405 base::MessageLoop::current()->RunUntilIdle(); | 393 base::MessageLoop::current()->RunUntilIdle(); |
| 406 | 394 |
| 407 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); | 395 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); |
| 408 | 396 |
| 409 // Delete the session. | 397 // Delete the session. |
| 410 session = NULL; | 398 session = NULL; |
| 411 EXPECT_EQ(NULL, spdy_stream1.get()); | 399 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 412 } | 400 } |
| 413 | 401 |
| 414 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { | 402 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { |
| 415 if (GetParam() > kProtoSPDY3) | |
| 416 return; | |
| 417 | |
| 418 session_deps_.host_resolver->set_synchronous_mode(true); | 403 session_deps_.host_resolver->set_synchronous_mode(true); |
| 419 | 404 |
| 420 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 405 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 421 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 406 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 422 session_deps_.time_func = TheNearFuture; | 407 session_deps_.time_func = TheNearFuture; |
| 423 | 408 |
| 424 CreateNetworkSession(); | 409 CreateNetworkSession(); |
| 425 | 410 |
| 426 scoped_refptr<SpdySession> session = GetSession(key_); | 411 scoped_refptr<SpdySession> session = GetSession(key_); |
| 427 | 412 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 // Verify that the second pushed stream evicted the first pushed stream. | 449 // Verify that the second pushed stream evicted the first pushed stream. |
| 465 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); | 450 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); |
| 466 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); | 451 iter = session->unclaimed_pushed_streams_.find("http://www.google.com/b.dat"); |
| 467 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); | 452 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); |
| 468 | 453 |
| 469 // Delete the session. | 454 // Delete the session. |
| 470 session = NULL; | 455 session = NULL; |
| 471 } | 456 } |
| 472 | 457 |
| 473 TEST_P(SpdySessionTest, FailedPing) { | 458 TEST_P(SpdySessionTest, FailedPing) { |
| 474 if (GetParam() > kProtoSPDY3) | |
| 475 return; | |
| 476 | |
| 477 session_deps_.host_resolver->set_synchronous_mode(true); | 459 session_deps_.host_resolver->set_synchronous_mode(true); |
| 478 | 460 |
| 479 MockConnect connect_data(SYNCHRONOUS, OK); | 461 MockConnect connect_data(SYNCHRONOUS, OK); |
| 480 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); | 462 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); |
| 481 MockRead reads[] = { | 463 MockRead reads[] = { |
| 482 CreateMockRead(*read_ping), | 464 CreateMockRead(*read_ping), |
| 483 MockRead(SYNCHRONOUS, 0, 0) // EOF | 465 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 484 }; | 466 }; |
| 485 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); | 467 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); |
| 486 MockWrite writes[] = { | 468 MockWrite writes[] = { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 EXPECT_EQ(0u, session->num_active_streams()); | 511 EXPECT_EQ(0u, session->num_active_streams()); |
| 530 EXPECT_EQ(0u, session->num_unclaimed_pushed_streams()); | 512 EXPECT_EQ(0u, session->num_unclaimed_pushed_streams()); |
| 531 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); | 513 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); |
| 532 | 514 |
| 533 // Delete the first session. | 515 // Delete the first session. |
| 534 session = NULL; | 516 session = NULL; |
| 535 EXPECT_EQ(NULL, spdy_stream1.get()); | 517 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 536 } | 518 } |
| 537 | 519 |
| 538 TEST_P(SpdySessionTest, CloseIdleSessions) { | 520 TEST_P(SpdySessionTest, CloseIdleSessions) { |
| 539 if (GetParam() > kProtoSPDY3) | |
| 540 return; | |
| 541 | |
| 542 MockConnect connect_data(SYNCHRONOUS, OK); | 521 MockConnect connect_data(SYNCHRONOUS, OK); |
| 543 MockRead reads[] = { | 522 MockRead reads[] = { |
| 544 MockRead(ASYNC, 0, 0) // EOF | 523 MockRead(ASYNC, 0, 0) // EOF |
| 545 }; | 524 }; |
| 546 | 525 |
| 547 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 526 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 548 data.set_connect_data(connect_data); | 527 data.set_connect_data(connect_data); |
| 549 session_deps_.socket_factory->AddSocketDataProvider(&data); | 528 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 550 | 529 |
| 551 CreateNetworkSession(); | 530 CreateNetworkSession(); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 655 EXPECT_FALSE(session2->is_active()); | 634 EXPECT_FALSE(session2->is_active()); |
| 656 EXPECT_TRUE(session2->IsClosed()); | 635 EXPECT_TRUE(session2->IsClosed()); |
| 657 } | 636 } |
| 658 | 637 |
| 659 // Start with max concurrent streams set to 1. Request two streams. Receive a | 638 // Start with max concurrent streams set to 1. Request two streams. Receive a |
| 660 // settings frame setting max concurrent streams to 2. Have the callback | 639 // settings frame setting max concurrent streams to 2. Have the callback |
| 661 // release the stream, which releases its reference (the last) to the session. | 640 // release the stream, which releases its reference (the last) to the session. |
| 662 // Make sure nothing blows up. | 641 // Make sure nothing blows up. |
| 663 // http://crbug.com/57331 | 642 // http://crbug.com/57331 |
| 664 TEST_P(SpdySessionTest, OnSettings) { | 643 TEST_P(SpdySessionTest, OnSettings) { |
| 665 if (GetParam() > kProtoSPDY3) | |
| 666 return; | |
| 667 | |
| 668 session_deps_.host_resolver->set_synchronous_mode(true); | 644 session_deps_.host_resolver->set_synchronous_mode(true); |
| 669 | 645 |
| 670 SettingsMap new_settings; | 646 SettingsMap new_settings; |
| 671 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 647 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 672 const uint32 max_concurrent_streams = 2; | 648 const uint32 max_concurrent_streams = 2; |
| 673 new_settings[kSpdySettingsIds1] = | 649 new_settings[kSpdySettingsIds1] = |
| 674 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 650 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 675 | 651 |
| 676 // Set up the socket so we read a SETTINGS frame that raises max concurrent | 652 // Set up the socket so we read a SETTINGS frame that raises max concurrent |
| 677 // streams to 2. | 653 // streams to 2. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 716 stream_releaser.MakeCallback(&request))); | 692 stream_releaser.MakeCallback(&request))); |
| 717 session = NULL; | 693 session = NULL; |
| 718 | 694 |
| 719 EXPECT_EQ(OK, stream_releaser.WaitForResult()); | 695 EXPECT_EQ(OK, stream_releaser.WaitForResult()); |
| 720 } | 696 } |
| 721 | 697 |
| 722 // Start with max concurrent streams set to 1 (that is persisted). Receive a | 698 // Start with max concurrent streams set to 1 (that is persisted). Receive a |
| 723 // settings frame setting max concurrent streams to 2 and which also clears the | 699 // settings frame setting max concurrent streams to 2 and which also clears the |
| 724 // persisted data. Verify that persisted data is correct. | 700 // persisted data. Verify that persisted data is correct. |
| 725 TEST_P(SpdySessionTest, ClearSettings) { | 701 TEST_P(SpdySessionTest, ClearSettings) { |
| 726 if (GetParam() > kProtoSPDY3) | |
| 727 return; | |
| 728 | |
| 729 session_deps_.host_resolver->set_synchronous_mode(true); | 702 session_deps_.host_resolver->set_synchronous_mode(true); |
| 730 | 703 |
| 731 SettingsMap new_settings; | 704 SettingsMap new_settings; |
| 732 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 705 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 733 const uint32 max_concurrent_streams = 2; | 706 const uint32 max_concurrent_streams = 2; |
| 734 new_settings[kSpdySettingsIds1] = | 707 new_settings[kSpdySettingsIds1] = |
| 735 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 708 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 736 | 709 |
| 737 // Set up the socket so we read a SETTINGS frame that raises max concurrent | 710 // Set up the socket so we read a SETTINGS frame that raises max concurrent |
| 738 // streams to 2 and clears previously persisted data. | 711 // streams to 2 and clears previously persisted data. |
| 739 MockConnect connect_data(SYNCHRONOUS, OK); | 712 MockConnect connect_data(SYNCHRONOUS, OK); |
| 740 scoped_ptr<SpdyFrame> settings_frame( | 713 scoped_ptr<SpdyFrame> settings_frame( |
| 741 spdy_util_.ConstructSpdySettings(new_settings)); | 714 spdy_util_.ConstructSpdySettings(new_settings)); |
| 742 uint8 flags = SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS; | 715 uint8 flags = SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS; |
| 743 test::SetFrameFlags(settings_frame.get(), flags, SPDY3); | 716 test::SetFrameFlags(settings_frame.get(), flags, spdy_util_.spdy_version()); |
| 744 MockRead reads[] = { | 717 MockRead reads[] = { |
| 745 CreateMockRead(*settings_frame), | 718 CreateMockRead(*settings_frame), |
| 746 MockRead(SYNCHRONOUS, 0, 0) // EOF | 719 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 747 }; | 720 }; |
| 748 | 721 |
| 749 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 722 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 750 data.set_connect_data(connect_data); | 723 data.set_connect_data(connect_data); |
| 751 session_deps_.socket_factory->AddSocketDataProvider(&data); | 724 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 752 | 725 |
| 753 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 726 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 EXPECT_EQ(2u, session->max_concurrent_streams()); | 765 EXPECT_EQ(2u, session->max_concurrent_streams()); |
| 793 | 766 |
| 794 session = NULL; | 767 session = NULL; |
| 795 } | 768 } |
| 796 | 769 |
| 797 // Start with max concurrent streams set to 1. Request two streams. When the | 770 // Start with max concurrent streams set to 1. Request two streams. When the |
| 798 // first completes, have the callback close itself, which should trigger the | 771 // first completes, have the callback close itself, which should trigger the |
| 799 // second stream creation. Then cancel that one immediately. Don't crash. | 772 // second stream creation. Then cancel that one immediately. Don't crash. |
| 800 // http://crbug.com/63532 | 773 // http://crbug.com/63532 |
| 801 TEST_P(SpdySessionTest, CancelPendingCreateStream) { | 774 TEST_P(SpdySessionTest, CancelPendingCreateStream) { |
| 802 if (GetParam() > kProtoSPDY3) | |
| 803 return; | |
| 804 | |
| 805 session_deps_.host_resolver->set_synchronous_mode(true); | 775 session_deps_.host_resolver->set_synchronous_mode(true); |
| 806 | 776 |
| 807 MockRead reads[] = { | 777 MockRead reads[] = { |
| 808 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 778 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 809 }; | 779 }; |
| 810 | 780 |
| 811 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 781 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 812 MockConnect connect_data(SYNCHRONOUS, OK); | 782 MockConnect connect_data(SYNCHRONOUS, OK); |
| 813 | 783 |
| 814 data.set_connect_data(connect_data); | 784 data.set_connect_data(connect_data); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 850 EXPECT_EQ(NULL, spdy_stream1.get()); | 820 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 851 | 821 |
| 852 request.CancelRequest(); | 822 request.CancelRequest(); |
| 853 callback.reset(); | 823 callback.reset(); |
| 854 | 824 |
| 855 // Should not crash when running the pending callback. | 825 // Should not crash when running the pending callback. |
| 856 base::MessageLoop::current()->RunUntilIdle(); | 826 base::MessageLoop::current()->RunUntilIdle(); |
| 857 } | 827 } |
| 858 | 828 |
| 859 TEST_P(SpdySessionTest, SendInitialSettingsOnNewSession) { | 829 TEST_P(SpdySessionTest, SendInitialSettingsOnNewSession) { |
| 860 if (GetParam() > kProtoSPDY3) | |
| 861 return; | |
| 862 | |
| 863 session_deps_.host_resolver->set_synchronous_mode(true); | 830 session_deps_.host_resolver->set_synchronous_mode(true); |
| 864 | 831 |
| 865 MockRead reads[] = { | 832 MockRead reads[] = { |
| 866 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 833 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 867 }; | 834 }; |
| 868 | 835 |
| 869 SettingsMap settings; | 836 SettingsMap settings; |
| 870 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 837 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 871 const SpdySettingsIds kSpdySettingsIds2 = SETTINGS_INITIAL_WINDOW_SIZE; | 838 const SpdySettingsIds kSpdySettingsIds2 = SETTINGS_INITIAL_WINDOW_SIZE; |
| 872 const uint32 kInitialRecvWindowSize = 10 * 1024 * 1024; | 839 const uint32 kInitialRecvWindowSize = 10 * 1024 * 1024; |
| 873 settings[kSpdySettingsIds1] = | 840 settings[kSpdySettingsIds1] = |
| 874 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | 841 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 875 if (spdy_util_.spdy_version() >= SPDY3) { | 842 if (spdy_util_.spdy_version() >= SPDY3) { |
| 876 settings[kSpdySettingsIds2] = | 843 settings[kSpdySettingsIds2] = |
| 877 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kInitialRecvWindowSize); | 844 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kInitialRecvWindowSize); |
| 878 } | 845 } |
| 879 MockConnect connect_data(SYNCHRONOUS, OK); | 846 MockConnect connect_data(SYNCHRONOUS, OK); |
| 880 scoped_ptr<SpdyFrame> settings_frame( | 847 scoped_ptr<SpdyFrame> settings_frame( |
| 881 spdy_util_.ConstructSpdySettings(settings)); | 848 spdy_util_.ConstructSpdySettings(settings)); |
| 849 scoped_ptr<SpdyFrame> initial_window_update( | |
| 850 spdy_util_.ConstructSpdyWindowUpdate( | |
| 851 kSessionFlowControlStreamId, | |
| 852 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 882 MockWrite writes[] = { | 853 MockWrite writes[] = { |
| 883 CreateMockWrite(*settings_frame), | 854 CreateMockWrite(*settings_frame), |
| 855 CreateMockWrite(*initial_window_update), | |
| 884 }; | 856 }; |
| 885 session_deps_.stream_initial_recv_window_size = kInitialRecvWindowSize; | 857 session_deps_.stream_initial_recv_window_size = kInitialRecvWindowSize; |
| 858 int num_writes = arraysize(writes); | |
| 859 // We don't have session windows for SPDY versions less than 3.1. | |
| 860 if (spdy_util_.protocol() < kProtoSPDY31) { | |
| 861 --num_writes; | |
| 862 } | |
| 886 | 863 |
| 887 StaticSocketDataProvider data( | 864 StaticSocketDataProvider data(reads, arraysize(reads), writes, num_writes); |
| 888 reads, arraysize(reads), writes, arraysize(writes)); | |
| 889 data.set_connect_data(connect_data); | 865 data.set_connect_data(connect_data); |
| 890 session_deps_.socket_factory->AddSocketDataProvider(&data); | 866 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 891 | 867 |
| 892 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 868 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 893 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 869 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 894 | 870 |
| 895 CreateNetworkSession(); | 871 CreateNetworkSession(); |
| 896 | 872 |
| 897 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | 873 SpdySessionPoolPeer pool_peer(spdy_session_pool_); |
| 898 pool_peer.EnableSendingInitialSettings(true); | 874 pool_peer.EnableSendingInitialSettings(true); |
| 899 | 875 |
| 900 scoped_refptr<SpdySession> session = CreateInitializedSession(); | 876 scoped_refptr<SpdySession> session = CreateInitializedSession(); |
| 901 | 877 |
| 902 base::MessageLoop::current()->RunUntilIdle(); | 878 base::MessageLoop::current()->RunUntilIdle(); |
| 903 EXPECT_TRUE(data.at_write_eof()); | 879 EXPECT_TRUE(data.at_write_eof()); |
| 904 } | 880 } |
| 905 | 881 |
| 906 TEST_P(SpdySessionTest, SendSettingsOnNewSession) { | 882 TEST_P(SpdySessionTest, SendSettingsOnNewSession) { |
| 907 if (GetParam() > kProtoSPDY3) | |
| 908 return; | |
| 909 | |
| 910 session_deps_.host_resolver->set_synchronous_mode(true); | 883 session_deps_.host_resolver->set_synchronous_mode(true); |
| 911 | 884 |
| 912 MockRead reads[] = { | 885 MockRead reads[] = { |
| 913 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 886 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 914 }; | 887 }; |
| 915 | 888 |
| 916 // Create the bogus setting that we want to verify is sent out. | 889 // Create the bogus setting that we want to verify is sent out. |
| 917 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But | 890 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But |
| 918 // to persist it into the HttpServerProperties, we need to mark as | 891 // to persist it into the HttpServerProperties, we need to mark as |
| 919 // SETTINGS_FLAG_PLEASE_PERSIST. | 892 // SETTINGS_FLAG_PLEASE_PERSIST. |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1197 | 1170 |
| 1198 TEST_P(SpdySessionTest, IPPoolingCloseCurrentSessions) { | 1171 TEST_P(SpdySessionTest, IPPoolingCloseCurrentSessions) { |
| 1199 IPPoolingTest(GetParam(), SPDY_POOL_CLOSE_CURRENT_SESSIONS); | 1172 IPPoolingTest(GetParam(), SPDY_POOL_CLOSE_CURRENT_SESSIONS); |
| 1200 } | 1173 } |
| 1201 | 1174 |
| 1202 TEST_P(SpdySessionTest, IPPoolingCloseIdleSessions) { | 1175 TEST_P(SpdySessionTest, IPPoolingCloseIdleSessions) { |
| 1203 IPPoolingTest(GetParam(), SPDY_POOL_CLOSE_IDLE_SESSIONS); | 1176 IPPoolingTest(GetParam(), SPDY_POOL_CLOSE_IDLE_SESSIONS); |
| 1204 } | 1177 } |
| 1205 | 1178 |
| 1206 TEST_P(SpdySessionTest, ClearSettingsStorageOnIPAddressChanged) { | 1179 TEST_P(SpdySessionTest, ClearSettingsStorageOnIPAddressChanged) { |
| 1207 if (GetParam() > kProtoSPDY3) | |
| 1208 return; | |
| 1209 | |
| 1210 CreateNetworkSession(); | 1180 CreateNetworkSession(); |
| 1211 | 1181 |
| 1212 HttpServerProperties* test_http_server_properties = | 1182 HttpServerProperties* test_http_server_properties = |
| 1213 spdy_session_pool_->http_server_properties(); | 1183 spdy_session_pool_->http_server_properties(); |
| 1214 SettingsFlagsAndValue flags_and_value1(SETTINGS_FLAG_PLEASE_PERSIST, 2); | 1184 SettingsFlagsAndValue flags_and_value1(SETTINGS_FLAG_PLEASE_PERSIST, 2); |
| 1215 test_http_server_properties->SetSpdySetting( | 1185 test_http_server_properties->SetSpdySetting( |
| 1216 test_host_port_pair_, | 1186 test_host_port_pair_, |
| 1217 SETTINGS_MAX_CONCURRENT_STREAMS, | 1187 SETTINGS_MAX_CONCURRENT_STREAMS, |
| 1218 SETTINGS_FLAG_PLEASE_PERSIST, | 1188 SETTINGS_FLAG_PLEASE_PERSIST, |
| 1219 2); | 1189 2); |
| 1220 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( | 1190 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( |
| 1221 test_host_port_pair_).size()); | 1191 test_host_port_pair_).size()); |
| 1222 spdy_session_pool_->OnIPAddressChanged(); | 1192 spdy_session_pool_->OnIPAddressChanged(); |
| 1223 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( | 1193 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( |
| 1224 test_host_port_pair_).size()); | 1194 test_host_port_pair_).size()); |
| 1225 } | 1195 } |
| 1226 | 1196 |
| 1227 TEST_P(SpdySessionTest, Initialize) { | 1197 TEST_P(SpdySessionTest, Initialize) { |
| 1228 if (GetParam() > kProtoSPDY3) | |
| 1229 return; | |
| 1230 | |
| 1231 CapturingBoundNetLog log; | 1198 CapturingBoundNetLog log; |
| 1232 session_deps_.net_log = log.bound().net_log(); | 1199 session_deps_.net_log = log.bound().net_log(); |
| 1233 session_deps_.host_resolver->set_synchronous_mode(true); | 1200 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1234 | 1201 |
| 1235 MockConnect connect_data(SYNCHRONOUS, OK); | 1202 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1236 MockRead reads[] = { | 1203 MockRead reads[] = { |
| 1237 MockRead(ASYNC, 0, 0) // EOF | 1204 MockRead(ASYNC, 0, 0) // EOF |
| 1238 }; | 1205 }; |
| 1239 | 1206 |
| 1240 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 1207 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1270 | 1237 |
| 1271 CapturingNetLog::CapturedEntry entry = entries[pos]; | 1238 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1272 NetLog::Source socket_source; | 1239 NetLog::Source socket_source; |
| 1273 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(), | 1240 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(), |
| 1274 &socket_source)); | 1241 &socket_source)); |
| 1275 EXPECT_TRUE(socket_source.IsValid()); | 1242 EXPECT_TRUE(socket_source.IsValid()); |
| 1276 EXPECT_NE(log.bound().source().id, socket_source.id); | 1243 EXPECT_NE(log.bound().source().id, socket_source.id); |
| 1277 } | 1244 } |
| 1278 | 1245 |
| 1279 TEST_P(SpdySessionTest, CloseSessionOnError) { | 1246 TEST_P(SpdySessionTest, CloseSessionOnError) { |
| 1280 if (GetParam() > kProtoSPDY3) | |
| 1281 return; | |
| 1282 | |
| 1283 session_deps_.host_resolver->set_synchronous_mode(true); | 1247 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1284 | 1248 |
| 1285 MockConnect connect_data(SYNCHRONOUS, OK); | 1249 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1286 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); | 1250 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); |
| 1287 MockRead reads[] = { | 1251 MockRead reads[] = { |
| 1288 CreateMockRead(*goaway), | 1252 CreateMockRead(*goaway), |
| 1289 MockRead(SYNCHRONOUS, 0, 0) // EOF | 1253 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 1290 }; | 1254 }; |
| 1291 | 1255 |
| 1292 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 1256 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1326 CapturingNetLog::CapturedEntry entry = entries[pos]; | 1290 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1327 int error_code = 0; | 1291 int error_code = 0; |
| 1328 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); | 1292 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); |
| 1329 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); | 1293 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); |
| 1330 } | 1294 } |
| 1331 | 1295 |
| 1332 // Queue up a low-priority SYN_STREAM followed by a high-priority | 1296 // Queue up a low-priority SYN_STREAM followed by a high-priority |
| 1333 // one. The high priority one should still send first and receive | 1297 // one. The high priority one should still send first and receive |
| 1334 // first. | 1298 // first. |
| 1335 TEST_P(SpdySessionTest, OutOfOrderSynStreams) { | 1299 TEST_P(SpdySessionTest, OutOfOrderSynStreams) { |
| 1336 if (GetParam() > kProtoSPDY3) | |
| 1337 return; | |
| 1338 | |
| 1339 // Construct the request. | 1300 // Construct the request. |
| 1340 MockConnect connect_data(SYNCHRONOUS, OK); | 1301 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1341 scoped_ptr<SpdyFrame> req_highest( | 1302 scoped_ptr<SpdyFrame> req_highest( |
| 1342 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, HIGHEST, true)); | 1303 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, HIGHEST, true)); |
| 1343 scoped_ptr<SpdyFrame> req_lowest( | 1304 scoped_ptr<SpdyFrame> req_lowest( |
| 1344 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 1305 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 1345 MockWrite writes[] = { | 1306 MockWrite writes[] = { |
| 1346 CreateMockWrite(*req_highest, 0), | 1307 CreateMockWrite(*req_highest, 0), |
| 1347 CreateMockWrite(*req_lowest, 1), | 1308 CreateMockWrite(*req_lowest, 1), |
| 1348 }; | 1309 }; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1411 | 1372 |
| 1412 data.RunFor(7); | 1373 data.RunFor(7); |
| 1413 | 1374 |
| 1414 EXPECT_FALSE(spdy_stream_lowest); | 1375 EXPECT_FALSE(spdy_stream_lowest); |
| 1415 EXPECT_FALSE(spdy_stream_highest); | 1376 EXPECT_FALSE(spdy_stream_highest); |
| 1416 EXPECT_EQ(3u, delegate_lowest.stream_id()); | 1377 EXPECT_EQ(3u, delegate_lowest.stream_id()); |
| 1417 EXPECT_EQ(1u, delegate_highest.stream_id()); | 1378 EXPECT_EQ(1u, delegate_highest.stream_id()); |
| 1418 } | 1379 } |
| 1419 | 1380 |
| 1420 TEST_P(SpdySessionTest, CancelStream) { | 1381 TEST_P(SpdySessionTest, CancelStream) { |
| 1421 if (GetParam() > kProtoSPDY3) | |
| 1422 return; | |
| 1423 | |
| 1424 MockConnect connect_data(SYNCHRONOUS, OK); | 1382 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1425 // Request 1, at HIGHEST priority, will be cancelled before it writes data. | 1383 // Request 1, at HIGHEST priority, will be cancelled before it writes data. |
| 1426 // Request 2, at LOWEST priority, will be a full request and will be id 1. | 1384 // Request 2, at LOWEST priority, will be a full request and will be id 1. |
| 1427 scoped_ptr<SpdyFrame> req2( | 1385 scoped_ptr<SpdyFrame> req2( |
| 1428 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 1386 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 1429 MockWrite writes[] = { | 1387 MockWrite writes[] = { |
| 1430 CreateMockWrite(*req2, 0), | 1388 CreateMockWrite(*req2, 0), |
| 1431 }; | 1389 }; |
| 1432 | 1390 |
| 1433 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 1391 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1493 EXPECT_EQ(1u, delegate2.stream_id()); | 1451 EXPECT_EQ(1u, delegate2.stream_id()); |
| 1494 | 1452 |
| 1495 spdy_stream2->Cancel(); | 1453 spdy_stream2->Cancel(); |
| 1496 EXPECT_EQ(NULL, spdy_stream2.get()); | 1454 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 1497 } | 1455 } |
| 1498 | 1456 |
| 1499 // Create two streams that are set to re-close themselves on close, | 1457 // Create two streams that are set to re-close themselves on close, |
| 1500 // and then close the session. Nothing should blow up. Also a | 1458 // and then close the session. Nothing should blow up. Also a |
| 1501 // regression test for http://crbug.com/139518 . | 1459 // regression test for http://crbug.com/139518 . |
| 1502 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedSelfClosingStreams) { | 1460 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedSelfClosingStreams) { |
| 1503 if (GetParam() > kProtoSPDY3) | |
| 1504 return; | |
| 1505 | |
| 1506 session_deps_.host_resolver->set_synchronous_mode(true); | 1461 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1507 | 1462 |
| 1508 MockConnect connect_data(SYNCHRONOUS, OK); | 1463 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1509 | 1464 |
| 1510 // No actual data will be sent. | 1465 // No actual data will be sent. |
| 1511 MockWrite writes[] = { | 1466 MockWrite writes[] = { |
| 1512 MockWrite(ASYNC, 0, 1) // EOF | 1467 MockWrite(ASYNC, 0, 1) // EOF |
| 1513 }; | 1468 }; |
| 1514 | 1469 |
| 1515 MockRead reads[] = { | 1470 MockRead reads[] = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1569 | 1524 |
| 1570 EXPECT_TRUE(delegate1.StreamIsClosed()); | 1525 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1571 EXPECT_TRUE(delegate2.StreamIsClosed()); | 1526 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1572 | 1527 |
| 1573 session = NULL; | 1528 session = NULL; |
| 1574 } | 1529 } |
| 1575 | 1530 |
| 1576 // Create two streams that are set to close each other on close, and | 1531 // Create two streams that are set to close each other on close, and |
| 1577 // then close the session. Nothing should blow up. | 1532 // then close the session. Nothing should blow up. |
| 1578 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) { | 1533 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) { |
| 1579 if (GetParam() > kProtoSPDY3) | |
| 1580 return; | |
| 1581 | |
| 1582 session_deps_.host_resolver->set_synchronous_mode(true); | 1534 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1583 | 1535 |
| 1584 MockConnect connect_data(SYNCHRONOUS, OK); | 1536 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1585 | 1537 |
| 1586 // No actual data will be sent. | 1538 // No actual data will be sent. |
| 1587 MockWrite writes[] = { | 1539 MockWrite writes[] = { |
| 1588 MockWrite(ASYNC, 0, 1) // EOF | 1540 MockWrite(ASYNC, 0, 1) // EOF |
| 1589 }; | 1541 }; |
| 1590 | 1542 |
| 1591 MockRead reads[] = { | 1543 MockRead reads[] = { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1647 | 1599 |
| 1648 EXPECT_TRUE(delegate1.StreamIsClosed()); | 1600 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1649 EXPECT_TRUE(delegate2.StreamIsClosed()); | 1601 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1650 | 1602 |
| 1651 session = NULL; | 1603 session = NULL; |
| 1652 } | 1604 } |
| 1653 | 1605 |
| 1654 // Create two streams that are set to re-close themselves on close, | 1606 // Create two streams that are set to re-close themselves on close, |
| 1655 // activate them, and then close the session. Nothing should blow up. | 1607 // activate them, and then close the session. Nothing should blow up. |
| 1656 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) { | 1608 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) { |
| 1657 if (GetParam() > kProtoSPDY3) | |
| 1658 return; | |
| 1659 | |
| 1660 session_deps_.host_resolver->set_synchronous_mode(true); | 1609 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1661 | 1610 |
| 1662 MockConnect connect_data(SYNCHRONOUS, OK); | 1611 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1663 | 1612 |
| 1664 scoped_ptr<SpdyFrame> req1( | 1613 scoped_ptr<SpdyFrame> req1( |
| 1665 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 1614 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 1666 scoped_ptr<SpdyFrame> req2( | 1615 scoped_ptr<SpdyFrame> req2( |
| 1667 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, MEDIUM, true)); | 1616 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, MEDIUM, true)); |
| 1668 MockWrite writes[] = { | 1617 MockWrite writes[] = { |
| 1669 CreateMockWrite(*req1, 0), | 1618 CreateMockWrite(*req1, 0), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1733 | 1682 |
| 1734 EXPECT_TRUE(delegate1.StreamIsClosed()); | 1683 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1735 EXPECT_TRUE(delegate2.StreamIsClosed()); | 1684 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1736 | 1685 |
| 1737 session = NULL; | 1686 session = NULL; |
| 1738 } | 1687 } |
| 1739 | 1688 |
| 1740 // Create two streams that are set to close each other on close, | 1689 // Create two streams that are set to close each other on close, |
| 1741 // activate them, and then close the session. Nothing should blow up. | 1690 // activate them, and then close the session. Nothing should blow up. |
| 1742 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) { | 1691 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) { |
| 1743 if (GetParam() > kProtoSPDY3) | |
| 1744 return; | |
| 1745 | |
| 1746 session_deps_.host_resolver->set_synchronous_mode(true); | 1692 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1747 | 1693 |
| 1748 MockConnect connect_data(SYNCHRONOUS, OK); | 1694 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1749 | 1695 |
| 1750 scoped_ptr<SpdyFrame> req1( | 1696 scoped_ptr<SpdyFrame> req1( |
| 1751 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 1697 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 1752 scoped_ptr<SpdyFrame> req2( | 1698 scoped_ptr<SpdyFrame> req2( |
| 1753 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, MEDIUM, true)); | 1699 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, MEDIUM, true)); |
| 1754 MockWrite writes[] = { | 1700 MockWrite writes[] = { |
| 1755 CreateMockWrite(*req1, 0), | 1701 CreateMockWrite(*req1, 0), |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1819 EXPECT_EQ(NULL, spdy_stream1.get()); | 1765 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 1820 EXPECT_EQ(NULL, spdy_stream2.get()); | 1766 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 1821 | 1767 |
| 1822 EXPECT_TRUE(delegate1.StreamIsClosed()); | 1768 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1823 EXPECT_TRUE(delegate2.StreamIsClosed()); | 1769 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1824 | 1770 |
| 1825 session = NULL; | 1771 session = NULL; |
| 1826 } | 1772 } |
| 1827 | 1773 |
| 1828 TEST_P(SpdySessionTest, VerifyDomainAuthentication) { | 1774 TEST_P(SpdySessionTest, VerifyDomainAuthentication) { |
| 1829 if (GetParam() > kProtoSPDY3) | |
| 1830 return; | |
| 1831 | |
| 1832 session_deps_.host_resolver->set_synchronous_mode(true); | 1775 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1833 | 1776 |
| 1834 MockConnect connect_data(SYNCHRONOUS, OK); | 1777 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1835 | 1778 |
| 1836 // No actual data will be sent. | 1779 // No actual data will be sent. |
| 1837 MockWrite writes[] = { | 1780 MockWrite writes[] = { |
| 1838 MockWrite(ASYNC, 0, 1) // EOF | 1781 MockWrite(ASYNC, 0, 1) // EOF |
| 1839 }; | 1782 }; |
| 1840 | 1783 |
| 1841 MockRead reads[] = { | 1784 MockRead reads[] = { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1890 BoundNetLog())); | 1833 BoundNetLog())); |
| 1891 | 1834 |
| 1892 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1835 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1893 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); | 1836 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); |
| 1894 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); | 1837 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); |
| 1895 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.com")); | 1838 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.com")); |
| 1896 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); | 1839 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); |
| 1897 } | 1840 } |
| 1898 | 1841 |
| 1899 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { | 1842 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { |
| 1900 if (GetParam() > kProtoSPDY3) | |
| 1901 return; | |
| 1902 | |
| 1903 session_deps_.host_resolver->set_synchronous_mode(true); | 1843 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1904 | 1844 |
| 1905 MockConnect connect_data(SYNCHRONOUS, OK); | 1845 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1906 | 1846 |
| 1907 // No actual data will be sent. | 1847 // No actual data will be sent. |
| 1908 MockWrite writes[] = { | 1848 MockWrite writes[] = { |
| 1909 MockWrite(ASYNC, 0, 1) // EOF | 1849 MockWrite(ASYNC, 0, 1) // EOF |
| 1910 }; | 1850 }; |
| 1911 | 1851 |
| 1912 MockRead reads[] = { | 1852 MockRead reads[] = { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1962 BoundNetLog())); | 1902 BoundNetLog())); |
| 1963 | 1903 |
| 1964 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 1904 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1965 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); | 1905 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); |
| 1966 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); | 1906 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); |
| 1967 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); | 1907 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); |
| 1968 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); | 1908 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); |
| 1969 } | 1909 } |
| 1970 | 1910 |
| 1971 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { | 1911 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { |
| 1972 if (GetParam() > kProtoSPDY3) | |
| 1973 return; | |
| 1974 | |
| 1975 // TODO(rtenneti): Define a helper class/methods and move the common code in | 1912 // TODO(rtenneti): Define a helper class/methods and move the common code in |
| 1976 // this file. | 1913 // this file. |
| 1977 MockConnect connect_data(SYNCHRONOUS, OK); | 1914 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1978 | 1915 |
| 1979 SettingsMap new_settings; | 1916 SettingsMap new_settings; |
| 1980 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 1917 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 1981 const uint32 max_concurrent_streams = 1; | 1918 const uint32 max_concurrent_streams = 1; |
| 1982 new_settings[kSpdySettingsIds1] = | 1919 new_settings[kSpdySettingsIds1] = |
| 1983 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 1920 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 1984 | 1921 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2103 | 2040 |
| 2104 EXPECT_EQ(0u, delegate3.stream_id()); | 2041 EXPECT_EQ(0u, delegate3.stream_id()); |
| 2105 data.RunFor(4); | 2042 data.RunFor(4); |
| 2106 EXPECT_EQ(NULL, stream3.get()); | 2043 EXPECT_EQ(NULL, stream3.get()); |
| 2107 EXPECT_EQ(5u, delegate3.stream_id()); | 2044 EXPECT_EQ(5u, delegate3.stream_id()); |
| 2108 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams()); | 2045 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams()); |
| 2109 EXPECT_EQ(0u, session->pending_create_stream_queues(LOWEST)); | 2046 EXPECT_EQ(0u, session->pending_create_stream_queues(LOWEST)); |
| 2110 } | 2047 } |
| 2111 | 2048 |
| 2112 TEST_P(SpdySessionTest, CancelTwoStalledCreateStream) { | 2049 TEST_P(SpdySessionTest, CancelTwoStalledCreateStream) { |
| 2113 if (GetParam() > kProtoSPDY3) | |
| 2114 return; | |
| 2115 | |
| 2116 session_deps_.host_resolver->set_synchronous_mode(true); | 2050 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2117 | 2051 |
| 2118 MockRead reads[] = { | 2052 MockRead reads[] = { |
| 2119 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 2053 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 2120 }; | 2054 }; |
| 2121 | 2055 |
| 2122 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 2056 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 2123 MockConnect connect_data(SYNCHRONOUS, OK); | 2057 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2124 | 2058 |
| 2125 data.set_connect_data(connect_data); | 2059 data.set_connect_data(connect_data); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2183 | 2117 |
| 2184 // Cancel the third stream. | 2118 // Cancel the third stream. |
| 2185 base::WeakPtr<SpdyStream> spdy_stream3 = request3.ReleaseStream(); | 2119 base::WeakPtr<SpdyStream> spdy_stream3 = request3.ReleaseStream(); |
| 2186 spdy_stream3->Cancel(); | 2120 spdy_stream3->Cancel(); |
| 2187 EXPECT_EQ(NULL, spdy_stream3.get()); | 2121 EXPECT_EQ(NULL, spdy_stream3.get()); |
| 2188 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams()); | 2122 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams()); |
| 2189 EXPECT_EQ(0u, session->pending_create_stream_queues(LOWEST)); | 2123 EXPECT_EQ(0u, session->pending_create_stream_queues(LOWEST)); |
| 2190 } | 2124 } |
| 2191 | 2125 |
| 2192 TEST_P(SpdySessionTest, NeedsCredentials) { | 2126 TEST_P(SpdySessionTest, NeedsCredentials) { |
| 2193 if (GetParam() > kProtoSPDY3) | |
| 2194 return; | |
| 2195 | |
| 2196 MockConnect connect_data(SYNCHRONOUS, OK); | 2127 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2197 MockRead reads[] = { | 2128 MockRead reads[] = { |
| 2198 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 2129 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 2199 }; | 2130 }; |
| 2200 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 2131 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 2201 data.set_connect_data(connect_data); | 2132 data.set_connect_data(connect_data); |
| 2202 session_deps_.socket_factory->AddSocketDataProvider(&data); | 2133 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2203 | 2134 |
| 2204 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 2135 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 2205 ssl.channel_id_sent = true; | 2136 ssl.channel_id_sent = true; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2244 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); | 2175 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); |
| 2245 | 2176 |
| 2246 EXPECT_EQ(spdy_util_.spdy_version() >= SPDY3, session->NeedsCredentials()); | 2177 EXPECT_EQ(spdy_util_.spdy_version() >= SPDY3, session->NeedsCredentials()); |
| 2247 | 2178 |
| 2248 // Flush the SpdySession::OnReadComplete() task. | 2179 // Flush the SpdySession::OnReadComplete() task. |
| 2249 base::MessageLoop::current()->RunUntilIdle(); | 2180 base::MessageLoop::current()->RunUntilIdle(); |
| 2250 | 2181 |
| 2251 spdy_session_pool_->Remove(session); | 2182 spdy_session_pool_->Remove(session); |
| 2252 } | 2183 } |
| 2253 | 2184 |
| 2254 TEST_P(SpdySessionTest, SendCredentials) { | |
|
Ryan Hamilton
2013/06/27 17:23:50
More huge diffs in this file. Any chance they can
akalin
2013/06/27 20:00:06
moved back.
| |
| 2255 if (GetParam() > kProtoSPDY3) | |
| 2256 return; | |
| 2257 | |
| 2258 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2259 MockRead reads[] = { | |
| 2260 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2261 }; | |
| 2262 SettingsMap settings; | |
| 2263 scoped_ptr<SpdyFrame> settings_frame( | |
| 2264 spdy_util_.ConstructSpdySettings(settings)); | |
| 2265 MockWrite writes[] = { | |
| 2266 CreateMockWrite(*settings_frame), | |
| 2267 }; | |
| 2268 StaticSocketDataProvider data(reads, arraysize(reads), | |
| 2269 writes, arraysize(writes)); | |
| 2270 data.set_connect_data(connect_data); | |
| 2271 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2272 | |
| 2273 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | |
| 2274 ssl.channel_id_sent = true; | |
| 2275 ssl.protocol_negotiated = kProtoSPDY3; | |
| 2276 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 2277 | |
| 2278 CreateNetworkSession(); | |
| 2279 | |
| 2280 const GURL kTestUrl("https://www.foo.com"); | |
| 2281 HostPortPair test_host_port_pair(kTestUrl.host(), 443); | |
| 2282 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), | |
| 2283 kPrivacyModeDisabled); | |
| 2284 | |
| 2285 scoped_refptr<SpdySession> session = GetSession(key); | |
| 2286 | |
| 2287 SSLConfig ssl_config; | |
| 2288 scoped_refptr<TransportSocketParams> transport_params( | |
| 2289 new TransportSocketParams(test_host_port_pair, | |
| 2290 MEDIUM, | |
| 2291 false, | |
| 2292 false, | |
| 2293 OnHostResolutionCallback())); | |
| 2294 scoped_refptr<SOCKSSocketParams> socks_params; | |
| 2295 scoped_refptr<HttpProxySocketParams> http_proxy_params; | |
| 2296 scoped_refptr<SSLSocketParams> ssl_params( | |
| 2297 new SSLSocketParams(transport_params, | |
| 2298 socks_params, | |
| 2299 http_proxy_params, | |
| 2300 ProxyServer::SCHEME_DIRECT, | |
| 2301 test_host_port_pair, | |
| 2302 ssl_config, | |
| 2303 0, | |
| 2304 false, | |
| 2305 false)); | |
| 2306 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 2307 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), | |
| 2308 ssl_params, MEDIUM, CompletionCallback(), | |
| 2309 http_session_->GetSSLSocketPool( | |
| 2310 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
| 2311 BoundNetLog())); | |
| 2312 | |
| 2313 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); | |
| 2314 EXPECT_TRUE(session->NeedsCredentials()); | |
| 2315 | |
| 2316 // Flush the SpdySession::OnReadComplete() task. | |
| 2317 base::MessageLoop::current()->RunUntilIdle(); | |
| 2318 | |
| 2319 spdy_session_pool_->Remove(session); | |
| 2320 EXPECT_FALSE(spdy_session_pool_->HasSession(key)); | |
| 2321 } | |
| 2322 | |
| 2323 TEST_P(SpdySessionTest, UpdateStreamsSendWindowSize) { | |
| 2324 if (GetParam() != kProtoSPDY3) | |
| 2325 return; | |
| 2326 | |
| 2327 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE | |
| 2328 // gets sent. | |
| 2329 SettingsMap new_settings; | |
| 2330 int32 window_size = 1; | |
| 2331 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | |
| 2332 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); | |
| 2333 | |
| 2334 // Set up the socket so we read a SETTINGS frame that sets | |
| 2335 // INITIAL_WINDOW_SIZE. | |
| 2336 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2337 scoped_ptr<SpdyFrame> settings_frame( | |
| 2338 spdy_util_.ConstructSpdySettings(new_settings)); | |
| 2339 MockRead reads[] = { | |
| 2340 CreateMockRead(*settings_frame, 0), | |
| 2341 MockRead(ASYNC, 0, 1) // EOF | |
| 2342 }; | |
| 2343 | |
| 2344 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 2345 | |
| 2346 scoped_ptr<DeterministicSocketData> data( | |
| 2347 new DeterministicSocketData(reads, arraysize(reads), NULL, 0)); | |
| 2348 data->set_connect_data(connect_data); | |
| 2349 session_deps_.deterministic_socket_factory->AddSocketDataProvider(data.get()); | |
| 2350 | |
| 2351 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | |
| 2352 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 2353 | |
| 2354 CreateDeterministicNetworkSession(); | |
| 2355 | |
| 2356 scoped_refptr<SpdySession> session = CreateInitializedSession(); | |
| 2357 base::WeakPtr<SpdyStream> spdy_stream1 = | |
| 2358 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | |
| 2359 session, test_url_, MEDIUM, BoundNetLog()); | |
| 2360 ASSERT_TRUE(spdy_stream1.get() != NULL); | |
| 2361 TestCompletionCallback callback1; | |
| 2362 EXPECT_NE(spdy_stream1->send_window_size(), window_size); | |
| 2363 | |
| 2364 data->RunFor(1); // Process the SETTINGS frame, but not the EOF | |
| 2365 base::MessageLoop::current()->RunUntilIdle(); | |
| 2366 EXPECT_EQ(session->stream_initial_send_window_size(), window_size); | |
| 2367 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); | |
| 2368 | |
| 2369 // Release the first one, this will allow the second to be created. | |
| 2370 spdy_stream1->Cancel(); | |
| 2371 EXPECT_EQ(NULL, spdy_stream1.get()); | |
| 2372 | |
| 2373 base::WeakPtr<SpdyStream> spdy_stream2 = | |
| 2374 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | |
| 2375 session, test_url_, MEDIUM, BoundNetLog()); | |
| 2376 ASSERT_TRUE(spdy_stream2.get() != NULL); | |
| 2377 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | |
| 2378 spdy_stream2->Cancel(); | |
| 2379 EXPECT_EQ(NULL, spdy_stream2.get()); | |
| 2380 } | |
| 2381 | |
| 2382 // Test that SpdySession::DoRead reads data from the socket without yielding. | 2185 // Test that SpdySession::DoRead reads data from the socket without yielding. |
| 2383 // This test makes 32k - 1 bytes of data available on the socket for reading. It | 2186 // This test makes 32k - 1 bytes of data available on the socket for reading. It |
| 2384 // then verifies that it has read all the available data without yielding. | 2187 // then verifies that it has read all the available data without yielding. |
| 2385 TEST_P(SpdySessionTest, ReadDataWithoutYielding) { | 2188 TEST_P(SpdySessionTest, ReadDataWithoutYielding) { |
| 2386 if (GetParam() > kProtoSPDY3) | |
| 2387 return; | |
| 2388 | |
| 2389 MockConnect connect_data(SYNCHRONOUS, OK); | 2189 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2390 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 2190 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2391 | 2191 |
| 2392 scoped_ptr<SpdyFrame> req1( | 2192 scoped_ptr<SpdyFrame> req1( |
| 2393 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 2193 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 2394 MockWrite writes[] = { | 2194 MockWrite writes[] = { |
| 2395 CreateMockWrite(*req1, 0), | 2195 CreateMockWrite(*req1, 0), |
| 2396 }; | 2196 }; |
| 2397 | 2197 |
| 2398 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). | 2198 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2468 EXPECT_EQ(0u, observer.executed_count()); | 2268 EXPECT_EQ(0u, observer.executed_count()); |
| 2469 EXPECT_TRUE(data.at_write_eof()); | 2269 EXPECT_TRUE(data.at_write_eof()); |
| 2470 EXPECT_TRUE(data.at_read_eof()); | 2270 EXPECT_TRUE(data.at_read_eof()); |
| 2471 } | 2271 } |
| 2472 | 2272 |
| 2473 // Test that SpdySession::DoRead yields while reading the data. This test makes | 2273 // Test that SpdySession::DoRead yields while reading the data. This test makes |
| 2474 // 32k + 1 bytes of data available on the socket for reading. It then verifies | 2274 // 32k + 1 bytes of data available on the socket for reading. It then verifies |
| 2475 // that DoRead has yielded even though there is data available for it to read | 2275 // that DoRead has yielded even though there is data available for it to read |
| 2476 // (i.e, socket()->Read didn't return ERR_IO_PENDING during socket reads). | 2276 // (i.e, socket()->Read didn't return ERR_IO_PENDING during socket reads). |
| 2477 TEST_P(SpdySessionTest, TestYieldingDuringReadData) { | 2277 TEST_P(SpdySessionTest, TestYieldingDuringReadData) { |
| 2478 if (GetParam() > kProtoSPDY3) | |
| 2479 return; | |
| 2480 | |
| 2481 MockConnect connect_data(SYNCHRONOUS, OK); | 2278 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2482 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 2279 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2483 | 2280 |
| 2484 scoped_ptr<SpdyFrame> req1( | 2281 scoped_ptr<SpdyFrame> req1( |
| 2485 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 2282 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 2486 MockWrite writes[] = { | 2283 MockWrite writes[] = { |
| 2487 CreateMockWrite(*req1, 0), | 2284 CreateMockWrite(*req1, 0), |
| 2488 }; | 2285 }; |
| 2489 | 2286 |
| 2490 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). | 2287 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2568 // | 2365 // |
| 2569 // MockRead of SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 2K | 2366 // MockRead of SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 2K |
| 2570 // ASYNC 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 2K. | 2367 // ASYNC 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 8K, SYNCHRONOUS 2K. |
| 2571 // | 2368 // |
| 2572 // The above reads 26K synchronously. Since that is less that 32K, we will | 2369 // The above reads 26K synchronously. Since that is less that 32K, we will |
| 2573 // attempt to read again. However, that DoRead() will return ERR_IO_PENDING | 2370 // attempt to read again. However, that DoRead() will return ERR_IO_PENDING |
| 2574 // (because of async read), so DoRead() will yield. When we come back, DoRead() | 2371 // (because of async read), so DoRead() will yield. When we come back, DoRead() |
| 2575 // will read the results from the async read, and rest of the data | 2372 // will read the results from the async read, and rest of the data |
| 2576 // synchronously. | 2373 // synchronously. |
| 2577 TEST_P(SpdySessionTest, TestYieldingDuringAsyncReadData) { | 2374 TEST_P(SpdySessionTest, TestYieldingDuringAsyncReadData) { |
| 2578 if (GetParam() > kProtoSPDY3) | |
| 2579 return; | |
| 2580 | |
| 2581 MockConnect connect_data(SYNCHRONOUS, OK); | 2375 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2582 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 2376 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2583 | 2377 |
| 2584 scoped_ptr<SpdyFrame> req1( | 2378 scoped_ptr<SpdyFrame> req1( |
| 2585 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 2379 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 2586 MockWrite writes[] = { | 2380 MockWrite writes[] = { |
| 2587 CreateMockWrite(*req1, 0), | 2381 CreateMockWrite(*req1, 0), |
| 2588 }; | 2382 }; |
| 2589 | 2383 |
| 2590 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). | 2384 // Build buffer of size kMaxReadBytes / 4 (-spdy_data_frame_size). |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2676 EXPECT_EQ(1u, observer.executed_count()); | 2470 EXPECT_EQ(1u, observer.executed_count()); |
| 2677 EXPECT_TRUE(data.at_write_eof()); | 2471 EXPECT_TRUE(data.at_write_eof()); |
| 2678 EXPECT_TRUE(data.at_read_eof()); | 2472 EXPECT_TRUE(data.at_read_eof()); |
| 2679 } | 2473 } |
| 2680 | 2474 |
| 2681 // Send a GoAway frame when SpdySession is in DoLoop. If scoped_refptr to | 2475 // Send a GoAway frame when SpdySession is in DoLoop. If scoped_refptr to |
| 2682 // <SpdySession> is deleted from SpdySession::DoLoop(), we get a crash because | 2476 // <SpdySession> is deleted from SpdySession::DoLoop(), we get a crash because |
| 2683 // GoAway could delete the SpdySession from the SpdySessionPool and the last | 2477 // GoAway could delete the SpdySession from the SpdySessionPool and the last |
| 2684 // reference to SpdySession. | 2478 // reference to SpdySession. |
| 2685 TEST_P(SpdySessionTest, GoAwayWhileInDoLoop) { | 2479 TEST_P(SpdySessionTest, GoAwayWhileInDoLoop) { |
| 2686 if (GetParam() > kProtoSPDY3) | |
| 2687 return; | |
| 2688 | |
| 2689 MockConnect connect_data(SYNCHRONOUS, OK); | 2480 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2690 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 2481 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2691 | 2482 |
| 2692 scoped_ptr<SpdyFrame> req1( | 2483 scoped_ptr<SpdyFrame> req1( |
| 2693 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 2484 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 2694 MockWrite writes[] = { | 2485 MockWrite writes[] = { |
| 2695 CreateMockWrite(*req1, 0), | 2486 CreateMockWrite(*req1, 0), |
| 2696 }; | 2487 }; |
| 2697 | 2488 |
| 2698 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2489 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2786 EXPECT_EQ(0, session->session_recv_window_size_); | 2577 EXPECT_EQ(0, session->session_recv_window_size_); |
| 2787 } else if (GetParam() == kProtoSPDY3) { | 2578 } else if (GetParam() == kProtoSPDY3) { |
| 2788 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM, session->flow_control_state()); | 2579 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM, session->flow_control_state()); |
| 2789 EXPECT_EQ(0, session->session_send_window_size_); | 2580 EXPECT_EQ(0, session->session_send_window_size_); |
| 2790 EXPECT_EQ(0, session->session_recv_window_size_); | 2581 EXPECT_EQ(0, session->session_recv_window_size_); |
| 2791 } else { | 2582 } else { |
| 2792 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | 2583 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, |
| 2793 session->flow_control_state()); | 2584 session->flow_control_state()); |
| 2794 EXPECT_EQ(kSpdySessionInitialWindowSize, | 2585 EXPECT_EQ(kSpdySessionInitialWindowSize, |
| 2795 session->session_send_window_size_); | 2586 session->session_send_window_size_); |
| 2796 EXPECT_EQ(kDefaultInitialRecvWindowSize, | 2587 EXPECT_EQ(kSpdySessionInitialWindowSize, |
| 2797 session->session_recv_window_size_); | 2588 session->session_recv_window_size_); |
| 2798 } | 2589 } |
| 2799 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 2590 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2800 } | 2591 } |
| 2801 | 2592 |
| 2593 // Tests the case of a non-SPDY request closing an idle SPDY session when no | |
| 2594 // pointers to the idle session are currently held. | |
| 2595 TEST_P(SpdySessionTest, CloseOneIdleConnection) { | |
| 2596 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 2597 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2598 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 2599 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2600 | |
| 2601 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2602 MockRead reads[] = { | |
| 2603 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2604 }; | |
| 2605 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 2606 data.set_connect_data(connect_data); | |
| 2607 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2608 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2609 | |
| 2610 CreateNetworkSession(); | |
| 2611 | |
| 2612 TransportClientSocketPool* pool = | |
| 2613 http_session_->GetTransportSocketPool( | |
| 2614 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 2615 | |
| 2616 // Create an idle SPDY session. | |
| 2617 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 2618 kPrivacyModeDisabled); | |
| 2619 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 2620 EXPECT_EQ( | |
| 2621 OK, | |
| 2622 InitializeSession(http_session_.get(), session1.get(), | |
| 2623 key1.host_port_pair())); | |
| 2624 EXPECT_FALSE(pool->IsStalled()); | |
| 2625 // Release the pointer to the session so it can be closed. | |
| 2626 session1 = NULL; | |
| 2627 | |
| 2628 // Trying to create a new connection should cause the pool to be stalled, and | |
| 2629 // post a task asynchronously to try and close the session. | |
| 2630 TestCompletionCallback callback2; | |
| 2631 HostPortPair host_port2("2.com", 80); | |
| 2632 scoped_refptr<TransportSocketParams> params2( | |
| 2633 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 2634 OnHostResolutionCallback())); | |
| 2635 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 2636 EXPECT_EQ(ERR_IO_PENDING, | |
| 2637 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 2638 callback2.callback(), pool, BoundNetLog())); | |
| 2639 EXPECT_TRUE(pool->IsStalled()); | |
| 2640 | |
| 2641 // The socket pool should close the connection asynchronously and establish a | |
| 2642 // new connection. | |
| 2643 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 2644 EXPECT_FALSE(pool->IsStalled()); | |
| 2645 } | |
| 2646 | |
| 2647 // Tests the case of a non-SPDY request closing an idle SPDY session when no | |
| 2648 // pointers to the idle session are currently held, in the case the SPDY session | |
| 2649 // has an alias. | |
| 2650 TEST_P(SpdySessionTest, CloseOneIdleConnectionWithAlias) { | |
| 2651 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 2652 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2653 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 2654 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2655 | |
| 2656 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2657 MockRead reads[] = { | |
| 2658 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2659 }; | |
| 2660 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 2661 data.set_connect_data(connect_data); | |
| 2662 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2663 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2664 | |
| 2665 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 2666 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 2667 "1.com", "192.168.0.2", std::string()); | |
| 2668 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 2669 "2.com", "192.168.0.2", std::string()); | |
| 2670 // Not strictly needed. | |
| 2671 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 2672 "3.com", "192.168.0.3", std::string()); | |
| 2673 | |
| 2674 CreateNetworkSession(); | |
| 2675 | |
| 2676 TransportClientSocketPool* pool = | |
| 2677 http_session_->GetTransportSocketPool( | |
| 2678 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 2679 | |
| 2680 // Create an idle SPDY session. | |
| 2681 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 2682 kPrivacyModeDisabled); | |
| 2683 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 2684 EXPECT_EQ( | |
| 2685 OK, | |
| 2686 InitializeSession(http_session_.get(), session1.get(), | |
| 2687 key1.host_port_pair())); | |
| 2688 EXPECT_FALSE(pool->IsStalled()); | |
| 2689 | |
| 2690 // Set up an alias for the idle SPDY session, increasing its ref count to 2. | |
| 2691 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), | |
| 2692 kPrivacyModeDisabled); | |
| 2693 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | |
| 2694 HostResolver::RequestInfo info(key2.host_port_pair()); | |
| 2695 AddressList addresses; | |
| 2696 // Pre-populate the DNS cache, since a synchronous resolution is required in | |
| 2697 // order to create the alias. | |
| 2698 session_deps_.host_resolver->Resolve( | |
| 2699 info, &addresses, CompletionCallback(), NULL, BoundNetLog()); | |
| 2700 // Add the alias for the first session's key. Has to be done manually since | |
| 2701 // the usual process is bypassed. | |
| 2702 pool_peer.AddAlias(addresses.front(), key1); | |
| 2703 // Get a session for |key2|, which should return the session created earlier. | |
| 2704 scoped_refptr<SpdySession> session2 = | |
| 2705 spdy_session_pool_->Get(key2, BoundNetLog()); | |
| 2706 ASSERT_EQ(session1.get(), session2.get()); | |
| 2707 EXPECT_FALSE(pool->IsStalled()); | |
| 2708 | |
| 2709 // Release both the pointers to the session so it can be closed. | |
| 2710 session1 = NULL; | |
| 2711 session2 = NULL; | |
| 2712 | |
| 2713 // Trying to create a new connection should cause the pool to be stalled, and | |
| 2714 // post a task asynchronously to try and close the session. | |
| 2715 TestCompletionCallback callback3; | |
| 2716 HostPortPair host_port3("3.com", 80); | |
| 2717 scoped_refptr<TransportSocketParams> params3( | |
| 2718 new TransportSocketParams(host_port3, DEFAULT_PRIORITY, false, false, | |
| 2719 OnHostResolutionCallback())); | |
| 2720 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle); | |
| 2721 EXPECT_EQ(ERR_IO_PENDING, | |
| 2722 connection3->Init(host_port3.ToString(), params3, DEFAULT_PRIORITY, | |
| 2723 callback3.callback(), pool, BoundNetLog())); | |
| 2724 EXPECT_TRUE(pool->IsStalled()); | |
| 2725 | |
| 2726 // The socket pool should close the connection asynchronously and establish a | |
| 2727 // new connection. | |
| 2728 EXPECT_EQ(OK, callback3.WaitForResult()); | |
| 2729 EXPECT_FALSE(pool->IsStalled()); | |
| 2730 } | |
| 2731 | |
| 2732 // Tests the case of a non-SPDY request closing an idle SPDY session when a | |
| 2733 // pointer to the idle session is still held. | |
| 2734 TEST_P(SpdySessionTest, CloseOneIdleConnectionSessionStillHeld) { | |
| 2735 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 2736 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2737 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 2738 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2739 | |
| 2740 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2741 MockRead reads[] = { | |
| 2742 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2743 }; | |
| 2744 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 2745 data.set_connect_data(connect_data); | |
| 2746 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2747 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2748 | |
| 2749 CreateNetworkSession(); | |
| 2750 | |
| 2751 TransportClientSocketPool* pool = | |
| 2752 http_session_->GetTransportSocketPool( | |
| 2753 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 2754 | |
| 2755 // Create an idle SPDY session. | |
| 2756 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 2757 kPrivacyModeDisabled); | |
| 2758 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 2759 EXPECT_EQ( | |
| 2760 OK, | |
| 2761 InitializeSession(http_session_.get(), session1.get(), | |
| 2762 key1.host_port_pair())); | |
| 2763 EXPECT_FALSE(pool->IsStalled()); | |
| 2764 | |
| 2765 // Trying to create a new connection should cause the pool to be stalled, and | |
| 2766 // post a task asynchronously to try and close the session. | |
| 2767 TestCompletionCallback callback2; | |
| 2768 HostPortPair host_port2("2.com", 80); | |
| 2769 scoped_refptr<TransportSocketParams> params2( | |
| 2770 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 2771 OnHostResolutionCallback())); | |
| 2772 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 2773 EXPECT_EQ(ERR_IO_PENDING, | |
| 2774 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 2775 callback2.callback(), pool, BoundNetLog())); | |
| 2776 EXPECT_TRUE(pool->IsStalled()); | |
| 2777 | |
| 2778 // Running the message loop should cause the session to prepare to be closed, | |
| 2779 // but since there's still an outstanding reference, it should not be closed | |
| 2780 // yet. | |
| 2781 base::RunLoop().RunUntilIdle(); | |
| 2782 EXPECT_TRUE(pool->IsStalled()); | |
| 2783 EXPECT_FALSE(callback2.have_result()); | |
| 2784 | |
| 2785 // Release the pointer to the session so it can be closed. | |
| 2786 session1 = NULL; | |
| 2787 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 2788 EXPECT_FALSE(pool->IsStalled()); | |
| 2789 } | |
| 2790 | |
| 2791 // Tests that a non-SPDY request can't close a SPDY session that's currently in | |
| 2792 // use. | |
| 2793 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) { | |
| 2794 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 2795 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2796 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 2797 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 2798 | |
| 2799 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2800 MockRead reads[] = { | |
| 2801 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2802 }; | |
| 2803 scoped_ptr<SpdyFrame> req1( | |
| 2804 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 2805 scoped_ptr<SpdyFrame> cancel1( | |
| 2806 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
| 2807 MockWrite writes[] = { | |
| 2808 CreateMockWrite(*req1, 1), | |
| 2809 CreateMockWrite(*cancel1, 1), | |
| 2810 }; | |
| 2811 StaticSocketDataProvider data(reads, arraysize(reads), | |
| 2812 writes, arraysize(writes)); | |
| 2813 data.set_connect_data(connect_data); | |
| 2814 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2815 | |
| 2816 CreateNetworkSession(); | |
| 2817 | |
| 2818 TransportClientSocketPool* pool = | |
| 2819 http_session_->GetTransportSocketPool( | |
| 2820 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 2821 | |
| 2822 // Create a SPDY session. | |
| 2823 GURL url1("http://www.google.com"); | |
| 2824 SpdySessionKey key1(HostPortPair(url1.host(), 80), | |
| 2825 ProxyServer::Direct(), kPrivacyModeDisabled); | |
| 2826 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 2827 EXPECT_EQ( | |
| 2828 OK, | |
| 2829 InitializeSession(http_session_.get(), session1.get(), | |
| 2830 key1.host_port_pair())); | |
| 2831 EXPECT_FALSE(pool->IsStalled()); | |
| 2832 | |
| 2833 // Create a stream using the session, and send a request. | |
| 2834 | |
| 2835 TestCompletionCallback callback1; | |
| 2836 base::WeakPtr<SpdyStream> spdy_stream1 = | |
| 2837 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 2838 session1, url1, DEFAULT_PRIORITY, | |
| 2839 BoundNetLog()); | |
| 2840 ASSERT_TRUE(spdy_stream1.get()); | |
| 2841 test::StreamDelegateDoNothing delegate1(spdy_stream1); | |
| 2842 spdy_stream1->SetDelegate(&delegate1); | |
| 2843 | |
| 2844 scoped_ptr<SpdyHeaderBlock> headers1( | |
| 2845 spdy_util_.ConstructGetHeaderBlock(url1.spec())); | |
| 2846 EXPECT_EQ(ERR_IO_PENDING, | |
| 2847 spdy_stream1->SendRequestHeaders( | |
| 2848 headers1.Pass(), NO_MORE_DATA_TO_SEND)); | |
| 2849 EXPECT_TRUE(spdy_stream1->HasUrl()); | |
| 2850 | |
| 2851 base::MessageLoop::current()->RunUntilIdle(); | |
| 2852 | |
| 2853 // Release the session, so holding onto a pointer here does not affect | |
| 2854 // anything. | |
| 2855 session1 = NULL; | |
| 2856 | |
| 2857 // Trying to create a new connection should cause the pool to be stalled, and | |
| 2858 // post a task asynchronously to try and close the session. | |
| 2859 TestCompletionCallback callback2; | |
| 2860 HostPortPair host_port2("2.com", 80); | |
| 2861 scoped_refptr<TransportSocketParams> params2( | |
| 2862 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 2863 OnHostResolutionCallback())); | |
| 2864 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 2865 EXPECT_EQ(ERR_IO_PENDING, | |
| 2866 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 2867 callback2.callback(), pool, BoundNetLog())); | |
| 2868 EXPECT_TRUE(pool->IsStalled()); | |
| 2869 | |
| 2870 // Running the message loop should cause the socket pool to ask the SPDY | |
| 2871 // session to close an idle socket, but since the socket is in use, nothing | |
| 2872 // happens. | |
| 2873 base::RunLoop().RunUntilIdle(); | |
| 2874 EXPECT_TRUE(pool->IsStalled()); | |
| 2875 EXPECT_FALSE(callback2.have_result()); | |
| 2876 | |
| 2877 // Cancelling the request should still not release the session's socket, | |
| 2878 // since the session is still kept alive by the SpdySessionPool. | |
| 2879 ASSERT_TRUE(spdy_stream1.get()); | |
| 2880 spdy_stream1->Cancel(); | |
| 2881 base::RunLoop().RunUntilIdle(); | |
| 2882 EXPECT_TRUE(pool->IsStalled()); | |
| 2883 EXPECT_FALSE(callback2.have_result()); | |
| 2884 } | |
| 2885 | |
| 2886 // Verify that SpdySessionKey and therefore SpdySession is different when | |
| 2887 // privacy mode is enabled or disabled. | |
| 2888 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { | |
| 2889 CreateDeterministicNetworkSession(); | |
| 2890 | |
| 2891 HostPortPair host_port_pair("www.google.com", 443); | |
| 2892 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), | |
| 2893 kPrivacyModeEnabled); | |
| 2894 SpdySessionKey key_privacy_disabled(host_port_pair, ProxyServer::Direct(), | |
| 2895 kPrivacyModeDisabled); | |
| 2896 | |
| 2897 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 2898 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 2899 | |
| 2900 // Add SpdySession with PrivacyMode Enabled to the pool. | |
| 2901 scoped_refptr<SpdySession> session_privacy_enabled = | |
| 2902 spdy_session_pool_->Get(key_privacy_enabled, BoundNetLog()); | |
| 2903 | |
| 2904 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 2905 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 2906 | |
| 2907 // Add SpdySession with PrivacyMode Disabled to the pool. | |
| 2908 scoped_refptr<SpdySession> session_privacy_disabled = | |
| 2909 spdy_session_pool_->Get(key_privacy_disabled, BoundNetLog()); | |
| 2910 | |
| 2911 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 2912 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 2913 | |
| 2914 spdy_session_pool_->Remove(session_privacy_enabled); | |
| 2915 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 2916 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 2917 | |
| 2918 spdy_session_pool_->Remove(session_privacy_disabled); | |
| 2919 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 2920 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 2921 } | |
| 2922 | |
| 2923 // The tests below are only for SPDY/3 and above. | |
| 2924 | |
| 2925 TEST_P(SpdySessionTest, SendCredentials) { | |
| 2926 if (GetParam() < kProtoSPDY3) | |
| 2927 return; | |
| 2928 | |
| 2929 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 2930 MockRead reads[] = { | |
| 2931 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 2932 }; | |
| 2933 SettingsMap settings; | |
| 2934 scoped_ptr<SpdyFrame> settings_frame( | |
| 2935 spdy_util_.ConstructSpdySettings(settings)); | |
| 2936 MockWrite writes[] = { | |
| 2937 CreateMockWrite(*settings_frame), | |
| 2938 }; | |
| 2939 StaticSocketDataProvider data(reads, arraysize(reads), | |
| 2940 writes, arraysize(writes)); | |
| 2941 data.set_connect_data(connect_data); | |
| 2942 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 2943 | |
| 2944 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | |
| 2945 ssl.channel_id_sent = true; | |
| 2946 ssl.protocol_negotiated = GetParam(); | |
| 2947 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 2948 | |
| 2949 CreateNetworkSession(); | |
| 2950 | |
| 2951 const GURL kTestUrl("https://www.foo.com"); | |
| 2952 HostPortPair test_host_port_pair(kTestUrl.host(), 443); | |
| 2953 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), | |
| 2954 kPrivacyModeDisabled); | |
| 2955 | |
| 2956 scoped_refptr<SpdySession> session = GetSession(key); | |
| 2957 | |
| 2958 SSLConfig ssl_config; | |
| 2959 scoped_refptr<TransportSocketParams> transport_params( | |
| 2960 new TransportSocketParams(test_host_port_pair, | |
| 2961 MEDIUM, | |
| 2962 false, | |
| 2963 false, | |
| 2964 OnHostResolutionCallback())); | |
| 2965 scoped_refptr<SOCKSSocketParams> socks_params; | |
| 2966 scoped_refptr<HttpProxySocketParams> http_proxy_params; | |
| 2967 scoped_refptr<SSLSocketParams> ssl_params( | |
| 2968 new SSLSocketParams(transport_params, | |
| 2969 socks_params, | |
| 2970 http_proxy_params, | |
| 2971 ProxyServer::SCHEME_DIRECT, | |
| 2972 test_host_port_pair, | |
| 2973 ssl_config, | |
| 2974 0, | |
| 2975 false, | |
| 2976 false)); | |
| 2977 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 2978 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), | |
| 2979 ssl_params, MEDIUM, CompletionCallback(), | |
| 2980 http_session_->GetSSLSocketPool( | |
| 2981 HttpNetworkSession::NORMAL_SOCKET_POOL), | |
| 2982 BoundNetLog())); | |
| 2983 | |
| 2984 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); | |
| 2985 EXPECT_TRUE(session->NeedsCredentials()); | |
| 2986 | |
| 2987 // Flush the SpdySession::OnReadComplete() task. | |
| 2988 base::MessageLoop::current()->RunUntilIdle(); | |
| 2989 | |
| 2990 spdy_session_pool_->Remove(session); | |
| 2991 EXPECT_FALSE(spdy_session_pool_->HasSession(key)); | |
| 2992 } | |
| 2993 | |
| 2994 TEST_P(SpdySessionTest, UpdateStreamsSendWindowSize) { | |
| 2995 if (GetParam() < kProtoSPDY3) | |
| 2996 return; | |
| 2997 | |
| 2998 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE | |
| 2999 // gets sent. | |
| 3000 SettingsMap new_settings; | |
| 3001 int32 window_size = 1; | |
| 3002 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | |
| 3003 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); | |
| 3004 | |
| 3005 // Set up the socket so we read a SETTINGS frame that sets | |
| 3006 // INITIAL_WINDOW_SIZE. | |
| 3007 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 3008 scoped_ptr<SpdyFrame> settings_frame( | |
| 3009 spdy_util_.ConstructSpdySettings(new_settings)); | |
| 3010 MockRead reads[] = { | |
| 3011 CreateMockRead(*settings_frame, 0), | |
| 3012 MockRead(ASYNC, 0, 1) // EOF | |
| 3013 }; | |
| 3014 | |
| 3015 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 3016 | |
| 3017 scoped_ptr<DeterministicSocketData> data( | |
| 3018 new DeterministicSocketData(reads, arraysize(reads), NULL, 0)); | |
| 3019 data->set_connect_data(connect_data); | |
| 3020 session_deps_.deterministic_socket_factory->AddSocketDataProvider(data.get()); | |
| 3021 | |
| 3022 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | |
| 3023 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 3024 | |
| 3025 CreateDeterministicNetworkSession(); | |
| 3026 | |
| 3027 scoped_refptr<SpdySession> session = CreateInitializedSession(); | |
| 3028 base::WeakPtr<SpdyStream> spdy_stream1 = | |
| 3029 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | |
| 3030 session, test_url_, MEDIUM, BoundNetLog()); | |
| 3031 ASSERT_TRUE(spdy_stream1.get() != NULL); | |
| 3032 TestCompletionCallback callback1; | |
| 3033 EXPECT_NE(spdy_stream1->send_window_size(), window_size); | |
| 3034 | |
| 3035 data->RunFor(1); // Process the SETTINGS frame, but not the EOF | |
| 3036 base::MessageLoop::current()->RunUntilIdle(); | |
| 3037 EXPECT_EQ(session->stream_initial_send_window_size(), window_size); | |
| 3038 EXPECT_EQ(spdy_stream1->send_window_size(), window_size); | |
| 3039 | |
| 3040 // Release the first one, this will allow the second to be created. | |
| 3041 spdy_stream1->Cancel(); | |
| 3042 EXPECT_EQ(NULL, spdy_stream1.get()); | |
| 3043 | |
| 3044 base::WeakPtr<SpdyStream> spdy_stream2 = | |
| 3045 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | |
| 3046 session, test_url_, MEDIUM, BoundNetLog()); | |
| 3047 ASSERT_TRUE(spdy_stream2.get() != NULL); | |
| 3048 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | |
| 3049 spdy_stream2->Cancel(); | |
| 3050 EXPECT_EQ(NULL, spdy_stream2.get()); | |
| 3051 } | |
| 3052 | |
| 3053 // The tests below are only for SPDY/3.1 and above. | |
| 3054 | |
| 2802 // SpdySession::{Increase,Decrease}RecvWindowSize should properly | 3055 // SpdySession::{Increase,Decrease}RecvWindowSize should properly |
| 2803 // adjust the session receive window size when the "enable_spdy_31" | 3056 // adjust the session receive window size for SPDY 3.1 and higher. In |
| 2804 // flag is set. In addition, SpdySession::IncreaseRecvWindowSize | 3057 // addition, SpdySession::IncreaseRecvWindowSize should trigger |
| 2805 // should trigger sending a WINDOW_UPDATE frame for a large enough | 3058 // sending a WINDOW_UPDATE frame for a large enough delta. |
| 2806 // delta. | |
| 2807 TEST_P(SpdySessionTest, AdjustRecvWindowSize) { | 3059 TEST_P(SpdySessionTest, AdjustRecvWindowSize) { |
| 2808 if (GetParam() < kProtoSPDY31) | 3060 if (GetParam() < kProtoSPDY31) |
| 2809 return; | 3061 return; |
| 2810 | 3062 |
| 2811 session_deps_.host_resolver->set_synchronous_mode(true); | 3063 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2812 | 3064 |
| 2813 const int32 delta_window_size = 100; | 3065 const int32 delta_window_size = 100; |
| 2814 | 3066 |
| 2815 MockConnect connect_data(SYNCHRONOUS, OK); | 3067 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2816 MockRead reads[] = { | 3068 MockRead reads[] = { |
| 2817 MockRead(ASYNC, 0, 2) // EOF | 3069 MockRead(ASYNC, 0, 1) // EOF |
| 2818 }; | 3070 }; |
| 2819 scoped_ptr<SpdyFrame> initial_window_update( | |
| 2820 spdy_util_.ConstructSpdyWindowUpdate( | |
| 2821 kSessionFlowControlStreamId, | |
| 2822 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 2823 scoped_ptr<SpdyFrame> window_update( | 3071 scoped_ptr<SpdyFrame> window_update( |
| 2824 spdy_util_.ConstructSpdyWindowUpdate( | 3072 spdy_util_.ConstructSpdyWindowUpdate( |
| 2825 kSessionFlowControlStreamId, | 3073 kSessionFlowControlStreamId, |
| 2826 kSpdySessionInitialWindowSize + delta_window_size)); | 3074 kSpdySessionInitialWindowSize + delta_window_size)); |
| 2827 MockWrite writes[] = { | 3075 MockWrite writes[] = { |
| 2828 CreateMockWrite(*initial_window_update, 0), | 3076 CreateMockWrite(*window_update, 0), |
| 2829 CreateMockWrite(*window_update, 1), | |
| 2830 }; | 3077 }; |
| 2831 DeterministicSocketData data(reads, arraysize(reads), | 3078 DeterministicSocketData data(reads, arraysize(reads), |
| 2832 writes, arraysize(writes)); | 3079 writes, arraysize(writes)); |
| 2833 data.set_connect_data(connect_data); | 3080 data.set_connect_data(connect_data); |
| 2834 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3081 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 2835 | 3082 |
| 2836 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 3083 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 2837 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); | 3084 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2838 | 3085 |
| 2839 CreateDeterministicNetworkSession(); | 3086 CreateDeterministicNetworkSession(); |
| 2840 scoped_refptr<SpdySession> session = GetSession(key_); | 3087 scoped_refptr<SpdySession> session = GetSession(key_); |
| 2841 InitializeSession( | 3088 InitializeSession( |
| 2842 http_session_.get(), session.get(), test_host_port_pair_); | 3089 http_session_.get(), session.get(), test_host_port_pair_); |
| 2843 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | 3090 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, |
| 2844 session->flow_control_state()); | 3091 session->flow_control_state()); |
| 2845 | 3092 |
| 2846 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3093 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 2847 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3094 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2848 | 3095 |
| 2849 session->IncreaseRecvWindowSize(delta_window_size); | 3096 session->IncreaseRecvWindowSize(delta_window_size); |
| 2850 EXPECT_EQ(kDefaultInitialRecvWindowSize + delta_window_size, | 3097 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size, |
| 2851 session->session_recv_window_size_); | 3098 session->session_recv_window_size_); |
| 2852 EXPECT_EQ(delta_window_size, session->session_unacked_recv_window_bytes_); | 3099 EXPECT_EQ(delta_window_size, session->session_unacked_recv_window_bytes_); |
| 2853 | 3100 |
| 2854 // Should trigger sending a WINDOW_UPDATE frame. | 3101 // Should trigger sending a WINDOW_UPDATE frame. |
| 2855 session->IncreaseRecvWindowSize(kSpdySessionInitialWindowSize); | 3102 session->IncreaseRecvWindowSize(kSpdySessionInitialWindowSize); |
| 2856 EXPECT_EQ(kDefaultInitialRecvWindowSize + delta_window_size + | 3103 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size + |
| 2857 kSpdySessionInitialWindowSize, | 3104 kSpdySessionInitialWindowSize, |
| 2858 session->session_recv_window_size_); | 3105 session->session_recv_window_size_); |
| 2859 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3106 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2860 | 3107 |
| 2861 data.RunFor(2); | 3108 data.RunFor(1); |
| 2862 | 3109 |
| 2863 session->DecreaseRecvWindowSize( | 3110 session->DecreaseRecvWindowSize( |
| 2864 kDefaultInitialRecvWindowSize + delta_window_size + | 3111 kSpdySessionInitialWindowSize + delta_window_size + |
| 2865 kSpdySessionInitialWindowSize); | 3112 kSpdySessionInitialWindowSize); |
| 2866 EXPECT_EQ(0, session->session_recv_window_size_); | 3113 EXPECT_EQ(0, session->session_recv_window_size_); |
| 2867 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3114 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2868 } | 3115 } |
| 2869 | 3116 |
| 2870 // SpdySession::{Increase,Decrease}SendWindowSize should properly | 3117 // SpdySession::{Increase,Decrease}SendWindowSize should properly |
| 2871 // adjust the session send window size when the "enable_spdy_31" flag | 3118 // adjust the session send window size when the "enable_spdy_31" flag |
| 2872 // is set. | 3119 // is set. |
| 2873 TEST_P(SpdySessionTest, AdjustSendWindowSize) { | 3120 TEST_P(SpdySessionTest, AdjustSendWindowSize) { |
| 2874 if (GetParam() < kProtoSPDY31) | 3121 if (GetParam() < kProtoSPDY31) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2907 // receive window size to decrease. | 3154 // receive window size to decrease. |
| 2908 TEST_P(SpdySessionTest, SessionFlowControlInactiveStream) { | 3155 TEST_P(SpdySessionTest, SessionFlowControlInactiveStream) { |
| 2909 if (GetParam() < kProtoSPDY31) | 3156 if (GetParam() < kProtoSPDY31) |
| 2910 return; | 3157 return; |
| 2911 | 3158 |
| 2912 session_deps_.host_resolver->set_synchronous_mode(true); | 3159 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2913 | 3160 |
| 2914 MockConnect connect_data(SYNCHRONOUS, OK); | 3161 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2915 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 3162 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 2916 MockRead reads[] = { | 3163 MockRead reads[] = { |
| 2917 CreateMockRead(*resp, 1), | 3164 CreateMockRead(*resp, 0), |
| 2918 MockRead(ASYNC, 0, 2) // EOF | 3165 MockRead(ASYNC, 0, 1) // EOF |
| 2919 }; | 3166 }; |
| 2920 scoped_ptr<SpdyFrame> initial_window_update( | 3167 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); |
| 2921 spdy_util_.ConstructSpdyWindowUpdate( | |
| 2922 kSessionFlowControlStreamId, | |
| 2923 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 2924 MockWrite writes[] = { | |
| 2925 CreateMockWrite(*initial_window_update, 0), | |
| 2926 }; | |
| 2927 DeterministicSocketData data(reads, arraysize(reads), | |
| 2928 writes, arraysize(writes)); | |
| 2929 data.set_connect_data(connect_data); | 3168 data.set_connect_data(connect_data); |
| 2930 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3169 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 2931 | 3170 |
| 2932 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 3171 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 2933 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); | 3172 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2934 | 3173 |
| 2935 CreateDeterministicNetworkSession(); | 3174 CreateDeterministicNetworkSession(); |
| 2936 scoped_refptr<SpdySession> session = GetSession(key_); | 3175 scoped_refptr<SpdySession> session = GetSession(key_); |
| 2937 InitializeSession( | 3176 InitializeSession( |
| 2938 http_session_.get(), session.get(), test_host_port_pair_); | 3177 http_session_.get(), session.get(), test_host_port_pair_); |
| 2939 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | 3178 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, |
| 2940 session->flow_control_state()); | 3179 session->flow_control_state()); |
| 2941 | 3180 |
| 2942 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3181 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 2943 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3182 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2944 | 3183 |
| 2945 data.RunFor(3); | 3184 data.RunFor(2); |
| 2946 | 3185 |
| 2947 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3186 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 2948 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3187 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 2949 } | 3188 } |
| 2950 | 3189 |
| 2951 // A delegate that drops any received data. | 3190 // A delegate that drops any received data. |
| 2952 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate { | 3191 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate { |
| 2953 public: | 3192 public: |
| 2954 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream, | 3193 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream, |
| 2955 base::StringPiece data) | 3194 base::StringPiece data) |
| 2956 : StreamDelegateSendImmediate(stream, data) {} | 3195 : StreamDelegateSendImmediate(stream, data) {} |
| 2957 | 3196 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2968 if (GetParam() < kProtoSPDY31) | 3207 if (GetParam() < kProtoSPDY31) |
| 2969 return; | 3208 return; |
| 2970 | 3209 |
| 2971 const char kStreamUrl[] = "http://www.google.com/"; | 3210 const char kStreamUrl[] = "http://www.google.com/"; |
| 2972 | 3211 |
| 2973 const int32 msg_data_size = 100; | 3212 const int32 msg_data_size = 100; |
| 2974 const std::string msg_data(msg_data_size, 'a'); | 3213 const std::string msg_data(msg_data_size, 'a'); |
| 2975 | 3214 |
| 2976 MockConnect connect_data(SYNCHRONOUS, OK); | 3215 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2977 | 3216 |
| 2978 scoped_ptr<SpdyFrame> initial_window_update( | |
| 2979 spdy_util_.ConstructSpdyWindowUpdate( | |
| 2980 kSessionFlowControlStreamId, | |
| 2981 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 2982 scoped_ptr<SpdyFrame> req( | 3217 scoped_ptr<SpdyFrame> req( |
| 2983 spdy_util_.ConstructSpdyPost( | 3218 spdy_util_.ConstructSpdyPost( |
| 2984 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); | 3219 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); |
| 2985 scoped_ptr<SpdyFrame> msg( | 3220 scoped_ptr<SpdyFrame> msg( |
| 2986 spdy_util_.ConstructSpdyBodyFrame( | 3221 spdy_util_.ConstructSpdyBodyFrame( |
| 2987 1, msg_data.data(), msg_data_size, false)); | 3222 1, msg_data.data(), msg_data_size, false)); |
| 2988 MockWrite writes[] = { | 3223 MockWrite writes[] = { |
| 2989 CreateMockWrite(*initial_window_update, 0), | 3224 CreateMockWrite(*req, 0), |
| 2990 CreateMockWrite(*req, 1), | 3225 CreateMockWrite(*msg, 2), |
| 2991 CreateMockWrite(*msg, 3), | |
| 2992 }; | 3226 }; |
| 2993 | 3227 |
| 2994 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3228 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2995 scoped_ptr<SpdyFrame> echo( | 3229 scoped_ptr<SpdyFrame> echo( |
| 2996 spdy_util_.ConstructSpdyBodyFrame( | 3230 spdy_util_.ConstructSpdyBodyFrame( |
| 2997 1, msg_data.data(), msg_data_size, false)); | 3231 1, msg_data.data(), msg_data_size, false)); |
| 2998 scoped_ptr<SpdyFrame> window_update( | 3232 scoped_ptr<SpdyFrame> window_update( |
| 2999 spdy_util_.ConstructSpdyWindowUpdate( | 3233 spdy_util_.ConstructSpdyWindowUpdate( |
| 3000 kSessionFlowControlStreamId, msg_data_size)); | 3234 kSessionFlowControlStreamId, msg_data_size)); |
| 3001 MockRead reads[] = { | 3235 MockRead reads[] = { |
| 3002 CreateMockRead(*resp, 2), | 3236 CreateMockRead(*resp, 1), |
| 3003 CreateMockRead(*echo, 4), | 3237 CreateMockRead(*echo, 3), |
| 3004 MockRead(ASYNC, 0, 5) // EOF | 3238 MockRead(ASYNC, 0, 4) // EOF |
| 3005 }; | 3239 }; |
| 3006 | 3240 |
| 3007 // Create SpdySession and SpdyStream and send the request. | 3241 // Create SpdySession and SpdyStream and send the request. |
| 3008 DeterministicSocketData data(reads, arraysize(reads), | 3242 DeterministicSocketData data(reads, arraysize(reads), |
| 3009 writes, arraysize(writes)); | 3243 writes, arraysize(writes)); |
| 3010 data.set_connect_data(connect_data); | 3244 data.set_connect_data(connect_data); |
| 3011 session_deps_.host_resolver->set_synchronous_mode(true); | 3245 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3012 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3246 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3013 | 3247 |
| 3014 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 3248 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 3027 | 3261 |
| 3028 DropReceivedDataDelegate delegate(stream, msg_data); | 3262 DropReceivedDataDelegate delegate(stream, msg_data); |
| 3029 stream->SetDelegate(&delegate); | 3263 stream->SetDelegate(&delegate); |
| 3030 | 3264 |
| 3031 scoped_ptr<SpdyHeaderBlock> headers( | 3265 scoped_ptr<SpdyHeaderBlock> headers( |
| 3032 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); | 3266 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); |
| 3033 EXPECT_EQ(ERR_IO_PENDING, | 3267 EXPECT_EQ(ERR_IO_PENDING, |
| 3034 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | 3268 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); |
| 3035 EXPECT_TRUE(stream->HasUrl()); | 3269 EXPECT_TRUE(stream->HasUrl()); |
| 3036 | 3270 |
| 3037 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3271 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3038 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3272 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3039 | 3273 |
| 3040 data.RunFor(5); | 3274 data.RunFor(4); |
| 3041 | 3275 |
| 3042 EXPECT_TRUE(data.at_write_eof()); | 3276 EXPECT_TRUE(data.at_write_eof()); |
| 3043 EXPECT_TRUE(data.at_read_eof()); | 3277 EXPECT_TRUE(data.at_read_eof()); |
| 3044 | 3278 |
| 3045 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3279 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3046 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); | 3280 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); |
| 3047 | 3281 |
| 3048 stream->Close(); | 3282 stream->Close(); |
| 3049 EXPECT_EQ(NULL, stream.get()); | 3283 EXPECT_EQ(NULL, stream.get()); |
| 3050 | 3284 |
| 3051 EXPECT_EQ(OK, delegate.WaitForClose()); | 3285 EXPECT_EQ(OK, delegate.WaitForClose()); |
| 3052 | 3286 |
| 3053 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3287 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3054 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); | 3288 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); |
| 3055 } | 3289 } |
| 3056 | 3290 |
| 3057 // Send data back and forth but close the stream before its data frame | 3291 // Send data back and forth but close the stream before its data frame |
| 3058 // can be written to the socket. The send window should then increase | 3292 // can be written to the socket. The send window should then increase |
| 3059 // to its original value, i.e. we shouldn't "leak" send window bytes. | 3293 // to its original value, i.e. we shouldn't "leak" send window bytes. |
| 3060 TEST_P(SpdySessionTest, SessionFlowControlNoSendLeaks) { | 3294 TEST_P(SpdySessionTest, SessionFlowControlNoSendLeaks) { |
| 3061 if (GetParam() < kProtoSPDY31) | 3295 if (GetParam() < kProtoSPDY31) |
| 3062 return; | 3296 return; |
| 3063 | 3297 |
| 3064 const char kStreamUrl[] = "http://www.google.com/"; | 3298 const char kStreamUrl[] = "http://www.google.com/"; |
| 3065 | 3299 |
| 3066 const int32 msg_data_size = 100; | 3300 const int32 msg_data_size = 100; |
| 3067 const std::string msg_data(msg_data_size, 'a'); | 3301 const std::string msg_data(msg_data_size, 'a'); |
| 3068 | 3302 |
| 3069 MockConnect connect_data(SYNCHRONOUS, OK); | 3303 MockConnect connect_data(SYNCHRONOUS, OK); |
| 3070 | 3304 |
| 3071 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3072 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3073 kSessionFlowControlStreamId, | |
| 3074 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3075 scoped_ptr<SpdyFrame> req( | 3305 scoped_ptr<SpdyFrame> req( |
| 3076 spdy_util_.ConstructSpdyPost( | 3306 spdy_util_.ConstructSpdyPost( |
| 3077 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); | 3307 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); |
| 3078 MockWrite writes[] = { | 3308 MockWrite writes[] = { |
| 3079 CreateMockWrite(*initial_window_update, 0), | 3309 CreateMockWrite(*req, 0), |
| 3080 CreateMockWrite(*req, 1), | |
| 3081 }; | 3310 }; |
| 3082 | 3311 |
| 3083 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3312 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3084 MockRead reads[] = { | 3313 MockRead reads[] = { |
| 3085 CreateMockRead(*resp, 2), | 3314 CreateMockRead(*resp, 1), |
| 3086 MockRead(ASYNC, 0, 3) // EOF | 3315 MockRead(ASYNC, 0, 2) // EOF |
| 3087 }; | 3316 }; |
| 3088 | 3317 |
| 3089 // Create SpdySession and SpdyStream and send the request. | 3318 // Create SpdySession and SpdyStream and send the request. |
| 3090 DeterministicSocketData data(reads, arraysize(reads), | 3319 DeterministicSocketData data(reads, arraysize(reads), |
| 3091 writes, arraysize(writes)); | 3320 writes, arraysize(writes)); |
| 3092 data.set_connect_data(connect_data); | 3321 data.set_connect_data(connect_data); |
| 3093 session_deps_.host_resolver->set_synchronous_mode(true); | 3322 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3094 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3323 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3095 | 3324 |
| 3096 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 3325 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 3111 stream->SetDelegate(&delegate); | 3340 stream->SetDelegate(&delegate); |
| 3112 | 3341 |
| 3113 scoped_ptr<SpdyHeaderBlock> headers( | 3342 scoped_ptr<SpdyHeaderBlock> headers( |
| 3114 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); | 3343 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); |
| 3115 EXPECT_EQ(ERR_IO_PENDING, | 3344 EXPECT_EQ(ERR_IO_PENDING, |
| 3116 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | 3345 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); |
| 3117 EXPECT_TRUE(stream->HasUrl()); | 3346 EXPECT_TRUE(stream->HasUrl()); |
| 3118 | 3347 |
| 3119 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3348 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3120 | 3349 |
| 3121 data.RunFor(2); | 3350 data.RunFor(1); |
| 3122 | 3351 |
| 3123 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3352 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3124 | 3353 |
| 3125 data.RunFor(1); | 3354 data.RunFor(1); |
| 3126 | 3355 |
| 3127 EXPECT_TRUE(data.at_write_eof()); | 3356 EXPECT_TRUE(data.at_write_eof()); |
| 3128 EXPECT_TRUE(data.at_read_eof()); | 3357 EXPECT_TRUE(data.at_read_eof()); |
| 3129 | 3358 |
| 3130 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, | 3359 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3131 session->session_send_window_size_); | 3360 session->session_send_window_size_); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3145 if (GetParam() < kProtoSPDY31) | 3374 if (GetParam() < kProtoSPDY31) |
| 3146 return; | 3375 return; |
| 3147 | 3376 |
| 3148 const char kStreamUrl[] = "http://www.google.com/"; | 3377 const char kStreamUrl[] = "http://www.google.com/"; |
| 3149 | 3378 |
| 3150 const int32 msg_data_size = 100; | 3379 const int32 msg_data_size = 100; |
| 3151 const std::string msg_data(msg_data_size, 'a'); | 3380 const std::string msg_data(msg_data_size, 'a'); |
| 3152 | 3381 |
| 3153 MockConnect connect_data(SYNCHRONOUS, OK); | 3382 MockConnect connect_data(SYNCHRONOUS, OK); |
| 3154 | 3383 |
| 3155 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3156 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3157 kSessionFlowControlStreamId, | |
| 3158 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3159 scoped_ptr<SpdyFrame> req( | 3384 scoped_ptr<SpdyFrame> req( |
| 3160 spdy_util_.ConstructSpdyPost( | 3385 spdy_util_.ConstructSpdyPost( |
| 3161 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); | 3386 kStreamUrl, 1, msg_data_size, MEDIUM, NULL, 0)); |
| 3162 scoped_ptr<SpdyFrame> msg( | 3387 scoped_ptr<SpdyFrame> msg( |
| 3163 spdy_util_.ConstructSpdyBodyFrame( | 3388 spdy_util_.ConstructSpdyBodyFrame( |
| 3164 1, msg_data.data(), msg_data_size, false)); | 3389 1, msg_data.data(), msg_data_size, false)); |
| 3165 MockWrite writes[] = { | 3390 MockWrite writes[] = { |
| 3166 CreateMockWrite(*initial_window_update, 0), | 3391 CreateMockWrite(*req, 0), |
| 3167 CreateMockWrite(*req, 1), | 3392 CreateMockWrite(*msg, 2), |
| 3168 CreateMockWrite(*msg, 3), | |
| 3169 }; | 3393 }; |
| 3170 | 3394 |
| 3171 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3395 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3172 scoped_ptr<SpdyFrame> echo( | 3396 scoped_ptr<SpdyFrame> echo( |
| 3173 spdy_util_.ConstructSpdyBodyFrame( | 3397 spdy_util_.ConstructSpdyBodyFrame( |
| 3174 1, msg_data.data(), msg_data_size, false)); | 3398 1, msg_data.data(), msg_data_size, false)); |
| 3175 scoped_ptr<SpdyFrame> window_update( | 3399 scoped_ptr<SpdyFrame> window_update( |
| 3176 spdy_util_.ConstructSpdyWindowUpdate( | 3400 spdy_util_.ConstructSpdyWindowUpdate( |
| 3177 kSessionFlowControlStreamId, msg_data_size)); | 3401 kSessionFlowControlStreamId, msg_data_size)); |
| 3178 MockRead reads[] = { | 3402 MockRead reads[] = { |
| 3179 CreateMockRead(*resp, 2), | 3403 CreateMockRead(*resp, 1), |
| 3180 CreateMockRead(*echo, 4), | 3404 CreateMockRead(*echo, 3), |
| 3181 CreateMockRead(*window_update, 5), | 3405 CreateMockRead(*window_update, 4), |
| 3182 MockRead(ASYNC, 0, 6) // EOF | 3406 MockRead(ASYNC, 0, 5) // EOF |
| 3183 }; | 3407 }; |
| 3184 | 3408 |
| 3185 // Create SpdySession and SpdyStream and send the request. | 3409 // Create SpdySession and SpdyStream and send the request. |
| 3186 DeterministicSocketData data(reads, arraysize(reads), | 3410 DeterministicSocketData data(reads, arraysize(reads), |
| 3187 writes, arraysize(writes)); | 3411 writes, arraysize(writes)); |
| 3188 data.set_connect_data(connect_data); | 3412 data.set_connect_data(connect_data); |
| 3189 session_deps_.host_resolver->set_synchronous_mode(true); | 3413 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3190 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3414 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3191 | 3415 |
| 3192 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 3416 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 3206 test::StreamDelegateSendImmediate delegate(stream, msg_data); | 3430 test::StreamDelegateSendImmediate delegate(stream, msg_data); |
| 3207 stream->SetDelegate(&delegate); | 3431 stream->SetDelegate(&delegate); |
| 3208 | 3432 |
| 3209 scoped_ptr<SpdyHeaderBlock> headers( | 3433 scoped_ptr<SpdyHeaderBlock> headers( |
| 3210 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); | 3434 spdy_util_.ConstructPostHeaderBlock(url.spec(), msg_data_size)); |
| 3211 EXPECT_EQ(ERR_IO_PENDING, | 3435 EXPECT_EQ(ERR_IO_PENDING, |
| 3212 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | 3436 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); |
| 3213 EXPECT_TRUE(stream->HasUrl()); | 3437 EXPECT_TRUE(stream->HasUrl()); |
| 3214 | 3438 |
| 3215 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3439 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3216 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3440 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3217 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3441 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3218 | 3442 |
| 3219 data.RunFor(2); | 3443 data.RunFor(1); |
| 3220 | 3444 |
| 3221 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3445 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3222 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3446 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3223 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3447 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3224 | 3448 |
| 3225 data.RunFor(1); | 3449 data.RunFor(1); |
| 3226 | 3450 |
| 3227 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, | 3451 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3228 session->session_send_window_size_); | 3452 session->session_send_window_size_); |
| 3229 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3453 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3230 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3454 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3231 | 3455 |
| 3232 data.RunFor(1); | 3456 data.RunFor(1); |
| 3233 | 3457 |
| 3234 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, | 3458 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3235 session->session_send_window_size_); | 3459 session->session_send_window_size_); |
| 3236 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3460 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3237 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3461 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3238 | 3462 |
| 3239 data.RunFor(1); | 3463 data.RunFor(1); |
| 3240 | 3464 |
| 3241 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, | 3465 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3242 session->session_send_window_size_); | 3466 session->session_send_window_size_); |
| 3243 EXPECT_EQ(kDefaultInitialRecvWindowSize - msg_data_size, | 3467 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3244 session->session_recv_window_size_); | 3468 session->session_recv_window_size_); |
| 3245 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3469 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3246 | 3470 |
| 3247 data.RunFor(1); | 3471 data.RunFor(1); |
| 3248 | 3472 |
| 3249 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3473 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3250 EXPECT_EQ(kDefaultInitialRecvWindowSize - msg_data_size, | 3474 EXPECT_EQ(kSpdySessionInitialWindowSize - msg_data_size, |
| 3251 session->session_recv_window_size_); | 3475 session->session_recv_window_size_); |
| 3252 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); | 3476 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); |
| 3253 | 3477 |
| 3254 EXPECT_TRUE(data.at_write_eof()); | 3478 EXPECT_TRUE(data.at_write_eof()); |
| 3255 EXPECT_TRUE(data.at_read_eof()); | 3479 EXPECT_TRUE(data.at_read_eof()); |
| 3256 | 3480 |
| 3257 EXPECT_EQ(msg_data, delegate.TakeReceivedData()); | 3481 EXPECT_EQ(msg_data, delegate.TakeReceivedData()); |
| 3258 | 3482 |
| 3259 // Draining the delegate's read queue should increase the session's | 3483 // Draining the delegate's read queue should increase the session's |
| 3260 // receive window. | 3484 // receive window. |
| 3261 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3485 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3262 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3486 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3263 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); | 3487 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); |
| 3264 | 3488 |
| 3265 stream->Close(); | 3489 stream->Close(); |
| 3266 EXPECT_EQ(NULL, stream.get()); | 3490 EXPECT_EQ(NULL, stream.get()); |
| 3267 | 3491 |
| 3268 EXPECT_EQ(OK, delegate.WaitForClose()); | 3492 EXPECT_EQ(OK, delegate.WaitForClose()); |
| 3269 | 3493 |
| 3270 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 3494 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
| 3271 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 3495 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); |
| 3272 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); | 3496 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); |
| 3273 } | 3497 } |
| 3274 | 3498 |
| 3275 // Given a stall function and an unstall function, runs a test to make | 3499 // Given a stall function and an unstall function, runs a test to make |
| 3276 // sure that a stream resumes after unstall. | 3500 // sure that a stream resumes after unstall. |
| 3277 void SpdySessionTest::RunResumeAfterUnstallTest( | 3501 void SpdySessionTest::RunResumeAfterUnstallTest( |
| 3278 const base::Callback<void(SpdySession*, SpdyStream*)>& stall_fn, | 3502 const base::Callback<void(SpdySession*, SpdyStream*)>& stall_fn, |
| 3279 const base::Callback<void(SpdySession*, SpdyStream*, int32)>& | 3503 const base::Callback<void(SpdySession*, SpdyStream*, int32)>& |
| 3280 unstall_function) { | 3504 unstall_function) { |
| 3281 const char kStreamUrl[] = "http://www.google.com/"; | 3505 const char kStreamUrl[] = "http://www.google.com/"; |
| 3282 GURL url(kStreamUrl); | 3506 GURL url(kStreamUrl); |
| 3283 | 3507 |
| 3284 session_deps_.host_resolver->set_synchronous_mode(true); | 3508 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3285 | 3509 |
| 3286 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3287 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3288 kSessionFlowControlStreamId, | |
| 3289 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3290 scoped_ptr<SpdyFrame> req( | 3510 scoped_ptr<SpdyFrame> req( |
| 3291 spdy_util_.ConstructSpdyPost( | 3511 spdy_util_.ConstructSpdyPost( |
| 3292 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); | 3512 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); |
| 3293 scoped_ptr<SpdyFrame> body( | 3513 scoped_ptr<SpdyFrame> body( |
| 3294 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, true)); | 3514 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, true)); |
| 3295 MockWrite writes[] = { | 3515 MockWrite writes[] = { |
| 3296 CreateMockWrite(*initial_window_update, 0), | 3516 CreateMockWrite(*req, 0), |
| 3297 CreateMockWrite(*req, 1), | 3517 CreateMockWrite(*body, 1), |
| 3298 CreateMockWrite(*body, 2), | |
| 3299 }; | 3518 }; |
| 3300 | 3519 |
| 3301 scoped_ptr<SpdyFrame> resp( | 3520 scoped_ptr<SpdyFrame> resp( |
| 3302 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3521 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3303 scoped_ptr<SpdyFrame> echo( | 3522 scoped_ptr<SpdyFrame> echo( |
| 3304 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, false)); | 3523 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, false)); |
| 3305 MockRead reads[] = { | 3524 MockRead reads[] = { |
| 3306 CreateMockRead(*resp, 3), | 3525 CreateMockRead(*resp, 2), |
| 3307 MockRead(ASYNC, 0, 0, 4), // EOF | 3526 MockRead(ASYNC, 0, 0, 3), // EOF |
| 3308 }; | 3527 }; |
| 3309 | 3528 |
| 3310 DeterministicSocketData data(reads, arraysize(reads), | 3529 DeterministicSocketData data(reads, arraysize(reads), |
| 3311 writes, arraysize(writes)); | 3530 writes, arraysize(writes)); |
| 3312 MockConnect connect_data(SYNCHRONOUS, OK); | 3531 MockConnect connect_data(SYNCHRONOUS, OK); |
| 3313 data.set_connect_data(connect_data); | 3532 data.set_connect_data(connect_data); |
| 3314 | 3533 |
| 3315 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3534 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3316 | 3535 |
| 3317 CreateDeterministicNetworkSession(); | 3536 CreateDeterministicNetworkSession(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 3334 | 3553 |
| 3335 scoped_ptr<SpdyHeaderBlock> headers( | 3554 scoped_ptr<SpdyHeaderBlock> headers( |
| 3336 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 3555 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
| 3337 EXPECT_EQ(ERR_IO_PENDING, | 3556 EXPECT_EQ(ERR_IO_PENDING, |
| 3338 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); | 3557 stream->SendRequestHeaders(headers.Pass(), MORE_DATA_TO_SEND)); |
| 3339 EXPECT_TRUE(stream->HasUrl()); | 3558 EXPECT_TRUE(stream->HasUrl()); |
| 3340 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 3559 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
| 3341 | 3560 |
| 3342 stall_fn.Run(session.get(), stream.get()); | 3561 stall_fn.Run(session.get(), stream.get()); |
| 3343 | 3562 |
| 3344 data.RunFor(2); | 3563 data.RunFor(1); |
| 3345 | 3564 |
| 3346 EXPECT_TRUE(stream->send_stalled_by_flow_control()); | 3565 EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
| 3347 | 3566 |
| 3348 unstall_function.Run(session.get(), stream.get(), kBodyDataSize); | 3567 unstall_function.Run(session.get(), stream.get(), kBodyDataSize); |
| 3349 | 3568 |
| 3350 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 3569 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
| 3351 | 3570 |
| 3352 data.RunFor(3); | 3571 data.RunFor(3); |
| 3353 | 3572 |
| 3354 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 3573 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3436 // increased. | 3655 // increased. |
| 3437 TEST_P(SpdySessionTest, ResumeByPriorityAfterSendWindowSizeIncrease) { | 3656 TEST_P(SpdySessionTest, ResumeByPriorityAfterSendWindowSizeIncrease) { |
| 3438 if (GetParam() < kProtoSPDY31) | 3657 if (GetParam() < kProtoSPDY31) |
| 3439 return; | 3658 return; |
| 3440 | 3659 |
| 3441 const char kStreamUrl[] = "http://www.google.com/"; | 3660 const char kStreamUrl[] = "http://www.google.com/"; |
| 3442 GURL url(kStreamUrl); | 3661 GURL url(kStreamUrl); |
| 3443 | 3662 |
| 3444 session_deps_.host_resolver->set_synchronous_mode(true); | 3663 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3445 | 3664 |
| 3446 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3447 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3448 kSessionFlowControlStreamId, | |
| 3449 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3450 scoped_ptr<SpdyFrame> req1( | 3665 scoped_ptr<SpdyFrame> req1( |
| 3451 spdy_util_.ConstructSpdyPost( | 3666 spdy_util_.ConstructSpdyPost( |
| 3452 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); | 3667 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); |
| 3453 scoped_ptr<SpdyFrame> req2( | 3668 scoped_ptr<SpdyFrame> req2( |
| 3454 spdy_util_.ConstructSpdyPost( | 3669 spdy_util_.ConstructSpdyPost( |
| 3455 kStreamUrl, 3, kBodyDataSize, MEDIUM, NULL, 0)); | 3670 kStreamUrl, 3, kBodyDataSize, MEDIUM, NULL, 0)); |
| 3456 scoped_ptr<SpdyFrame> body1( | 3671 scoped_ptr<SpdyFrame> body1( |
| 3457 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, true)); | 3672 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, true)); |
| 3458 scoped_ptr<SpdyFrame> body2( | 3673 scoped_ptr<SpdyFrame> body2( |
| 3459 spdy_util_.ConstructSpdyBodyFrame(3, kBodyData, kBodyDataSize, true)); | 3674 spdy_util_.ConstructSpdyBodyFrame(3, kBodyData, kBodyDataSize, true)); |
| 3460 MockWrite writes[] = { | 3675 MockWrite writes[] = { |
| 3461 CreateMockWrite(*initial_window_update, 0), | 3676 CreateMockWrite(*req1, 0), |
| 3462 CreateMockWrite(*req1, 1), | 3677 CreateMockWrite(*req2, 1), |
| 3463 CreateMockWrite(*req2, 2), | 3678 CreateMockWrite(*body2, 2), |
| 3464 CreateMockWrite(*body2, 3), | 3679 CreateMockWrite(*body1, 3), |
| 3465 CreateMockWrite(*body1, 4), | |
| 3466 }; | 3680 }; |
| 3467 | 3681 |
| 3468 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3682 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3469 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 3683 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 3470 MockRead reads[] = { | 3684 MockRead reads[] = { |
| 3471 CreateMockRead(*resp1, 5), | 3685 CreateMockRead(*resp1, 4), |
| 3472 CreateMockRead(*resp2, 6), | 3686 CreateMockRead(*resp2, 5), |
| 3473 MockRead(ASYNC, 0, 0, 7), // EOF | 3687 MockRead(ASYNC, 0, 0, 6), // EOF |
| 3474 }; | 3688 }; |
| 3475 | 3689 |
| 3476 DeterministicSocketData data(reads, arraysize(reads), | 3690 DeterministicSocketData data(reads, arraysize(reads), |
| 3477 writes, arraysize(writes)); | 3691 writes, arraysize(writes)); |
| 3478 MockConnect connect_data(SYNCHRONOUS, OK); | 3692 MockConnect connect_data(SYNCHRONOUS, OK); |
| 3479 data.set_connect_data(connect_data); | 3693 data.set_connect_data(connect_data); |
| 3480 | 3694 |
| 3481 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3695 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3482 | 3696 |
| 3483 CreateDeterministicNetworkSession(); | 3697 CreateDeterministicNetworkSession(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 3512 | 3726 |
| 3513 StallSessionSend(session.get()); | 3727 StallSessionSend(session.get()); |
| 3514 | 3728 |
| 3515 scoped_ptr<SpdyHeaderBlock> headers1( | 3729 scoped_ptr<SpdyHeaderBlock> headers1( |
| 3516 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 3730 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
| 3517 EXPECT_EQ(ERR_IO_PENDING, | 3731 EXPECT_EQ(ERR_IO_PENDING, |
| 3518 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); | 3732 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); |
| 3519 EXPECT_TRUE(stream1->HasUrl()); | 3733 EXPECT_TRUE(stream1->HasUrl()); |
| 3520 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); | 3734 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); |
| 3521 | 3735 |
| 3522 data.RunFor(2); | 3736 data.RunFor(1); |
| 3523 EXPECT_EQ(1u, stream1->stream_id()); | 3737 EXPECT_EQ(1u, stream1->stream_id()); |
| 3524 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3738 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3525 | 3739 |
| 3526 scoped_ptr<SpdyHeaderBlock> headers2( | 3740 scoped_ptr<SpdyHeaderBlock> headers2( |
| 3527 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 3741 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
| 3528 EXPECT_EQ(ERR_IO_PENDING, | 3742 EXPECT_EQ(ERR_IO_PENDING, |
| 3529 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); | 3743 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); |
| 3530 EXPECT_TRUE(stream2->HasUrl()); | 3744 EXPECT_TRUE(stream2->HasUrl()); |
| 3531 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); | 3745 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); |
| 3532 | 3746 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 3555 | 3769 |
| 3556 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 3770 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
| 3557 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 3771 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
| 3558 | 3772 |
| 3559 EXPECT_TRUE(delegate1.send_headers_completed()); | 3773 EXPECT_TRUE(delegate1.send_headers_completed()); |
| 3560 EXPECT_EQ("200", delegate1.GetResponseHeaderValue(":status")); | 3774 EXPECT_EQ("200", delegate1.GetResponseHeaderValue(":status")); |
| 3561 EXPECT_EQ("HTTP/1.1", delegate1.GetResponseHeaderValue(":version")); | 3775 EXPECT_EQ("HTTP/1.1", delegate1.GetResponseHeaderValue(":version")); |
| 3562 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 3776 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
| 3563 | 3777 |
| 3564 EXPECT_TRUE(delegate2.send_headers_completed()); | 3778 EXPECT_TRUE(delegate2.send_headers_completed()); |
| 3565 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | |
| 3566 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | |
| 3567 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | |
| 3568 | |
| 3569 EXPECT_TRUE(data.at_write_eof()); | |
| 3570 } | |
| 3571 | |
| 3572 // Delegate that closes a given stream after sending its body. | |
| 3573 class StreamClosingDelegate : public test::StreamDelegateWithBody { | |
| 3574 public: | |
| 3575 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | |
| 3576 base::StringPiece data) | |
| 3577 : StreamDelegateWithBody(stream, data) {} | |
| 3578 | |
| 3579 virtual ~StreamClosingDelegate() {} | |
| 3580 | |
| 3581 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { | |
| 3582 stream_to_close_ = stream_to_close; | |
| 3583 } | |
| 3584 | |
| 3585 virtual void OnDataSent() OVERRIDE { | |
| 3586 test::StreamDelegateWithBody::OnDataSent(); | |
| 3587 if (stream_to_close_.get()) { | |
| 3588 stream_to_close_->Close(); | |
| 3589 EXPECT_EQ(NULL, stream_to_close_.get()); | |
| 3590 } | |
| 3591 } | |
| 3592 | |
| 3593 private: | |
| 3594 base::WeakPtr<SpdyStream> stream_to_close_; | |
| 3595 }; | |
| 3596 | |
| 3597 // Cause a stall by reducing the flow control send window to | |
| 3598 // 0. Unstalling the session should properly handle deleted streams. | |
| 3599 TEST_P(SpdySessionTest, SendWindowSizeIncreaseWithDeletedStreams) { | |
| 3600 if (GetParam() < kProtoSPDY31) | |
| 3601 return; | |
| 3602 | |
| 3603 const char kStreamUrl[] = "http://www.google.com/"; | |
| 3604 GURL url(kStreamUrl); | |
| 3605 | |
| 3606 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 3607 | |
| 3608 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3609 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3610 kSessionFlowControlStreamId, | |
| 3611 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3612 scoped_ptr<SpdyFrame> req1( | |
| 3613 spdy_util_.ConstructSpdyPost( | |
| 3614 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3615 scoped_ptr<SpdyFrame> req2( | |
| 3616 spdy_util_.ConstructSpdyPost( | |
| 3617 kStreamUrl, 3, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3618 scoped_ptr<SpdyFrame> req3( | |
| 3619 spdy_util_.ConstructSpdyPost( | |
| 3620 kStreamUrl, 5, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3621 scoped_ptr<SpdyFrame> body2( | |
| 3622 spdy_util_.ConstructSpdyBodyFrame(3, kBodyData, kBodyDataSize, true)); | |
| 3623 MockWrite writes[] = { | |
| 3624 CreateMockWrite(*initial_window_update, 0), | |
| 3625 CreateMockWrite(*req1, 1), | |
| 3626 CreateMockWrite(*req2, 2), | |
| 3627 CreateMockWrite(*req3, 3), | |
| 3628 CreateMockWrite(*body2, 4), | |
| 3629 }; | |
| 3630 | |
| 3631 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | |
| 3632 MockRead reads[] = { | |
| 3633 CreateMockRead(*resp2, 5), | |
| 3634 MockRead(ASYNC, 0, 0, 6), // EOF | |
| 3635 }; | |
| 3636 | |
| 3637 DeterministicSocketData data(reads, arraysize(reads), | |
| 3638 writes, arraysize(writes)); | |
| 3639 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 3640 data.set_connect_data(connect_data); | |
| 3641 | |
| 3642 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | |
| 3643 | |
| 3644 CreateDeterministicNetworkSession(); | |
| 3645 scoped_refptr<SpdySession> session = GetSession(key_); | |
| 3646 InitializeSession( | |
| 3647 http_session_.get(), session.get(), test_host_port_pair_); | |
| 3648 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | |
| 3649 session->flow_control_state()); | |
| 3650 | |
| 3651 base::WeakPtr<SpdyStream> stream1 = | |
| 3652 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 3653 session, url, LOWEST, BoundNetLog()); | |
| 3654 ASSERT_TRUE(stream1.get() != NULL); | |
| 3655 | |
| 3656 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); | |
| 3657 stream1->SetDelegate(&delegate1); | |
| 3658 | |
| 3659 EXPECT_FALSE(stream1->HasUrl()); | |
| 3660 | |
| 3661 base::WeakPtr<SpdyStream> stream2 = | |
| 3662 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 3663 session, url, LOWEST, BoundNetLog()); | |
| 3664 ASSERT_TRUE(stream2.get() != NULL); | |
| 3665 | |
| 3666 StreamClosingDelegate delegate2(stream2, kBodyDataStringPiece); | |
| 3667 stream2->SetDelegate(&delegate2); | |
| 3668 | |
| 3669 EXPECT_FALSE(stream2->HasUrl()); | |
| 3670 | |
| 3671 base::WeakPtr<SpdyStream> stream3 = | |
| 3672 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 3673 session, url, LOWEST, BoundNetLog()); | |
| 3674 ASSERT_TRUE(stream3.get() != NULL); | |
| 3675 | |
| 3676 test::StreamDelegateWithBody delegate3(stream3, kBodyDataStringPiece); | |
| 3677 stream3->SetDelegate(&delegate3); | |
| 3678 | |
| 3679 EXPECT_FALSE(stream3->HasUrl()); | |
| 3680 | |
| 3681 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | |
| 3682 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | |
| 3683 EXPECT_FALSE(stream3->send_stalled_by_flow_control()); | |
| 3684 | |
| 3685 StallSessionSend(session.get()); | |
| 3686 | |
| 3687 scoped_ptr<SpdyHeaderBlock> headers1( | |
| 3688 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 3689 EXPECT_EQ(ERR_IO_PENDING, | |
| 3690 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); | |
| 3691 EXPECT_TRUE(stream1->HasUrl()); | |
| 3692 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); | |
| 3693 | |
| 3694 data.RunFor(2); | |
| 3695 EXPECT_EQ(1u, stream1->stream_id()); | |
| 3696 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | |
| 3697 | |
| 3698 scoped_ptr<SpdyHeaderBlock> headers2( | |
| 3699 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 3700 EXPECT_EQ(ERR_IO_PENDING, | |
| 3701 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); | |
| 3702 EXPECT_TRUE(stream2->HasUrl()); | |
| 3703 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); | |
| 3704 | |
| 3705 data.RunFor(1); | |
| 3706 EXPECT_EQ(3u, stream2->stream_id()); | |
| 3707 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | |
| 3708 | |
| 3709 scoped_ptr<SpdyHeaderBlock> headers3( | |
| 3710 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 3711 EXPECT_EQ(ERR_IO_PENDING, | |
| 3712 stream3->SendRequestHeaders(headers3.Pass(), MORE_DATA_TO_SEND)); | |
| 3713 EXPECT_TRUE(stream3->HasUrl()); | |
| 3714 EXPECT_EQ(kStreamUrl, stream3->GetUrl().spec()); | |
| 3715 | |
| 3716 data.RunFor(1); | |
| 3717 EXPECT_EQ(5u, stream3->stream_id()); | |
| 3718 EXPECT_TRUE(stream3->send_stalled_by_flow_control()); | |
| 3719 | |
| 3720 SpdyStreamId stream_id1 = stream1->stream_id(); | |
| 3721 SpdyStreamId stream_id2 = stream2->stream_id(); | |
| 3722 SpdyStreamId stream_id3 = stream3->stream_id(); | |
| 3723 | |
| 3724 // Close stream1 preemptively. | |
| 3725 session->CloseActiveStream(stream_id1, ERR_CONNECTION_CLOSED); | |
| 3726 EXPECT_EQ(NULL, stream1.get()); | |
| 3727 | |
| 3728 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | |
| 3729 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | |
| 3730 EXPECT_TRUE(session->IsStreamActive(stream_id3)); | |
| 3731 | |
| 3732 // Unstall stream2, which should then close stream3. | |
| 3733 delegate2.set_stream_to_close(stream3); | |
| 3734 UnstallSessionSend(session.get(), kBodyDataSize); | |
| 3735 | |
| 3736 data.RunFor(1); | |
| 3737 EXPECT_EQ(NULL, stream3.get()); | |
| 3738 | |
| 3739 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | |
| 3740 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | |
| 3741 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | |
| 3742 EXPECT_FALSE(session->IsStreamActive(stream_id3)); | |
| 3743 | |
| 3744 data.RunFor(2); | |
| 3745 EXPECT_EQ(NULL, stream2.get()); | |
| 3746 | |
| 3747 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | |
| 3748 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | |
| 3749 EXPECT_EQ(OK, delegate3.WaitForClose()); | |
| 3750 | |
| 3751 EXPECT_TRUE(delegate1.send_headers_completed()); | |
| 3752 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | |
| 3753 | |
| 3754 EXPECT_TRUE(delegate2.send_headers_completed()); | |
| 3755 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | 3779 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); |
| 3756 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | 3780 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); |
| 3757 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3781 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
| 3758 | 3782 |
| 3759 EXPECT_TRUE(delegate3.send_headers_completed()); | |
| 3760 EXPECT_EQ(std::string(), delegate3.TakeReceivedData()); | |
| 3761 | |
| 3762 EXPECT_TRUE(data.at_write_eof()); | 3783 EXPECT_TRUE(data.at_write_eof()); |
| 3763 } | 3784 } |
| 3764 | 3785 |
| 3786 // Delegate that closes a given stream after sending its body. | |
| 3787 class StreamClosingDelegate : public test::StreamDelegateWithBody { | |
| 3788 public: | |
| 3789 StreamClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | |
| 3790 base::StringPiece data) | |
| 3791 : StreamDelegateWithBody(stream, data) {} | |
| 3792 | |
| 3793 virtual ~StreamClosingDelegate() {} | |
| 3794 | |
| 3795 void set_stream_to_close(const base::WeakPtr<SpdyStream>& stream_to_close) { | |
| 3796 stream_to_close_ = stream_to_close; | |
| 3797 } | |
| 3798 | |
| 3799 virtual void OnDataSent() OVERRIDE { | |
| 3800 test::StreamDelegateWithBody::OnDataSent(); | |
| 3801 if (stream_to_close_.get()) { | |
| 3802 stream_to_close_->Close(); | |
| 3803 EXPECT_EQ(NULL, stream_to_close_.get()); | |
| 3804 } | |
| 3805 } | |
| 3806 | |
| 3807 private: | |
| 3808 base::WeakPtr<SpdyStream> stream_to_close_; | |
| 3809 }; | |
| 3810 | |
| 3765 // Cause a stall by reducing the flow control send window to | 3811 // Cause a stall by reducing the flow control send window to |
| 3766 // 0. Unstalling the session should properly handle the session itself | 3812 // 0. Unstalling the session should properly handle deleted streams. |
| 3767 // being closed. | 3813 TEST_P(SpdySessionTest, SendWindowSizeIncreaseWithDeletedStreams) { |
| 3768 TEST_P(SpdySessionTest, SendWindowSizeIncreaseWithDeletedSession) { | |
| 3769 if (GetParam() < kProtoSPDY31) | 3814 if (GetParam() < kProtoSPDY31) |
| 3770 return; | 3815 return; |
| 3771 | 3816 |
| 3772 const char kStreamUrl[] = "http://www.google.com/"; | 3817 const char kStreamUrl[] = "http://www.google.com/"; |
| 3773 GURL url(kStreamUrl); | 3818 GURL url(kStreamUrl); |
| 3774 | 3819 |
| 3775 session_deps_.host_resolver->set_synchronous_mode(true); | 3820 session_deps_.host_resolver->set_synchronous_mode(true); |
| 3776 | 3821 |
| 3777 scoped_ptr<SpdyFrame> initial_window_update( | |
| 3778 spdy_util_.ConstructSpdyWindowUpdate( | |
| 3779 kSessionFlowControlStreamId, | |
| 3780 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | |
| 3781 scoped_ptr<SpdyFrame> req1( | 3822 scoped_ptr<SpdyFrame> req1( |
| 3782 spdy_util_.ConstructSpdyPost( | 3823 spdy_util_.ConstructSpdyPost( |
| 3783 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); | 3824 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); |
| 3784 scoped_ptr<SpdyFrame> req2( | 3825 scoped_ptr<SpdyFrame> req2( |
| 3785 spdy_util_.ConstructSpdyPost( | 3826 spdy_util_.ConstructSpdyPost( |
| 3786 kStreamUrl, 3, kBodyDataSize, LOWEST, NULL, 0)); | 3827 kStreamUrl, 3, kBodyDataSize, LOWEST, NULL, 0)); |
| 3787 scoped_ptr<SpdyFrame> body1( | 3828 scoped_ptr<SpdyFrame> req3( |
| 3788 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, false)); | 3829 spdy_util_.ConstructSpdyPost( |
| 3830 kStreamUrl, 5, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3831 scoped_ptr<SpdyFrame> body2( | |
| 3832 spdy_util_.ConstructSpdyBodyFrame(3, kBodyData, kBodyDataSize, true)); | |
| 3789 MockWrite writes[] = { | 3833 MockWrite writes[] = { |
| 3790 CreateMockWrite(*initial_window_update, 0), | 3834 CreateMockWrite(*req1, 0), |
| 3791 CreateMockWrite(*req1, 1), | 3835 CreateMockWrite(*req2, 1), |
| 3792 CreateMockWrite(*req2, 2), | 3836 CreateMockWrite(*req3, 2), |
| 3837 CreateMockWrite(*body2, 3), | |
| 3793 }; | 3838 }; |
| 3794 | 3839 |
| 3840 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | |
| 3795 MockRead reads[] = { | 3841 MockRead reads[] = { |
| 3796 MockRead(ASYNC, 0, 0, 3), // EOF | 3842 CreateMockRead(*resp2, 4), |
| 3843 MockRead(ASYNC, 0, 0, 5), // EOF | |
| 3797 }; | 3844 }; |
| 3798 | 3845 |
| 3799 DeterministicSocketData data(reads, arraysize(reads), | 3846 DeterministicSocketData data(reads, arraysize(reads), |
| 3800 writes, arraysize(writes)); | 3847 writes, arraysize(writes)); |
| 3801 MockConnect connect_data(SYNCHRONOUS, OK); | 3848 MockConnect connect_data(SYNCHRONOUS, OK); |
| 3802 data.set_connect_data(connect_data); | 3849 data.set_connect_data(connect_data); |
| 3803 | 3850 |
| 3804 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 3851 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 3805 | 3852 |
| 3806 CreateDeterministicNetworkSession(); | 3853 CreateDeterministicNetworkSession(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 3818 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); | 3865 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); |
| 3819 stream1->SetDelegate(&delegate1); | 3866 stream1->SetDelegate(&delegate1); |
| 3820 | 3867 |
| 3821 EXPECT_FALSE(stream1->HasUrl()); | 3868 EXPECT_FALSE(stream1->HasUrl()); |
| 3822 | 3869 |
| 3823 base::WeakPtr<SpdyStream> stream2 = | 3870 base::WeakPtr<SpdyStream> stream2 = |
| 3824 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | 3871 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, |
| 3825 session, url, LOWEST, BoundNetLog()); | 3872 session, url, LOWEST, BoundNetLog()); |
| 3826 ASSERT_TRUE(stream2.get() != NULL); | 3873 ASSERT_TRUE(stream2.get() != NULL); |
| 3827 | 3874 |
| 3828 test::StreamDelegateWithBody delegate2(stream2, kBodyDataStringPiece); | 3875 StreamClosingDelegate delegate2(stream2, kBodyDataStringPiece); |
| 3829 stream2->SetDelegate(&delegate2); | 3876 stream2->SetDelegate(&delegate2); |
| 3830 | 3877 |
| 3831 EXPECT_FALSE(stream2->HasUrl()); | 3878 EXPECT_FALSE(stream2->HasUrl()); |
| 3832 | 3879 |
| 3880 base::WeakPtr<SpdyStream> stream3 = | |
| 3881 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 3882 session, url, LOWEST, BoundNetLog()); | |
| 3883 ASSERT_TRUE(stream3.get() != NULL); | |
| 3884 | |
| 3885 test::StreamDelegateWithBody delegate3(stream3, kBodyDataStringPiece); | |
| 3886 stream3->SetDelegate(&delegate3); | |
| 3887 | |
| 3888 EXPECT_FALSE(stream3->HasUrl()); | |
| 3889 | |
| 3833 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | 3890 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); |
| 3834 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | 3891 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); |
| 3892 EXPECT_FALSE(stream3->send_stalled_by_flow_control()); | |
| 3835 | 3893 |
| 3836 StallSessionSend(session.get()); | 3894 StallSessionSend(session.get()); |
| 3837 | 3895 |
| 3838 scoped_ptr<SpdyHeaderBlock> headers1( | 3896 scoped_ptr<SpdyHeaderBlock> headers1( |
| 3839 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 3897 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
| 3840 EXPECT_EQ(ERR_IO_PENDING, | 3898 EXPECT_EQ(ERR_IO_PENDING, |
| 3841 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); | 3899 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); |
| 3842 EXPECT_TRUE(stream1->HasUrl()); | 3900 EXPECT_TRUE(stream1->HasUrl()); |
| 3843 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); | 3901 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); |
| 3844 | 3902 |
| 3845 data.RunFor(2); | 3903 data.RunFor(1); |
| 3846 EXPECT_EQ(1u, stream1->stream_id()); | 3904 EXPECT_EQ(1u, stream1->stream_id()); |
| 3847 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | 3905 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); |
| 3848 | 3906 |
| 3849 scoped_ptr<SpdyHeaderBlock> headers2( | 3907 scoped_ptr<SpdyHeaderBlock> headers2( |
| 3850 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 3908 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
| 3851 EXPECT_EQ(ERR_IO_PENDING, | 3909 EXPECT_EQ(ERR_IO_PENDING, |
| 3852 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); | 3910 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); |
| 3853 EXPECT_TRUE(stream2->HasUrl()); | 3911 EXPECT_TRUE(stream2->HasUrl()); |
| 3854 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); | 3912 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); |
| 3855 | 3913 |
| 3856 data.RunFor(1); | 3914 data.RunFor(1); |
| 3857 EXPECT_EQ(3u, stream2->stream_id()); | 3915 EXPECT_EQ(3u, stream2->stream_id()); |
| 3858 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | 3916 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); |
| 3859 | 3917 |
| 3918 scoped_ptr<SpdyHeaderBlock> headers3( | |
| 3919 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 3920 EXPECT_EQ(ERR_IO_PENDING, | |
| 3921 stream3->SendRequestHeaders(headers3.Pass(), MORE_DATA_TO_SEND)); | |
| 3922 EXPECT_TRUE(stream3->HasUrl()); | |
| 3923 EXPECT_EQ(kStreamUrl, stream3->GetUrl().spec()); | |
| 3924 | |
| 3925 data.RunFor(1); | |
| 3926 EXPECT_EQ(5u, stream3->stream_id()); | |
| 3927 EXPECT_TRUE(stream3->send_stalled_by_flow_control()); | |
| 3928 | |
| 3929 SpdyStreamId stream_id1 = stream1->stream_id(); | |
| 3930 SpdyStreamId stream_id2 = stream2->stream_id(); | |
| 3931 SpdyStreamId stream_id3 = stream3->stream_id(); | |
| 3932 | |
| 3933 // Close stream1 preemptively. | |
| 3934 session->CloseActiveStream(stream_id1, ERR_CONNECTION_CLOSED); | |
| 3935 EXPECT_EQ(NULL, stream1.get()); | |
| 3936 | |
| 3937 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | |
| 3938 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | |
| 3939 EXPECT_TRUE(session->IsStreamActive(stream_id3)); | |
| 3940 | |
| 3941 // Unstall stream2, which should then close stream3. | |
| 3942 delegate2.set_stream_to_close(stream3); | |
| 3943 UnstallSessionSend(session.get(), kBodyDataSize); | |
| 3944 | |
| 3945 data.RunFor(1); | |
| 3946 EXPECT_EQ(NULL, stream3.get()); | |
| 3947 | |
| 3948 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | |
| 3949 EXPECT_FALSE(session->IsStreamActive(stream_id1)); | |
| 3950 EXPECT_TRUE(session->IsStreamActive(stream_id2)); | |
| 3951 EXPECT_FALSE(session->IsStreamActive(stream_id3)); | |
| 3952 | |
| 3953 data.RunFor(2); | |
| 3954 EXPECT_EQ(NULL, stream2.get()); | |
| 3955 | |
| 3956 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | |
| 3957 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | |
| 3958 EXPECT_EQ(OK, delegate3.WaitForClose()); | |
| 3959 | |
| 3960 EXPECT_TRUE(delegate1.send_headers_completed()); | |
| 3961 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | |
| 3962 | |
| 3963 EXPECT_TRUE(delegate2.send_headers_completed()); | |
| 3964 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | |
| 3965 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | |
| 3966 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | |
| 3967 | |
| 3968 EXPECT_TRUE(delegate3.send_headers_completed()); | |
| 3969 EXPECT_EQ(std::string(), delegate3.TakeReceivedData()); | |
| 3970 | |
| 3971 EXPECT_TRUE(data.at_write_eof()); | |
| 3972 } | |
| 3973 | |
| 3974 // Cause a stall by reducing the flow control send window to | |
| 3975 // 0. Unstalling the session should properly handle the session itself | |
| 3976 // being closed. | |
| 3977 TEST_P(SpdySessionTest, SendWindowSizeIncreaseWithDeletedSession) { | |
| 3978 if (GetParam() < kProtoSPDY31) | |
| 3979 return; | |
| 3980 | |
| 3981 const char kStreamUrl[] = "http://www.google.com/"; | |
| 3982 GURL url(kStreamUrl); | |
| 3983 | |
| 3984 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 3985 | |
| 3986 scoped_ptr<SpdyFrame> req1( | |
| 3987 spdy_util_.ConstructSpdyPost( | |
| 3988 kStreamUrl, 1, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3989 scoped_ptr<SpdyFrame> req2( | |
| 3990 spdy_util_.ConstructSpdyPost( | |
| 3991 kStreamUrl, 3, kBodyDataSize, LOWEST, NULL, 0)); | |
| 3992 scoped_ptr<SpdyFrame> body1( | |
| 3993 spdy_util_.ConstructSpdyBodyFrame(1, kBodyData, kBodyDataSize, false)); | |
| 3994 MockWrite writes[] = { | |
| 3995 CreateMockWrite(*req1, 0), | |
| 3996 CreateMockWrite(*req2, 1), | |
| 3997 }; | |
| 3998 | |
| 3999 MockRead reads[] = { | |
| 4000 MockRead(ASYNC, 0, 0, 2), // EOF | |
| 4001 }; | |
| 4002 | |
| 4003 DeterministicSocketData data(reads, arraysize(reads), | |
| 4004 writes, arraysize(writes)); | |
| 4005 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 4006 data.set_connect_data(connect_data); | |
| 4007 | |
| 4008 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | |
| 4009 | |
| 4010 CreateDeterministicNetworkSession(); | |
| 4011 scoped_refptr<SpdySession> session = GetSession(key_); | |
| 4012 InitializeSession( | |
| 4013 http_session_.get(), session.get(), test_host_port_pair_); | |
| 4014 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, | |
| 4015 session->flow_control_state()); | |
| 4016 | |
| 4017 base::WeakPtr<SpdyStream> stream1 = | |
| 4018 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 4019 session, url, LOWEST, BoundNetLog()); | |
| 4020 ASSERT_TRUE(stream1.get() != NULL); | |
| 4021 | |
| 4022 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); | |
| 4023 stream1->SetDelegate(&delegate1); | |
| 4024 | |
| 4025 EXPECT_FALSE(stream1->HasUrl()); | |
| 4026 | |
| 4027 base::WeakPtr<SpdyStream> stream2 = | |
| 4028 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 4029 session, url, LOWEST, BoundNetLog()); | |
| 4030 ASSERT_TRUE(stream2.get() != NULL); | |
| 4031 | |
| 4032 test::StreamDelegateWithBody delegate2(stream2, kBodyDataStringPiece); | |
| 4033 stream2->SetDelegate(&delegate2); | |
| 4034 | |
| 4035 EXPECT_FALSE(stream2->HasUrl()); | |
| 4036 | |
| 4037 EXPECT_FALSE(stream1->send_stalled_by_flow_control()); | |
| 4038 EXPECT_FALSE(stream2->send_stalled_by_flow_control()); | |
| 4039 | |
| 4040 StallSessionSend(session.get()); | |
| 4041 | |
| 4042 scoped_ptr<SpdyHeaderBlock> headers1( | |
| 4043 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 4044 EXPECT_EQ(ERR_IO_PENDING, | |
| 4045 stream1->SendRequestHeaders(headers1.Pass(), MORE_DATA_TO_SEND)); | |
| 4046 EXPECT_TRUE(stream1->HasUrl()); | |
| 4047 EXPECT_EQ(kStreamUrl, stream1->GetUrl().spec()); | |
| 4048 | |
| 4049 data.RunFor(1); | |
| 4050 EXPECT_EQ(1u, stream1->stream_id()); | |
| 4051 EXPECT_TRUE(stream1->send_stalled_by_flow_control()); | |
| 4052 | |
| 4053 scoped_ptr<SpdyHeaderBlock> headers2( | |
| 4054 spdy_util_.ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | |
| 4055 EXPECT_EQ(ERR_IO_PENDING, | |
| 4056 stream2->SendRequestHeaders(headers2.Pass(), MORE_DATA_TO_SEND)); | |
| 4057 EXPECT_TRUE(stream2->HasUrl()); | |
| 4058 EXPECT_EQ(kStreamUrl, stream2->GetUrl().spec()); | |
| 4059 | |
| 4060 data.RunFor(1); | |
| 4061 EXPECT_EQ(3u, stream2->stream_id()); | |
| 4062 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | |
| 4063 | |
| 3860 EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); | 4064 EXPECT_TRUE(spdy_session_pool_->HasSession(key_)); |
| 3861 | 4065 |
| 3862 // Unstall stream1. | 4066 // Unstall stream1. |
| 3863 UnstallSessionSend(session.get(), kBodyDataSize); | 4067 UnstallSessionSend(session.get(), kBodyDataSize); |
| 3864 | 4068 |
| 3865 // Close the session (since we can't do it from within the delegate | 4069 // Close the session (since we can't do it from within the delegate |
| 3866 // method, since it's in the stream's loop). | 4070 // method, since it's in the stream's loop). |
| 3867 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, true, "Closing session"); | 4071 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, true, "Closing session"); |
| 3868 session = NULL; | 4072 session = NULL; |
| 3869 | 4073 |
| 3870 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); | 4074 EXPECT_FALSE(spdy_session_pool_->HasSession(key_)); |
| 3871 | 4075 |
| 3872 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 4076 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
| 3873 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 4077 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
| 3874 | 4078 |
| 3875 EXPECT_TRUE(delegate1.send_headers_completed()); | 4079 EXPECT_TRUE(delegate1.send_headers_completed()); |
| 3876 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 4080 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
| 3877 | 4081 |
| 3878 EXPECT_TRUE(delegate2.send_headers_completed()); | 4082 EXPECT_TRUE(delegate2.send_headers_completed()); |
| 3879 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 4083 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
| 3880 | 4084 |
| 3881 EXPECT_TRUE(data.at_write_eof()); | 4085 EXPECT_TRUE(data.at_write_eof()); |
| 3882 } | 4086 } |
| 3883 | 4087 |
| 3884 // Tests the case of a non-SPDY request closing an idle SPDY session when no | |
| 3885 // pointers to the idle session are currently held. | |
| 3886 TEST_P(SpdySessionTest, CloseOneIdleConnection) { | |
| 3887 if (GetParam() > kProtoSPDY3) | |
| 3888 return; | |
| 3889 | |
| 3890 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 3891 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 3892 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 3893 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 3894 | |
| 3895 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 3896 MockRead reads[] = { | |
| 3897 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 3898 }; | |
| 3899 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 3900 data.set_connect_data(connect_data); | |
| 3901 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 3902 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 3903 | |
| 3904 CreateNetworkSession(); | |
| 3905 | |
| 3906 TransportClientSocketPool* pool = | |
| 3907 http_session_->GetTransportSocketPool( | |
| 3908 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 3909 | |
| 3910 // Create an idle SPDY session. | |
| 3911 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 3912 kPrivacyModeDisabled); | |
| 3913 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 3914 EXPECT_EQ( | |
| 3915 OK, | |
| 3916 InitializeSession(http_session_.get(), session1.get(), | |
| 3917 key1.host_port_pair())); | |
| 3918 EXPECT_FALSE(pool->IsStalled()); | |
| 3919 // Release the pointer to the session so it can be closed. | |
| 3920 session1 = NULL; | |
| 3921 | |
| 3922 // Trying to create a new connection should cause the pool to be stalled, and | |
| 3923 // post a task asynchronously to try and close the session. | |
| 3924 TestCompletionCallback callback2; | |
| 3925 HostPortPair host_port2("2.com", 80); | |
| 3926 scoped_refptr<TransportSocketParams> params2( | |
| 3927 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 3928 OnHostResolutionCallback())); | |
| 3929 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 3930 EXPECT_EQ(ERR_IO_PENDING, | |
| 3931 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 3932 callback2.callback(), pool, BoundNetLog())); | |
| 3933 EXPECT_TRUE(pool->IsStalled()); | |
| 3934 | |
| 3935 // The socket pool should close the connection asynchronously and establish a | |
| 3936 // new connection. | |
| 3937 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 3938 EXPECT_FALSE(pool->IsStalled()); | |
| 3939 } | |
| 3940 | |
| 3941 // Tests the case of a non-SPDY request closing an idle SPDY session when no | |
| 3942 // pointers to the idle session are currently held, in the case the SPDY session | |
| 3943 // has an alias. | |
| 3944 TEST_P(SpdySessionTest, CloseOneIdleConnectionWithAlias) { | |
| 3945 if (GetParam() > kProtoSPDY3) | |
| 3946 return; | |
| 3947 | |
| 3948 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 3949 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 3950 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 3951 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 3952 | |
| 3953 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 3954 MockRead reads[] = { | |
| 3955 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 3956 }; | |
| 3957 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 3958 data.set_connect_data(connect_data); | |
| 3959 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 3960 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 3961 | |
| 3962 session_deps_.host_resolver->set_synchronous_mode(true); | |
| 3963 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 3964 "1.com", "192.168.0.2", std::string()); | |
| 3965 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 3966 "2.com", "192.168.0.2", std::string()); | |
| 3967 // Not strictly needed. | |
| 3968 session_deps_.host_resolver->rules()->AddIPLiteralRule( | |
| 3969 "3.com", "192.168.0.3", std::string()); | |
| 3970 | |
| 3971 CreateNetworkSession(); | |
| 3972 | |
| 3973 TransportClientSocketPool* pool = | |
| 3974 http_session_->GetTransportSocketPool( | |
| 3975 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 3976 | |
| 3977 // Create an idle SPDY session. | |
| 3978 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 3979 kPrivacyModeDisabled); | |
| 3980 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 3981 EXPECT_EQ( | |
| 3982 OK, | |
| 3983 InitializeSession(http_session_.get(), session1.get(), | |
| 3984 key1.host_port_pair())); | |
| 3985 EXPECT_FALSE(pool->IsStalled()); | |
| 3986 | |
| 3987 // Set up an alias for the idle SPDY session, increasing its ref count to 2. | |
| 3988 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), | |
| 3989 kPrivacyModeDisabled); | |
| 3990 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | |
| 3991 HostResolver::RequestInfo info(key2.host_port_pair()); | |
| 3992 AddressList addresses; | |
| 3993 // Pre-populate the DNS cache, since a synchronous resolution is required in | |
| 3994 // order to create the alias. | |
| 3995 session_deps_.host_resolver->Resolve( | |
| 3996 info, &addresses, CompletionCallback(), NULL, BoundNetLog()); | |
| 3997 // Add the alias for the first session's key. Has to be done manually since | |
| 3998 // the usual process is bypassed. | |
| 3999 pool_peer.AddAlias(addresses.front(), key1); | |
| 4000 // Get a session for |key2|, which should return the session created earlier. | |
| 4001 scoped_refptr<SpdySession> session2 = | |
| 4002 spdy_session_pool_->Get(key2, BoundNetLog()); | |
| 4003 ASSERT_EQ(session1.get(), session2.get()); | |
| 4004 EXPECT_FALSE(pool->IsStalled()); | |
| 4005 | |
| 4006 // Release both the pointers to the session so it can be closed. | |
| 4007 session1 = NULL; | |
| 4008 session2 = NULL; | |
| 4009 | |
| 4010 // Trying to create a new connection should cause the pool to be stalled, and | |
| 4011 // post a task asynchronously to try and close the session. | |
| 4012 TestCompletionCallback callback3; | |
| 4013 HostPortPair host_port3("3.com", 80); | |
| 4014 scoped_refptr<TransportSocketParams> params3( | |
| 4015 new TransportSocketParams(host_port3, DEFAULT_PRIORITY, false, false, | |
| 4016 OnHostResolutionCallback())); | |
| 4017 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle); | |
| 4018 EXPECT_EQ(ERR_IO_PENDING, | |
| 4019 connection3->Init(host_port3.ToString(), params3, DEFAULT_PRIORITY, | |
| 4020 callback3.callback(), pool, BoundNetLog())); | |
| 4021 EXPECT_TRUE(pool->IsStalled()); | |
| 4022 | |
| 4023 // The socket pool should close the connection asynchronously and establish a | |
| 4024 // new connection. | |
| 4025 EXPECT_EQ(OK, callback3.WaitForResult()); | |
| 4026 EXPECT_FALSE(pool->IsStalled()); | |
| 4027 } | |
| 4028 | |
| 4029 // Tests the case of a non-SPDY request closing an idle SPDY session when a | |
| 4030 // pointer to the idle session is still held. | |
| 4031 TEST_P(SpdySessionTest, CloseOneIdleConnectionSessionStillHeld) { | |
| 4032 if (GetParam() > kProtoSPDY3) | |
| 4033 return; | |
| 4034 | |
| 4035 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 4036 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 4037 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 4038 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 4039 | |
| 4040 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 4041 MockRead reads[] = { | |
| 4042 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 4043 }; | |
| 4044 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | |
| 4045 data.set_connect_data(connect_data); | |
| 4046 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4047 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4048 | |
| 4049 CreateNetworkSession(); | |
| 4050 | |
| 4051 TransportClientSocketPool* pool = | |
| 4052 http_session_->GetTransportSocketPool( | |
| 4053 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 4054 | |
| 4055 // Create an idle SPDY session. | |
| 4056 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | |
| 4057 kPrivacyModeDisabled); | |
| 4058 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 4059 EXPECT_EQ( | |
| 4060 OK, | |
| 4061 InitializeSession(http_session_.get(), session1.get(), | |
| 4062 key1.host_port_pair())); | |
| 4063 EXPECT_FALSE(pool->IsStalled()); | |
| 4064 | |
| 4065 // Trying to create a new connection should cause the pool to be stalled, and | |
| 4066 // post a task asynchronously to try and close the session. | |
| 4067 TestCompletionCallback callback2; | |
| 4068 HostPortPair host_port2("2.com", 80); | |
| 4069 scoped_refptr<TransportSocketParams> params2( | |
| 4070 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 4071 OnHostResolutionCallback())); | |
| 4072 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 4073 EXPECT_EQ(ERR_IO_PENDING, | |
| 4074 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 4075 callback2.callback(), pool, BoundNetLog())); | |
| 4076 EXPECT_TRUE(pool->IsStalled()); | |
| 4077 | |
| 4078 // Running the message loop should cause the session to prepare to be closed, | |
| 4079 // but since there's still an outstanding reference, it should not be closed | |
| 4080 // yet. | |
| 4081 base::RunLoop().RunUntilIdle(); | |
| 4082 EXPECT_TRUE(pool->IsStalled()); | |
| 4083 EXPECT_FALSE(callback2.have_result()); | |
| 4084 | |
| 4085 // Release the pointer to the session so it can be closed. | |
| 4086 session1 = NULL; | |
| 4087 EXPECT_EQ(OK, callback2.WaitForResult()); | |
| 4088 EXPECT_FALSE(pool->IsStalled()); | |
| 4089 } | |
| 4090 | |
| 4091 // Tests that a non-SPDY request can't close a SPDY session that's currently in | |
| 4092 // use. | |
| 4093 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) { | |
| 4094 if (GetParam() > kProtoSPDY3) | |
| 4095 return; | |
| 4096 | |
| 4097 ClientSocketPoolManager::set_max_sockets_per_group( | |
| 4098 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 4099 ClientSocketPoolManager::set_max_sockets_per_pool( | |
| 4100 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); | |
| 4101 | |
| 4102 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 4103 MockRead reads[] = { | |
| 4104 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 4105 }; | |
| 4106 scoped_ptr<SpdyFrame> req1( | |
| 4107 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | |
| 4108 scoped_ptr<SpdyFrame> cancel1( | |
| 4109 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | |
| 4110 MockWrite writes[] = { | |
| 4111 CreateMockWrite(*req1, 1), | |
| 4112 CreateMockWrite(*cancel1, 1), | |
| 4113 }; | |
| 4114 StaticSocketDataProvider data(reads, arraysize(reads), | |
| 4115 writes, arraysize(writes)); | |
| 4116 data.set_connect_data(connect_data); | |
| 4117 session_deps_.socket_factory->AddSocketDataProvider(&data); | |
| 4118 | |
| 4119 CreateNetworkSession(); | |
| 4120 | |
| 4121 TransportClientSocketPool* pool = | |
| 4122 http_session_->GetTransportSocketPool( | |
| 4123 HttpNetworkSession::NORMAL_SOCKET_POOL); | |
| 4124 | |
| 4125 // Create a SPDY session. | |
| 4126 GURL url1("http://www.google.com"); | |
| 4127 SpdySessionKey key1(HostPortPair(url1.host(), 80), | |
| 4128 ProxyServer::Direct(), kPrivacyModeDisabled); | |
| 4129 scoped_refptr<SpdySession> session1 = GetSession(key1); | |
| 4130 EXPECT_EQ( | |
| 4131 OK, | |
| 4132 InitializeSession(http_session_.get(), session1.get(), | |
| 4133 key1.host_port_pair())); | |
| 4134 EXPECT_FALSE(pool->IsStalled()); | |
| 4135 | |
| 4136 // Create a stream using the session, and send a request. | |
| 4137 | |
| 4138 TestCompletionCallback callback1; | |
| 4139 base::WeakPtr<SpdyStream> spdy_stream1 = | |
| 4140 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, | |
| 4141 session1, url1, DEFAULT_PRIORITY, | |
| 4142 BoundNetLog()); | |
| 4143 ASSERT_TRUE(spdy_stream1.get()); | |
| 4144 test::StreamDelegateDoNothing delegate1(spdy_stream1); | |
| 4145 spdy_stream1->SetDelegate(&delegate1); | |
| 4146 | |
| 4147 scoped_ptr<SpdyHeaderBlock> headers1( | |
| 4148 spdy_util_.ConstructGetHeaderBlock(url1.spec())); | |
| 4149 EXPECT_EQ(ERR_IO_PENDING, | |
| 4150 spdy_stream1->SendRequestHeaders( | |
| 4151 headers1.Pass(), NO_MORE_DATA_TO_SEND)); | |
| 4152 EXPECT_TRUE(spdy_stream1->HasUrl()); | |
| 4153 | |
| 4154 base::MessageLoop::current()->RunUntilIdle(); | |
| 4155 | |
| 4156 // Release the session, so holding onto a pointer here does not affect | |
| 4157 // anything. | |
| 4158 session1 = NULL; | |
| 4159 | |
| 4160 // Trying to create a new connection should cause the pool to be stalled, and | |
| 4161 // post a task asynchronously to try and close the session. | |
| 4162 TestCompletionCallback callback2; | |
| 4163 HostPortPair host_port2("2.com", 80); | |
| 4164 scoped_refptr<TransportSocketParams> params2( | |
| 4165 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, | |
| 4166 OnHostResolutionCallback())); | |
| 4167 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); | |
| 4168 EXPECT_EQ(ERR_IO_PENDING, | |
| 4169 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, | |
| 4170 callback2.callback(), pool, BoundNetLog())); | |
| 4171 EXPECT_TRUE(pool->IsStalled()); | |
| 4172 | |
| 4173 // Running the message loop should cause the socket pool to ask the SPDY | |
| 4174 // session to close an idle socket, but since the socket is in use, nothing | |
| 4175 // happens. | |
| 4176 base::RunLoop().RunUntilIdle(); | |
| 4177 EXPECT_TRUE(pool->IsStalled()); | |
| 4178 EXPECT_FALSE(callback2.have_result()); | |
| 4179 | |
| 4180 // Cancelling the request should still not release the session's socket, | |
| 4181 // since the session is still kept alive by the SpdySessionPool. | |
| 4182 ASSERT_TRUE(spdy_stream1.get()); | |
| 4183 spdy_stream1->Cancel(); | |
| 4184 base::RunLoop().RunUntilIdle(); | |
| 4185 EXPECT_TRUE(pool->IsStalled()); | |
| 4186 EXPECT_FALSE(callback2.have_result()); | |
| 4187 } | |
| 4188 | |
| 4189 // Verify that SpdySessionKey and therefore SpdySession is different when | |
| 4190 // privacy mode is enabled or disabled. | |
| 4191 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { | |
| 4192 CreateDeterministicNetworkSession(); | |
| 4193 | |
| 4194 HostPortPair host_port_pair("www.google.com", 443); | |
| 4195 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), | |
| 4196 kPrivacyModeEnabled); | |
| 4197 SpdySessionKey key_privacy_disabled(host_port_pair, ProxyServer::Direct(), | |
| 4198 kPrivacyModeDisabled); | |
| 4199 | |
| 4200 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 4201 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 4202 | |
| 4203 // Add SpdySession with PrivacyMode Enabled to the pool. | |
| 4204 scoped_refptr<SpdySession> session_privacy_enabled = | |
| 4205 spdy_session_pool_->Get(key_privacy_enabled, BoundNetLog()); | |
| 4206 | |
| 4207 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 4208 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 4209 | |
| 4210 // Add SpdySession with PrivacyMode Disabled to the pool. | |
| 4211 scoped_refptr<SpdySession> session_privacy_disabled = | |
| 4212 spdy_session_pool_->Get(key_privacy_disabled, BoundNetLog()); | |
| 4213 | |
| 4214 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 4215 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 4216 | |
| 4217 spdy_session_pool_->Remove(session_privacy_enabled); | |
| 4218 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 4219 EXPECT_TRUE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 4220 | |
| 4221 spdy_session_pool_->Remove(session_privacy_disabled); | |
| 4222 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_enabled)); | |
| 4223 EXPECT_FALSE(spdy_session_pool_->HasSession(key_privacy_disabled)); | |
| 4224 } | |
| 4225 | |
| 4226 } // namespace net | 4088 } // namespace net |
| OLD | NEW |