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

Side by Side Diff: components/component_updater/test/url_request_post_interceptor.h

Issue 514473002: Componentize component_updater: Break content/ dependency for rest of component_updater tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ 5 #ifndef CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_
6 #define CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ 6 #define CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/memory/ref_counted.h"
15 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace base { 19 namespace base {
19 class FilePath; 20 class FilePath;
21 class SequencedTaskRunner;
20 } 22 }
21 23
22 namespace net { 24 namespace net {
23 class URLRequest; 25 class URLRequest;
24 } 26 }
25 27
26 namespace component_updater { 28 namespace component_updater {
27 29
28 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and 30 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
29 // the RSA public key the following hash: 31 // the RSA public key the following hash:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 87
86 // Resets the state of the interceptor so that new expectations can be set. 88 // Resets the state of the interceptor so that new expectations can be set.
87 void Reset(); 89 void Reset();
88 90
89 class Delegate; 91 class Delegate;
90 92
91 private: 93 private:
92 friend class URLRequestPostInterceptorFactory; 94 friend class URLRequestPostInterceptorFactory;
93 typedef std::pair<const RequestMatcher*, std::string> Expectation; 95 typedef std::pair<const RequestMatcher*, std::string> Expectation;
94 96
95 explicit URLRequestPostInterceptor(const GURL& url); 97 explicit URLRequestPostInterceptor(
Sorin Jianu 2014/08/27 17:36:02 In general, explicit is used for one param ctor in
tommycli 2014/08/27 17:59:22 Done.
98 const GURL& url,
99 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
96 ~URLRequestPostInterceptor(); 100 ~URLRequestPostInterceptor();
97 101
98 void ClearExpectations(); 102 void ClearExpectations();
99 const GURL url_; 103 const GURL url_;
104 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
100 105
101 mutable base::Lock interceptor_lock_; 106 mutable base::Lock interceptor_lock_;
102 mutable int hit_count_; 107 mutable int hit_count_;
103 mutable std::vector<std::string> requests_; 108 mutable std::vector<std::string> requests_;
104 mutable std::queue<Expectation> expectations_; 109 mutable std::queue<Expectation> expectations_;
105 110
106 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptor); 111 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptor);
107 }; 112 };
108 113
109 class URLRequestPostInterceptorFactory { 114 class URLRequestPostInterceptorFactory {
110 public: 115 public:
111 URLRequestPostInterceptorFactory(const std::string& scheme, 116 URLRequestPostInterceptorFactory(
112 const std::string& hostname); 117 const std::string& scheme,
118 const std::string& hostname,
119 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
113 ~URLRequestPostInterceptorFactory(); 120 ~URLRequestPostInterceptorFactory();
114 121
115 // Creates an interceptor object for the specified url path. Returns NULL 122 // Creates an interceptor object for the specified url path. Returns NULL
116 // in case of errors or a valid interceptor object otherwise. The caller 123 // in case of errors or a valid interceptor object otherwise. The caller
117 // does not own the returned object. 124 // does not own the returned object.
118 URLRequestPostInterceptor* CreateInterceptor(const base::FilePath& filepath); 125 URLRequestPostInterceptor* CreateInterceptor(const base::FilePath& filepath);
119 126
120 private: 127 private:
121 const std::string scheme_; 128 const std::string scheme_;
122 const std::string hostname_; 129 const std::string hostname_;
130 scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
123 131
124 // After creation, |delegate_| lives on the IO thread and it is owned by 132 // After creation, |delegate_| lives on the IO thread and it is owned by
125 // a URLRequestFilter after registration. A task to unregister it and 133 // a URLRequestFilter after registration. A task to unregister it and
126 // implicitly destroy it is posted from ~URLRequestPostInterceptorFactory(). 134 // implicitly destroy it is posted from ~URLRequestPostInterceptorFactory().
127 URLRequestPostInterceptor::Delegate* delegate_; 135 URLRequestPostInterceptor::Delegate* delegate_;
128 136
129 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptorFactory); 137 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptorFactory);
130 }; 138 };
131 139
132 // Intercepts HTTP POST requests sent to "localhost2". 140 // Intercepts HTTP POST requests sent to "localhost2".
133 class InterceptorFactory : public URLRequestPostInterceptorFactory { 141 class InterceptorFactory : public URLRequestPostInterceptorFactory {
134 public: 142 public:
135 InterceptorFactory(); 143 InterceptorFactory(
Sorin Jianu 2014/08/27 17:36:02 explicit
tommycli 2014/08/27 17:59:22 Done.
144 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner);
136 ~InterceptorFactory(); 145 ~InterceptorFactory();
137 146
138 URLRequestPostInterceptor* CreateInterceptor(); 147 URLRequestPostInterceptor* CreateInterceptor();
139 148
140 private: 149 private:
141 DISALLOW_COPY_AND_ASSIGN(InterceptorFactory); 150 DISALLOW_COPY_AND_ASSIGN(InterceptorFactory);
142 }; 151 };
143 152
144 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher { 153 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher {
145 public: 154 public:
146 explicit PartialMatch(const std::string& expected) : expected_(expected) {} 155 explicit PartialMatch(const std::string& expected) : expected_(expected) {}
147 virtual bool Match(const std::string& actual) const OVERRIDE; 156 virtual bool Match(const std::string& actual) const OVERRIDE;
148 157
149 private: 158 private:
150 const std::string expected_; 159 const std::string expected_;
151 160
152 DISALLOW_COPY_AND_ASSIGN(PartialMatch); 161 DISALLOW_COPY_AND_ASSIGN(PartialMatch);
153 }; 162 };
154 163
155 } // namespace component_updater 164 } // namespace component_updater
156 165
157 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ 166 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698