[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 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. |
| 4 | |
[email protected] | 4172b08 | 2013-02-25 18:07:34 | [diff] [blame] | 5 | #ifndef CONTENT_TEST_TEST_WEB_CONTENTS_H_ |
| 6 | #define CONTENT_TEST_TEST_WEB_CONTENTS_H_ |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 7 | |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 12 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | b1e3f20 | 2012-06-04 14:45:50 | [diff] [blame] | 13 | #include "content/public/test/web_contents_tester.h" |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 14 | #include "content/test/test_render_frame_host.h" |
| 15 | #include "content/test/test_render_view_host.h" |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 16 | #include "ui/base/page_transition_types.h" |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 17 | |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 18 | class GURL; |
| 19 | class Referrer; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 20 | class SiteInstanceImpl; |
| 21 | |
| 22 | namespace content { |
| 23 | |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 24 | class NavigationData; |
| 25 | class NavigationHandle; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 26 | class RenderViewHost; |
| 27 | class TestRenderViewHost; |
| 28 | class WebContentsTester; |
| 29 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 30 | // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 31 | // and does not do anything involving views. |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 32 | class TestWebContents : public WebContentsImpl, public WebContentsTester { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 33 | public: |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 34 | ~TestWebContents() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 35 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 36 | static TestWebContents* Create(BrowserContext* browser_context, |
dcheng | bccd6b8 | 2016-03-30 16:24:19 | [diff] [blame] | 37 | scoped_refptr<SiteInstance> instance); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 38 | |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 39 | // WebContentsImpl overrides (returning the same values, but in Test* types) |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 40 | TestRenderFrameHost* GetMainFrame() override; |
| 41 | TestRenderViewHost* GetRenderViewHost() const override; |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 42 | // Overrides to avoid establishing Mojo connection with renderer process. |
| 43 | int DownloadImage(const GURL& url, |
| 44 | bool is_favicon, |
| 45 | uint32_t max_bitmap_size, |
| 46 | bool bypass_cache, |
| 47 | const ImageDownloadCallback& callback) override; |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 48 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 49 | // WebContentsTester implementation. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 50 | void CommitPendingNavigation() override; |
| 51 | TestRenderFrameHost* GetPendingMainFrame() const override; |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 52 | void StartNavigation(const GURL& url) override; |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 53 | void NavigateAndCommit(const GURL& url) override; |
| 54 | void TestSetIsLoading(bool value) override; |
| 55 | void ProceedWithCrossSiteNavigation() override; |
| 56 | void TestDidNavigate(RenderFrameHost* render_frame_host, |
| 57 | int page_id, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 58 | int nav_entry_id, |
| 59 | bool did_create_new_entry, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 60 | const GURL& url, |
| 61 | ui::PageTransition transition) override; |
| 62 | void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host, |
| 63 | int page_id, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 64 | int nav_entry_id, |
| 65 | bool did_create_new_entry, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 66 | const GURL& url, |
| 67 | const Referrer& referrer, |
| 68 | ui::PageTransition transition) override; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 69 | const std::string& GetSaveFrameHeaders() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 70 | |
clamy | 5bf3611 | 2015-04-17 15:23:22 | [diff] [blame] | 71 | // True if a cross-site navigation is pending. |
| 72 | bool CrossProcessNavigationPending(); |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 73 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 74 | // Prevent interaction with views. |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 75 | bool CreateRenderViewForRenderManager( |
| 76 | RenderViewHost* render_view_host, |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 77 | int opener_frame_routing_id, |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 78 | int proxy_routing_id, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 79 | const FrameReplicationState& replicated_frame_state) override; |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 80 | void UpdateRenderViewSizeForRenderManager() override {} |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 81 | |
| 82 | // Returns a clone of this TestWebContents. The returned object is also a |
| 83 | // TestWebContents. The caller owns the returned object. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 84 | WebContents* Clone() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 85 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 86 | // Allow mocking of the RenderViewHostDelegateView. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 87 | RenderViewHostDelegateView* GetDelegateView() override; |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 88 | void set_delegate_view(RenderViewHostDelegateView* view) { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 89 | delegate_view_override_ = view; |
| 90 | } |
| 91 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 92 | // Allows us to simulate this tab's main frame having an opener that points |
| 93 | // to the main frame of the |opener|. |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 94 | void SetOpener(TestWebContents* opener); |
| 95 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 96 | // Allows us to simulate that a contents was created via CreateNewWindow. |
| 97 | void AddPendingContents(TestWebContents* contents); |
| 98 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 99 | // Establish expected arguments for |SetHistoryOffsetAndLength()|. When |
| 100 | // |SetHistoryOffsetAndLength()| is called, the arguments are compared |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 101 | // with the expected arguments specified here. |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 102 | void ExpectSetHistoryOffsetAndLength(int history_offset, |
| 103 | int history_length); |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 104 | |
| 105 | // Compares the arguments passed in with the expected arguments passed in |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 106 | // to |ExpectSetHistoryOffsetAndLength()|. |
| 107 | void SetHistoryOffsetAndLength(int history_offset, |
| 108 | int history_length) override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 109 | |
[email protected] | 61ac9e24 | 2014-03-21 20:55:26 | [diff] [blame] | 110 | void TestDidFinishLoad(const GURL& url); |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 111 | void TestDidFailLoadWithError(const GURL& url, |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 112 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 113 | const base::string16& error_description, |
| 114 | bool was_ignored_by_handler); |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 115 | |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 116 | void SetNavigationData( |
| 117 | NavigationHandle* navigation_handle, |
| 118 | std::unique_ptr<NavigationData> navigation_data) override; |
| 119 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 120 | protected: |
| 121 | // The deprecated WebContentsTester still needs to subclass this. |
| 122 | explicit TestWebContents(BrowserContext* browser_context); |
| 123 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 124 | private: |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 125 | // WebContentsImpl overrides |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 126 | void CreateNewWindow( |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 127 | SiteInstance* source_site_instance, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 128 | int32_t route_id, |
| 129 | int32_t main_frame_route_id, |
| 130 | int32_t main_frame_widget_route_id, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame^] | 131 | const mojom::CreateNewWindowParams& params, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame] | 132 | SessionStorageNamespace* session_storage_namespace) override; |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 133 | void CreateNewWidget(int32_t render_process_id, |
| 134 | int32_t route_id, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 135 | blink::WebPopupType popup_type) override; |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 136 | void CreateNewFullscreenWidget(int32_t render_process_id, |
| 137 | int32_t route_id) override; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 138 | void ShowCreatedWindow(int process_id, |
| 139 | int route_id, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 140 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 141 | const gfx::Rect& initial_rect, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 142 | bool user_gesture) override; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 143 | void ShowCreatedWidget(int process_id, |
| 144 | int route_id, |
| 145 | const gfx::Rect& initial_rect) override; |
| 146 | void ShowCreatedFullscreenWidget(int process_id, int route_id) override; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 147 | void SaveFrameWithHeaders(const GURL& url, |
| 148 | const Referrer& referrer, |
| 149 | const std::string& headers) override; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 150 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 151 | RenderViewHostDelegateView* delegate_view_override_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 152 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 153 | // Expectations for arguments of |SetHistoryOffsetAndLength()|. |
| 154 | bool expect_set_history_offset_and_length_; |
| 155 | int expect_set_history_offset_and_length_history_offset_; |
| 156 | int expect_set_history_offset_and_length_history_length_; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 157 | std::string save_frame_headers_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | } // namespace content |
| 161 | |
[email protected] | 4172b08 | 2013-02-25 18:07:34 | [diff] [blame] | 162 | #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_ |