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

Unified Diff: content/test/net/url_request_prepackaged_interceptor.cc

Issue 12967016: Improve <adview> implementation and add tests. (Closed) Base URL: https://git.chromium.org/chromium/src.git@master
Patch Set: Disable test with dependency on binary file. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/test/net/url_request_prepackaged_interceptor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/test/net/url_request_prepackaged_interceptor.cc
diff --git a/content/test/net/url_request_prepackaged_interceptor.cc b/content/test/net/url_request_prepackaged_interceptor.cc
index f8603ef5de0f4e56b49a8e8710b5b52f8255fea2..9150a7ef88b104a1a933145922a79723254d4480 100644
--- a/content/test/net/url_request_prepackaged_interceptor.cc
+++ b/content/test/net/url_request_prepackaged_interceptor.cc
@@ -38,23 +38,26 @@ class URLRequestPrepackagedJob : public net::URLRequestFileJob {
class URLRequestPrepackagedInterceptor::Delegate
: public net::URLRequestJobFactory::ProtocolHandler {
public:
- Delegate() : hit_count_(0) {}
+ Delegate(const std::string& scheme, const std::string& hostname)
+ : scheme_(scheme), hostname_(hostname), hit_count_(0) {}
virtual ~Delegate() {}
void Register() {
net::URLRequestFilter::GetInstance()->AddHostnameProtocolHandler(
- "http", "localhost",
+ scheme_, hostname_,
scoped_ptr<net::URLRequestJobFactory::ProtocolHandler>(this));
}
- static void Unregister() {
- net::URLRequestFilter::GetInstance()->RemoveHostnameHandler("http",
- "localhost");
+ static void Unregister(
+ const std::string& scheme,
+ const std::string& hostname) {
+ net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(scheme,
+ hostname);
}
// When requests for |url| arrive, respond with the contents of |path|. The
- // hostname of |url| must be "localhost" to avoid DNS lookups, and the scheme
- // must be "http".
+ // hostname and scheme of |url| must match the corresponding parameters
+ // passed as constructor arguments.
void SetResponse(const GURL& url,
const base::FilePath& path,
bool ignore_query) {
@@ -84,8 +87,8 @@ class URLRequestPrepackagedInterceptor::Delegate
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const OVERRIDE {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- if (request->url().scheme() != "http" ||
- request->url().host() != "localhost") {
+ if (request->url().scheme() != scheme_ ||
+ request->url().host() != hostname_) {
return NULL;
}
@@ -112,6 +115,9 @@ class URLRequestPrepackagedInterceptor::Delegate
it->second);
}
+ const std::string scheme_;
+ const std::string hostname_;
+
ResponseMap responses_;
ResponseMap ignore_query_responses_;
@@ -122,8 +128,12 @@ class URLRequestPrepackagedInterceptor::Delegate
};
-URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor()
- : delegate_(new Delegate) {
+URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor(
+ const std::string& scheme,
+ const std::string& hostname)
+ : scheme_(scheme),
+ hostname_(hostname),
+ delegate_(new Delegate(scheme, hostname)) {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&Delegate::Register,
base::Unretained(delegate_)));
@@ -131,13 +141,16 @@ URLRequestPrepackagedInterceptor::URLRequestPrepackagedInterceptor()
URLRequestPrepackagedInterceptor::~URLRequestPrepackagedInterceptor() {
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&Delegate::Unregister));
+ base::Bind(&Delegate::Unregister,
+ scheme_,
+ hostname_));
}
-void URLRequestPrepackagedInterceptor::SetResponse(const GURL& url,
- const base::FilePath& path) {
- CHECK_EQ("http", url.scheme());
- CHECK_EQ("localhost", url.host());
+void URLRequestPrepackagedInterceptor::SetResponse(
+ const GURL& url,
+ const base::FilePath& path) {
+ CHECK_EQ(scheme_, url.scheme());
+ CHECK_EQ(hostname_, url.host());
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&Delegate::SetResponse,
base::Unretained(delegate_), url, path,
@@ -147,8 +160,8 @@ void URLRequestPrepackagedInterceptor::SetResponse(const GURL& url,
void URLRequestPrepackagedInterceptor::SetResponseIgnoreQuery(
const GURL& url,
const base::FilePath& path) {
- CHECK_EQ("http", url.scheme());
- CHECK_EQ("localhost", url.host());
+ CHECK_EQ(scheme_, url.scheme());
+ CHECK_EQ(hostname_, url.host());
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&Delegate::SetResponse,
base::Unretained(delegate_), url, path,
@@ -159,4 +172,10 @@ int URLRequestPrepackagedInterceptor::GetHitCount() {
return delegate_->GetHitCount();
}
+
+URLLocalHostRequestPrepackagedInterceptor
+ ::URLLocalHostRequestPrepackagedInterceptor()
+ : URLRequestPrepackagedInterceptor("http", "localhost") {
+}
+
} // namespace content
« no previous file with comments | « content/test/net/url_request_prepackaged_interceptor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698