Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: ios/web/public/test/fakes/test_web_state_delegate.h

Issue 2737943003: Moved window opening callback to WebStateDelegate. (Closed)
Patch Set: Self review Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <set>
11 12
12 #include "base/mac/scoped_nsobject.h" 13 #include "base/mac/scoped_nsobject.h"
13 #import "ios/web/public/web_state/web_state_delegate.h" 14 #import "ios/web/public/web_state/web_state_delegate.h"
14 #import "ios/web/public/test/fakes/test_java_script_dialog_presenter.h" 15 #import "ios/web/public/test/fakes/test_java_script_dialog_presenter.h"
15 16
16 namespace web { 17 namespace web {
17 18
19 // Encapsulates parameters passed to CreateNewWebState.
20 struct TestCreateNewWebStateRequest {
21 WebState* web_state = nullptr;
22 GURL url;
23 GURL opener_url;
24 bool initiated_by_user = false;
25 };
26
18 // Encapsulates parameters passed to OpenURLFromWebState. 27 // Encapsulates parameters passed to OpenURLFromWebState.
19 struct TestOpenURLRequest { 28 struct TestOpenURLRequest {
20 TestOpenURLRequest(); 29 TestOpenURLRequest();
21 TestOpenURLRequest(const TestOpenURLRequest&); 30 TestOpenURLRequest(const TestOpenURLRequest&);
22 ~TestOpenURLRequest(); 31 ~TestOpenURLRequest();
23 WebState* web_state = nullptr; 32 WebState* web_state = nullptr;
24 WebState::OpenURLParams params; 33 WebState::OpenURLParams params;
25 }; 34 };
26 35
27 // Encapsulates parameters passed to ShowRepostFormWarningDialog. 36 // Encapsulates parameters passed to ShowRepostFormWarningDialog.
28 struct TestRepostFormRequest { 37 struct TestRepostFormRequest {
29 TestRepostFormRequest(); 38 TestRepostFormRequest();
30 TestRepostFormRequest(const TestRepostFormRequest&); 39 TestRepostFormRequest(const TestRepostFormRequest&);
31 ~TestRepostFormRequest(); 40 ~TestRepostFormRequest();
32 WebState* web_state = nullptr; 41 WebState* web_state = nullptr;
33 base::Callback<void(bool)> callback; 42 base::Callback<void(bool)> callback;
34 }; 43 };
35 44
36 // Encapsulates parameters passed to OnAuthRequired. 45 // Encapsulates parameters passed to OnAuthRequired.
37 struct TestAuthenticationRequest { 46 struct TestAuthenticationRequest {
38 TestAuthenticationRequest(); 47 TestAuthenticationRequest();
39 TestAuthenticationRequest(const TestAuthenticationRequest&); 48 TestAuthenticationRequest(const TestAuthenticationRequest&);
40 ~TestAuthenticationRequest(); 49 ~TestAuthenticationRequest();
41 WebState* web_state = nullptr; 50 WebState* web_state = nullptr;
42 base::scoped_nsobject<NSURLProtectionSpace> protection_space; 51 base::scoped_nsobject<NSURLProtectionSpace> protection_space;
43 base::scoped_nsobject<NSURLCredential> credential; 52 base::scoped_nsobject<NSURLCredential> credential;
44 WebStateDelegate::AuthCallback auth_callback; 53 WebStateDelegate::AuthCallback auth_callback;
45 }; 54 };
46 55
56 // Encapsulates information about popup.
57 struct TestPopup {
58 TestPopup(const GURL& url, const GURL& opener_url)
59 : url(url), opener_url(opener_url) {}
60 GURL url;
61 GURL opener_url;
62 };
63
47 // Fake WebStateDelegate used for testing purposes. 64 // Fake WebStateDelegate used for testing purposes.
48 class TestWebStateDelegate : public WebStateDelegate { 65 class TestWebStateDelegate : public WebStateDelegate {
49 public: 66 public:
50 TestWebStateDelegate(); 67 TestWebStateDelegate();
51 ~TestWebStateDelegate() override; 68 ~TestWebStateDelegate() override;
52 69
53 // WebStateDelegate overrides: 70 // WebStateDelegate overrides:
71 WebState* CreateNewWebState(WebState* source,
72 const GURL& url,
73 const GURL& opener_url,
74 bool initiated_by_user) override;
54 WebState* OpenURLFromWebState(WebState*, 75 WebState* OpenURLFromWebState(WebState*,
55 const WebState::OpenURLParams&) override; 76 const WebState::OpenURLParams&) override;
56 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter(WebState*) override; 77 JavaScriptDialogPresenter* GetJavaScriptDialogPresenter(WebState*) override;
57 bool HandleContextMenu(WebState* source, 78 bool HandleContextMenu(WebState* source,
58 const ContextMenuParams& params) override; 79 const ContextMenuParams& params) override;
59 void ShowRepostFormWarningDialog( 80 void ShowRepostFormWarningDialog(
60 WebState* source, 81 WebState* source,
61 const base::Callback<void(bool)>& callback) override; 82 const base::Callback<void(bool)>& callback) override;
62 TestJavaScriptDialogPresenter* GetTestJavaScriptDialogPresenter(); 83 TestJavaScriptDialogPresenter* GetTestJavaScriptDialogPresenter();
63 void OnAuthRequired(WebState* source, 84 void OnAuthRequired(WebState* source,
64 NSURLProtectionSpace* protection_space, 85 NSURLProtectionSpace* protection_space,
65 NSURLCredential* proposed_credential, 86 NSURLCredential* proposed_credential,
66 const AuthCallback& callback) override; 87 const AuthCallback& callback) override;
67 88
89 // Allows popups requested by a page with |opener_url|.
90 void allow_popups(const GURL& opener_url) {
91 allowed_popups_.insert(opener_url);
92 }
93
94 // Returns list of all child windows opened via CreateNewWebState.
rohitrao (ping after 24h) 2017/03/09 00:26:14 Does this transfer ownership of the WebStates to t
Eugene But (OOO till 7-30) 2017/03/09 01:23:59 No, it returns the result by const reference to in
95 const std::vector<std::unique_ptr<WebState>>& child_windows() const {
96 return child_windows_;
97 }
98
99 // Returns list of all popups requested via CreateNewWebState.
100 const std::vector<TestPopup>& popups() const { return popups_; }
101
68 // True if the WebStateDelegate HandleContextMenu method has been called. 102 // True if the WebStateDelegate HandleContextMenu method has been called.
69 bool handle_context_menu_called() const { 103 bool handle_context_menu_called() const {
70 return handle_context_menu_called_; 104 return handle_context_menu_called_;
71 } 105 }
72 106
107 // Returns the last Web State creation request passed to |CreateNewWebState|.
108 TestCreateNewWebStateRequest* last_create_new_web_state_request() const {
109 return last_create_new_web_state_request_.get();
110 }
111
73 // Returns the last Open URL request passed to |OpenURLFromWebState|. 112 // Returns the last Open URL request passed to |OpenURLFromWebState|.
74 TestOpenURLRequest* last_open_url_request() const { 113 TestOpenURLRequest* last_open_url_request() const {
75 return last_open_url_request_.get(); 114 return last_open_url_request_.get();
76 } 115 }
77 116
78 // Returns the last Repost Form request passed to 117 // Returns the last Repost Form request passed to
79 // |ShowRepostFormWarningDialog|. 118 // |ShowRepostFormWarningDialog|.
80 TestRepostFormRequest* last_repost_form_request() const { 119 TestRepostFormRequest* last_repost_form_request() const {
81 return last_repost_form_request_.get(); 120 return last_repost_form_request_.get();
82 } 121 }
83 122
84 // True if the WebStateDelegate GetJavaScriptDialogPresenter method has been 123 // True if the WebStateDelegate GetJavaScriptDialogPresenter method has been
85 // called. 124 // called.
86 bool get_java_script_dialog_presenter_called() const { 125 bool get_java_script_dialog_presenter_called() const {
87 return get_java_script_dialog_presenter_called_; 126 return get_java_script_dialog_presenter_called_;
88 } 127 }
89 128
90 // Returns the last HTTP Authentication request passed to |OnAuthRequired|. 129 // Returns the last HTTP Authentication request passed to |OnAuthRequired|.
91 TestAuthenticationRequest* last_authentication_request() const { 130 TestAuthenticationRequest* last_authentication_request() const {
92 return last_authentication_request_.get(); 131 return last_authentication_request_.get();
93 } 132 }
94 133
95 // Clears the last HTTP Authentication request passed to |OnAuthRequired|. 134 // Clears the last HTTP Authentication request passed to |OnAuthRequired|.
96 void ClearLastAuthenticationRequest() { 135 void ClearLastAuthenticationRequest() {
97 last_authentication_request_.reset(); 136 last_authentication_request_.reset();
98 } 137 }
99 138
100 private: 139 private:
140 std::vector<std::unique_ptr<WebState>> child_windows_;
141 // A page can open popup if its URL is in this set.
142 std::set<GURL> allowed_popups_;
143 std::vector<TestPopup> popups_;
101 bool handle_context_menu_called_ = false; 144 bool handle_context_menu_called_ = false;
145 std::unique_ptr<TestCreateNewWebStateRequest>
146 last_create_new_web_state_request_;
102 std::unique_ptr<TestOpenURLRequest> last_open_url_request_; 147 std::unique_ptr<TestOpenURLRequest> last_open_url_request_;
103 std::unique_ptr<TestRepostFormRequest> last_repost_form_request_; 148 std::unique_ptr<TestRepostFormRequest> last_repost_form_request_;
104 bool get_java_script_dialog_presenter_called_ = false; 149 bool get_java_script_dialog_presenter_called_ = false;
105 TestJavaScriptDialogPresenter java_script_dialog_presenter_; 150 TestJavaScriptDialogPresenter java_script_dialog_presenter_;
106 std::unique_ptr<TestAuthenticationRequest> last_authentication_request_; 151 std::unique_ptr<TestAuthenticationRequest> last_authentication_request_;
107 }; 152 };
108 153
109 } // namespace web 154 } // namespace web
110 155
111 #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_ 156 #endif // IOS_WEB_PUBLIC_TEST_FAKES_TEST_WEB_STATE_DELEGATE_H_
OLDNEW
« no previous file with comments | « ios/web/public/test/crw_mock_web_state_delegate.mm ('k') | ios/web/public/test/fakes/test_web_state_delegate.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698