[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] | 0c4e92e6 | 2012-04-11 15:19:00 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_WEB_CONTENTS_TEST_WEB_CONTENTS_H_ |
| 6 | #define CONTENT_BROWSER_WEB_CONTENTS_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] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 9 | #include "content/public/common/page_transition_types.h" |
[email protected] | b1e3f20 | 2012-06-04 14:45:50 | [diff] [blame] | 10 | #include "content/public/test/web_contents_tester.h" |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 11 | #include "webkit/glue/webpreferences.h" |
| 12 | |
| 13 | class SiteInstanceImpl; |
| 14 | |
| 15 | namespace content { |
| 16 | |
| 17 | class RenderViewHost; |
| 18 | class TestRenderViewHost; |
| 19 | class WebContentsTester; |
| 20 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 21 | // Subclass WebContentsImpl to ensure it creates TestRenderViewHosts |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 22 | // and does not do anything involving views. |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 23 | class TestWebContents : public WebContentsImpl, public WebContentsTester { |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 24 | public: |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 25 | virtual ~TestWebContents(); |
| 26 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame^] | 27 | static TestWebContents* Create(BrowserContext* browser_context, |
| 28 | SiteInstance* instance); |
| 29 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 30 | // WebContentsTester implementation. |
| 31 | virtual void CommitPendingNavigation() OVERRIDE; |
| 32 | virtual int GetNumberOfFocusCalls() OVERRIDE; |
| 33 | virtual RenderViewHost* GetPendingRenderViewHost() const OVERRIDE; |
| 34 | virtual void NavigateAndCommit(const GURL& url) OVERRIDE; |
[email protected] | 9565b0c | 2012-05-15 21:12:26 | [diff] [blame] | 35 | virtual void TestSetIsLoading(bool value) OVERRIDE; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 36 | virtual void ProceedWithCrossSiteNavigation() OVERRIDE; |
| 37 | virtual void TestDidNavigate(RenderViewHost* render_view_host, |
| 38 | int page_id, |
| 39 | const GURL& url, |
| 40 | PageTransition transition) OVERRIDE; |
| 41 | virtual void TestDidNavigateWithReferrer(RenderViewHost* render_view_host, |
| 42 | int page_id, |
| 43 | const GURL& url, |
| 44 | const Referrer& referrer, |
| 45 | PageTransition transition) OVERRIDE; |
[email protected] | 6717bf27 | 2012-05-11 23:31:25 | [diff] [blame] | 46 | virtual webkit_glue::WebPreferences TestGetWebkitPrefs() OVERRIDE; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 47 | |
| 48 | TestRenderViewHost* pending_test_rvh() const; |
| 49 | |
| 50 | // State accessor. |
| 51 | bool cross_navigation_pending() { |
| 52 | return render_manager_.cross_navigation_pending_; |
| 53 | } |
| 54 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 55 | // Overrides WebContentsImpl::ShouldTransitionCrossSite so that we can test |
| 56 | // both alternatives without using command-line switches. |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 57 | bool ShouldTransitionCrossSite() { return transition_cross_site; } |
| 58 | |
| 59 | // Prevent interaction with views. |
| 60 | virtual bool CreateRenderViewForRenderManager( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 61 | RenderViewHost* render_view_host, int opener_route_id) OVERRIDE; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 62 | virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE {} |
| 63 | |
| 64 | // Returns a clone of this TestWebContents. The returned object is also a |
| 65 | // TestWebContents. The caller owns the returned object. |
| 66 | virtual WebContents* Clone() OVERRIDE; |
| 67 | |
| 68 | // Set by individual tests. |
| 69 | bool transition_cross_site; |
| 70 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 71 | // Allow mocking of the RenderViewHostDelegateView. |
| 72 | virtual RenderViewHostDelegateView* GetDelegateView() OVERRIDE; |
| 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] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 80 | // Establish expected arguments for |SetHistoryLengthAndPrune()|. When |
| 81 | // |SetHistoryLengthAndPrune()| is called, the arguments are compared |
| 82 | // with the expected arguments specified here. |
| 83 | void ExpectSetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 84 | int history_length, |
| 85 | int32 min_page_id); |
| 86 | |
| 87 | // Compares the arguments passed in with the expected arguments passed in |
| 88 | // to |ExpectSetHistoryLengthAndPrune()|. |
| 89 | virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 90 | int history_length, |
| 91 | int32 min_page_id) OVERRIDE; |
| 92 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame^] | 93 | protected: |
| 94 | // The deprecated WebContentsTester still needs to subclass this. |
| 95 | explicit TestWebContents(BrowserContext* browser_context); |
| 96 | |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 97 | private: |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 98 | // WebContentsImpl overrides |
| 99 | virtual void CreateNewWindow( |
| 100 | int route_id, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 101 | const ViewHostMsg_CreateWindow_Params& params, |
| 102 | SessionStorageNamespace* session_storage_namespace) OVERRIDE; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 103 | virtual void CreateNewWidget(int route_id, |
| 104 | WebKit::WebPopupType popup_type) OVERRIDE; |
| 105 | virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; |
| 106 | virtual void ShowCreatedWindow(int route_id, |
| 107 | WindowOpenDisposition disposition, |
| 108 | const gfx::Rect& initial_pos, |
| 109 | bool user_gesture) OVERRIDE; |
| 110 | virtual void ShowCreatedWidget(int route_id, |
| 111 | const gfx::Rect& initial_pos) OVERRIDE; |
| 112 | virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; |
| 113 | |
| 114 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 115 | RenderViewHostDelegateView* delegate_view_override_; |
[email protected] | 80e776ae | 2012-03-23 16:17:20 | [diff] [blame] | 116 | |
| 117 | // Expectations for arguments of |SetHistoryLengthAndPrune()|. |
| 118 | bool expect_set_history_length_and_prune_; |
| 119 | scoped_refptr<const SiteInstanceImpl> |
| 120 | expect_set_history_length_and_prune_site_instance_; |
| 121 | int expect_set_history_length_and_prune_history_length_; |
| 122 | int32 expect_set_history_length_and_prune_min_page_id_; |
| 123 | }; |
| 124 | |
| 125 | } // namespace content |
| 126 | |
[email protected] | 0c4e92e6 | 2012-04-11 15:19:00 | [diff] [blame] | 127 | #endif // CONTENT_BROWSER_WEB_CONTENTS_TEST_WEB_CONTENTS_H_ |