blob: 92baea038c66b6825a65f3c28d228275d7dd00e1 [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,
57 int page_id,
avi7c6f35e2015-05-08 17:52:3858 int nav_entry_id,
59 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0960 const GURL& url,
61 ui::PageTransition transition) override;
62 void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
63 int page_id,
avi7c6f35e2015-05-08 17:52:3864 int nav_entry_id,
65 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0966 const GURL& url,
67 const Referrer& referrer,
68 ui::PageTransition transition) override;
kundaji6db683c2015-05-14 19:40:1569 const std::string& GetSaveFrameHeaders() override;
[email protected]80e776ae2012-03-23 16:17:2070
clamy5bf36112015-04-17 15:23:2271 // True if a cross-site navigation is pending.
72 bool CrossProcessNavigationPending();
[email protected]80e776ae2012-03-23 16:17:2073
[email protected]80e776ae2012-03-23 16:17:2074 // Prevent interaction with views.
nasko4c0feb62015-06-05 18:37:0675 bool CreateRenderViewForRenderManager(
76 RenderViewHost* render_view_host,
alexmos5ac402d2015-07-09 07:51:1077 int opener_frame_routing_id,
nasko4c0feb62015-06-05 18:37:0678 int proxy_routing_id,
lfgbede6392015-09-11 21:54:0679 const FrameReplicationState& replicated_frame_state) override;
dchenge933b3eb2014-10-21 11:44:0980 void UpdateRenderViewSizeForRenderManager() override {}
[email protected]80e776ae2012-03-23 16:17:2081
82 // Returns a clone of this TestWebContents. The returned object is also a
83 // TestWebContents. The caller owns the returned object.
dchenge933b3eb2014-10-21 11:44:0984 WebContents* Clone() override;
[email protected]80e776ae2012-03-23 16:17:2085
[email protected]5a3bdf52012-05-24 15:12:5786 // Allow mocking of the RenderViewHostDelegateView.
dchenge933b3eb2014-10-21 11:44:0987 RenderViewHostDelegateView* GetDelegateView() override;
[email protected]5a3bdf52012-05-24 15:12:5788 void set_delegate_view(RenderViewHostDelegateView* view) {
[email protected]80e776ae2012-03-23 16:17:2089 delegate_view_override_ = view;
90 }
91
alexmose201c7cd2015-06-10 17:14:2192 // Allows us to simulate this tab's main frame having an opener that points
93 // to the main frame of the |opener|.
[email protected]14392a52012-05-02 20:28:4494 void SetOpener(TestWebContents* opener);
95
[email protected]ceee8cd2013-03-08 04:59:5196 // Allows us to simulate that a contents was created via CreateNewWindow.
97 void AddPendingContents(TestWebContents* contents);
98
avi2b177592014-12-10 02:08:0299 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
100 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
[email protected]80e776ae2012-03-23 16:17:20101 // with the expected arguments specified here.
avi2b177592014-12-10 02:08:02102 void ExpectSetHistoryOffsetAndLength(int history_offset,
103 int history_length);
[email protected]80e776ae2012-03-23 16:17:20104
105 // Compares the arguments passed in with the expected arguments passed in
avi2b177592014-12-10 02:08:02106 // to |ExpectSetHistoryOffsetAndLength()|.
107 void SetHistoryOffsetAndLength(int history_offset,
108 int history_length) override;
[email protected]80e776ae2012-03-23 16:17:20109
[email protected]61ac9e242014-03-21 20:55:26110 void TestDidFinishLoad(const GURL& url);
[email protected]501052ff2014-02-21 22:19:07111 void TestDidFailLoadWithError(const GURL& url,
[email protected]b502ed462013-01-08 08:20:06112 int error_code,
gsennton6fbb38692015-06-24 19:23:55113 const base::string16& error_description,
114 bool was_ignored_by_handler);
[email protected]b502ed462013-01-08 08:20:06115
ryansturmfe328162016-05-11 22:28:47116 void SetNavigationData(
117 NavigationHandle* navigation_handle,
118 std::unique_ptr<NavigationData> navigation_data) override;
119
[email protected]d1198fd2012-08-13 22:50:19120 protected:
121 // The deprecated WebContentsTester still needs to subclass this.
122 explicit TestWebContents(BrowserContext* browser_context);
123
[email protected]80e776ae2012-03-23 16:17:20124 private:
[email protected]bafe6cd2012-05-23 23:09:50125 // WebContentsImpl overrides
dchenge933b3eb2014-10-21 11:44:09126 void CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:43127 SiteInstance* source_site_instance,
dcheng3ce04b62015-10-26 23:30:55128 int32_t route_id,
129 int32_t main_frame_route_id,
130 int32_t main_frame_widget_route_id,
rockot5c478a72016-09-28 23:14:18131 const mojom::CreateNewWindowParams& params,
anand.ratn71fc3adc2014-10-06 13:50:07132 SessionStorageNamespace* session_storage_namespace) override;
avi66a07722015-12-25 23:38:12133 void CreateNewWidget(int32_t render_process_id,
134 int32_t route_id,
dchenge933b3eb2014-10-21 11:44:09135 blink::WebPopupType popup_type) override;
avi66a07722015-12-25 23:38:12136 void CreateNewFullscreenWidget(int32_t render_process_id,
137 int32_t route_id) override;
alexmosc2a8cec2016-05-23 22:19:53138 void ShowCreatedWindow(int process_id,
139 int route_id,
dchenge933b3eb2014-10-21 11:44:09140 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39141 const gfx::Rect& initial_rect,
dchenge933b3eb2014-10-21 11:44:09142 bool user_gesture) override;
alexmosc2a8cec2016-05-23 22:19:53143 void ShowCreatedWidget(int process_id,
144 int route_id,
145 const gfx::Rect& initial_rect) override;
146 void ShowCreatedFullscreenWidget(int process_id, int route_id) override;
kundaji6db683c2015-05-14 19:40:15147 void SaveFrameWithHeaders(const GURL& url,
148 const Referrer& referrer,
149 const std::string& headers) override;
[email protected]bafe6cd2012-05-23 23:09:50150
[email protected]5a3bdf52012-05-24 15:12:57151 RenderViewHostDelegateView* delegate_view_override_;
[email protected]80e776ae2012-03-23 16:17:20152
avi2b177592014-12-10 02:08:02153 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
154 bool expect_set_history_offset_and_length_;
155 int expect_set_history_offset_and_length_history_offset_;
156 int expect_set_history_offset_and_length_history_length_;
kundaji6db683c2015-05-14 19:40:15157 std::string save_frame_headers_;
[email protected]80e776ae2012-03-23 16:17:20158};
159
160} // namespace content
161
[email protected]4172b082013-02-25 18:07:34162#endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_