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