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

Unified Diff: chrome/browser/component_updater/test/url_request_post_interceptor.cc

Issue 74893002: Changed the update protocol for component updater from v2 to v3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed feedback from cdn@ Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/component_updater/test/url_request_post_interceptor.cc
diff --git a/chrome/browser/component_updater/test/url_request_post_interceptor.cc b/chrome/browser/component_updater/test/url_request_post_interceptor.cc
index 3a511f1798a8532876e8bc0973db0fc3332d79d9..2f0f99263b6a6fbc536d93c9fddd60700da87226 100644
--- a/chrome/browser/component_updater/test/url_request_post_interceptor.cc
+++ b/chrome/browser/component_updater/test/url_request_post_interceptor.cc
@@ -18,6 +18,7 @@ using content::BrowserThread;
namespace component_updater {
+// Returns a canned response.
class URLRequestMockJob : public net::URLRequestSimpleJob {
public:
URLRequestMockJob(net::URLRequest* request,
@@ -27,6 +28,10 @@ class URLRequestMockJob : public net::URLRequestSimpleJob {
response_(response) {}
protected:
+ virtual int GetResponseCode() const OVERRIDE {
+ return 200;
+ }
+
virtual int GetData(std::string* mime_type,
std::string* charset,
std::string* data,
@@ -45,9 +50,14 @@ class URLRequestMockJob : public net::URLRequestSimpleJob {
};
URLRequestPostInterceptor::URLRequestPostInterceptor(const GURL& url)
- : url_(url), hit_count_(0), miss_count_(0) {}
+ : url_(url), hit_count_(0) {}
URLRequestPostInterceptor::~URLRequestPostInterceptor() {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ ClearExpectations();
+}
+
+void URLRequestPostInterceptor::ClearExpectations() {
while (!expectations_.empty()) {
Expectation expectation(expectations_.front());
delete expectation.first;
@@ -67,10 +77,9 @@ bool URLRequestPostInterceptor::ExpectRequest(
bool URLRequestPostInterceptor::ExpectRequest(
class RequestMatcher* request_matcher,
- const std::string& filepath) {
+ const base::FilePath& filepath) {
std::string response;
- const base::FilePath path(base::FilePath().AppendASCII(filepath));
- if (filepath.empty() || !base::ReadFileToString(path, &response))
+ if (filepath.empty() || !base::ReadFileToString(filepath, &response))
return false;
expectations_.push(std::make_pair(request_matcher, response));
return true;
@@ -81,9 +90,9 @@ int URLRequestPostInterceptor::GetHitCount() const {
return hit_count_;
}
-int URLRequestPostInterceptor::GetMissCount() const {
+int URLRequestPostInterceptor::GetCount() const {
base::AutoLock auto_lock(interceptor_lock_);
- return requests_.size() - hit_count_;
+ return static_cast<int>(requests_.size());
}
std::vector<std::string>
@@ -106,6 +115,13 @@ std::string URLRequestPostInterceptor::GetRequestsAsString() const {
return s;
}
+void URLRequestPostInterceptor::Reset() {
+ base::AutoLock auto_lock(interceptor_lock_);
+ hit_count_ = 0;
+ requests_.clear();
+ ClearExpectations();
+}
+
class URLRequestPostInterceptor::Delegate
: public net::URLRequestJobFactory::ProtocolHandler {
@@ -180,13 +196,12 @@ class URLRequestPostInterceptor::Delegate
const URLRequestPostInterceptor::Expectation& expectation(
interceptor->expectations_.front());
if (expectation.first->Match(request_body)) {
+ const std::string response(expectation.second);
delete expectation.first;
interceptor->expectations_.pop();
++interceptor->hit_count_;
- return new URLRequestMockJob(request,
- network_delegate,
- expectation.second);
+ return new URLRequestMockJob(request, network_delegate, response);
}
}
@@ -222,11 +237,11 @@ URLRequestPostInterceptorFactory::~URLRequestPostInterceptorFactory() {
}
URLRequestPostInterceptor* URLRequestPostInterceptorFactory::CreateInterceptor(
- const std::string& file_path) {
+ const base::FilePath& filepath) {
const GURL base_url(base::StringPrintf("%s://%s",
scheme_.c_str(),
hostname_.c_str()));
- GURL absolute_url(base_url.Resolve(file_path));
+ GURL absolute_url(base_url.Resolve(filepath.MaybeAsASCII()));
URLRequestPostInterceptor* interceptor(
new URLRequestPostInterceptor(absolute_url));
bool res = BrowserThread::PostTask(

Powered by Google App Engine
This is Rietveld 408576698