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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 defer_on_redirect_(false), | 47 defer_on_redirect_(false), |
48 seen_redirects_(0), | 48 seen_redirects_(0), |
49 cancel_on_receive_response_(false), | 49 cancel_on_receive_response_(false), |
50 received_response_(false), | 50 received_response_(false), |
51 total_encoded_data_length_(0), | 51 total_encoded_data_length_(0), |
52 total_downloaded_data_length_(0), | 52 total_downloaded_data_length_(0), |
53 complete_(false), | 53 complete_(false), |
54 bridge_(bridge) { | 54 bridge_(bridge) { |
55 } | 55 } |
56 | 56 |
57 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 57 virtual void OnUploadProgress(uint64 position, uint64 size) override { |
58 } | 58 } |
59 | 59 |
60 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, | 60 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
61 const ResourceResponseInfo& info) OVERRIDE { | 61 const ResourceResponseInfo& info) override { |
62 ++seen_redirects_; | 62 ++seen_redirects_; |
63 if (defer_on_redirect_) | 63 if (defer_on_redirect_) |
64 bridge_->SetDefersLoading(true); | 64 bridge_->SetDefersLoading(true); |
65 return follow_redirects_; | 65 return follow_redirects_; |
66 } | 66 } |
67 | 67 |
68 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE { | 68 virtual void OnReceivedResponse(const ResourceResponseInfo& info) override { |
69 EXPECT_FALSE(received_response_); | 69 EXPECT_FALSE(received_response_); |
70 received_response_ = true; | 70 received_response_ = true; |
71 if (cancel_on_receive_response_) | 71 if (cancel_on_receive_response_) |
72 bridge_->Cancel(); | 72 bridge_->Cancel(); |
73 } | 73 } |
74 | 74 |
75 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE { | 75 virtual void OnDownloadedData(int len, int encoded_data_length) override { |
76 total_downloaded_data_length_ += len; | 76 total_downloaded_data_length_ += len; |
77 total_encoded_data_length_ += encoded_data_length; | 77 total_encoded_data_length_ += encoded_data_length; |
78 } | 78 } |
79 | 79 |
80 virtual void OnReceivedData(const char* data, | 80 virtual void OnReceivedData(const char* data, |
81 int data_length, | 81 int data_length, |
82 int encoded_data_length) OVERRIDE { | 82 int encoded_data_length) override { |
83 EXPECT_TRUE(received_response_); | 83 EXPECT_TRUE(received_response_); |
84 EXPECT_FALSE(complete_); | 84 EXPECT_FALSE(complete_); |
85 data_.append(data, data_length); | 85 data_.append(data, data_length); |
86 total_encoded_data_length_ += encoded_data_length; | 86 total_encoded_data_length_ += encoded_data_length; |
87 } | 87 } |
88 | 88 |
89 virtual void OnCompletedRequest( | 89 virtual void OnCompletedRequest( |
90 int error_code, | 90 int error_code, |
91 bool was_ignored_by_handler, | 91 bool was_ignored_by_handler, |
92 bool stale_copy_in_cache, | 92 bool stale_copy_in_cache, |
93 const std::string& security_info, | 93 const std::string& security_info, |
94 const base::TimeTicks& completion_time, | 94 const base::TimeTicks& completion_time, |
95 int64 total_transfer_size) OVERRIDE { | 95 int64 total_transfer_size) override { |
96 EXPECT_TRUE(received_response_); | 96 EXPECT_TRUE(received_response_); |
97 EXPECT_FALSE(complete_); | 97 EXPECT_FALSE(complete_); |
98 complete_ = true; | 98 complete_ = true; |
99 } | 99 } |
100 | 100 |
101 void set_follow_redirects(bool follow_redirects) { | 101 void set_follow_redirects(bool follow_redirects) { |
102 follow_redirects_ = follow_redirects; | 102 follow_redirects_ = follow_redirects; |
103 } | 103 } |
104 | 104 |
105 void set_defer_on_redirect(bool defer_on_redirect) { | 105 void set_defer_on_redirect(bool defer_on_redirect) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 public: | 157 public: |
158 ResourceDispatcherTest() : dispatcher_(this) {} | 158 ResourceDispatcherTest() : dispatcher_(this) {} |
159 | 159 |
160 virtual ~ResourceDispatcherTest() { | 160 virtual ~ResourceDispatcherTest() { |
161 STLDeleteContainerPairSecondPointers(shared_memory_map_.begin(), | 161 STLDeleteContainerPairSecondPointers(shared_memory_map_.begin(), |
162 shared_memory_map_.end()); | 162 shared_memory_map_.end()); |
163 } | 163 } |
164 | 164 |
165 // Emulates IPC send operations (IPC::Sender) by adding | 165 // Emulates IPC send operations (IPC::Sender) by adding |
166 // pending messages to the queue. | 166 // pending messages to the queue. |
167 virtual bool Send(IPC::Message* msg) OVERRIDE { | 167 virtual bool Send(IPC::Message* msg) override { |
168 message_queue_.push_back(IPC::Message(*msg)); | 168 message_queue_.push_back(IPC::Message(*msg)); |
169 delete msg; | 169 delete msg; |
170 return true; | 170 return true; |
171 } | 171 } |
172 | 172 |
173 size_t queued_messages() const { return message_queue_.size(); } | 173 size_t queued_messages() const { return message_queue_.size(); } |
174 | 174 |
175 // Returns the ID of the consumed request. Can't make assumptions about the | 175 // Returns the ID of the consumed request. Can't make assumptions about the |
176 // ID, because numbering is based on a global. | 176 // ID, because numbering is based on a global. |
177 int ConsumeRequestResource() { | 177 int ConsumeRequestResource() { |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 // FIXME | 697 // FIXME |
698 } | 698 } |
699 | 699 |
700 TEST_F(ResourceDispatcherTest, SerializedPostData) { | 700 TEST_F(ResourceDispatcherTest, SerializedPostData) { |
701 // FIXME | 701 // FIXME |
702 } | 702 } |
703 | 703 |
704 class TimeConversionTest : public ResourceDispatcherTest, | 704 class TimeConversionTest : public ResourceDispatcherTest, |
705 public RequestPeer { | 705 public RequestPeer { |
706 public: | 706 public: |
707 virtual bool Send(IPC::Message* msg) OVERRIDE { | 707 virtual bool Send(IPC::Message* msg) override { |
708 delete msg; | 708 delete msg; |
709 return true; | 709 return true; |
710 } | 710 } |
711 | 711 |
712 void PerformTest(const ResourceResponseHead& response_head) { | 712 void PerformTest(const ResourceResponseHead& response_head) { |
713 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); | 713 scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); |
714 bridge->Start(this); | 714 bridge->Start(this); |
715 | 715 |
716 dispatcher()->OnMessageReceived( | 716 dispatcher()->OnMessageReceived( |
717 ResourceMsg_ReceivedResponse(0, response_head)); | 717 ResourceMsg_ReceivedResponse(0, response_head)); |
718 } | 718 } |
719 | 719 |
720 // RequestPeer methods. | 720 // RequestPeer methods. |
721 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { | 721 virtual void OnUploadProgress(uint64 position, uint64 size) override { |
722 } | 722 } |
723 | 723 |
724 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, | 724 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
725 const ResourceResponseInfo& info) OVERRIDE { | 725 const ResourceResponseInfo& info) override { |
726 return true; | 726 return true; |
727 } | 727 } |
728 | 728 |
729 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE { | 729 virtual void OnReceivedResponse(const ResourceResponseInfo& info) override { |
730 response_info_ = info; | 730 response_info_ = info; |
731 } | 731 } |
732 | 732 |
733 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE { | 733 virtual void OnDownloadedData(int len, int encoded_data_length) override { |
734 } | 734 } |
735 | 735 |
736 virtual void OnReceivedData(const char* data, | 736 virtual void OnReceivedData(const char* data, |
737 int data_length, | 737 int data_length, |
738 int encoded_data_length) OVERRIDE { | 738 int encoded_data_length) override { |
739 } | 739 } |
740 | 740 |
741 virtual void OnCompletedRequest( | 741 virtual void OnCompletedRequest( |
742 int error_code, | 742 int error_code, |
743 bool was_ignored_by_handler, | 743 bool was_ignored_by_handler, |
744 bool stale_copy_in_cache, | 744 bool stale_copy_in_cache, |
745 const std::string& security_info, | 745 const std::string& security_info, |
746 const base::TimeTicks& completion_time, | 746 const base::TimeTicks& completion_time, |
747 int64 total_transfer_size) OVERRIDE { | 747 int64 total_transfer_size) override { |
748 } | 748 } |
749 | 749 |
750 const ResourceResponseInfo& response_info() const { return response_info_; } | 750 const ResourceResponseInfo& response_info() const { return response_info_; } |
751 | 751 |
752 private: | 752 private: |
753 ResourceResponseInfo response_info_; | 753 ResourceResponseInfo response_info_; |
754 }; | 754 }; |
755 | 755 |
756 // TODO(simonjam): Enable this when 10829031 lands. | 756 // TODO(simonjam): Enable this when 10829031 lands. |
757 TEST_F(TimeConversionTest, DISABLED_ProperlyInitialized) { | 757 TEST_F(TimeConversionTest, DISABLED_ProperlyInitialized) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 ResourceResponseHead response_head; | 789 ResourceResponseHead response_head; |
790 | 790 |
791 PerformTest(response_head); | 791 PerformTest(response_head); |
792 | 792 |
793 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); | 793 EXPECT_EQ(base::TimeTicks(), response_info().load_timing.request_start); |
794 EXPECT_EQ(base::TimeTicks(), | 794 EXPECT_EQ(base::TimeTicks(), |
795 response_info().load_timing.connect_timing.dns_start); | 795 response_info().load_timing.connect_timing.dns_start); |
796 } | 796 } |
797 | 797 |
798 } // namespace content | 798 } // namespace content |
OLD | NEW |