| 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 CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ | 5 #ifndef CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ |
| 6 #define CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_H_ | 6 #define CONTENT_BROWSER_LOADER_MOCK_RESOURCE_LOADER_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 "content/browser/loader/resource_controller.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "content/browser/loader/resource_handler.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 | 15 |
| 15 class GURL; | 16 class GURL; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 struct RedirectInfo; | 19 struct RedirectInfo; |
| 19 class URLRequestStatus; | 20 class URLRequestStatus; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 class ResourceHandler; | |
| 24 struct ResourceResponse; | 24 struct ResourceResponse; |
| 25 | 25 |
| 26 // Class that takes the place of the ResourceLoader for tests. It simplifies | 26 // Class that takes the place of the ResourceLoader for tests. It simplifies |
| 27 // testing ResourceHandlers by managing callbacks and performing basic sanity | 27 // testing ResourceHandlers by managing callbacks and performing basic sanity |
| 28 // checks. The test fixture is responsible for advancing states. | 28 // checks. The test fixture is responsible for advancing states. |
| 29 class MockResourceLoader : public ResourceController { | 29 class MockResourceLoader : public ResourceHandler::Delegate { |
| 30 public: | 30 public: |
| 31 explicit MockResourceLoader(ResourceHandler* resource_handler); | 31 explicit MockResourceLoader(ResourceHandler* resource_handler); |
| 32 ~MockResourceLoader() override; | 32 ~MockResourceLoader() override; |
| 33 | 33 |
| 34 // Idle means the ResourceHandler is waiting for the next call from the | 34 // Idle means the ResourceHandler is waiting for the next call from the |
| 35 // TestFixture/ResourceLoader, CALLBACK_PENDING means that the ResourceHandler | 35 // TestFixture/ResourceLoader, CALLBACK_PENDING means that the ResourceHandler |
| 36 // will resume the request at some future point to resume the request, and | 36 // will resume the request at some future point to resume the request, and |
| 37 // CANCELED means the ResourceHandler cancelled the request. | 37 // CANCELED means the ResourceHandler cancelled the request. |
| 38 enum class Status { | 38 enum class Status { |
| 39 // The MockLoader is waiting for more data from hte test fixture. | 39 // The MockLoader is waiting for more data from hte test fixture. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 Status OnReadCompleted(int bytes_read); | 58 Status OnReadCompleted(int bytes_read); |
| 59 Status OnResponseCompleted(const net::URLRequestStatus& status); | 59 Status OnResponseCompleted(const net::URLRequestStatus& status); |
| 60 | 60 |
| 61 Status status() const { return status_; } | 61 Status status() const { return status_; } |
| 62 | 62 |
| 63 // Network error passed to the first CancelWithError() / Cancel() call, which | 63 // Network error passed to the first CancelWithError() / Cancel() call, which |
| 64 // is the one the real code uses in the case of multiple cancels. | 64 // is the one the real code uses in the case of multiple cancels. |
| 65 int error_code() const { return error_code_; } | 65 int error_code() const { return error_code_; } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 // ResourceController implementation. | 68 class TestResourceController; |
| 69 void Cancel() override; | 69 |
| 70 void CancelAndIgnore() override; | 70 // ResourceHandler::Delegate implementation: |
| 71 void CancelWithError(int error_code) override; | 71 void OutOfBandCancel(int error_code, bool tell_renderer) override; |
| 72 void Resume() override; | 72 |
| 73 void OnCancel(int error_code); |
| 74 void OnResume(); |
| 73 | 75 |
| 74 ResourceHandler* const resource_handler_; | 76 ResourceHandler* const resource_handler_; |
| 75 | 77 |
| 76 Status status_ = Status::IDLE; | 78 Status status_ = Status::IDLE; |
| 77 int error_code_ = net::OK; | 79 int error_code_ = net::OK; |
| 80 bool canceled_out_of_band_ = false; |
| 81 |
| 82 base::WeakPtrFactory<MockResourceLoader> weak_factory_; |
| 78 | 83 |
| 79 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader); | 84 DISALLOW_COPY_AND_ASSIGN(MockResourceLoader); |
| 80 }; | 85 }; |
| 81 | 86 |
| 82 } // namespace content | 87 } // namespace content |
| 83 | 88 |
| 84 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_ | 89 #endif // CONTENT_BROWSER_LOADER_TEST_RESOURCE_HANDLER_WRAPPER_H_ |
| OLD | NEW |