OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_ | |
6 #define NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/ref_counted.h" | |
12 | |
13 class GURL; | |
14 | |
15 namespace base { | |
16 class FilePath; | |
17 class TaskRunner; | |
18 } | |
19 | |
20 namespace net { | |
21 | |
22 // Intercepts HTTP requests and gives pre-defined responses to specified URLs. | |
23 // The pre-defined responses are loaded from files on disk. The interception | |
24 // occurs while the TestURLRequestInterceptor is alive. This class may be | |
25 // instantiated on any thread. This is unlike most other classes in /net, | |
26 // which may only be instantiated on the |network_task_runner| thread. We allow | |
27 // instantiation on any thread for convenient usage on test threads. | |
Ryan Sleevi
2014/09/03 00:23:31
1) Don't use pronouns in comments ("We" allow)
2)
tommycli
2014/09/05 15:03:08
Done.
| |
28 class TestURLRequestInterceptor { | |
29 public: | |
30 // Registers an interceptor for urls using |scheme| and |hostname|. Urls | |
Ryan Sleevi
2014/09/03 00:23:31
s/urls/URLs/
s/Urls/URLs/
tommycli
2014/09/05 15:03:08
Done.
| |
31 // passed to "SetResponse" are required to use |scheme| and |hostname|. | |
32 TestURLRequestInterceptor( | |
33 const std::string& scheme, | |
34 const std::string& hostname, | |
35 const scoped_refptr<base::TaskRunner>& network_task_runner, | |
36 const scoped_refptr<base::TaskRunner>& worker_task_runner); | |
Ryan Sleevi
2014/09/03 00:23:31
Document both |network_task_runner| and |worker_ta
tommycli
2014/09/05 15:03:08
Done.
| |
37 virtual ~TestURLRequestInterceptor(); | |
38 | |
39 // When requests for |url| arrive, respond with the contents of |path|. The | |
40 // hostname and scheme of |url| must match the corresponding parameters | |
41 // passed as constructor arguments. | |
42 void SetResponse(const GURL& url, const base::FilePath& path); | |
43 | |
44 // Identical to SetResponse except that query parameters are ignored on | |
Ryan Sleevi
2014/09/03 00:23:31
s/SetResponse/SetResponse,/
tommycli
2014/09/05 15:03:08
Done.
| |
45 // incoming URLs when comparing against |url|. | |
46 void SetResponseIgnoreQuery(const GURL& url, const base::FilePath& path); | |
47 | |
48 // Returns how many requests have been issued that have a stored reply. | |
49 int GetHitCount(); | |
50 | |
51 private: | |
52 class Delegate; | |
53 | |
54 const std::string scheme_; | |
55 const std::string hostname_; | |
56 | |
57 scoped_refptr<base::TaskRunner> network_task_runner_; | |
58 | |
59 // After creation, |delegate_| lives on the thread of the | |
60 // |network_task_runner_|, and a task to delete it is posted from | |
61 // ~TestURLRequestInterceptor(). | |
62 Delegate* delegate_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(TestURLRequestInterceptor); | |
65 }; | |
66 | |
67 // Specialization of TestURLRequestInterceptor where scheme is "http" and | |
68 // hostname is "localhost". | |
69 class LocalHostTestURLRequestInterceptor : public TestURLRequestInterceptor { | |
70 public: | |
71 LocalHostTestURLRequestInterceptor( | |
72 const scoped_refptr<base::TaskRunner>& network_task_runner, | |
73 const scoped_refptr<base::TaskRunner>& worker_task_runner); | |
74 | |
75 private: | |
76 DISALLOW_COPY_AND_ASSIGN(LocalHostTestURLRequestInterceptor); | |
77 }; | |
78 | |
79 } // namespace net | |
80 | |
81 #endif // NET_URL_REQUEST_TEST_URL_REQUEST_INTERCEPTOR_H_ | |
OLD | NEW |