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

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

Issue 493953002: Componentize component_updater: Move a bunch of tests to component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | Annotate | Revision Log
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 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
15 #include "url/gurl.h" 16 #include "url/gurl.h"
16 17
17 namespace base { 18 namespace base {
18 class FilePath; 19 class FilePath;
19 } 20 }
20 21
21 namespace net { 22 namespace net {
22 class URLRequest; 23 class URLRequest;
23 } 24 }
24 25
25 namespace component_updater { 26 namespace component_updater {
26 27
28 // component 1 has extension id "jebgalgnebhfojomionfpkfelancnnkf", and
29 // the RSA public key the following hash:
30 const uint8 jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
31 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
32 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
33 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
34 // component 2 has extension id "abagagagagagagagagagagagagagagag", and
35 // the RSA public key the following hash:
36 const uint8 abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
37 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
38 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
39 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x01};
40 // component 3 has extension id "ihfokbkgjpifnbbojhneepfflplebdkc", and
41 // the RSA public key the following hash:
42 const uint8 ihfo_hash[] = {0x87, 0x5e, 0xa1, 0xa6, 0x9f, 0x85, 0xd1, 0x1e,
43 0x97, 0xd4, 0x4f, 0x55, 0xbf, 0xb4, 0x13, 0xa2,
44 0xe7, 0xc5, 0xc8, 0xf5, 0x60, 0x19, 0x78, 0x1b,
45 0x6d, 0xe9, 0x4c, 0xeb, 0x96, 0x05, 0x42, 0x17};
46
27 // Intercepts requests to a file path, counts them, and captures the body of 47 // Intercepts requests to a file path, counts them, and captures the body of
28 // the requests. Optionally, for each request, it can return a canned response 48 // the requests. Optionally, for each request, it can return a canned response
29 // from a given file. The class maintains a queue of expectations, and returns 49 // from a given file. The class maintains a queue of expectations, and returns
30 // one and only one response for each request that matches and it is 50 // one and only one response for each request that matches and it is
31 // intercepted. 51 // intercepted.
32 class URLRequestPostInterceptor { 52 class URLRequestPostInterceptor {
33 public: 53 public:
34 // Allows a generic string maching interface when setting up expectations. 54 // Allows a generic string maching interface when setting up expectations.
35 class RequestMatcher { 55 class RequestMatcher {
36 public: 56 public:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const std::string hostname_; 122 const std::string hostname_;
103 123
104 // After creation, |delegate_| lives on the IO thread and it is owned by 124 // After creation, |delegate_| lives on the IO thread and it is owned by
105 // a URLRequestFilter after registration. A task to unregister it and 125 // a URLRequestFilter after registration. A task to unregister it and
106 // implicitly destroy it is posted from ~URLRequestPostInterceptorFactory(). 126 // implicitly destroy it is posted from ~URLRequestPostInterceptorFactory().
107 URLRequestPostInterceptor::Delegate* delegate_; 127 URLRequestPostInterceptor::Delegate* delegate_;
108 128
109 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptorFactory); 129 DISALLOW_COPY_AND_ASSIGN(URLRequestPostInterceptorFactory);
110 }; 130 };
111 131
132 // Intercepts HTTP POST requests sent to "localhost2".
133 class InterceptorFactory : public URLRequestPostInterceptorFactory {
134 public:
135 InterceptorFactory();
136 ~InterceptorFactory();
137
138 URLRequestPostInterceptor* CreateInterceptor();
139
140 private:
141 DISALLOW_COPY_AND_ASSIGN(InterceptorFactory);
142 };
143
144 class PartialMatch : public URLRequestPostInterceptor::RequestMatcher {
145 public:
146 explicit PartialMatch(const std::string& expected) : expected_(expected) {}
147 virtual bool Match(const std::string& actual) const OVERRIDE;
148
149 private:
150 const std::string expected_;
151
152 DISALLOW_COPY_AND_ASSIGN(PartialMatch);
153 };
154
112 } // namespace component_updater 155 } // namespace component_updater
113 156
114 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_ 157 #endif // CHROME_BROWSER_COMPONENT_UPDATER_TEST_URL_REQUEST_POST_INTERCEPTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698