blob: 5ddd706105aab151ea8528208e2ee7b6ea954cff [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
[email protected]93ddb3c2012-04-11 21:44:298#include "content/browser/web_contents/web_contents_impl.h"
[email protected]b3a97b52014-07-09 06:25:059#include "content/public/common/web_preferences.h"
[email protected]b1e3f202012-06-04 14:45:5010#include "content/public/test/web_contents_tester.h"
[email protected]6b50e362014-08-15 05:15:5911#include "content/test/test_render_frame_host.h"
12#include "content/test/test_render_view_host.h"
Sylvain Defresnec6ccc77d2014-09-19 10:19:3513#include "ui/base/page_transition_types.h"
[email protected]80e776ae2012-03-23 16:17:2014
15class SiteInstanceImpl;
16
17namespace content {
18
19class RenderViewHost;
20class TestRenderViewHost;
21class WebContentsTester;
22
[email protected]2db9bd72012-04-13 20:20:5623// Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
[email protected]80e776ae2012-03-23 16:17:2024// and does not do anything involving views.
[email protected]2db9bd72012-04-13 20:20:5625class TestWebContents : public WebContentsImpl, public WebContentsTester {
[email protected]80e776ae2012-03-23 16:17:2026 public:
[email protected]80e776ae2012-03-23 16:17:2027 virtual ~TestWebContents();
28
[email protected]d1198fd2012-08-13 22:50:1929 static TestWebContents* Create(BrowserContext* browser_context,
30 SiteInstance* instance);
31
[email protected]6b50e362014-08-15 05:15:5932 // WebContentsImpl overrides (returning the same values, but in Test* types)
anand.ratn71fc3adc2014-10-06 13:50:0733 virtual TestRenderFrameHost* GetMainFrame() override;
34 virtual TestRenderViewHost* GetRenderViewHost() const override;
[email protected]6b50e362014-08-15 05:15:5935
[email protected]80e776ae2012-03-23 16:17:2036 // WebContentsTester implementation.
anand.ratn71fc3adc2014-10-06 13:50:0737 virtual void CommitPendingNavigation() override;
38 virtual TestRenderFrameHost* GetPendingMainFrame() const override;
39 virtual void NavigateAndCommit(const GURL& url) override;
40 virtual void TestSetIsLoading(bool value) override;
41 virtual void ProceedWithCrossSiteNavigation() override;
[email protected]6b50e362014-08-15 05:15:5942 virtual void TestDidNavigate(RenderFrameHost* render_frame_host,
[email protected]80e776ae2012-03-23 16:17:2043 int page_id,
44 const GURL& url,
anand.ratn71fc3adc2014-10-06 13:50:0745 ui::PageTransition transition) override;
Sylvain Defresnec6ccc77d2014-09-19 10:19:3546 virtual void TestDidNavigateWithReferrer(
47 RenderFrameHost* render_frame_host,
48 int page_id,
49 const GURL& url,
50 const Referrer& referrer,
anand.ratn71fc3adc2014-10-06 13:50:0751 ui::PageTransition transition) override;
52 virtual WebPreferences TestComputeWebkitPrefs() override;
[email protected]80e776ae2012-03-23 16:17:2053
[email protected]80e776ae2012-03-23 16:17:2054 // State accessor.
55 bool cross_navigation_pending() {
[email protected]fa944cb82013-11-15 17:51:2156 return GetRenderManager()->cross_navigation_pending_;
[email protected]80e776ae2012-03-23 16:17:2057 }
58
[email protected]80e776ae2012-03-23 16:17:2059 // Prevent interaction with views.
60 virtual bool CreateRenderViewForRenderManager(
[email protected]bffc8302014-01-23 20:52:1661 RenderViewHost* render_view_host,
62 int opener_route_id,
[email protected]5a7100d2014-05-19 01:29:0463 int proxy_routing_id,
anand.ratn71fc3adc2014-10-06 13:50:0764 bool for_main_frame) override;
65 virtual void UpdateRenderViewSizeForRenderManager() override {}
[email protected]80e776ae2012-03-23 16:17:2066
67 // Returns a clone of this TestWebContents. The returned object is also a
68 // TestWebContents. The caller owns the returned object.
anand.ratn71fc3adc2014-10-06 13:50:0769 virtual WebContents* Clone() override;
[email protected]80e776ae2012-03-23 16:17:2070
[email protected]5a3bdf52012-05-24 15:12:5771 // Allow mocking of the RenderViewHostDelegateView.
anand.ratn71fc3adc2014-10-06 13:50:0772 virtual RenderViewHostDelegateView* GetDelegateView() override;
[email protected]5a3bdf52012-05-24 15:12:5773 void set_delegate_view(RenderViewHostDelegateView* view) {
[email protected]80e776ae2012-03-23 16:17:2074 delegate_view_override_ = view;
75 }
76
[email protected]14392a52012-05-02 20:28:4477 // Allows us to simulate this tab having an opener.
78 void SetOpener(TestWebContents* opener);
79
[email protected]ceee8cd2013-03-08 04:59:5180 // Allows us to simulate that a contents was created via CreateNewWindow.
81 void AddPendingContents(TestWebContents* contents);
82
[email protected]80e776ae2012-03-23 16:17:2083 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When
84 // |SetHistoryLengthAndPrune()| is called, the arguments are compared
85 // with the expected arguments specified here.
86 void ExpectSetHistoryLengthAndPrune(const SiteInstance* site_instance,
87 int history_length,
88 int32 min_page_id);
89
90 // Compares the arguments passed in with the expected arguments passed in
91 // to |ExpectSetHistoryLengthAndPrune()|.
92 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance,
93 int history_length,
anand.ratn71fc3adc2014-10-06 13:50:0794 int32 min_page_id) override;
[email protected]80e776ae2012-03-23 16:17:2095
[email protected]61ac9e242014-03-21 20:55:2696 void TestDidFinishLoad(const GURL& url);
[email protected]501052ff2014-02-21 22:19:0797 void TestDidFailLoadWithError(const GURL& url,
[email protected]b502ed462013-01-08 08:20:0698 int error_code,
[email protected]fcf75d42013-12-03 20:11:2699 const base::string16& error_description);
[email protected]b502ed462013-01-08 08:20:06100
[email protected]d1198fd2012-08-13 22:50:19101 protected:
102 // The deprecated WebContentsTester still needs to subclass this.
103 explicit TestWebContents(BrowserContext* browser_context);
104
[email protected]80e776ae2012-03-23 16:17:20105 private:
[email protected]bafe6cd2012-05-23 23:09:50106 // WebContentsImpl overrides
107 virtual void CreateNewWindow(
[email protected]04cbd3d2013-12-04 04:58:20108 int render_process_id,
[email protected]bafe6cd2012-05-23 23:09:50109 int route_id,
[email protected]227692c52013-05-31 22:43:04110 int main_frame_route_id,
[email protected]97714c82012-06-06 10:15:13111 const ViewHostMsg_CreateWindow_Params& params,
anand.ratn71fc3adc2014-10-06 13:50:07112 SessionStorageNamespace* session_storage_namespace) override;
[email protected]a8504022013-12-04 20:23:51113 virtual void CreateNewWidget(int render_process_id,
114 int route_id,
anand.ratn71fc3adc2014-10-06 13:50:07115 blink::WebPopupType popup_type) override;
[email protected]a8504022013-12-04 20:23:51116 virtual void CreateNewFullscreenWidget(int render_process_id,
anand.ratn71fc3adc2014-10-06 13:50:07117 int route_id) override;
[email protected]bafe6cd2012-05-23 23:09:50118 virtual void ShowCreatedWindow(int route_id,
119 WindowOpenDisposition disposition,
120 const gfx::Rect& initial_pos,
anand.ratn71fc3adc2014-10-06 13:50:07121 bool user_gesture) override;
[email protected]bafe6cd2012-05-23 23:09:50122 virtual void ShowCreatedWidget(int route_id,
anand.ratn71fc3adc2014-10-06 13:50:07123 const gfx::Rect& initial_pos) override;
124 virtual void ShowCreatedFullscreenWidget(int route_id) override;
[email protected]bafe6cd2012-05-23 23:09:50125
126
[email protected]5a3bdf52012-05-24 15:12:57127 RenderViewHostDelegateView* delegate_view_override_;
[email protected]80e776ae2012-03-23 16:17:20128
129 // Expectations for arguments of |SetHistoryLengthAndPrune()|.
130 bool expect_set_history_length_and_prune_;
131 scoped_refptr<const SiteInstanceImpl>
132 expect_set_history_length_and_prune_site_instance_;
133 int expect_set_history_length_and_prune_history_length_;
134 int32 expect_set_history_length_and_prune_min_page_id_;
135};
136
137} // namespace content
138
[email protected]4172b082013-02-25 18:07:34139#endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_