blob: 17134f2bf0e76ee59f92c8afccbed84718157ad3 [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
kundaji6db683c2015-05-14 19:40:158#include <string>
9
[email protected]93ddb3c2012-04-11 21:44:2910#include "content/browser/web_contents/web_contents_impl.h"
[email protected]b1e3f202012-06-04 14:45:5011#include "content/public/test/web_contents_tester.h"
[email protected]6b50e362014-08-15 05:15:5912#include "content/test/test_render_frame_host.h"
13#include "content/test/test_render_view_host.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3514#include "ui/base/page_transition_types.h"
[email protected]80e776ae2012-03-23 16:17:2015
kundaji6db683c2015-05-14 19:40:1516class GURL;
17class Referrer;
[email protected]80e776ae2012-03-23 16:17:2018class SiteInstanceImpl;
19
20namespace content {
21
22class RenderViewHost;
23class TestRenderViewHost;
24class WebContentsTester;
25
[email protected]2db9bd72012-04-13 20:20:5626// Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
[email protected]80e776ae2012-03-23 16:17:2027// and does not do anything involving views.
[email protected]2db9bd72012-04-13 20:20:5628class TestWebContents : public WebContentsImpl, public WebContentsTester {
[email protected]80e776ae2012-03-23 16:17:2029 public:
dchenge933b3eb2014-10-21 11:44:0930 ~TestWebContents() override;
[email protected]80e776ae2012-03-23 16:17:2031
[email protected]d1198fd2012-08-13 22:50:1932 static TestWebContents* Create(BrowserContext* browser_context,
33 SiteInstance* instance);
34
[email protected]6b50e362014-08-15 05:15:5935 // WebContentsImpl overrides (returning the same values, but in Test* types)
dchenge933b3eb2014-10-21 11:44:0936 TestRenderFrameHost* GetMainFrame() override;
37 TestRenderViewHost* GetRenderViewHost() const override;
halton.huoca2eabd2015-07-06 08:17:4038 // Overrides to avoid establishing Mojo connection with renderer process.
39 int DownloadImage(const GURL& url,
40 bool is_favicon,
41 uint32_t max_bitmap_size,
42 bool bypass_cache,
43 const ImageDownloadCallback& callback) override;
[email protected]6b50e362014-08-15 05:15:5944
[email protected]80e776ae2012-03-23 16:17:2045 // WebContentsTester implementation.
dchenge933b3eb2014-10-21 11:44:0946 void CommitPendingNavigation() override;
47 TestRenderFrameHost* GetPendingMainFrame() const override;
clamy0e119882015-07-31 16:12:3348 void StartNavigation(const GURL& url) override;
dchenge933b3eb2014-10-21 11:44:0949 void NavigateAndCommit(const GURL& url) override;
50 void TestSetIsLoading(bool value) override;
51 void ProceedWithCrossSiteNavigation() override;
52 void TestDidNavigate(RenderFrameHost* render_frame_host,
53 int page_id,
avi7c6f35e2015-05-08 17:52:3854 int nav_entry_id,
55 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0956 const GURL& url,
57 ui::PageTransition transition) override;
58 void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
59 int page_id,
avi7c6f35e2015-05-08 17:52:3860 int nav_entry_id,
61 bool did_create_new_entry,
dchenge933b3eb2014-10-21 11:44:0962 const GURL& url,
63 const Referrer& referrer,
64 ui::PageTransition transition) override;
kundaji6db683c2015-05-14 19:40:1565 const std::string& GetSaveFrameHeaders() override;
[email protected]80e776ae2012-03-23 16:17:2066
clamy5bf36112015-04-17 15:23:2267 // True if a cross-site navigation is pending.
68 bool CrossProcessNavigationPending();
[email protected]80e776ae2012-03-23 16:17:2069
[email protected]80e776ae2012-03-23 16:17:2070 // Prevent interaction with views.
nasko4c0feb62015-06-05 18:37:0671 bool CreateRenderViewForRenderManager(
72 RenderViewHost* render_view_host,
alexmos5ac402d2015-07-09 07:51:1073 int opener_frame_routing_id,
nasko4c0feb62015-06-05 18:37:0674 int proxy_routing_id,
75 const FrameReplicationState& replicated_frame_state,
76 bool for_main_frame) override;
dchenge933b3eb2014-10-21 11:44:0977 void UpdateRenderViewSizeForRenderManager() override {}
[email protected]80e776ae2012-03-23 16:17:2078
79 // Returns a clone of this TestWebContents. The returned object is also a
80 // TestWebContents. The caller owns the returned object.
dchenge933b3eb2014-10-21 11:44:0981 WebContents* Clone() override;
[email protected]80e776ae2012-03-23 16:17:2082
[email protected]5a3bdf52012-05-24 15:12:5783 // Allow mocking of the RenderViewHostDelegateView.
dchenge933b3eb2014-10-21 11:44:0984 RenderViewHostDelegateView* GetDelegateView() override;
[email protected]5a3bdf52012-05-24 15:12:5785 void set_delegate_view(RenderViewHostDelegateView* view) {
[email protected]80e776ae2012-03-23 16:17:2086 delegate_view_override_ = view;
87 }
88
alexmose201c7cd2015-06-10 17:14:2189 // Allows us to simulate this tab's main frame having an opener that points
90 // to the main frame of the |opener|.
[email protected]14392a52012-05-02 20:28:4491 void SetOpener(TestWebContents* opener);
92
[email protected]ceee8cd2013-03-08 04:59:5193 // Allows us to simulate that a contents was created via CreateNewWindow.
94 void AddPendingContents(TestWebContents* contents);
95
avi2b177592014-12-10 02:08:0296 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
97 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
[email protected]80e776ae2012-03-23 16:17:2098 // with the expected arguments specified here.
avi2b177592014-12-10 02:08:0299 void ExpectSetHistoryOffsetAndLength(int history_offset,
100 int history_length);
[email protected]80e776ae2012-03-23 16:17:20101
102 // Compares the arguments passed in with the expected arguments passed in
avi2b177592014-12-10 02:08:02103 // to |ExpectSetHistoryOffsetAndLength()|.
104 void SetHistoryOffsetAndLength(int history_offset,
105 int history_length) override;
[email protected]80e776ae2012-03-23 16:17:20106
[email protected]61ac9e242014-03-21 20:55:26107 void TestDidFinishLoad(const GURL& url);
[email protected]501052ff2014-02-21 22:19:07108 void TestDidFailLoadWithError(const GURL& url,
[email protected]b502ed462013-01-08 08:20:06109 int error_code,
gsennton6fbb38692015-06-24 19:23:55110 const base::string16& error_description,
111 bool was_ignored_by_handler);
[email protected]b502ed462013-01-08 08:20:06112
[email protected]d1198fd2012-08-13 22:50:19113 protected:
114 // The deprecated WebContentsTester still needs to subclass this.
115 explicit TestWebContents(BrowserContext* browser_context);
116
[email protected]80e776ae2012-03-23 16:17:20117 private:
[email protected]bafe6cd2012-05-23 23:09:50118 // WebContentsImpl overrides
dchenge933b3eb2014-10-21 11:44:09119 void CreateNewWindow(
alexmos4cf2aa32015-07-15 23:40:43120 SiteInstance* source_site_instance,
[email protected]bafe6cd2012-05-23 23:09:50121 int route_id,
[email protected]227692c52013-05-31 22:43:04122 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:13123 const ViewHostMsg_CreateWindow_Params& params,
anand.ratn71fc3adc2014-10-06 13:50:07124 SessionStorageNamespace* session_storage_namespace) override;
dchenge933b3eb2014-10-21 11:44:09125 void CreateNewWidget(int render_process_id,
126 int route_id,
127 blink::WebPopupType popup_type) override;
128 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
129 void ShowCreatedWindow(int route_id,
130 WindowOpenDisposition disposition,
bokan107a47f2015-02-03 23:23:39131 const gfx::Rect& initial_rect,
dchenge933b3eb2014-10-21 11:44:09132 bool user_gesture) override;
bokan107a47f2015-02-03 23:23:39133 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
dchenge933b3eb2014-10-21 11:44:09134 void ShowCreatedFullscreenWidget(int route_id) override;
kundaji6db683c2015-05-14 19:40:15135 void SaveFrameWithHeaders(const GURL& url,
136 const Referrer& referrer,
137 const std::string& headers) override;
[email protected]bafe6cd2012-05-23 23:09:50138
[email protected]5a3bdf52012-05-24 15:12:57139 RenderViewHostDelegateView* delegate_view_override_;
[email protected]80e776ae2012-03-23 16:17:20140
avi2b177592014-12-10 02:08:02141 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
142 bool expect_set_history_offset_and_length_;
143 int expect_set_history_offset_and_length_history_offset_;
144 int expect_set_history_offset_and_length_history_length_;
kundaji6db683c2015-05-14 19:40:15145 std::string save_frame_headers_;
[email protected]80e776ae2012-03-23 16:17:20146};
147
148} // namespace content
149
[email protected]4172b082013-02-25 18:07:34150#endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_