blob: 05ca1b92c84e8e30707eed2ee41b6713fbe336b2 [file] [log] [blame]
[email protected]80e776ae2012-03-23 16:17:201// Copyright (c) 2012 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
[email protected]4172b082013-02-25 18:07:345#ifndef CONTENT_TEST_TEST_WEB_CONTENTS_H_
6#define CONTENT_TEST_TEST_WEB_CONTENTS_H_
[email protected]80e776ae2012-03-23 16:17:207
avi66a07722015-12-25 23:38:128#include <stdint.h>
9
kundaji6db683c2015-05-14 19:40:1510#include <string>
11
[email protected]93ddb3c2012-04-11 21:44:2912#include "content/browser/web_contents/web_contents_impl.h"
[email protected]b1e3f202012-06-04 14:45:5013#include "content/public/test/web_contents_tester.h"
[email protected]6b50e362014-08-15 05:15:5914#include "content/test/test_render_frame_host.h"
15#include "content/test/test_render_view_host.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3516#include "ui/base/page_transition_types.h"
[email protected]80e776ae2012-03-23 16:17:2017
kundaji6db683c2015-05-14 19:40:1518class GURL;
19class Referrer;
[email protected]80e776ae2012-03-23 16:17:2020class SiteInstanceImpl;
21
22namespace content {
23
ryansturmfe328162016-05-11 22:28:4724class NavigationData;
25class NavigationHandle;
[email protected]80e776ae2012-03-23 16:17:2026class RenderViewHost;
27class TestRenderViewHost;
28class WebContentsTester;
29
[email protected]2db9bd72012-04-13 20:20:5630// Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
[email protected]80e776ae2012-03-23 16:17:2031// and does not do anything involving views.
[email protected]2db9bd72012-04-13 20:20:5632class TestWebContents : public WebContentsImpl, public WebContentsTester {
[email protected]80e776ae2012-03-23 16:17:2033 public:
dchenge933b3eb2014-10-21 11:44:0934 ~TestWebContents() override;
[email protected]80e776ae2012-03-23 16:17:2035
[email protected]d1198fd2012-08-13 22:50:1936 static TestWebContents* Create(BrowserContext* browser_context,
dchengbccd6b82016-03-30 16:24:1937 scoped_refptr<SiteInstance> instance);
[email protected]d1198fd2012-08-13 22:50:1938
[email protected]6b50e362014-08-15 05:15:5939 // WebContentsImpl overrides (returning the same values, but in Test* types)
dchenge933b3eb2014-10-21 11:44:0940 TestRenderFrameHost* GetMainFrame() override;
41 TestRenderViewHost* GetRenderViewHost() const override;
halton.huoca2eabd2015-07-06 08:17:4042 // Overrides to avoid establishing Mojo connection with renderer process.
43 int DownloadImage(const GURL& url,
44 bool is_favicon,
45 uint32_t max_bitmap_size,
46 bool bypass_cache,
47 const ImageDownloadCallback& callback) override;
[email protected]6b50e362014-08-15 05:15:5948
[email protected]80e776ae2012-03-23 16:17:2049 // WebContentsTester implementation.
dchenge933b3eb2014-10-21 11:44:0950 void CommitPendingNavigation() override;
51 TestRenderFrameHost* GetPendingMainFrame() const override;
clamy0e119882015-07-31 16:12:3352 void StartNavigation(const GURL& url) override;
dchenge933b3eb2014-10-21 11:44:0953 void NavigateAndCommit(const GURL& url) override;
54 void TestSetIsLoading(bool value) override;
55 void ProceedWithCrossSiteNavigation() override;
56 void TestDidNavigate(RenderFrameHost* render_frame_host,
avi7c6f35e2015-05-08 17:52:3857 int nav_entry_id,
58 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0959 const GURL& url,
60 ui::PageTransition transition) override;
61 void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
avi7c6f35e2015-05-08 17:52:3862 int nav_entry_id,
63 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0964 const GURL& url,
65 const Referrer& referrer,
66 ui::PageTransition transition) override;
kundaji6db683c2015-05-14 19:40:1567 const std::string& GetSaveFrameHeaders() override;
[email protected]80e776ae2012-03-23 16:17:2068
clamy5bf36112015-04-17 15:23:2269 // True if a cross-site navigation is pending.
70 bool CrossProcessNavigationPending();
[email protected]80e776ae2012-03-23 16:17:2071
[email protected]80e776ae2012-03-23 16:17:2072 // Prevent interaction with views.
nasko4c0feb62015-06-05 18:37:0673 bool CreateRenderViewForRenderManager(
74 RenderViewHost* render_view_host,
alexmos5ac402d2015-07-09 07:51:1075 int opener_frame_routing_id,
nasko4c0feb62015-06-05 18:37:0676 int proxy_routing_id,
lfgbede6392015-09-11 21:54:0677 const FrameReplicationState& replicated_frame_state) override;
dchenge933b3eb2014-10-21 11:44:0978 void UpdateRenderViewSizeForRenderManager() override {}
[email protected]80e776ae2012-03-23 16:17:2079
80 // Returns a clone of this TestWebContents. The returned object is also a
81 // TestWebContents. The caller owns the returned object.
dchenge933b3eb2014-10-21 11:44:0982 WebContents* Clone() override;
[email protected]80e776ae2012-03-23 16:17:2083
[email protected]5a3bdf52012-05-24 15:12:5784 // Allow mocking of the RenderViewHostDelegateView.
dchenge933b3eb2014-10-21 11:44:0985 RenderViewHostDelegateView* GetDelegateView() override;
[email protected]5a3bdf52012-05-24 15:12:5786 void set_delegate_view(RenderViewHostDelegateView* view) {
[email protected]80e776ae2012-03-23 16:17:2087 delegate_view_override_ = view;
88 }
89
alexmose201c7cd2015-06-10 17:14:2190 // Allows us to simulate this tab's main frame having an opener that points
91 // to the main frame of the |opener|.
[email protected]14392a52012-05-02 20:28:4492 void SetOpener(TestWebContents* opener);
93
[email protected]ceee8cd2013-03-08 04:59:5194 // Allows us to simulate that a contents was created via CreateNewWindow.
95 void AddPendingContents(TestWebContents* contents);
96
avi2b177592014-12-10 02:08:0297 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
98 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
[email protected]80e776ae2012-03-23 16:17:2099 // with the expected arguments specified here.
avi2b177592014-12-10 02:08:02100 void ExpectSetHistoryOffsetAndLength(int history_offset,
101 int history_length);
[email protected]80e776ae2012-03-23 16:17:20102
103 // Compares the arguments passed in with the expected arguments passed in
avi2b177592014-12-10 02:08:02104 // to |ExpectSetHistoryOffsetAndLength()|.
105 void SetHistoryOffsetAndLength(int history_offset,
106 int history_length) override;
[email protected]80e776ae2012-03-23 16:17:20107
[email protected]61ac9e242014-03-21 20:55:26108 void TestDidFinishLoad(const GURL& url);
[email protected]501052ff2014-02-21 22:19:07109 void TestDidFailLoadWithError(const GURL& url,
[email protected]b502ed462013-01-08 08:20:06110 int error_code,
gsennton6fbb38692015-06-24 19:23:55111 const base::string16& error_description,
112 bool was_ignored_by_handler);
[email protected]b502ed462013-01-08 08:20:06113
ryansturmfe328162016-05-11 22:28:47114 void SetNavigationData(
115 NavigationHandle* navigation_handle,
116 std::unique_ptr<NavigationData> navigation_data) override;
117
[email protected]d1198fd2012-08-13 22:50:19118 protected:
119 // The deprecated WebContentsTester still needs to subclass this.
120 explicit TestWebContents(BrowserContext* browser_context);
121
[email protected]80e776ae2012-03-23 16:17:20122 private:
[email protected]bafe6cd2012-05-23 23:09:50123 // WebContentsImpl overrides
dchenge933b3eb2014-10-21 11:44:09124 void CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:43125 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:55126 int32_t route_id,
127 int32_t main_frame_route_id,
128 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:18129 const mojom::CreateNewWindowParams& params,
anand.ratn71fc3adc2014-10-06 13:50:07130 SessionStorageNamespace* session_storage_namespace) override;
avi66a07722015-12-25 23:38:12131 void CreateNewWidget(int32_t render_process_id,
132 int32_t route_id,
dchenge933b3eb2014-10-21 11:44:09133 blink::WebPopupType popup_type) override;
avi66a07722015-12-25 23:38:12134 void CreateNewFullscreenWidget(int32_t render_process_id,
135 int32_t route_id) override;
alexmosc2a8cec2016-05-23 22:19:53136 void ShowCreatedWindow(int process_id,
137 int route_id,
dchenge933b3eb2014-10-21 11:44:09138 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39139 const gfx::Rect& initial_rect,
dchenge933b3eb2014-10-21 11:44:09140 bool user_gesture) override;
alexmosc2a8cec2016-05-23 22:19:53141 void ShowCreatedWidget(int process_id,
142 int route_id,
143 const gfx::Rect& initial_rect) override;
144 void ShowCreatedFullscreenWidget(int process_id, int route_id) override;
kundaji6db683c2015-05-14 19:40:15145 void SaveFrameWithHeaders(const GURL& url,
146 const Referrer& referrer,
147 const std::string& headers) override;
[email protected]bafe6cd2012-05-23 23:09:50148
[email protected]5a3bdf52012-05-24 15:12:57149 RenderViewHostDelegateView* delegate_view_override_;
[email protected]80e776ae2012-03-23 16:17:20150
avi2b177592014-12-10 02:08:02151 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
152 bool expect_set_history_offset_and_length_;
153 int expect_set_history_offset_and_length_history_offset_;
154 int expect_set_history_offset_and_length_history_length_;
kundaji6db683c2015-05-14 19:40:15155 std::string save_frame_headers_;
[email protected]80e776ae2012-03-23 16:17:20156};
157
158} // namespace content
159
[email protected]4172b082013-02-25 18:07:34160#endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_