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
) override
;
76 void UpdateRenderViewSizeForRenderManager() override
{}
78 // Returns a clone of this TestWebContents. The returned object is also a
79 // TestWebContents. The caller owns the returned object.
80 WebContents
* Clone() override
;
82 // Allow mocking of the RenderViewHostDelegateView.
83 RenderViewHostDelegateView
* GetDelegateView() override
;
84 void set_delegate_view(RenderViewHostDelegateView
* view
) {
85 delegate_view_override_
= view
;
88 // Allows us to simulate this tab's main frame having an opener that points
89 // to the main frame of the |opener|.
90 void SetOpener(TestWebContents
* opener
);
92 // Allows us to simulate that a contents was created via CreateNewWindow.
93 void AddPendingContents(TestWebContents
* contents
);
95 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
96 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
97 // with the expected arguments specified here.
98 void ExpectSetHistoryOffsetAndLength(int history_offset
,
101 // Compares the arguments passed in with the expected arguments passed in
102 // to |ExpectSetHistoryOffsetAndLength()|.
103 void SetHistoryOffsetAndLength(int history_offset
,
104 int history_length
) override
;
106 void TestDidFinishLoad(const GURL
& url
);
107 void TestDidFailLoadWithError(const GURL
& url
,
109 const base::string16
& error_description
,
110 bool was_ignored_by_handler
);
113 // The deprecated WebContentsTester still needs to subclass this.
114 explicit TestWebContents(BrowserContext
* browser_context
);
117 // WebContentsImpl overrides
118 void CreateNewWindow(
119 SiteInstance
* source_site_instance
,
121 int main_frame_route_id
,
122 const ViewHostMsg_CreateWindow_Params
& params
,
123 SessionStorageNamespace
* session_storage_namespace
) override
;
124 void CreateNewWidget(int32 render_process_id
,
127 blink::WebPopupType popup_type
) override
;
128 void CreateNewFullscreenWidget(int32 render_process_id
,
130 int32 surface_id
) override
;
131 void ShowCreatedWindow(int route_id
,
132 WindowOpenDisposition disposition
,
133 const gfx::Rect
& initial_rect
,
134 bool user_gesture
) override
;
135 void ShowCreatedWidget(int route_id
, const gfx::Rect
& initial_rect
) override
;
136 void ShowCreatedFullscreenWidget(int route_id
) override
;
137 void SaveFrameWithHeaders(const GURL
& url
,
138 const Referrer
& referrer
,
139 const std::string
& headers
) override
;
141 RenderViewHostDelegateView
* delegate_view_override_
;
143 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
144 bool expect_set_history_offset_and_length_
;
145 int expect_set_history_offset_and_length_history_offset_
;
146 int expect_set_history_offset_and_length_history_length_
;
147 std::string save_frame_headers_
;
150 } // namespace content
152 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_