[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, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 57 | int nav_entry_id, |
| 58 | bool did_create_new_entry, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 59 | const GURL& url, |
| 60 | ui::PageTransition transition) override; |
| 61 | void TestDidNavigateWithReferrer(RenderFrameHost* render_frame_host, |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 62 | int nav_entry_id, |
| 63 | bool did_create_new_entry, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 64 | const GURL& url, |
| 65 | const Referrer& referrer, |
| 66 | ui::PageTransition transition) override; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 67 | const std::string& GetSaveFrameHeaders() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 68 | |
clamy | 5bf3611 | 2015-04-17 15:23:22 | [diff] [blame] | 69 | // True if a cross-site navigation is pending. |
| 70 | bool CrossProcessNavigationPending(); |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 71 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 72 | // Prevent interaction with views. |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 73 | bool CreateRenderViewForRenderManager( |
| 74 | RenderViewHost* render_view_host, |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 75 | int opener_frame_routing_id, |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 76 | int proxy_routing_id, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 77 | const FrameReplicationState& replicated_frame_state) override; |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 78 | void UpdateRenderViewSizeForRenderManager() override {} |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 79 | |
| 80 | // Returns a clone of this TestWebContents. The returned object is also a |
| 81 | // TestWebContents. The caller owns the returned object. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 82 | WebContents* Clone() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 83 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 84 | // Allow mocking of the RenderViewHostDelegateView. |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 85 | RenderViewHostDelegateView* GetDelegateView() override; |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 86 | void set_delegate_view(RenderViewHostDelegateView* view) { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 87 | delegate_view_override_ = view; |
| 88 | } |
| 89 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 90 | // Allows us to simulate this tab's main frame having an opener that points |
| 91 | // to the main frame of the |opener|. |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 92 | void SetOpener(TestWebContents* opener); |
| 93 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 94 | // Allows us to simulate that a contents was created via CreateNewWindow. |
| 95 | void AddPendingContents(TestWebContents* contents); |
| 96 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 97 | // Establish expected arguments for |SetHistoryOffsetAndLength()|. When |
| 98 | // |SetHistoryOffsetAndLength()| is called, the arguments are compared |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 99 | // with the expected arguments specified here. |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 100 | void ExpectSetHistoryOffsetAndLength(int history_offset, |
| 101 | int history_length); |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 102 | |
| 103 | // Compares the arguments passed in with the expected arguments passed in |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 104 | // to |ExpectSetHistoryOffsetAndLength()|. |
| 105 | void SetHistoryOffsetAndLength(int history_offset, |
| 106 | int history_length) override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 107 | |
[email protected] | 61ac9e24 | 2014-03-21 20:55:26 | [diff] [blame] | 108 | void TestDidFinishLoad(const GURL& url); |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 109 | void TestDidFailLoadWithError(const GURL& url, |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 110 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 111 | const base::string16& error_description, |
| 112 | bool was_ignored_by_handler); |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 113 | |
ryansturm | fe32816 | 2016-05-11 22:28:47 | [diff] [blame] | 114 | void SetNavigationData( |
| 115 | NavigationHandle* navigation_handle, |
| 116 | std::unique_ptr<NavigationData> navigation_data) override; |
| 117 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 118 | protected: |
| 119 | // The deprecated WebContentsTester still needs to subclass this. |
| 120 | explicit TestWebContents(BrowserContext* browser_context); |
| 121 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 122 | private: |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 123 | // WebContentsImpl overrides |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 124 | void CreateNewWindow( |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 125 | SiteInstance* source_site_instance, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 126 | int32_t route_id, |
| 127 | int32_t main_frame_route_id, |
| 128 | int32_t main_frame_widget_route_id, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 129 | const mojom::CreateNewWindowParams& params, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame] | 130 | SessionStorageNamespace* session_storage_namespace) override; |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 131 | void CreateNewWidget(int32_t render_process_id, |
| 132 | int32_t route_id, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 133 | blink::WebPopupType popup_type) override; |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 134 | void CreateNewFullscreenWidget(int32_t render_process_id, |
| 135 | int32_t route_id) override; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 136 | void ShowCreatedWindow(int process_id, |
| 137 | int route_id, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 138 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 139 | const gfx::Rect& initial_rect, |
dcheng | e933b3eb | 2014-10-21 11:44:09 | [diff] [blame] | 140 | bool user_gesture) override; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 141 | void ShowCreatedWidget(int process_id, |
| 142 | int route_id, |
| 143 | const gfx::Rect& initial_rect) override; |
| 144 | void ShowCreatedFullscreenWidget(int process_id, int route_id) override; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 145 | void SaveFrameWithHeaders(const GURL& url, |
| 146 | const Referrer& referrer, |
| 147 | const std::string& headers) override; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 148 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 149 | RenderViewHostDelegateView* delegate_view_override_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 150 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 151 | // Expectations for arguments of |SetHistoryOffsetAndLength()|. |
| 152 | bool expect_set_history_offset_and_length_; |
| 153 | int expect_set_history_offset_and_length_history_offset_; |
| 154 | int expect_set_history_offset_and_length_history_length_; |
kundaji | 6db683c | 2015-05-14 19:40:15 | [diff] [blame] | 155 | std::string save_frame_headers_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | } // namespace content |
| 159 | |
[email protected] | 4172b08 | 2013-02-25 18:07:34 | [diff] [blame] | 160 | #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_ |