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

Unified Diff: headless/public/util/testing/generic_url_request_mocks.cc

Issue 2815003003: Headless (breaking change): A better GenericURLRequestJob::Delegate API (Closed)
Patch Set: Changes for Sami Created 3 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 | « headless/public/util/testing/generic_url_request_mocks.h ('k') | headless/public/util/url_fetcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/public/util/testing/generic_url_request_mocks.cc
diff --git a/headless/public/util/testing/generic_url_request_mocks.cc b/headless/public/util/testing/generic_url_request_mocks.cc
index 3d5e6825be494f5772442cd669e941a2903c9650..4a7d37deb4ad539c711885aeded9cf64022a1cd8 100644
--- a/headless/public/util/testing/generic_url_request_mocks.cc
+++ b/headless/public/util/testing/generic_url_request_mocks.cc
@@ -15,45 +15,43 @@ namespace headless {
// MockGenericURLRequestJobDelegate
MockGenericURLRequestJobDelegate::MockGenericURLRequestJobDelegate()
- : should_block_(false),
- main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+ : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
+
MockGenericURLRequestJobDelegate::~MockGenericURLRequestJobDelegate() {}
-bool MockGenericURLRequestJobDelegate::BlockOrRewriteRequest(
- const GURL& url,
- const std::string& devtools_id,
- const std::string& method,
- const std::string& referrer,
- GenericURLRequestJob::RewriteCallback callback) {
- if (should_block_) {
- // Simulate the client acknowledging the callback from a different thread.
- main_thread_task_runner_->PostTask(
- FROM_HERE, base::Bind(
- [](GenericURLRequestJob::RewriteCallback callback,
- std::string method) {
- callback.Run(
- GenericURLRequestJob::RewriteResult::kDeny, GURL(),
- method);
- },
- callback, method));
- }
- return should_block_;
+// GenericURLRequestJob::Delegate methods:
+void MockGenericURLRequestJobDelegate::OnPendingRequest(
+ PendingRequest* pending_request) {
+ // Simulate the client acknowledging the callback from a different thread.
+ main_thread_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&MockGenericURLRequestJobDelegate::ApplyPolicy,
+ base::Unretained(this), pending_request));
}
-const GenericURLRequestJob::HttpResponse*
-MockGenericURLRequestJobDelegate::MaybeMatchResource(
- const GURL& url,
- const std::string& devtools_id,
- const std::string& method,
- const net::HttpRequestHeaders& request_headers) {
- return nullptr;
+void MockGenericURLRequestJobDelegate::SetPolicy(Policy policy) {
+ policy_ = policy;
}
+void MockGenericURLRequestJobDelegate::ApplyPolicy(
+ PendingRequest* pending_request) {
+ if (policy_.is_null()) {
+ pending_request->AllowRequest();
+ } else {
+ policy_.Run(pending_request);
+ }
+}
+
+void MockGenericURLRequestJobDelegate::OnResourceLoadFailed(
+ const Request* request,
+ net::Error error) {}
+
void MockGenericURLRequestJobDelegate::OnResourceLoadComplete(
+ const Request* request,
const GURL& final_url,
- const std::string& devtools_id,
- const std::string& mime_type,
- int http_response_code) {}
+ int http_response_code,
+ scoped_refptr<net::HttpResponseHeaders> response_headers,
+ const char* body,
+ size_t body_size) {}
// MockCookieStore
MockCookieStore::MockCookieStore() {}
« no previous file with comments | « headless/public/util/testing/generic_url_request_mocks.h ('k') | headless/public/util/url_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698