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_
10 #include "content/browser/web_contents/web_contents_impl.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"
14 #include "ui/base/page_transition_types.h"
18 class SiteInstanceImpl
;
23 class TestRenderViewHost
;
24 class WebContentsTester
;
26 // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts
27 // and does not do anything involving views.
28 class TestWebContents
: public WebContentsImpl
, public WebContentsTester
{
30 ~TestWebContents() override
;
32 static TestWebContents
* Create(BrowserContext
* browser_context
,
33 SiteInstance
* instance
);
35 // WebContentsImpl overrides (returning the same values, but in Test* types)
36 TestRenderFrameHost
* GetMainFrame() override
;
37 TestRenderViewHost
* GetRenderViewHost() const override
;
38 // Overrides to avoid establishing Mojo connection with renderer process.
39 int DownloadImage(const GURL
& url
,
41 uint32_t max_bitmap_size
,
43 const ImageDownloadCallback
& callback
) override
;
45 // WebContentsTester implementation.
46 void CommitPendingNavigation() override
;
47 TestRenderFrameHost
* GetPendingMainFrame() const override
;
48 void StartNavigation(const GURL
& url
) override
;
49 void NavigateAndCommit(const GURL
& url
) override
;
50 void TestSetIsLoading(bool value
) override
;
51 void ProceedWithCrossSiteNavigation() override
;
52 void TestDidNavigate(RenderFrameHost
* render_frame_host
,
55 bool did_create_new_entry
,
57 ui::PageTransition transition
) override
;
58 void TestDidNavigateWithReferrer(RenderFrameHost
* render_frame_host
,
61 bool did_create_new_entry
,
63 const Referrer
& referrer
,
64 ui::PageTransition transition
) override
;
65 const std::string
& GetSaveFrameHeaders() override
;
67 // True if a cross-site navigation is pending.
68 bool CrossProcessNavigationPending();
70 // Prevent interaction with views.
71 bool CreateRenderViewForRenderManager(
72 RenderViewHost
* render_view_host
,
73 int opener_frame_routing_id
,
75 const FrameReplicationState
& replicated_frame_state
,
76 bool for_main_frame
) override
;
77 void UpdateRenderViewSizeForRenderManager() override
{}
79 // Returns a clone of this TestWebContents. The returned object is also a
80 // TestWebContents. The caller owns the returned object.
81 WebContents
* Clone() override
;
83 // Allow mocking of the RenderViewHostDelegateView.
84 RenderViewHostDelegateView
* GetDelegateView() override
;
85 void set_delegate_view(RenderViewHostDelegateView
* view
) {
86 delegate_view_override_
= view
;
89 // Allows us to simulate this tab's main frame having an opener that points
90 // to the main frame of the |opener|.
91 void SetOpener(TestWebContents
* opener
);
93 // Allows us to simulate that a contents was created via CreateNewWindow.
94 void AddPendingContents(TestWebContents
* contents
);
96 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
97 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
98 // with the expected arguments specified here.
99 void ExpectSetHistoryOffsetAndLength(int history_offset
,
102 // Compares the arguments passed in with the expected arguments passed in
103 // to |ExpectSetHistoryOffsetAndLength()|.
104 void SetHistoryOffsetAndLength(int history_offset
,
105 int history_length
) override
;
107 void TestDidFinishLoad(const GURL
& url
);
108 void TestDidFailLoadWithError(const GURL
& url
,
110 const base::string16
& error_description
,
111 bool was_ignored_by_handler
);
114 // The deprecated WebContentsTester still needs to subclass this.
115 explicit TestWebContents(BrowserContext
* browser_context
);
118 // WebContentsImpl overrides
119 void CreateNewWindow(
120 SiteInstance
* source_site_instance
,
122 int main_frame_route_id
,
123 const ViewHostMsg_CreateWindow_Params
& params
,
124 SessionStorageNamespace
* session_storage_namespace
) override
;
125 void CreateNewWidget(int32 render_process_id
,
128 blink::WebPopupType popup_type
) override
;
129 void CreateNewFullscreenWidget(int32 render_process_id
,
131 int32 surface_id
) override
;
132 void ShowCreatedWindow(int route_id
,
133 WindowOpenDisposition disposition
,
134 const gfx::Rect
& initial_rect
,
135 bool user_gesture
) override
;
136 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_rect
) override
;
137 void ShowCreatedFullscreenWidget(int route_id
) override
;
138 void SaveFrameWithHeaders(const GURL
& url
,
139 const Referrer
& referrer
,
140 const std::string
& headers
) override
;
142 RenderViewHostDelegateView
* delegate_view_override_
;
144 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
145 bool expect_set_history_offset_and_length_
;
146 int expect_set_history_offset_and_length_history_offset_
;
147 int expect_set_history_offset_and_length_history_length_
;
148 std::string save_frame_headers_
;
151 } // namespace content
153 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_