1 // 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.
5 #ifndef CONTENT_TEST_TEST_WEB_CONTENTS_H_
6 #define CONTENT_TEST_TEST_WEB_CONTENTS_H_
8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/common/page_transition_types.h"
10 #include "content/public/common/web_preferences.h"
11 #include "content/public/test/web_contents_tester.h"
12 #include "content/test/test_render_frame_host.h"
13 #include "content/test/test_render_view_host.h"
15 class SiteInstanceImpl
;
20 class TestRenderViewHost
;
21 class WebContentsTester
;
23 // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
24 // and does not do anything involving views.
25 class TestWebContents
: public WebContentsImpl
, public WebContentsTester
{
27 virtual ~TestWebContents();
29 static TestWebContents
* Create(BrowserContext
* browser_context
,
30 SiteInstance
* instance
);
32 // WebContentsImpl overrides (returning the same values, but in Test* types)
33 virtual TestRenderFrameHost
* GetMainFrame() OVERRIDE
;
34 virtual TestRenderViewHost
* GetRenderViewHost() const OVERRIDE
;
36 // WebContentsTester implementation.
37 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
;
42 virtual void TestDidNavigate(RenderFrameHost
* render_frame_host
,
45 PageTransition transition
) OVERRIDE
;
46 virtual void TestDidNavigateWithReferrer(RenderFrameHost
* render_frame_host
,
49 const Referrer
& referrer
,
50 PageTransition transition
) OVERRIDE
;
51 virtual WebPreferences
TestComputeWebkitPrefs() OVERRIDE
;
54 bool cross_navigation_pending() {
55 return GetRenderManager()->cross_navigation_pending_
;
58 // Prevent interaction with views.
59 virtual bool CreateRenderViewForRenderManager(
60 RenderViewHost
* render_view_host
,
63 bool for_main_frame
) OVERRIDE
;
64 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE
{}
66 // Returns a clone of this TestWebContents. The returned object is also a
67 // TestWebContents. The caller owns the returned object.
68 virtual WebContents
* Clone() OVERRIDE
;
70 // Allow mocking of the RenderViewHostDelegateView.
71 virtual RenderViewHostDelegateView
* GetDelegateView() OVERRIDE
;
72 void set_delegate_view(RenderViewHostDelegateView
* view
) {
73 delegate_view_override_
= view
;
76 // Allows us to simulate this tab having an opener.
77 void SetOpener(TestWebContents
* opener
);
79 // Allows us to simulate that a contents was created via CreateNewWindow.
80 void AddPendingContents(TestWebContents
* contents
);
82 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When
83 // |SetHistoryLengthAndPrune()| is called, the arguments are compared
84 // with the expected arguments specified here.
85 void ExpectSetHistoryLengthAndPrune(const SiteInstance
* site_instance
,
89 // Compares the arguments passed in with the expected arguments passed in
90 // to |ExpectSetHistoryLengthAndPrune()|.
91 virtual void SetHistoryLengthAndPrune(const SiteInstance
* site_instance
,
93 int32 min_page_id
) OVERRIDE
;
95 void TestDidFinishLoad(const GURL
& url
);
96 void TestDidFailLoadWithError(const GURL
& url
,
98 const base::string16
& error_description
);
101 // The deprecated WebContentsTester still needs to subclass this.
102 explicit TestWebContents(BrowserContext
* browser_context
);
105 // WebContentsImpl overrides
106 virtual void CreateNewWindow(
107 int render_process_id
,
109 int main_frame_route_id
,
110 const ViewHostMsg_CreateWindow_Params
& params
,
111 SessionStorageNamespace
* session_storage_namespace
) OVERRIDE
;
112 virtual void CreateNewWidget(int render_process_id
,
114 blink::WebPopupType popup_type
) OVERRIDE
;
115 virtual void CreateNewFullscreenWidget(int render_process_id
,
116 int route_id
) OVERRIDE
;
117 virtual void ShowCreatedWindow(int route_id
,
118 WindowOpenDisposition disposition
,
119 const gfx::Rect
& initial_pos
,
120 bool user_gesture
) OVERRIDE
;
121 virtual void ShowCreatedWidget(int route_id
,
122 const gfx::Rect
& initial_pos
) OVERRIDE
;
123 virtual void ShowCreatedFullscreenWidget(int route_id
) OVERRIDE
;
126 RenderViewHostDelegateView
* delegate_view_override_
;
128 // Expectations for arguments of |SetHistoryLengthAndPrune()|.
129 bool expect_set_history_length_and_prune_
;
130 scoped_refptr
<const SiteInstanceImpl
>
131 expect_set_history_length_and_prune_site_instance_
;
132 int expect_set_history_length_and_prune_history_length_
;
133 int32 expect_set_history_length_and_prune_min_page_id_
;
136 } // namespace content
138 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_