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/test/web_contents_tester.h"
10 #include "content/test/test_render_frame_host.h"
11 #include "content/test/test_render_view_host.h"
12 #include "ui/base/page_transition_types.h"
14 class SiteInstanceImpl
;
19 class TestRenderViewHost
;
20 class WebContentsTester
;
22 // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
23 // and does not do anything involving views.
24 class TestWebContents
: public WebContentsImpl
, public WebContentsTester
{
26 ~TestWebContents() override
;
28 static TestWebContents
* Create(BrowserContext
* browser_context
,
29 SiteInstance
* instance
);
31 // WebContentsImpl overrides (returning the same values, but in Test* types)
32 TestRenderFrameHost
* GetMainFrame() override
;
33 TestRenderViewHost
* GetRenderViewHost() const override
;
35 // WebContentsTester implementation.
36 void CommitPendingNavigation() override
;
37 TestRenderFrameHost
* GetPendingMainFrame() const override
;
38 void NavigateAndCommit(const GURL
& url
) override
;
39 void TestSetIsLoading(bool value
) override
;
40 void ProceedWithCrossSiteNavigation() override
;
41 void TestDidNavigate(RenderFrameHost
* render_frame_host
,
44 ui::PageTransition transition
) override
;
45 void TestDidNavigateWithReferrer(RenderFrameHost
* render_frame_host
,
48 const Referrer
& referrer
,
49 ui::PageTransition transition
) override
;
52 bool cross_navigation_pending() {
53 return GetRenderManager()->cross_navigation_pending_
;
56 // Prevent interaction with views.
57 bool CreateRenderViewForRenderManager(RenderViewHost
* render_view_host
,
60 bool for_main_frame
) override
;
61 void UpdateRenderViewSizeForRenderManager() override
{}
63 // Returns a clone of this TestWebContents. The returned object is also a
64 // TestWebContents. The caller owns the returned object.
65 WebContents
* Clone() override
;
67 // Allow mocking of the RenderViewHostDelegateView.
68 RenderViewHostDelegateView
* GetDelegateView() override
;
69 void set_delegate_view(RenderViewHostDelegateView
* view
) {
70 delegate_view_override_
= view
;
73 // Allows us to simulate this tab having an opener.
74 void SetOpener(TestWebContents
* opener
);
76 // Allows us to simulate that a contents was created via CreateNewWindow.
77 void AddPendingContents(TestWebContents
* contents
);
79 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
80 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
81 // with the expected arguments specified here.
82 void ExpectSetHistoryOffsetAndLength(int history_offset
,
85 // Compares the arguments passed in with the expected arguments passed in
86 // to |ExpectSetHistoryOffsetAndLength()|.
87 void SetHistoryOffsetAndLength(int history_offset
,
88 int history_length
) override
;
90 void TestDidFinishLoad(const GURL
& url
);
91 void TestDidFailLoadWithError(const GURL
& url
,
93 const base::string16
& error_description
);
96 // The deprecated WebContentsTester still needs to subclass this.
97 explicit TestWebContents(BrowserContext
* browser_context
);
100 // WebContentsImpl overrides
101 void CreateNewWindow(
102 int render_process_id
,
104 int main_frame_route_id
,
105 const ViewHostMsg_CreateWindow_Params
& params
,
106 SessionStorageNamespace
* session_storage_namespace
) override
;
107 void CreateNewWidget(int render_process_id
,
109 blink::WebPopupType popup_type
) override
;
110 void CreateNewFullscreenWidget(int render_process_id
, int route_id
) override
;
111 void ShowCreatedWindow(int route_id
,
112 WindowOpenDisposition disposition
,
113 const gfx::Rect
& initial_rect
,
114 bool user_gesture
) override
;
115 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_rect
) override
;
116 void ShowCreatedFullscreenWidget(int route_id
) override
;
118 RenderViewHostDelegateView
* delegate_view_override_
;
120 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
121 bool expect_set_history_offset_and_length_
;
122 int expect_set_history_offset_and_length_history_offset_
;
123 int expect_set_history_offset_and_length_history_length_
;
126 } // namespace content
128 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_