OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "headless/public/util/testing/generic_url_request_mocks.h" | 5 #include "headless/public/util/testing/generic_url_request_mocks.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
11 class URLRequestJob; | 11 class URLRequestJob; |
12 } // namespace net | 12 } // namespace net |
13 | 13 |
14 namespace headless { | 14 namespace headless { |
15 | 15 |
16 // MockGenericURLRequestJobDelegate | 16 // MockGenericURLRequestJobDelegate |
17 MockGenericURLRequestJobDelegate::MockGenericURLRequestJobDelegate() | 17 MockGenericURLRequestJobDelegate::MockGenericURLRequestJobDelegate() |
18 : should_block_(false), | 18 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
19 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 19 |
20 MockGenericURLRequestJobDelegate::~MockGenericURLRequestJobDelegate() {} | 20 MockGenericURLRequestJobDelegate::~MockGenericURLRequestJobDelegate() {} |
21 | 21 |
22 bool MockGenericURLRequestJobDelegate::BlockOrRewriteRequest( | 22 // GenericURLRequestJob::Delegate methods: |
23 const GURL& url, | 23 void MockGenericURLRequestJobDelegate::OnPendingRequest( |
24 const std::string& devtools_id, | 24 PendingRequest* pending_request) { |
25 const std::string& method, | 25 // Simulate the client acknowledging the callback from a different thread. |
26 const std::string& referrer, | 26 main_thread_task_runner_->PostTask( |
27 GenericURLRequestJob::RewriteCallback callback) { | 27 FROM_HERE, base::Bind(&MockGenericURLRequestJobDelegate::ApplyPolicy, |
28 if (should_block_) { | 28 base::Unretained(this), pending_request)); |
29 // Simulate the client acknowledging the callback from a different thread. | |
30 main_thread_task_runner_->PostTask( | |
31 FROM_HERE, base::Bind( | |
32 [](GenericURLRequestJob::RewriteCallback callback, | |
33 std::string method) { | |
34 callback.Run( | |
35 GenericURLRequestJob::RewriteResult::kDeny, GURL(), | |
36 method); | |
37 }, | |
38 callback, method)); | |
39 } | |
40 return should_block_; | |
41 } | 29 } |
42 | 30 |
43 const GenericURLRequestJob::HttpResponse* | 31 void MockGenericURLRequestJobDelegate::SetPolicy(Policy policy) { |
44 MockGenericURLRequestJobDelegate::MaybeMatchResource( | 32 policy_ = policy; |
45 const GURL& url, | |
46 const std::string& devtools_id, | |
47 const std::string& method, | |
48 const net::HttpRequestHeaders& request_headers) { | |
49 return nullptr; | |
50 } | 33 } |
51 | 34 |
| 35 void MockGenericURLRequestJobDelegate::ApplyPolicy( |
| 36 PendingRequest* pending_request) { |
| 37 if (policy_.is_null()) { |
| 38 pending_request->AllowRequest(); |
| 39 } else { |
| 40 policy_.Run(pending_request); |
| 41 } |
| 42 } |
| 43 |
| 44 void MockGenericURLRequestJobDelegate::OnResourceLoadFailed( |
| 45 const Request* request, |
| 46 net::Error error) {} |
| 47 |
52 void MockGenericURLRequestJobDelegate::OnResourceLoadComplete( | 48 void MockGenericURLRequestJobDelegate::OnResourceLoadComplete( |
| 49 const Request* request, |
53 const GURL& final_url, | 50 const GURL& final_url, |
54 const std::string& devtools_id, | 51 int http_response_code, |
55 const std::string& mime_type, | 52 scoped_refptr<net::HttpResponseHeaders> response_headers, |
56 int http_response_code) {} | 53 const char* body, |
| 54 size_t body_size) {} |
57 | 55 |
58 // MockCookieStore | 56 // MockCookieStore |
59 MockCookieStore::MockCookieStore() {} | 57 MockCookieStore::MockCookieStore() {} |
60 MockCookieStore::~MockCookieStore() {} | 58 MockCookieStore::~MockCookieStore() {} |
61 | 59 |
62 void MockCookieStore::SetCookieWithOptionsAsync( | 60 void MockCookieStore::SetCookieWithOptionsAsync( |
63 const GURL& url, | 61 const GURL& url, |
64 const std::string& cookie_line, | 62 const std::string& cookie_line, |
65 const net::CookieOptions& options, | 63 const net::CookieOptions& options, |
66 const SetCookiesCallback& callback) { | 64 const SetCookiesCallback& callback) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 int bytes_read) {} | 175 int bytes_read) {} |
178 const std::string& MockURLRequestDelegate::response_data() const { | 176 const std::string& MockURLRequestDelegate::response_data() const { |
179 return response_data_; | 177 return response_data_; |
180 } | 178 } |
181 | 179 |
182 const net::IOBufferWithSize* MockURLRequestDelegate::metadata() const { | 180 const net::IOBufferWithSize* MockURLRequestDelegate::metadata() const { |
183 return nullptr; | 181 return nullptr; |
184 } | 182 } |
185 | 183 |
186 } // namespace headless | 184 } // namespace headless |
OLD | NEW |