summaryrefslogtreecommitdiff
path: root/chromium/content/child/test_request_peer.h
blob: fa2d59d7352db2b145d04034fa1bf5e0a6c02ff6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_CHILD_TEST_REQUEST_PEER_H_
#define CONTENT_CHILD_TEST_REQUEST_PEER_H_

#include <stdint.h>
#include <memory>
#include <string>
#include <vector>
#include "base/time/time.h"
#include "content/public/child/request_peer.h"

namespace net {
struct RedirectInfo;
}  // namespace net

namespace content {

class ReceivedData;
class ResourceDispatcher;
struct ResourceResponseInfo;

// Listens for request response data and stores it so that it can be compared
// to the reference data.
class TestRequestPeer : public RequestPeer {
 public:
  struct Context;
  TestRequestPeer(ResourceDispatcher* dispatcher, Context* context);
  ~TestRequestPeer() override;

  void OnUploadProgress(uint64_t position, uint64_t size) override;
  bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
                          const ResourceResponseInfo& info) override;
  void OnReceivedResponse(const ResourceResponseInfo& info) override;
  void OnDownloadedData(int len, int encoded_data_length) override;
  void OnReceivedData(std::unique_ptr<ReceivedData> data) override;
  void OnTransferSizeUpdated(int transfer_size_diff) override;
  void OnReceivedCachedMetadata(const char* data, int len) override;
  void OnCompletedRequest(int error_code,
                          bool was_ignored_by_handler,
                          bool stale_copy_in_cache,
                          const base::TimeTicks& completion_time,
                          int64_t total_transfer_size,
                          int64_t encoded_body_size) override;

  struct Context final {
    Context();
    ~Context();

    // True if should follow redirects, false if should cancel them.
    bool follow_redirects = true;
    // True if the request should be deferred on redirects.
    bool defer_on_redirect = false;

    // Number of total redirects seen.
    int seen_redirects = 0;

    bool cancel_on_receive_response = false;
    bool cancel_on_receive_data = false;
    bool received_response = false;

    std::vector<char> cached_metadata;
    // Data received. If downloading to file, remains empty.
    std::string data;

    // Total encoded data length, regardless of whether downloading to a file or
    // not.
    int total_encoded_data_length = 0;
    bool defer_on_transfer_size_updated = false;

    // Total length when downloading to a file.
    int total_downloaded_data_length = 0;

    bool complete = false;
    bool cancelled = false;
    int request_id = -1;
  };

 private:
  ResourceDispatcher* dispatcher_;
  Context* context_;

  DISALLOW_COPY_AND_ASSIGN(TestRequestPeer);
};

}  // namespace content

#endif  // CONTENT_CHILD_TEST_REQUEST_PEER_H_