Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / net / filter / mock_filter_context.h
blob41c9e9e1e21d4d228ed70185e75f5dd587729c36
1 // Copyright 2014 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.
5 #ifndef NET_FILTER_MOCK_FILTER_CONTEXT_H_
6 #define NET_FILTER_MOCK_FILTER_CONTEXT_H_
8 #include <string>
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/net_log.h"
12 #include "net/filter/filter.h"
13 #include "url/gurl.h"
15 namespace net {
17 class URLRequestContext;
19 class MockFilterContext : public FilterContext {
20 public:
21 MockFilterContext();
22 ~MockFilterContext() override;
24 void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; }
25 void SetURL(const GURL& gurl) { gurl_ = gurl; }
26 void SetContentDisposition(const std::string& disposition) {
27 content_disposition_ = disposition;
29 void SetRequestTime(const base::Time time) { request_time_ = time; }
30 void SetCached(bool is_cached) { is_cached_content_ = is_cached; }
31 void SetDownload(bool is_download) { is_download_ = is_download; }
32 void SetResponseCode(int response_code) { response_code_ = response_code; }
33 void SetSdchResponse(bool is_sdch_response) {
34 is_sdch_response_ = is_sdch_response;
36 URLRequestContext* GetModifiableURLRequestContext() const {
37 return context_.get();
40 // After a URLRequest's destructor is called, some interfaces may become
41 // unstable. This method is used to signal that state, so we can tag use
42 // of those interfaces as coding errors.
43 void NukeUnstableInterfaces();
45 bool GetMimeType(std::string* mime_type) const override;
47 // What URL was used to access this data?
48 // Return false if gurl is not present.
49 bool GetURL(GURL* gurl) const override;
51 // What Content-Disposition did the server supply for this data?
52 // Return false if Content-Disposition was not present.
53 bool GetContentDisposition(std::string* disposition) const override;
55 // What was this data requested from a server?
56 base::Time GetRequestTime() const override;
58 // Is data supplied from cache, or fresh across the net?
59 bool IsCachedContent() const override;
61 // Is this a download?
62 bool IsDownload() const override;
64 // Was this data flagged as a response to a request with an SDCH dictionary?
65 bool SdchResponseExpected() const override;
67 // How many bytes were fed to filter(s) so far?
68 int64 GetByteReadCount() const override;
70 int GetResponseCode() const override;
72 // The URLRequestContext associated with the request.
73 const URLRequestContext* GetURLRequestContext() const override;
75 void RecordPacketStats(StatisticSelector statistic) const override {}
77 const BoundNetLog& GetNetLog() const override;
79 private:
80 int buffer_size_;
81 std::string mime_type_;
82 std::string content_disposition_;
83 GURL gurl_;
84 base::Time request_time_;
85 bool is_cached_content_;
86 bool is_download_;
87 bool is_sdch_response_;
88 bool ok_to_call_get_url_;
89 int response_code_;
90 scoped_ptr<URLRequestContext> context_;
91 BoundNetLog net_log_;
93 DISALLOW_COPY_AND_ASSIGN(MockFilterContext);
96 } // namespace net
98 #endif // NET_FILTER_MOCK_FILTER_CONTEXT_H_