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/web_preferences.h"
10 #include "content/public/test/web_contents_tester.h"
11 #include "content/test/test_render_frame_host.h"
12 #include "content/test/test_render_view_host.h"
13 #include "ui/base/page_transition_types.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 ~TestWebContents() override
;
29 static TestWebContents
* Create(BrowserContext
* browser_context
,
30 SiteInstance
* instance
);
32 // WebContentsImpl overrides (returning the same values, but in Test* types)
33 TestRenderFrameHost
* GetMainFrame() override
;
34 TestRenderViewHost
* GetRenderViewHost() const override
;
36 // WebContentsTester implementation.
37 void CommitPendingNavigation() override
;
38 TestRenderFrameHost
* GetPendingMainFrame() const override
;
39 void NavigateAndCommit(const GURL
& url
) override
;
40 void TestSetIsLoading(bool value
) override
;
41 void ProceedWithCrossSiteNavigation() override
;
42 void TestDidNavigate(RenderFrameHost
* render_frame_host
,
45 ui::PageTransition transition
) override
;
46 void TestDidNavigateWithReferrer(RenderFrameHost
* render_frame_host
,
49 const Referrer
& referrer
,
50 ui::PageTransition transition
) override
;
51 WebPreferences
TestComputeWebkitPrefs() override
;
54 bool cross_navigation_pending() {
55 return GetRenderManager()->cross_navigation_pending_
;
58 // Prevent interaction with views.
59 bool CreateRenderViewForRenderManager(RenderViewHost
* render_view_host
,
62 bool for_main_frame
) override
;
63 void UpdateRenderViewSizeForRenderManager() override
{}
65 // Returns a clone of this TestWebContents. The returned object is also a
66 // TestWebContents. The caller owns the returned object.
67 WebContents
* Clone() override
;
69 // Allow mocking of the RenderViewHostDelegateView.
70 RenderViewHostDelegateView
* GetDelegateView() override
;
71 void set_delegate_view(RenderViewHostDelegateView
* view
) {
72 delegate_view_override_
= view
;
75 // Allows us to simulate this tab having an opener.
76 void SetOpener(TestWebContents
* opener
);
78 // Allows us to simulate that a contents was created via CreateNewWindow.
79 void AddPendingContents(TestWebContents
* contents
);
81 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When
82 // |SetHistoryLengthAndPrune()| is called, the arguments are compared
83 // with the expected arguments specified here.
84 void ExpectSetHistoryLengthAndPrune(const SiteInstance
* site_instance
,
88 // Compares the arguments passed in with the expected arguments passed in
89 // to |ExpectSetHistoryLengthAndPrune()|.
90 void SetHistoryLengthAndPrune(const SiteInstance
* site_instance
,
92 int32 min_page_id
) override
;
94 void TestDidFinishLoad(const GURL
& url
);
95 void TestDidFailLoadWithError(const GURL
& url
,
97 const base::string16
& error_description
);
100 // The deprecated WebContentsTester still needs to subclass this.
101 explicit TestWebContents(BrowserContext
* browser_context
);
104 // WebContentsImpl overrides
105 void CreateNewWindow(
106 int render_process_id
,
108 int main_frame_route_id
,
109 const ViewHostMsg_CreateWindow_Params
& params
,
110 SessionStorageNamespace
* session_storage_namespace
) override
;
111 void CreateNewWidget(int render_process_id
,
113 blink::WebPopupType popup_type
) override
;
114 void CreateNewFullscreenWidget(int render_process_id
, int route_id
) override
;
115 void ShowCreatedWindow(int route_id
,
116 WindowOpenDisposition disposition
,
117 const gfx::Rect
& initial_pos
,
118 bool user_gesture
) override
;
119 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_pos
) override
;
120 void ShowCreatedFullscreenWidget(int route_id
) override
;
122 RenderViewHostDelegateView
* delegate_view_override_
;
124 // Expectations for arguments of |SetHistoryLengthAndPrune()|.
125 bool expect_set_history_length_and_prune_
;
126 scoped_refptr
<const SiteInstanceImpl
>
127 expect_set_history_length_and_prune_site_instance_
;
128 int expect_set_history_length_and_prune_history_length_
;
129 int32 expect_set_history_length_and_prune_min_page_id_
;
132 } // namespace content
134 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_