Move more string_util functions to base namespace.
[chromium-blink-merge.git] / content / test / test_web_contents.h
blobb94aed63cd2737cc0042f9a6df2baa96cb4643eb
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 <string>
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"
16 class GURL;
17 class Referrer;
18 class SiteInstanceImpl;
20 namespace content {
22 class RenderViewHost;
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 {
29 public:
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;
39 // WebContentsTester implementation.
40 void CommitPendingNavigation() override;
41 TestRenderFrameHost* GetPendingMainFrame() const override;
42 void NavigateAndCommit(const GURL& url) override;
43 void TestSetIsLoading(bool value) override;
44 void ProceedWithCrossSiteNavigation() override;
45 void TestDidNavigate(RenderFrameHost* render_frame_host,
46 int page_id,
47 int nav_entry_id,
48 bool did_create_new_entry,
49 const GURL& url,
50 ui::PageTransition transition) override;
51 void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
52 int page_id,
53 int nav_entry_id,
54 bool did_create_new_entry,
55 const GURL& url,
56 const Referrer& referrer,
57 ui::PageTransition transition) override;
58 const std::string& GetSaveFrameHeaders() override;
60 // True if a cross-site navigation is pending.
61 bool CrossProcessNavigationPending();
63 // Prevent interaction with views.
64 bool CreateRenderViewForRenderManager(
65 RenderViewHost* render_view_host,
66 int opener_route_id,
67 int proxy_routing_id,
68 const FrameReplicationState& replicated_frame_state,
69 bool for_main_frame) override;
70 void UpdateRenderViewSizeForRenderManager() override {}
72 // Returns a clone of this TestWebContents. The returned object is also a
73 // TestWebContents. The caller owns the returned object.
74 WebContents* Clone() override;
76 // Allow mocking of the RenderViewHostDelegateView.
77 RenderViewHostDelegateView* GetDelegateView() override;
78 void set_delegate_view(RenderViewHostDelegateView* view) {
79 delegate_view_override_ = view;
82 // Allows us to simulate this tab's main frame having an opener that points
83 // to the main frame of the |opener|.
84 void SetOpener(TestWebContents* opener);
86 // Allows us to simulate that a contents was created via CreateNewWindow.
87 void AddPendingContents(TestWebContents* contents);
89 // Establish expected arguments for |SetHistoryOffsetAndLength()|. When
90 // |SetHistoryOffsetAndLength()| is called, the arguments are compared
91 // with the expected arguments specified here.
92 void ExpectSetHistoryOffsetAndLength(int history_offset,
93 int history_length);
95 // Compares the arguments passed in with the expected arguments passed in
96 // to |ExpectSetHistoryOffsetAndLength()|.
97 void SetHistoryOffsetAndLength(int history_offset,
98 int history_length) override;
100 void TestDidFinishLoad(const GURL& url);
101 void TestDidFailLoadWithError(const GURL& url,
102 int error_code,
103 const base::string16& error_description);
105 protected:
106 // The deprecated WebContentsTester still needs to subclass this.
107 explicit TestWebContents(BrowserContext* browser_context);
109 private:
110 // WebContentsImpl overrides
111 void CreateNewWindow(
112 int render_process_id,
113 int route_id,
114 int main_frame_route_id,
115 const ViewHostMsg_CreateWindow_Params& params,
116 SessionStorageNamespace* session_storage_namespace) override;
117 void CreateNewWidget(int render_process_id,
118 int route_id,
119 blink::WebPopupType popup_type) override;
120 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
121 void ShowCreatedWindow(int route_id,
122 WindowOpenDisposition disposition,
123 const gfx::Rect& initial_rect,
124 bool user_gesture) override;
125 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
126 void ShowCreatedFullscreenWidget(int route_id) override;
127 void SaveFrameWithHeaders(const GURL& url,
128 const Referrer& referrer,
129 const std::string& headers) override;
131 RenderViewHostDelegateView* delegate_view_override_;
133 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
134 bool expect_set_history_offset_and_length_;
135 int expect_set_history_offset_and_length_history_offset_;
136 int expect_set_history_offset_and_length_history_length_;
137 std::string save_frame_headers_;
140 } // namespace content
142 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_