OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "content/public/common/page_transition_types.h" | 10 #include "content/public/common/page_transition_types.h" |
| 11 #include "content/test/web_contents_tester.h" |
11 #include "webkit/glue/webpreferences.h" | 12 #include "webkit/glue/webpreferences.h" |
12 | 13 |
13 class SiteInstanceImpl; | 14 class SiteInstanceImpl; |
14 | 15 |
15 namespace content { | 16 namespace content { |
16 class RenderViewHost; | 17 class RenderViewHost; |
17 class TestRenderViewHost; | 18 class TestRenderViewHost; |
| 19 class WebContentsTester; |
18 } | 20 } |
19 | 21 |
20 // Subclass TabContents to ensure it creates TestRenderViewHosts | 22 // Subclass TabContents to ensure it creates TestRenderViewHosts |
21 // and does not do anything involving views. | 23 // and does not do anything involving views. |
22 // | 24 // |
23 // TODO(joi): Rename TestWebContents. | 25 // TODO(joi): Rename TestWebContents. |
24 // TODO(joi): Move to content namespace. | 26 // TODO(joi): Move to content namespace. |
25 class TestTabContents : public TabContents { | 27 class TestTabContents : public TabContents, public content::WebContentsTester { |
26 public: | 28 public: |
27 TestTabContents(content::BrowserContext* browser_context, | 29 TestTabContents(content::BrowserContext* browser_context, |
28 content::SiteInstance* instance); | 30 content::SiteInstance* instance); |
29 virtual ~TestTabContents(); | 31 virtual ~TestTabContents(); |
30 | 32 |
31 content::RenderViewHost* pending_rvh() const; | 33 // WebContentsTester implementation. |
| 34 virtual void CommitPendingNavigation() OVERRIDE; |
| 35 virtual int GetNumberOfFocusCalls() OVERRIDE; |
| 36 virtual content::RenderViewHost* pending_rvh() const OVERRIDE; |
| 37 virtual void NavigateAndCommit(const GURL& url) OVERRIDE; |
| 38 virtual void ProceedWithCrossSiteNavigation() OVERRIDE; |
| 39 virtual void TestDidNavigate(content::RenderViewHost* render_view_host, |
| 40 int page_id, |
| 41 const GURL& url, |
| 42 content::PageTransition transition) OVERRIDE; |
| 43 virtual void TestDidNavigateWithReferrer( |
| 44 content::RenderViewHost* render_view_host, |
| 45 int page_id, |
| 46 const GURL& url, |
| 47 const content::Referrer& referrer, |
| 48 content::PageTransition transition) OVERRIDE; |
| 49 virtual WebPreferences TestGetWebkitPrefs() OVERRIDE; |
32 | 50 |
33 // TODO(joi): Make sure this one is hidden once TestTabContents | |
34 // hides internal types from embedders. | |
35 content::TestRenderViewHost* pending_test_rvh() const; | 51 content::TestRenderViewHost* pending_test_rvh() const; |
36 | 52 |
37 // State accessor. | 53 // State accessor. |
38 bool cross_navigation_pending() { | 54 bool cross_navigation_pending() { |
39 return render_manager_.cross_navigation_pending_; | 55 return render_manager_.cross_navigation_pending_; |
40 } | 56 } |
41 | 57 |
42 // Overrides TabContents::ShouldTransitionCrossSite so that we can test both | 58 // Overrides TabContents::ShouldTransitionCrossSite so that we can test both |
43 // alternatives without using command-line switches. | 59 // alternatives without using command-line switches. |
44 bool ShouldTransitionCrossSite() { return transition_cross_site; } | 60 bool ShouldTransitionCrossSite() { return transition_cross_site; } |
45 | 61 |
46 void TestDidNavigate(content::RenderViewHost* render_view_host, | |
47 int page_id, | |
48 const GURL& url, | |
49 content::PageTransition transition); | |
50 void TestDidNavigateWithReferrer(content::RenderViewHost* render_view_host, | |
51 int page_id, | |
52 const GURL& url, | |
53 const content::Referrer& referrer, | |
54 content::PageTransition transition); | |
55 | |
56 // Promote GetWebkitPrefs to public. | |
57 WebPreferences TestGetWebkitPrefs() { | |
58 return GetWebkitPrefs(); | |
59 } | |
60 | |
61 // Prevent interaction with views. | 62 // Prevent interaction with views. |
62 virtual bool CreateRenderViewForRenderManager( | 63 virtual bool CreateRenderViewForRenderManager( |
63 content::RenderViewHost* render_view_host) OVERRIDE; | 64 content::RenderViewHost* render_view_host) OVERRIDE; |
64 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE {} | 65 virtual void UpdateRenderViewSizeForRenderManager() OVERRIDE {} |
65 | 66 |
66 // Returns a clone of this TestTabContents. The returned object is also a | 67 // Returns a clone of this TestTabContents. The returned object is also a |
67 // TestTabContents. The caller owns the returned object. | 68 // TestTabContents. The caller owns the returned object. |
68 virtual content::WebContents* Clone() OVERRIDE; | 69 virtual content::WebContents* Clone() OVERRIDE; |
69 | 70 |
70 // Creates a pending navigation to the given URL with the default parameters | |
71 // and then commits the load with a page ID one larger than any seen. This | |
72 // emulates what happens on a new navigation. | |
73 void NavigateAndCommit(const GURL& url); | |
74 | |
75 // Simulates the appropriate RenderView (pending if any, current otherwise) | |
76 // sending a navigate notification for the NavigationController pending entry. | |
77 void CommitPendingNavigation(); | |
78 | |
79 // Simulates the current RVH notifying that it has unloaded so that the | |
80 // pending RVH navigation can proceed. | |
81 // Does nothing if no cross-navigation is pending. | |
82 void ProceedWithCrossSiteNavigation(); | |
83 | |
84 // Set by individual tests. | 71 // Set by individual tests. |
85 bool transition_cross_site; | 72 bool transition_cross_site; |
86 | 73 |
87 // Allow mocking of the RenderViewHostDelegate::View. | 74 // Allow mocking of the RenderViewHostDelegate::View. |
88 virtual content::RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE; | 75 virtual content::RenderViewHostDelegate::View* GetViewDelegate() OVERRIDE; |
89 void set_view_delegate(content::RenderViewHostDelegate::View* view) { | 76 void set_view_delegate(content::RenderViewHostDelegate::View* view) { |
90 delegate_view_override_ = view; | 77 delegate_view_override_ = view; |
91 } | 78 } |
92 | 79 |
93 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When | 80 // Establish expected arguments for |SetHistoryLengthAndPrune()|. When |
(...skipping 16 matching lines...) Expand all Loading... |
110 | 97 |
111 // Expectations for arguments of |SetHistoryLengthAndPrune()|. | 98 // Expectations for arguments of |SetHistoryLengthAndPrune()|. |
112 bool expect_set_history_length_and_prune_; | 99 bool expect_set_history_length_and_prune_; |
113 scoped_refptr<const SiteInstanceImpl> | 100 scoped_refptr<const SiteInstanceImpl> |
114 expect_set_history_length_and_prune_site_instance_; | 101 expect_set_history_length_and_prune_site_instance_; |
115 int expect_set_history_length_and_prune_history_length_; | 102 int expect_set_history_length_and_prune_history_length_; |
116 int32 expect_set_history_length_and_prune_min_page_id_; | 103 int32 expect_set_history_length_and_prune_min_page_id_; |
117 }; | 104 }; |
118 | 105 |
119 #endif // CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ | 106 #endif // CONTENT_BROWSER_TAB_CONTENTS_TEST_TAB_CONTENTS_H_ |
OLD | NEW |