OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ |
| 6 #define CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "content/public/browser/navigation_throttle.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 class NavigationHandle; |
| 15 |
| 16 // This class can be used to cancel navigations synchronously or asynchronously |
| 17 // at a specific time in the NavigationThrottle lifecycle. |
| 18 // |
| 19 // Consider using it in conjunction with NavigationSimulator. |
| 20 // TODO(clamy): Check if this could be used in unit tests exercising |
| 21 // NavigationThrottle code. |
| 22 class CancellingNavigationThrottle : public NavigationThrottle { |
| 23 public: |
| 24 enum CancelTime { |
| 25 WILL_START_REQUEST, |
| 26 WILL_REDIRECT_REQUEST, |
| 27 WILL_PROCESS_RESPONSE, |
| 28 NEVER, |
| 29 }; |
| 30 |
| 31 enum ResultSynchrony { |
| 32 SYNCHRONOUS, |
| 33 ASYNCHRONOUS, |
| 34 }; |
| 35 |
| 36 CancellingNavigationThrottle(NavigationHandle* handle, |
| 37 CancelTime cancel_time, |
| 38 ResultSynchrony sync); |
| 39 ~CancellingNavigationThrottle() override; |
| 40 |
| 41 // NavigationThrottle: |
| 42 NavigationThrottle::ThrottleCheckResult WillStartRequest() override; |
| 43 NavigationThrottle::ThrottleCheckResult WillRedirectRequest() override; |
| 44 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override; |
| 45 const char* GetNameForLogging() override; |
| 46 |
| 47 private: |
| 48 NavigationThrottle::ThrottleCheckResult ProcessState(bool should_cancel); |
| 49 void MaybeCancel(bool cancel); |
| 50 |
| 51 private: |
| 52 const CancelTime cancel_time_; |
| 53 const ResultSynchrony sync_; |
| 54 |
| 55 base::WeakPtrFactory<CancellingNavigationThrottle> weak_ptr_factory_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(CancellingNavigationThrottle); |
| 58 }; |
| 59 |
| 60 } // namespace content |
| 61 |
| 62 #endif // CONTENT_PUBLIC_TEST_CANCELLING_NAVIGATION_THROTTLE_H_ |
OLD | NEW |