OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_CHILD_TEST_REQUEST_PEER_H_ |
| 6 #define CONTENT_CHILD_TEST_REQUEST_PEER_H_ |
| 7 |
| 8 #include <stdint.h> |
| 9 #include <memory> |
| 10 #include <string> |
| 11 #include "base/time/time.h" |
| 12 #include "content/public/child/request_peer.h" |
| 13 |
| 14 namespace net { |
| 15 struct RedirectInfo; |
| 16 } // namespace net |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class ReceivedData; |
| 21 class ResourceDispatcher; |
| 22 struct ResourceResponseInfo; |
| 23 |
| 24 // Listens for request response data and stores it so that it can be compared |
| 25 // to the reference data. |
| 26 class TestRequestPeer : public RequestPeer { |
| 27 public: |
| 28 struct Context; |
| 29 TestRequestPeer(ResourceDispatcher* dispatcher, Context* context); |
| 30 ~TestRequestPeer() override; |
| 31 |
| 32 void OnUploadProgress(uint64_t position, uint64_t size) override; |
| 33 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
| 34 const ResourceResponseInfo& info) override; |
| 35 void OnReceivedResponse(const ResourceResponseInfo& info) override; |
| 36 void OnDownloadedData(int len, int encoded_data_length) override; |
| 37 void OnReceivedData(std::unique_ptr<ReceivedData> data) override; |
| 38 void OnTransferSizeUpdated(int transfer_size_diff) override; |
| 39 void OnCompletedRequest(int error_code, |
| 40 bool was_ignored_by_handler, |
| 41 bool stale_copy_in_cache, |
| 42 const base::TimeTicks& completion_time, |
| 43 int64_t total_transfer_size, |
| 44 int64_t encoded_body_size) override; |
| 45 |
| 46 struct Context final { |
| 47 Context(); |
| 48 ~Context(); |
| 49 |
| 50 // True if should follow redirects, false if should cancel them. |
| 51 bool follow_redirects = true; |
| 52 // True if the request should be deferred on redirects. |
| 53 bool defer_on_redirect = false; |
| 54 |
| 55 // Number of total redirects seen. |
| 56 int seen_redirects = 0; |
| 57 |
| 58 bool cancel_on_receive_response = false; |
| 59 bool cancel_on_receive_data = false; |
| 60 bool received_response = false; |
| 61 |
| 62 // Data received. If downloading to file, remains empty. |
| 63 std::string data; |
| 64 |
| 65 // Total encoded data length, regardless of whether downloading to a file or |
| 66 // not. |
| 67 int total_encoded_data_length = 0; |
| 68 // Total length when downloading to a file. |
| 69 int total_downloaded_data_length = 0; |
| 70 |
| 71 bool complete = false; |
| 72 bool cancelled = false; |
| 73 int request_id = -1; |
| 74 }; |
| 75 |
| 76 private: |
| 77 ResourceDispatcher* dispatcher_; |
| 78 Context* context_; |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(TestRequestPeer); |
| 81 }; |
| 82 |
| 83 } // namespace content |
| 84 |
| 85 #endif // CONTENT_CHILD_TEST_REQUEST_PEER_H_ |
OLD | NEW |