Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: net/test/url_request/url_request_mock_http_job.h

Issue 586143002: Initial implementation of Cronet Async API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added ReportMockErrorFromQuery to URLRequestMockHTTPJob. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // A URLRequestJob class that pulls the net and http headers from disk. 5 // A URLRequestJob class that pulls the net and http headers from disk.
6 6
7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ 7 #ifndef NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ 8 #define NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
9 9
10 #include <string> 10 #include <string>
(...skipping 17 matching lines...) Expand all
28 28
29 class URLRequestMockHTTPJob : public URLRequestFileJob { 29 class URLRequestMockHTTPJob : public URLRequestFileJob {
30 public: 30 public:
31 // Note that all file IO is done using |worker_pool|. 31 // Note that all file IO is done using |worker_pool|.
32 URLRequestMockHTTPJob(URLRequest* request, 32 URLRequestMockHTTPJob(URLRequest* request,
33 NetworkDelegate* network_delegate, 33 NetworkDelegate* network_delegate,
34 const base::FilePath& file_path, 34 const base::FilePath& file_path,
35 const scoped_refptr<base::TaskRunner>& task_runner); 35 const scoped_refptr<base::TaskRunner>& task_runner);
36 36
37 virtual void Start() override; 37 virtual void Start() override;
38 virtual bool ReadRawData(IOBuffer* buf,
39 int buf_size,
40 int* bytes_read) override;
38 virtual bool GetMimeType(std::string* mime_type) const override; 41 virtual bool GetMimeType(std::string* mime_type) const override;
39 virtual int GetResponseCode() const override; 42 virtual int GetResponseCode() const override;
40 virtual bool GetCharset(std::string* charset) override; 43 virtual bool GetCharset(std::string* charset) override;
41 virtual void GetResponseInfo(HttpResponseInfo* info) override; 44 virtual void GetResponseInfo(HttpResponseInfo* info) override;
42 virtual bool IsRedirectResponse(GURL* location, 45 virtual bool IsRedirectResponse(GURL* location,
43 int* http_status_code) override; 46 int* http_status_code) override;
44 47
45 // Adds the testing URLs to the URLRequestFilter. 48 // Adds the testing URLs to the URLRequestFilter.
46 static void AddUrlHandler( 49 static void AddUrlHandler(
47 const base::FilePath& base_path, 50 const base::FilePath& base_path,
48 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); 51 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
49 52
50 // Respond to all HTTP requests of |hostname| with contents of the file 53 // Respond to all HTTP requests of |hostname| with contents of the file
51 // located at |file_path|. 54 // located at |file_path|.
52 static void AddHostnameToFileHandler( 55 static void AddHostnameToFileHandler(
53 const std::string& hostname, 56 const std::string& hostname,
54 const base::FilePath& file, 57 const base::FilePath& file,
55 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); 58 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
56 59
57 // Given the path to a file relative to the path passed to AddUrlHandler(), 60 // Given the path to a file relative to the path passed to AddUrlHandler(),
58 // construct a mock URL. 61 // construct a mock URL.
59 static GURL GetMockUrl(const base::FilePath& path); 62 static GURL GetMockUrl(const base::FilePath& path);
mmenke 2014/10/16 16:39:34 Suggest adding GetMockUrlWithFailure(const base::F
mef 2014/10/16 21:36:50 Done.
60 63
61 // Returns a URLRequestJobFactory::ProtocolHandler that serves 64 // Returns a URLRequestJobFactory::ProtocolHandler that serves
62 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the 65 // URLRequestMockHTTPJob's responding like an HTTP server. |base_path| is the
63 // file path leading to the root of the directory to use as the root of the 66 // file path leading to the root of the directory to use as the root of the
64 // HTTP server. 67 // HTTP server.
65 static scoped_ptr<URLRequestInterceptor> CreateInterceptor( 68 static scoped_ptr<URLRequestInterceptor> CreateInterceptor(
66 const base::FilePath& base_path, 69 const base::FilePath& base_path,
67 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); 70 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
68 71
69 // Returns a URLRequestJobFactory::ProtocolHandler that serves 72 // Returns a URLRequestJobFactory::ProtocolHandler that serves
70 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all 73 // URLRequestMockHTTPJob's responding like an HTTP server. It responds to all
71 // requests with the contents of |file|. 74 // requests with the contents of |file|.
72 static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile( 75 static scoped_ptr<URLRequestInterceptor> CreateInterceptorForSingleFile(
73 const base::FilePath& file, 76 const base::FilePath& file,
74 const scoped_refptr<base::SequencedWorkerPool>& worker_pool); 77 const scoped_refptr<base::SequencedWorkerPool>& worker_pool);
75 78
76 protected: 79 protected:
77 virtual ~URLRequestMockHTTPJob(); 80 virtual ~URLRequestMockHTTPJob();
78 81
79 private: 82 private:
80 void GetResponseInfoConst(HttpResponseInfo* info) const; 83 void GetResponseInfoConst(HttpResponseInfo* info) const;
81 void GetRawHeaders(std::string raw_headers); 84 void GetRawHeaders(std::string raw_headers);
85 bool ReportMockErrorFromQuery(const std::string& step);
mmenke 2014/10/16 16:39:34 Think this function name is a little weird. Maybe
mef 2014/10/17 20:19:41 Done.
82 std::string raw_headers_; 86 std::string raw_headers_;
83 const scoped_refptr<base::TaskRunner> task_runner_; 87 const scoped_refptr<base::TaskRunner> task_runner_;
84 88
85 base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_; 89 base::WeakPtrFactory<URLRequestMockHTTPJob> weak_ptr_factory_;
86 90
87 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob); 91 DISALLOW_COPY_AND_ASSIGN(URLRequestMockHTTPJob);
88 }; 92 };
89 93
90 } // namespace net 94 } // namespace net
91 95
92 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_ 96 #endif // NET_TEST_URL_REQUEST_URL_REQUEST_MOCK_HTTP_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698