• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
MockFilterContext(int buffer_size)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 
SetBufferSize(int buffer_size)25   void SetBufferSize(int buffer_size) { buffer_size_ = buffer_size; }
SetMimeType(const std::string & mime_type)26   void SetMimeType(const std::string& mime_type) { mime_type_ = mime_type; }
SetURL(const GURL & gurl)27   void SetURL(const GURL& gurl) { gurl_ = gurl; }
SetRequestTime(const base::Time time)28   void SetRequestTime(const base::Time time) { request_time_ = time; }
SetCached(bool is_cached)29   void SetCached(bool is_cached) { is_cached_content_ = is_cached; }
SetDownload(bool is_download)30   void SetDownload(bool is_download) { is_download_ = is_download; }
SetResponseCode(int response_code)31   void SetResponseCode(int response_code) { response_code_ = response_code; }
SetSdchResponse(bool is_sdch_response)32   void SetSdchResponse(bool is_sdch_response) {
33     is_sdch_response_ = is_sdch_response;
34   }
35 
GetMimeType(std::string * mime_type)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.
GetURL(GURL * gurl)43   virtual bool GetURL(GURL* gurl) const {
44     *gurl = gurl_;
45     return true;
46   }
47 
48   // What was this data requested from a server?
GetRequestTime()49   virtual base::Time GetRequestTime() const {
50     return request_time_;
51   }
52 
53   // Is data supplied from cache, or fresh across the net?
IsCachedContent()54   virtual bool IsCachedContent() const { return is_cached_content_; }
55 
56   // Is this a download?
IsDownload()57   virtual bool IsDownload() const { return is_download_; }
58 
59   // Was this data flagged as a response to a request with an SDCH dictionary?
IsSdchResponse()60   virtual bool IsSdchResponse() const { return is_sdch_response_; }
61 
62   // How many bytes were fed to filter(s) so far?
GetByteReadCount()63   virtual int64 GetByteReadCount() const { return 0; }
64 
GetResponseCode()65   virtual int GetResponseCode() const { return response_code_; }
66 
67   // What is the desirable input buffer size for these filters?
GetInputStreamBufferSize()68   virtual int GetInputStreamBufferSize() const { return buffer_size_; }
69 
RecordPacketStats(StatisticSelector statistic)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