OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ | 5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ |
6 #define CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ | 6 #define CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "content/browser/tab_contents/tab_contents.h" | 9 #include "content/browser/tab_contents/tab_contents.h" |
10 #include "webkit/glue/webpreferences.h" | 10 #include "webkit/glue/webpreferences.h" |
11 | 11 |
12 class Profile; | 12 class Profile; |
13 class TestRenderViewHost; | 13 class TestRenderViewHost; |
14 | 14 |
15 // Subclass TabContents to ensure it creates TestRenderViewHosts and does | 15 // Subclass TabContents to ensure it creates TestRenderViewHosts and does |
16 // not do anything involving views. | 16 // not do anything involving views. |
17 class TestTabContents : public TabContents { | 17 class TestTabContents : public TabContents { |
18 public: | 18 public: |
19 // The render view host factory will be passed on to the | 19 // The render view host factory will be passed on to the |
20 TestTabContents(Profile* profile, SiteInstance* instance); | 20 TestTabContents(Profile* profile, SiteInstance* instance); |
21 | 21 |
| 22 virtual ~TestTabContents(); |
| 23 |
22 TestRenderViewHost* pending_rvh() const; | 24 TestRenderViewHost* pending_rvh() const; |
23 | 25 |
24 // State accessor. | 26 // State accessor. |
25 bool cross_navigation_pending() { | 27 bool cross_navigation_pending() { |
26 return render_manager_.cross_navigation_pending_; | 28 return render_manager_.cross_navigation_pending_; |
27 } | 29 } |
28 | 30 |
29 // Overrides TabContents::ShouldTransitionCrossSite so that we can test both | 31 // Overrides TabContents::ShouldTransitionCrossSite so that we can test both |
30 // alternatives without using command-line switches. | 32 // alternatives without using command-line switches. |
31 bool ShouldTransitionCrossSite() { return transition_cross_site; } | 33 bool ShouldTransitionCrossSite() { return transition_cross_site; } |
32 | 34 |
33 // Promote DidNavigate to public. | 35 // Promote DidNavigate to public. |
34 void TestDidNavigate(RenderViewHost* render_view_host, | 36 void TestDidNavigate(RenderViewHost* render_view_host, |
35 const ViewHostMsg_FrameNavigate_Params& params) { | 37 const ViewHostMsg_FrameNavigate_Params& params) { |
36 DidNavigate(render_view_host, params); | 38 DidNavigate(render_view_host, params); |
37 } | 39 } |
38 | 40 |
39 // Promote GetWebkitPrefs to public. | 41 // Promote GetWebkitPrefs to public. |
40 WebPreferences TestGetWebkitPrefs() { | 42 WebPreferences TestGetWebkitPrefs() { |
41 return GetWebkitPrefs(); | 43 return GetWebkitPrefs(); |
42 } | 44 } |
43 | 45 |
44 // Prevent interaction with views. | 46 // Prevent interaction with views. |
45 virtual bool CreateRenderViewForRenderManager( | 47 virtual bool CreateRenderViewForRenderManager( |
46 RenderViewHost* render_view_host); | 48 RenderViewHost* render_view_host) OVERRIDE; |
47 virtual void UpdateRenderViewSizeForRenderManager() {} | 49 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE {} |
48 | 50 |
49 // Returns a clone of this TestTabContents. The returned object is also a | 51 // Returns a clone of this TestTabContents. The returned object is also a |
50 // TestTabContents. The caller owns the returned object. | 52 // TestTabContents. The caller owns the returned object. |
51 virtual TabContents* Clone(); | 53 virtual TabContents* Clone() OVERRIDE; |
52 | 54 |
53 // Creates a pending navigation to the given URL with the default parameters | 55 // Creates a pending navigation to the given URL with the default parameters |
54 // and then commits the load with a page ID one larger than any seen. This | 56 // and then commits the load with a page ID one larger than any seen. This |
55 // emulates what happens on a new navigation. | 57 // emulates what happens on a new navigation. |
56 void NavigateAndCommit(const GURL& url); | 58 void NavigateAndCommit(const GURL& url); |
57 | 59 |
58 // Simulates the appropriate RenderView (pending if any, current otherwise) | 60 // Simulates the appropriate RenderView (pending if any, current otherwise) |
59 // sending a navigate notification for the NavigationController pending entry. | 61 // sending a navigate notification for the NavigationController pending entry. |
60 void CommitPendingNavigation(); | 62 void CommitPendingNavigation(); |
61 | 63 |
62 // Simulates the current RVH notifying that it has unloaded so that the | 64 // Simulates the current RVH notifying that it has unloaded so that the |
63 // pending RVH navigation can proceed. | 65 // pending RVH navigation can proceed. |
64 // Does nothing if no cross-navigation is pending. | 66 // Does nothing if no cross-navigation is pending. |
65 void ProceedWithCrossSiteNavigation(); | 67 void ProceedWithCrossSiteNavigation(); |
66 | 68 |
67 // Set by individual tests. | 69 // Set by individual tests. |
68 bool transition_cross_site; | 70 bool transition_cross_site; |
69 | 71 |
70 // Allow mocking of the RenderViewHostDelegate::View. | 72 // Allow mocking of the RenderViewHostDelegate::View. |
71 virtual RenderViewHostDelegate::View* GetViewDelegate(); | 73 virtual RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE; |
72 void set_view_delegate(RenderViewHostDelegate::View* view) { | 74 void set_view_delegate(RenderViewHostDelegate::View* view) { |
73 delegate_view_override_ = view; | 75 delegate_view_override_ = view; |
74 } | 76 } |
| 77 |
| 78 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When |
| 79 // |SetHistoryLengthAndPrune()| is called, the arguments are compared |
| 80 // with the expected arguments specified here. |
| 81 void ExpectSetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 82 int history_length, |
| 83 int32 min_page_id); |
| 84 |
| 85 // Compares the arguments passed in with the expected arguments passed in |
| 86 // to |ExpectSetHistoryLengthAndPrune()|. |
| 87 virtual void SetHistoryLengthAndPrune(const SiteInstance* site_instance, |
| 88 int history_length, |
| 89 int32 min_page_id) OVERRIDE; |
| 90 |
75 private: | 91 private: |
76 RenderViewHostDelegate::View* delegate_view_override_; | 92 RenderViewHostDelegate::View* delegate_view_override_; |
| 93 |
| 94 // Expectations for arguments of |SetHistoryLengthAndPrune()|. |
| 95 bool expect_set_history_length_and_prune_; |
| 96 scoped_refptr<const SiteInstance> |
| 97 expect_set_history_length_and_prune_site_instance_; |
| 98 int expect_set_history_length_and_prune_history_length_; |
| 99 int32 expect_set_history_length_and_prune_min_page_id_; |
77 }; | 100 }; |
78 | 101 |
79 #endif // CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ | 102 #endif // CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ |
OLD | NEW |