| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ | 5 #ifndef IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ |
| 6 #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ | 6 #define IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ |
| 7 | 7 |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #import "ios/web/public/web_state/web_state_delegate.h" | 13 #import "ios/web/public/web_state/web_state_delegate.h" |
| 14 #import "ios/web/public/test/fakes/test_java_script_dialog_presenter.h" | 14 #import "ios/web/public/test/fakes/test_java_script_dialog_presenter.h" |
| 15 | 15 |
| 16 namespace web { | 16 namespace web { |
| 17 | 17 |
| 18 // Encapsulates parameters passed to OpenURLFromWebState. |
| 19 struct TestOpenURLRequest { |
| 20 TestOpenURLRequest(); |
| 21 TestOpenURLRequest(const TestOpenURLRequest&); |
| 22 ~TestOpenURLRequest(); |
| 23 WebState* web_state = nullptr; |
| 24 WebState::OpenURLParams params; |
| 25 }; |
| 26 |
| 18 // Encapsulates parameters passed to ShowRepostFormWarningDialog. | 27 // Encapsulates parameters passed to ShowRepostFormWarningDialog. |
| 19 struct TestRepostFormRequest { | 28 struct TestRepostFormRequest { |
| 20 TestRepostFormRequest(); | 29 TestRepostFormRequest(); |
| 21 TestRepostFormRequest(const TestRepostFormRequest&); | 30 TestRepostFormRequest(const TestRepostFormRequest&); |
| 22 ~TestRepostFormRequest(); | 31 ~TestRepostFormRequest(); |
| 23 WebState* web_state = nullptr; | 32 WebState* web_state = nullptr; |
| 24 base::Callback<void(bool)> callback; | 33 base::Callback<void(bool)> callback; |
| 25 }; | 34 }; |
| 26 | 35 |
| 27 // Encapsulates parameters passed to OnAuthRequired. | 36 // Encapsulates parameters passed to OnAuthRequired. |
| 28 struct TestAuthenticationRequest { | 37 struct TestAuthenticationRequest { |
| 29 TestAuthenticationRequest(); | 38 TestAuthenticationRequest(); |
| 30 TestAuthenticationRequest(const TestAuthenticationRequest&); | 39 TestAuthenticationRequest(const TestAuthenticationRequest&); |
| 31 ~TestAuthenticationRequest(); | 40 ~TestAuthenticationRequest(); |
| 32 WebState* web_state = nullptr; | 41 WebState* web_state = nullptr; |
| 33 base::scoped_nsobject<NSURLProtectionSpace> protection_space; | 42 base::scoped_nsobject<NSURLProtectionSpace> protection_space; |
| 34 base::scoped_nsobject<NSURLCredential> credential; | 43 base::scoped_nsobject<NSURLCredential> credential; |
| 35 WebStateDelegate::AuthCallback auth_callback; | 44 WebStateDelegate::AuthCallback auth_callback; |
| 36 }; | 45 }; |
| 37 | 46 |
| 38 // Fake WebStateDelegate used for testing purposes. | 47 // Fake WebStateDelegate used for testing purposes. |
| 39 class TestWebStateDelegate : public WebStateDelegate { | 48 class TestWebStateDelegate : public WebStateDelegate { |
| 40 public: | 49 public: |
| 41 TestWebStateDelegate(); | 50 TestWebStateDelegate(); |
| 42 ~TestWebStateDelegate() override; | 51 ~TestWebStateDelegate() override; |
| 43 | 52 |
| 44 // WebStateDelegate overrides: | 53 // WebStateDelegate overrides: |
| 54 WebState* OpenURLFromWebState(WebState*, |
| 55 const WebState::OpenURLParams&) override; |
| 45 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter(WebState*) override; | 56 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter(WebState*) override; |
| 46 bool HandleContextMenu(WebState* source, | 57 bool HandleContextMenu(WebState* source, |
| 47 const ContextMenuParams& params) override; | 58 const ContextMenuParams& params) override; |
| 48 void ShowRepostFormWarningDialog( | 59 void ShowRepostFormWarningDialog( |
| 49 WebState* source, | 60 WebState* source, |
| 50 const base::Callback<void(bool)>& callback) override; | 61 const base::Callback<void(bool)>& callback) override; |
| 51 TestJavaScriptDialogPresenter* GetTestJavaScriptDialogPresenter(); | 62 TestJavaScriptDialogPresenter* GetTestJavaScriptDialogPresenter(); |
| 52 void OnAuthRequired(WebState* source, | 63 void OnAuthRequired(WebState* source, |
| 53 NSURLProtectionSpace* protection_space, | 64 NSURLProtectionSpace* protection_space, |
| 54 NSURLCredential* proposed_credential, | 65 NSURLCredential* proposed_credential, |
| 55 const AuthCallback& callback) override; | 66 const AuthCallback& callback) override; |
| 56 | 67 |
| 57 // True if the WebStateDelegate HandleContextMenu method has been called. | 68 // True if the WebStateDelegate HandleContextMenu method has been called. |
| 58 bool handle_context_menu_called() const { | 69 bool handle_context_menu_called() const { |
| 59 return handle_context_menu_called_; | 70 return handle_context_menu_called_; |
| 60 } | 71 } |
| 61 | 72 |
| 73 // Returns the last Open URL request passed to |OpenURLFromWebState|. |
| 74 TestOpenURLRequest* last_open_url_request() const { |
| 75 return last_open_url_request_.get(); |
| 76 } |
| 77 |
| 62 // Returns the last Repost Form request passed to | 78 // Returns the last Repost Form request passed to |
| 63 // |ShowRepostFormWarningDialog|. | 79 // |ShowRepostFormWarningDialog|. |
| 64 TestRepostFormRequest* last_repost_form_request() const { | 80 TestRepostFormRequest* last_repost_form_request() const { |
| 65 return last_repost_form_request_.get(); | 81 return last_repost_form_request_.get(); |
| 66 } | 82 } |
| 67 | 83 |
| 68 // True if the WebStateDelegate GetJavaScriptDialogPresenter method has been | 84 // True if the WebStateDelegate GetJavaScriptDialogPresenter method has been |
| 69 // called. | 85 // called. |
| 70 bool get_java_script_dialog_presenter_called() const { | 86 bool get_java_script_dialog_presenter_called() const { |
| 71 return get_java_script_dialog_presenter_called_; | 87 return get_java_script_dialog_presenter_called_; |
| 72 } | 88 } |
| 73 | 89 |
| 74 // Returns the last HTTP Authentication request passed to |OnAuthRequired|. | 90 // Returns the last HTTP Authentication request passed to |OnAuthRequired|. |
| 75 TestAuthenticationRequest* last_authentication_request() const { | 91 TestAuthenticationRequest* last_authentication_request() const { |
| 76 return last_authentication_request_.get(); | 92 return last_authentication_request_.get(); |
| 77 } | 93 } |
| 78 | 94 |
| 79 // Clears the last HTTP Authentication request passed to |OnAuthRequired|. | 95 // Clears the last HTTP Authentication request passed to |OnAuthRequired|. |
| 80 void ClearLastAuthenticationRequest() { | 96 void ClearLastAuthenticationRequest() { |
| 81 last_authentication_request_.reset(); | 97 last_authentication_request_.reset(); |
| 82 } | 98 } |
| 83 | 99 |
| 84 private: | 100 private: |
| 85 bool handle_context_menu_called_ = false; | 101 bool handle_context_menu_called_ = false; |
| 102 std::unique_ptr<TestOpenURLRequest> last_open_url_request_; |
| 86 std::unique_ptr<TestRepostFormRequest> last_repost_form_request_; | 103 std::unique_ptr<TestRepostFormRequest> last_repost_form_request_; |
| 87 bool get_java_script_dialog_presenter_called_ = false; | 104 bool get_java_script_dialog_presenter_called_ = false; |
| 88 TestJavaScriptDialogPresenter java_script_dialog_presenter_; | 105 TestJavaScriptDialogPresenter java_script_dialog_presenter_; |
| 89 std::unique_ptr<TestAuthenticationRequest> last_authentication_request_; | 106 std::unique_ptr<TestAuthenticationRequest> last_authentication_request_; |
| 90 }; | 107 }; |
| 91 | 108 |
| 92 } // namespace web | 109 } // namespace web |
| 93 | 110 |
| 94 #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ | 111 #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ |
| OLD | NEW |