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

Unified Diff: ios/web/public/test/fakes/test_web_state_delegate.h

Issue 2737943003: Moved window opening callback to WebStateDelegate. (Closed)
Patch Set: Rebased 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/public/test/fakes/test_web_state_delegate.h
diff --git a/ios/web/public/test/fakes/test_web_state_delegate.h b/ios/web/public/test/fakes/test_web_state_delegate.h
index dc20ad113b226412d741a422d6fd9277184a1699..3dfca1e4d1bec55b3f5b2894833d6d80e65739bc 100644
--- a/ios/web/public/test/fakes/test_web_state_delegate.h
+++ b/ios/web/public/test/fakes/test_web_state_delegate.h
@@ -8,6 +8,7 @@
#import <Foundation/Foundation.h>
#include <memory>
+#include <set>
#include "base/mac/scoped_nsobject.h"
#import "ios/web/public/web_state/web_state_delegate.h"
@@ -15,6 +16,14 @@
namespace web {
+// Encapsulates parameters passed to CreateNewWebState.
+struct TestCreateNewWebStateRequest {
+ WebState* web_state = nullptr;
+ GURL url;
+ GURL opener_url;
+ bool initiated_by_user = false;
+};
+
// Encapsulates parameters passed to OpenURLFromWebState.
struct TestOpenURLRequest {
TestOpenURLRequest();
@@ -44,6 +53,14 @@ struct TestAuthenticationRequest {
WebStateDelegate::AuthCallback auth_callback;
};
+// Encapsulates information about popup.
+struct TestPopup {
+ TestPopup(const GURL& url, const GURL& opener_url)
+ : url(url), opener_url(opener_url) {}
+ GURL url;
+ GURL opener_url;
+};
+
// Fake WebStateDelegate used for testing purposes.
class TestWebStateDelegate : public WebStateDelegate {
public:
@@ -51,6 +68,10 @@ class TestWebStateDelegate : public WebStateDelegate {
~TestWebStateDelegate() override;
// WebStateDelegate overrides:
+ WebState* CreateNewWebState(WebState* source,
+ const GURL& url,
+ const GURL& opener_url,
+ bool initiated_by_user) override;
WebState* OpenURLFromWebState(WebState*,
const WebState::OpenURLParams&) override;
JavaScriptDialogPresenter* GetJavaScriptDialogPresenter(WebState*) override;
@@ -65,11 +86,29 @@ class TestWebStateDelegate : public WebStateDelegate {
NSURLCredential* proposed_credential,
const AuthCallback& callback) override;
+ // Allows popups requested by a page with |opener_url|.
+ void allow_popups(const GURL& opener_url) {
+ allowed_popups_.insert(opener_url);
+ }
+
+ // Returns list of all child windows opened via CreateNewWebState.
+ const std::vector<std::unique_ptr<WebState>>& child_windows() const {
+ return child_windows_;
+ }
+
+ // Returns list of all popups requested via CreateNewWebState.
+ const std::vector<TestPopup>& popups() const { return popups_; }
+
// True if the WebStateDelegate HandleContextMenu method has been called.
bool handle_context_menu_called() const {
return handle_context_menu_called_;
}
+ // Returns the last Web State creation request passed to |CreateNewWebState|.
+ TestCreateNewWebStateRequest* last_create_new_web_state_request() const {
+ return last_create_new_web_state_request_.get();
+ }
+
// Returns the last Open URL request passed to |OpenURLFromWebState|.
TestOpenURLRequest* last_open_url_request() const {
return last_open_url_request_.get();
@@ -98,7 +137,13 @@ class TestWebStateDelegate : public WebStateDelegate {
}
private:
+ std::vector<std::unique_ptr<WebState>> child_windows_;
+ // A page can open popup if its URL is in this set.
+ std::set<GURL> allowed_popups_;
+ std::vector<TestPopup> popups_;
bool handle_context_menu_called_ = false;
+ std::unique_ptr<TestCreateNewWebStateRequest>
+ last_create_new_web_state_request_;
std::unique_ptr<TestOpenURLRequest> last_open_url_request_;
std::unique_ptr<TestRepostFormRequest> last_repost_form_request_;
bool get_java_script_dialog_presenter_called_ = false;
« 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