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