| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_network_transaction.h" | 5 #include "net/spdy/spdy_network_transaction.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/base/completion_callback.h" | 10 #include "net/base/completion_callback.h" |
| 11 #include "net/base/mock_host_resolver.h" | 11 #include "net/base/mock_host_resolver.h" |
| 12 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
| 13 #include "net/base/ssl_config_service_defaults.h" | 13 #include "net/base/ssl_config_service_defaults.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/base/upload_data.h" | 15 #include "net/base/upload_data.h" |
| 16 #include "net/http/http_auth_handler_factory.h" | 16 #include "net/http/http_auth_handler_factory.h" |
| 17 #include "net/http/http_network_session.h" | 17 #include "net/http/http_network_session.h" |
| 18 #include "net/http/http_transaction_unittest.h" | 18 #include "net/http/http_transaction_unittest.h" |
| 19 #include "net/proxy/proxy_config_service_fixed.h" | 19 #include "net/proxy/proxy_config_service_fixed.h" |
| 20 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
| 21 #include "net/spdy/spdy_framer.h" | 21 #include "net/spdy/spdy_framer.h" |
| 22 #include "net/spdy/spdy_protocol.h" | 22 #include "net/spdy/spdy_protocol.h" |
| 23 #include "testing/platform_test.h" | 23 #include "testing/platform_test.h" |
| 24 | 24 |
| 25 #define NET_TRACE(level, s) DLOG(level) << s << __FUNCTION__ << "() " |
| 26 |
| 25 //----------------------------------------------------------------------------- | 27 //----------------------------------------------------------------------------- |
| 26 | 28 |
| 27 namespace net { | 29 namespace net { |
| 28 | 30 |
| 29 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace! | 31 // NOTE: In GCC, on a Mac, this can't be in an anonymous namespace! |
| 30 // This struct holds information used to construct spdy control and data frames. | 32 // This struct holds information used to construct spdy control and data frames. |
| 31 struct SpdyHeaderInfo { | 33 struct SpdyHeaderInfo { |
| 32 int kind; | 34 int kind; |
| 33 spdy::SpdyStreamId id; | 35 spdy::SpdyStreamId id; |
| 34 spdy::SpdyStreamId assoc_id; | 36 spdy::SpdyStreamId assoc_id; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { | 686 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)) { |
| 685 set_connect_data(connect); | 687 set_connect_data(connect); |
| 686 } | 688 } |
| 687 | 689 |
| 688 virtual MockRead GetNextRead() { | 690 virtual MockRead GetNextRead() { |
| 689 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); | 691 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); |
| 690 if (next_read.sequence_number & MockRead::STOPLOOP) | 692 if (next_read.sequence_number & MockRead::STOPLOOP) |
| 691 EndLoop(); | 693 EndLoop(); |
| 692 if ((next_read.sequence_number & ~MockRead::STOPLOOP) <= | 694 if ((next_read.sequence_number & ~MockRead::STOPLOOP) <= |
| 693 sequence_number_++) { | 695 sequence_number_++) { |
| 694 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 696 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 |
| 695 << sequence_number_ - 1 << ": Read " << read_index(); | 697 << ": Read " << read_index(); |
| 696 DumpMockRead(next_read); | 698 DumpMockRead(next_read); |
| 697 return StaticSocketDataProvider::GetNextRead(); | 699 return StaticSocketDataProvider::GetNextRead(); |
| 698 } | 700 } |
| 699 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 701 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ - 1 |
| 700 << sequence_number_ - 1 << ": I/O Pending"; | 702 << ": I/O Pending"; |
| 701 MockRead result = MockRead(true, ERR_IO_PENDING); | 703 MockRead result = MockRead(true, ERR_IO_PENDING); |
| 702 DumpMockRead(result); | 704 DumpMockRead(result); |
| 703 return result; | 705 return result; |
| 704 } | 706 } |
| 705 | 707 |
| 706 virtual MockWriteResult OnWrite(const std::string& data) { | 708 virtual MockWriteResult OnWrite(const std::string& data) { |
| 707 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 709 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 708 << sequence_number_ << ": Write " << write_index(); | 710 << ": Write " << write_index(); |
| 709 DumpMockRead(PeekWrite()); | 711 DumpMockRead(PeekWrite()); |
| 710 ++sequence_number_; | 712 ++sequence_number_; |
| 711 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 713 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 712 factory_.NewRunnableMethod(&OrderedSocketData::CompleteRead), 100); | 714 factory_.NewRunnableMethod(&OrderedSocketData::CompleteRead), 100); |
| 713 return StaticSocketDataProvider::OnWrite(data); | 715 return StaticSocketDataProvider::OnWrite(data); |
| 714 } | 716 } |
| 715 | 717 |
| 716 virtual void Reset() { | 718 virtual void Reset() { |
| 717 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 719 NET_TRACE(INFO, " *** ") << "Stage " |
| 718 << sequence_number_ << ": Reset()"; | 720 << sequence_number_ << ": Reset()"; |
| 719 sequence_number_ = 0; | 721 sequence_number_ = 0; |
| 720 loop_stop_stage_ = 0; | 722 loop_stop_stage_ = 0; |
| 721 set_socket(NULL); | 723 set_socket(NULL); |
| 722 factory_.RevokeAll(); | 724 factory_.RevokeAll(); |
| 723 StaticSocketDataProvider::Reset(); | 725 StaticSocketDataProvider::Reset(); |
| 724 } | 726 } |
| 725 | 727 |
| 726 void SetCompletionCallback(CompletionCallback* callback) { | 728 void SetCompletionCallback(CompletionCallback* callback) { |
| 727 callback_ = callback; | 729 callback_ = callback; |
| 728 } | 730 } |
| 729 | 731 |
| 730 // Posts a quit message to the current message loop, if one is running. | 732 // Posts a quit message to the current message loop, if one is running. |
| 731 void EndLoop() { | 733 void EndLoop() { |
| 732 // If we've already stopped the loop, don't do it again until we've advanced | 734 // If we've already stopped the loop, don't do it again until we've advanced |
| 733 // to the next sequence_number. | 735 // to the next sequence_number. |
| 734 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 736 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ << ": EndLoop()"; |
| 735 << sequence_number_ << ": EndLoop()"; | |
| 736 if (loop_stop_stage_ > 0) { | 737 if (loop_stop_stage_ > 0) { |
| 737 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); | 738 const MockRead& next_read = StaticSocketDataProvider::PeekRead(); |
| 738 if ((next_read.sequence_number & ~MockRead::STOPLOOP) > | 739 if ((next_read.sequence_number & ~MockRead::STOPLOOP) > |
| 739 loop_stop_stage_) { | 740 loop_stop_stage_) { |
| 740 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 741 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 741 << sequence_number_ << ": Clearing stop index"; | 742 << ": Clearing stop index"; |
| 742 loop_stop_stage_ = 0; | 743 loop_stop_stage_ = 0; |
| 743 } else { | 744 } else { |
| 744 return; | 745 return; |
| 745 } | 746 } |
| 746 } | 747 } |
| 747 // Record the sequence_number at which we stopped the loop. | 748 // Record the sequence_number at which we stopped the loop. |
| 748 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 749 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_ |
| 749 << sequence_number_ << ": Posting Quit at read " << read_index(); | 750 << ": Posting Quit at read " << read_index(); |
| 750 loop_stop_stage_ = sequence_number_; | 751 loop_stop_stage_ = sequence_number_; |
| 751 if (callback_) | 752 if (callback_) |
| 752 callback_->RunWithParams(Tuple1<int>(ERR_IO_PENDING)); | 753 callback_->RunWithParams(Tuple1<int>(ERR_IO_PENDING)); |
| 753 } | 754 } |
| 754 | 755 |
| 755 void CompleteRead() { | 756 void CompleteRead() { |
| 756 if (socket()) { | 757 if (socket()) { |
| 757 DLOG(INFO) << " *** " << __FUNCTION__ << "() Stage " | 758 NET_TRACE(INFO, " *** ") << "Stage " << sequence_number_; |
| 758 << sequence_number_; | |
| 759 socket()->OnReadComplete(GetNextRead()); | 759 socket()->OnReadComplete(GetNextRead()); |
| 760 } | 760 } |
| 761 } | 761 } |
| 762 | 762 |
| 763 private: | 763 private: |
| 764 int sequence_number_; | 764 int sequence_number_; |
| 765 int loop_stop_stage_; | 765 int loop_stop_stage_; |
| 766 CompletionCallback* callback_; | 766 CompletionCallback* callback_; |
| 767 ScopedRunnableMethodFactory<OrderedSocketData> factory_; | 767 ScopedRunnableMethodFactory<OrderedSocketData> factory_; |
| 768 }; | 768 }; |
| (...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2449 // We shouldn't get here in this test. | 2449 // We shouldn't get here in this test. |
| 2450 FAIL() << "Unexpected read: " << rv; | 2450 FAIL() << "Unexpected read: " << rv; |
| 2451 } while (rv > 0); | 2451 } while (rv > 0); |
| 2452 | 2452 |
| 2453 // Flush the MessageLoop; this will cause the buffered IO task | 2453 // Flush the MessageLoop; this will cause the buffered IO task |
| 2454 // to run for the final time. | 2454 // to run for the final time. |
| 2455 MessageLoop::current()->RunAllPending(); | 2455 MessageLoop::current()->RunAllPending(); |
| 2456 } | 2456 } |
| 2457 | 2457 |
| 2458 } // namespace net | 2458 } // namespace net |
| OLD | NEW |