[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 | |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 8 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 9 | #include "content/public/common/web_preferences.h" |
[email protected] | b1e3f20 | 2012-06-04 14:45:50 | [diff] [blame] | 10 | #include "content/public/test/web_contents_tester.h" |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 11 | #include "content/test/test_render_frame_host.h" |
| 12 | #include "content/test/test_render_view_host.h" |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 13 | #include "ui/base/page_transition_types.h" |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 14 | |
| 15 | class SiteInstanceImpl; |
| 16 | |
| 17 | namespace content { |
| 18 | |
| 19 | class RenderViewHost; |
| 20 | class TestRenderViewHost; |
| 21 | class WebContentsTester; |
| 22 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 23 | // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 24 | // and does not do anything involving views. |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 25 | class TestWebContents : public WebContentsImpl, public WebContentsTester { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 26 | public: |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 27 | virtual ~TestWebContents(); |
| 28 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 29 | static TestWebContents* Create(BrowserContext* browser_context, |
| 30 | SiteInstance* instance); |
| 31 | |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 32 | // WebContentsImpl overrides (returning the same values, but in Test* types) |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 33 | virtual TestRenderFrameHost* GetMainFrame() override; |
| 34 | virtual TestRenderViewHost* GetRenderViewHost() const override; |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 35 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 36 | // WebContentsTester implementation. |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 37 | virtual void CommitPendingNavigation() override; |
| 38 | virtual TestRenderFrameHost* GetPendingMainFrame() const override; |
| 39 | virtual void NavigateAndCommit(const GURL& url) override; |
| 40 | virtual void TestSetIsLoading(bool value) override; |
| 41 | virtual void ProceedWithCrossSiteNavigation() override; |
[email protected] | 6b50e36 | 2014-08-15 05:15:59 | [diff] [blame] | 42 | virtual void TestDidNavigate(RenderFrameHost* render_frame_host, |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 43 | int page_id, |
| 44 | const GURL& url, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 45 | ui::PageTransition transition) override; |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 46 | virtual void TestDidNavigateWithReferrer( |
| 47 | RenderFrameHost* render_frame_host, |
| 48 | int page_id, |
| 49 | const GURL& url, |
| 50 | const Referrer& referrer, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 51 | ui::PageTransition transition) override; |
| 52 | virtual WebPreferences TestComputeWebkitPrefs() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 53 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 54 | // State accessor. |
| 55 | bool cross_navigation_pending() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 56 | return GetRenderManager()->cross_navigation_pending_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 57 | } |
| 58 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 59 | // Prevent interaction with views. |
| 60 | virtual bool CreateRenderViewForRenderManager( |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 61 | RenderViewHost* render_view_host, |
| 62 | int opener_route_id, |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 63 | int proxy_routing_id, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 64 | bool for_main_frame) override; |
| 65 | virtual void UpdateRenderViewSizeForRenderManager() override {} |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 66 | |
| 67 | // Returns a clone of this TestWebContents. The returned object is also a |
| 68 | // TestWebContents. The caller owns the returned object. |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 69 | virtual WebContents* Clone() override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 70 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 71 | // Allow mocking of the RenderViewHostDelegateView. |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 72 | virtual RenderViewHostDelegateView* GetDelegateView() override; |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 73 | void set_delegate_view(RenderViewHostDelegateView* view) { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 74 | delegate_view_override_ = view; |
| 75 | } |
| 76 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 77 | // Allows us to simulate this tab having an opener. |
| 78 | void SetOpener(TestWebContents* opener); |
| 79 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 80 | // Allows us to simulate that a contents was created via CreateNewWindow. |
| 81 | void AddPendingContents(TestWebContents* contents); |
| 82 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 83 | // Establish expected arguments for |SetHistoryLengthAndPrune()|. When |
| 84 | // |SetHistoryLengthAndPrune()| is called, the arguments are compared |
| 85 | // with the expected arguments specified here. |
| 86 | void ExpectSetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 87 | int history_length, |
| 88 | int32 min_page_id); |
| 89 | |
| 90 | // Compares the arguments passed in with the expected arguments passed in |
| 91 | // to |ExpectSetHistoryLengthAndPrune()|. |
| 92 | virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 93 | int history_length, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 94 | int32 min_page_id) override; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 95 | |
[email protected] | 61ac9e24 | 2014-03-21 20:55:26 | [diff] [blame] | 96 | void TestDidFinishLoad(const GURL& url); |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 97 | void TestDidFailLoadWithError(const GURL& url, |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 98 | int error_code, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 99 | const base::string16& error_description); |
[email protected] | b502ed46 | 2013-01-08 08:20:06 | [diff] [blame] | 100 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 101 | protected: |
| 102 | // The deprecated WebContentsTester still needs to subclass this. |
| 103 | explicit TestWebContents(BrowserContext* browser_context); |
| 104 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 105 | private: |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 106 | // WebContentsImpl overrides |
| 107 | virtual void CreateNewWindow( |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 108 | int render_process_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 109 | int route_id, |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 110 | int main_frame_route_id, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 111 | const ViewHostMsg_CreateWindow_Params& params, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 112 | SessionStorageNamespace* session_storage_namespace) override; |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 113 | virtual void CreateNewWidget(int render_process_id, |
| 114 | int route_id, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 115 | blink::WebPopupType popup_type) override; |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 116 | virtual void CreateNewFullscreenWidget(int render_process_id, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 117 | int route_id) override; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 118 | virtual void ShowCreatedWindow(int route_id, |
| 119 | WindowOpenDisposition disposition, |
| 120 | const gfx::Rect& initial_pos, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 121 | bool user_gesture) override; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 122 | virtual void ShowCreatedWidget(int route_id, |
anand.ratn | 71fc3adc | 2014-10-06 13:50:07 | [diff] [blame^] | 123 | const gfx::Rect& initial_pos) override; |
| 124 | virtual void ShowCreatedFullscreenWidget(int route_id) override; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 125 | |
| 126 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 127 | RenderViewHostDelegateView* delegate_view_override_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 128 | |
| 129 | // Expectations for arguments of |SetHistoryLengthAndPrune()|. |
| 130 | bool expect_set_history_length_and_prune_; |
| 131 | scoped_refptr<const SiteInstanceImpl> |
| 132 | expect_set_history_length_and_prune_site_instance_; |
| 133 | int expect_set_history_length_and_prune_history_length_; |
| 134 | int32 expect_set_history_length_and_prune_min_page_id_; |
| 135 | }; |
| 136 | |
| 137 | } // namespace content |
| 138 | |
[email protected] | 4172b08 | 2013-02-25 18:07:34 | [diff] [blame] | 139 | #endif // CONTENT_TEST_TEST_WEB_CONTENTS_H_ |