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