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