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