| 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/util/generic_url_request_job.h" | 13 #include "headless/public/util/generic_url_request_job.h" |
| 13 #include "headless/public/util/testing/generic_url_request_mocks.h" | 14 #include "headless/public/util/testing/generic_url_request_mocks.h" |
| 14 #include "net/cookies/cookie_store.h" | 15 #include "net/cookies/cookie_store.h" |
| 15 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
| 17 #include "net/url_request/url_request_job_factory.h" | 18 #include "net/url_request/url_request_job_factory.h" |
| 18 | 19 |
| 19 namespace headless { | 20 namespace headless { |
| 20 | 21 |
| 21 class MockGenericURLRequestJobDelegate : public GenericURLRequestJob::Delegate { | 22 class HEADLESS_EXPORT MockGenericURLRequestJobDelegate |
| 23 : public GenericURLRequestJob::Delegate { |
| 22 public: | 24 public: |
| 23 MockGenericURLRequestJobDelegate(); | 25 MockGenericURLRequestJobDelegate(); |
| 24 ~MockGenericURLRequestJobDelegate() override; | 26 ~MockGenericURLRequestJobDelegate() override; |
| 25 | 27 |
| 26 bool BlockOrRewriteRequest( | 28 bool BlockOrRewriteRequest( |
| 27 const GURL& url, | 29 const GURL& url, |
| 28 const std::string& devtools_id, | 30 const std::string& devtools_id, |
| 29 const std::string& method, | 31 const std::string& method, |
| 30 const std::string& referrer, | 32 const std::string& referrer, |
| 31 GenericURLRequestJob::RewriteCallback callback) override; | 33 GenericURLRequestJob::RewriteCallback callback) override; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 43 | 45 |
| 44 void SetShouldBlock(bool should_block) { should_block_ = should_block; } | 46 void SetShouldBlock(bool should_block) { should_block_ = should_block; } |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 bool should_block_; | 49 bool should_block_; |
| 48 | 50 |
| 49 DISALLOW_COPY_AND_ASSIGN(MockGenericURLRequestJobDelegate); | 51 DISALLOW_COPY_AND_ASSIGN(MockGenericURLRequestJobDelegate); |
| 50 }; | 52 }; |
| 51 | 53 |
| 52 // TODO(alexclarke): We may be able to replace this with the CookieMonster. | 54 // TODO(alexclarke): We may be able to replace this with the CookieMonster. |
| 53 class MockCookieStore : public net::CookieStore { | 55 class HEADLESS_EXPORT MockCookieStore : public net::CookieStore { |
| 54 public: | 56 public: |
| 55 MockCookieStore(); | 57 MockCookieStore(); |
| 56 ~MockCookieStore() override; | 58 ~MockCookieStore() override; |
| 57 | 59 |
| 58 // net::CookieStore implementation: | 60 // net::CookieStore implementation: |
| 59 void SetCookieWithOptionsAsync(const GURL& url, | 61 void SetCookieWithOptionsAsync(const GURL& url, |
| 60 const std::string& cookie_line, | 62 const std::string& cookie_line, |
| 61 const net::CookieOptions& options, | 63 const net::CookieOptions& options, |
| 62 const SetCookiesCallback& callback) override; | 64 const SetCookiesCallback& callback) override; |
| 63 | 65 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 private: | 123 private: |
| 122 void SendCookies(const GURL& url, | 124 void SendCookies(const GURL& url, |
| 123 const net::CookieOptions& options, | 125 const net::CookieOptions& options, |
| 124 const GetCookieListCallback& callback); | 126 const GetCookieListCallback& callback); |
| 125 | 127 |
| 126 net::CookieList cookies_; | 128 net::CookieList cookies_; |
| 127 | 129 |
| 128 DISALLOW_COPY_AND_ASSIGN(MockCookieStore); | 130 DISALLOW_COPY_AND_ASSIGN(MockCookieStore); |
| 129 }; | 131 }; |
| 130 | 132 |
| 131 class MockURLRequestDelegate : public net::URLRequest::Delegate { | 133 class HEADLESS_EXPORT MockURLRequestDelegate |
| 134 : public net::URLRequest::Delegate { |
| 132 public: | 135 public: |
| 133 MockURLRequestDelegate(); | 136 MockURLRequestDelegate(); |
| 134 ~MockURLRequestDelegate() override; | 137 ~MockURLRequestDelegate() override; |
| 135 | 138 |
| 136 void OnResponseStarted(net::URLRequest* request) override; | 139 void OnResponseStarted(net::URLRequest* request) override; |
| 137 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; | 140 void OnReadCompleted(net::URLRequest* request, int bytes_read) override; |
| 138 const std::string& response_data() const; | 141 const std::string& response_data() const; |
| 139 const net::IOBufferWithSize* metadata() const; | 142 const net::IOBufferWithSize* metadata() const; |
| 140 | 143 |
| 141 private: | 144 private: |
| 142 std::string response_data_; | 145 std::string response_data_; |
| 143 | 146 |
| 144 DISALLOW_COPY_AND_ASSIGN(MockURLRequestDelegate); | 147 DISALLOW_COPY_AND_ASSIGN(MockURLRequestDelegate); |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 } // namespace headless | 150 } // namespace headless |
| 148 | 151 |
| 149 #endif // HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ | 152 #endif // HEADLESS_PUBLIC_UTIL_TESTING_GENERIC_URL_REQUEST_MOCKS_H_ |
| OLD | NEW |