Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / test / test_web_contents.h
blob3e45d8a9a3b6bcc425e1a091ee9355b2404d42fa
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;
38 // Overrides to avoid establishing Mojo connection with renderer process.
39 int DownloadImage(const GURL& url,
40 bool is_favicon,
41 uint32_t max_bitmap_size,
42 bool bypass_cache,
43 const ImageDownloadCallback& callback) override;
45 // WebContentsTester implementation.
46 void CommitPendingNavigation() override;
47 TestRenderFrameHost* GetPendingMainFrame() const override;
48 void NavigateAndCommit(const GURL& url) override;
49 void TestSetIsLoading(bool value) override;
50 void ProceedWithCrossSiteNavigation() override;
51 void TestDidNavigate(RenderFrameHost* render_frame_host,
52 int page_id,
53 int nav_entry_id,
54 bool did_create_new_entry,
55 const GURL& url,
56 ui::PageTransition transition) override;
57 void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host,
58 int page_id,
59 int nav_entry_id,
60 bool did_create_new_entry,
61 const GURL& url,
62 const Referrer& referrer,
63 ui::PageTransition transition) override;
64 const std::string& GetSaveFrameHeaders() override;
66 // True if a cross-site navigation is pending.
67 bool CrossProcessNavigationPending();
69 // Prevent interaction with views.
70 bool CreateRenderViewForRenderManager(
71 RenderViewHost* render_view_host,
72 int opener_frame_routing_id,
73 int proxy_routing_id,
74 const FrameReplicationState& replicated_frame_state,
75 bool for_main_frame) 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,
99 int history_length);
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,
108 int error_code,
109 const base::string16& error_description,
110 bool was_ignored_by_handler);
112 protected:
113 // The deprecated WebContentsTester still needs to subclass this.
114 explicit TestWebContents(BrowserContext* browser_context);
116 private:
117 // WebContentsImpl overrides
118 void CreateNewWindow(
119 SiteInstance* source_site_instance,
120 int route_id,
121 int main_frame_route_id,
122 const ViewHostMsg_CreateWindow_Params& params,
123 SessionStorageNamespace* session_storage_namespace) override;
124 void CreateNewWidget(int render_process_id,
125 int route_id,
126 blink::WebPopupType popup_type) override;
127 void CreateNewFullscreenWidget(int render_process_id, int route_id) override;
128 void ShowCreatedWindow(int route_id,
129 WindowOpenDisposition disposition,
130 const gfx::Rect& initial_rect,
131 bool user_gesture) override;
132 void ShowCreatedWidget(int route_id, const gfx::Rect& initial_rect) override;
133 void ShowCreatedFullscreenWidget(int route_id) override;
134 void SaveFrameWithHeaders(const GURL& url,
135 const Referrer& referrer,
136 const std::string& headers) override;
138 RenderViewHostDelegateView* delegate_view_override_;
140 // Expectations for arguments of |SetHistoryOffsetAndLength()|.
141 bool expect_set_history_offset_and_length_;
142 int expect_set_history_offset_and_length_history_offset_;
143 int expect_set_history_offset_and_length_history_length_;
144 std::string save_frame_headers_;
147 } // namespace content
149 #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_