OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 5 #ifndef NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
6 #define NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 6 #define NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" |
10 #include "net/filter/filter.h" | 11 #include "net/filter/filter.h" |
11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
| 16 class URLRequestContext; |
| 17 |
15 class MockFilterContext : public FilterContext { | 18 class MockFilterContext : public FilterContext { |
16 public: | 19 public: |
17 MockFilterContext(); | 20 MockFilterContext(); |
18 virtual ~MockFilterContext(); | 21 virtual ~MockFilterContext(); |
19 | 22 |
20 void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; } | 23 void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; } |
21 void SetURL(const GURL& gurl) { gurl_ = gurl; } | 24 void SetURL(const GURL& gurl) { gurl_ = gurl; } |
22 void SetContentDisposition(const std::string& disposition) { | 25 void SetContentDisposition(const std::string& disposition) { |
23 content_disposition_ = disposition; | 26 content_disposition_ = disposition; |
24 } | 27 } |
25 void SetRequestTime(const base::Time time) { request_time_ = time; } | 28 void SetRequestTime(const base::Time time) { request_time_ = time; } |
26 void SetCached(bool is_cached) { is_cached_content_ = is_cached; } | 29 void SetCached(bool is_cached) { is_cached_content_ = is_cached; } |
27 void SetDownload(bool is_download) { is_download_ = is_download; } | 30 void SetDownload(bool is_download) { is_download_ = is_download; } |
28 void SetResponseCode(int response_code) { response_code_ = response_code; } | 31 void SetResponseCode(int response_code) { response_code_ = response_code; } |
29 void SetSdchResponse(bool is_sdch_response) { | 32 void SetSdchResponse(bool is_sdch_response) { |
30 is_sdch_response_ = is_sdch_response; | 33 is_sdch_response_ = is_sdch_response; |
31 } | 34 } |
| 35 URLRequestContext* GetModifiableURLRequestContext() const { |
| 36 return context_.get(); |
| 37 } |
32 | 38 |
33 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 39 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
34 | 40 |
35 // What URL was used to access this data? | 41 // What URL was used to access this data? |
36 // Return false if gurl is not present. | 42 // Return false if gurl is not present. |
37 virtual bool GetURL(GURL* gurl) const OVERRIDE; | 43 virtual bool GetURL(GURL* gurl) const OVERRIDE; |
38 | 44 |
39 // What Content-Disposition did the server supply for this data? | 45 // What Content-Disposition did the server supply for this data? |
40 // Return false if Content-Disposition was not present. | 46 // Return false if Content-Disposition was not present. |
41 virtual bool GetContentDisposition(std::string* disposition) const OVERRIDE; | 47 virtual bool GetContentDisposition(std::string* disposition) const OVERRIDE; |
42 | 48 |
43 // What was this data requested from a server? | 49 // What was this data requested from a server? |
44 virtual base::Time GetRequestTime() const OVERRIDE; | 50 virtual base::Time GetRequestTime() const OVERRIDE; |
45 | 51 |
46 // Is data supplied from cache, or fresh across the net? | 52 // Is data supplied from cache, or fresh across the net? |
47 virtual bool IsCachedContent() const OVERRIDE; | 53 virtual bool IsCachedContent() const OVERRIDE; |
48 | 54 |
49 // Is this a download? | 55 // Is this a download? |
50 virtual bool IsDownload() const OVERRIDE; | 56 virtual bool IsDownload() const OVERRIDE; |
51 | 57 |
52 // Was this data flagged as a response to a request with an SDCH dictionary? | 58 // Was this data flagged as a response to a request with an SDCH dictionary? |
53 virtual bool IsSdchResponse() const OVERRIDE; | 59 virtual bool IsSdchResponse() const OVERRIDE; |
54 | 60 |
55 // How many bytes were fed to filter(s) so far? | 61 // How many bytes were fed to filter(s) so far? |
56 virtual int64 GetByteReadCount() const OVERRIDE; | 62 virtual int64 GetByteReadCount() const OVERRIDE; |
57 | 63 |
58 virtual int GetResponseCode() const OVERRIDE; | 64 virtual int GetResponseCode() const OVERRIDE; |
59 | 65 |
| 66 // The URLRequestContext associated with the request. |
| 67 virtual const URLRequestContext* GetURLRequestContext() const OVERRIDE; |
| 68 |
60 virtual void RecordPacketStats(StatisticSelector statistic) const OVERRIDE {} | 69 virtual void RecordPacketStats(StatisticSelector statistic) const OVERRIDE {} |
61 | 70 |
62 private: | 71 private: |
63 int buffer_size_; | 72 int buffer_size_; |
64 std::string mime_type_; | 73 std::string mime_type_; |
65 std::string content_disposition_; | 74 std::string content_disposition_; |
66 GURL gurl_; | 75 GURL gurl_; |
67 base::Time request_time_; | 76 base::Time request_time_; |
68 bool is_cached_content_; | 77 bool is_cached_content_; |
69 bool is_download_; | 78 bool is_download_; |
70 bool is_sdch_response_; | 79 bool is_sdch_response_; |
71 int response_code_; | 80 int response_code_; |
| 81 scoped_ptr<URLRequestContext> context_; |
72 | 82 |
73 DISALLOW_COPY_AND_ASSIGN(MockFilterContext); | 83 DISALLOW_COPY_AND_ASSIGN(MockFilterContext); |
74 }; | 84 }; |
75 | 85 |
76 } // namespace net | 86 } // namespace net |
77 | 87 |
78 #endif // NET_FILTER_MOCK_FILTER_CONTEXT_H_ | 88 #endif // NET_FILTER_MOCK_FILTER_CONTEXT_H_ |
OLD | NEW |