| 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 #ifndef HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ | 5 #ifndef HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ |
| 6 #define HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ | 6 #define HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "headless/public/headless_export.h" | 12 #include "headless/public/headless_export.h" |
| 13 #include "headless/public/util/generic_url_request_job.h" | 13 #include "headless/public/util/generic_url_request_job.h" |
| 14 #include "headless/public/util/testing/generic_url_request_mocks.h" | 14 #include "headless/public/util/testing/generic_url_request_mocks.h" |
| 15 #include "net/cookies/cookie_store.h" | 15 #include "net/cookies/cookie_store.h" |
| 16 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 17 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 18 #include "net/url_request/url_request_job_factory.h" | 18 #include "net/url_request/url_request_job_factory.h" |
| 19 | 19 |
| 20 namespace headless { | 20 namespace headless { |
| 21 | 21 |
| 22 class HEADLESS_EXPORT MockGenericURLRequestJobDelegate | 22 class HEADLESS_EXPORT MockGenericURLRequestJobDelegate |
| 23 : public GenericURLRequestJob::Delegate { | 23 : public GenericURLRequestJob::Delegate { |
| 24 public: | 24 public: |
| 25 MockGenericURLRequestJobDelegate(); | 25 MockGenericURLRequestJobDelegate(); |
| 26 ~MockGenericURLRequestJobDelegate() override; | 26 ~MockGenericURLRequestJobDelegate() override; |
| 27 | 27 |
| 28 bool BlockOrRewriteRequest( | 28 // GenericURLRequestJob::Delegate methods: |
| 29 const GURL& url, | 29 void OnPendingRequest(PendingRequest* pending_request) override; |
| 30 const std::string& devtools_id, | 30 void OnResourceLoadFailed(const Request* request, net::Error error) override; |
| 31 const std::string& method, | 31 void OnResourceLoadComplete( |
| 32 const std::string& referrer, | 32 const Request* request, |
| 33 GenericURLRequestJob::RewriteCallback callback) override; | 33 const GURL& final_url, |
| 34 int http_response_code, |
| 35 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 36 const char* body, |
| 37 size_t body_size) override; |
| 34 | 38 |
| 35 const GenericURLRequestJob::HttpResponse* MaybeMatchResource( | 39 using Policy = base::Callback<void(PendingRequest* pending_request)>; |
| 36 const GURL& url, | |
| 37 const std::string& devtools_id, | |
| 38 const std::string& method, | |
| 39 const net::HttpRequestHeaders& request_headers) override; | |
| 40 | 40 |
| 41 void OnResourceLoadComplete(const GURL& final_url, | 41 void SetPolicy(Policy policy); |
| 42 const std::string& devtools_id, | |
| 43 const std::string& mime_type, | |
| 44 int http_response_code) override; | |
| 45 | |
| 46 void SetShouldBlock(bool should_block) { should_block_ = should_block; } | |
| 47 | 42 |
| 48 private: | 43 private: |
| 49 bool should_block_; | 44 void ApplyPolicy(PendingRequest* pending_request); |
| 45 |
| 46 Policy policy_; |
| 50 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 47 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 51 | 48 |
| 52 DISALLOW_COPY_AND_ASSIGN(MockGenericURLRequestJobDelegate); | 49 DISALLOW_COPY_AND_ASSIGN(MockGenericURLRequestJobDelegate); |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 // TODO(alexclarke): We may be able to replace this with the CookieMonster. | 52 // TODO(alexclarke): We may be able to replace this with the CookieMonster. |
| 56 class HEADLESS_EXPORT MockCookieStore : public net::CookieStore { | 53 class HEADLESS_EXPORT MockCookieStore : public net::CookieStore { |
| 57 public: | 54 public: |
| 58 MockCookieStore(); | 55 MockCookieStore(); |
| 59 ~MockCookieStore() override; | 56 ~MockCookieStore() override; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 141 |
| 145 private: | 142 private: |
| 146 std::string response_data_; | 143 std::string response_data_; |
| 147 | 144 |
| 148 DISALLOW_COPY_AND_ASSIGN(MockURLRequestDelegate); | 145 DISALLOW_COPY_AND_ASSIGN(MockURLRequestDelegate); |
| 149 }; | 146 }; |
| 150 | 147 |
| 151 } // namespace headless | 148 } // namespace headless |
| 152 | 149 |
| 153 #endif // HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ | 150 #endif // HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ |
| OLD | NEW |