Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/browser/renderer_host/test_render_view_host.h

Issue 9600036: Move Render(View|Widget)Host and associated classes to content namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "content/browser/renderer_host/mock_render_process_host.h" 13 #include "content/browser/renderer_host/mock_render_process_host.h"
14 #include "content/browser/renderer_host/render_view_host_factory.h" 14 #include "content/browser/renderer_host/render_view_host_factory.h"
15 #include "content/browser/renderer_host/render_view_host_impl.h" 15 #include "content/browser/renderer_host/render_view_host_impl.h"
16 #include "content/browser/renderer_host/render_widget_host_view_base.h" 16 #include "content/browser/renderer_host/render_widget_host_view_base.h"
17 #include "content/public/common/page_transition_types.h" 17 #include "content/public/common/page_transition_types.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 19
20 // This file provides a testing framework for mocking out the RenderProcessHost
21 // layer. It allows you to test RenderViewHost, TabContents,
22 // NavigationController, and other layers above that without running an actual
23 // renderer process.
24 //
25 // To use, derive your test base class from RenderViewHostTestHarness.
26
20 #if defined(USE_AURA) 27 #if defined(USE_AURA)
21 namespace aura { 28 namespace aura {
22 class RootWindow; 29 class RootWindow;
23 namespace test { 30 namespace test {
24 class TestStackingClient; 31 class TestStackingClient;
25 } 32 }
26 } 33 }
27 #endif 34 #endif
28 35
29 namespace content { 36 namespace content {
30 class BrowserContext; 37 class BrowserContext;
31 class NavigationController; 38 class NavigationController;
32 class RenderProcessHostFactory; 39 class RenderProcessHostFactory;
33 class SiteInstance; 40 class SiteInstance;
34 } 41 }
35 42
36 namespace gfx { 43 namespace gfx {
37 class Rect; 44 class Rect;
38 } 45 }
39 46
40 class TestTabContents; 47 class TestTabContents;
41 struct ViewHostMsg_FrameNavigate_Params; 48 struct ViewHostMsg_FrameNavigate_Params;
42 49
50 namespace content {
51
43 // Utility function to initialize ViewHostMsg_NavigateParams_Params 52 // Utility function to initialize ViewHostMsg_NavigateParams_Params
44 // with given |page_id|, |url| and |transition_type|. 53 // with given |page_id|, |url| and |transition_type|.
45 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params, 54 void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
46 int page_id, 55 int page_id,
47 const GURL& url, 56 const GURL& url,
48 content::PageTransition transition_type); 57 PageTransition transition_type);
49
50 // This file provides a testing framework for mocking out the RenderProcessHost
51 // layer. It allows you to test RenderViewHost, TabContents,
52 // NavigationController, and other layers above that without running an actual
53 // renderer process.
54 //
55 // To use, derive your test base class from RenderViewHostTestHarness.
56
57
58 namespace content {
59 58
60 // TestRenderViewHostView ------------------------------------------------------ 59 // TestRenderViewHostView ------------------------------------------------------
61 60
62 // Subclass the RenderViewHost's view so that we can call Show(), etc., 61 // Subclass the RenderViewHost's view so that we can call Show(), etc.,
63 // without having side-effects. 62 // without having side-effects.
64 class TestRenderWidgetHostView : public RenderWidgetHostViewBase { 63 class TestRenderWidgetHostView : public RenderWidgetHostViewBase {
65 public: 64 public:
66 explicit TestRenderWidgetHostView(RenderWidgetHost* rwh); 65 explicit TestRenderWidgetHostView(RenderWidgetHost* rwh);
67 virtual ~TestRenderWidgetHostView(); 66 virtual ~TestRenderWidgetHostView();
68 67
(...skipping 19 matching lines...) Expand all
88 #if defined(TOOLKIT_USES_GTK) 87 #if defined(TOOLKIT_USES_GTK)
89 virtual GdkEventButton* GetLastMouseDown() OVERRIDE; 88 virtual GdkEventButton* GetLastMouseDown() OVERRIDE;
90 #if !defined(TOOLKIT_VIEWS) 89 #if !defined(TOOLKIT_VIEWS)
91 virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE; 90 virtual gfx::NativeView BuildInputMethodsGtkMenu() OVERRIDE;
92 #endif // !defined(TOOLKIT_VIEWS) 91 #endif // !defined(TOOLKIT_VIEWS)
93 #endif // defined(TOOLKIT_USES_GTK) 92 #endif // defined(TOOLKIT_USES_GTK)
94 virtual void UnhandledWheelEvent( 93 virtual void UnhandledWheelEvent(
95 const WebKit::WebMouseWheelEvent& event) OVERRIDE {} 94 const WebKit::WebMouseWheelEvent& event) OVERRIDE {}
96 95
97 // RenderWidgetHostViewPort implementation. 96 // RenderWidgetHostViewPort implementation.
98 virtual void InitAsPopup(content::RenderWidgetHostView* parent_host_view, 97 virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
99 const gfx::Rect& pos) OVERRIDE {} 98 const gfx::Rect& pos) OVERRIDE {}
100 virtual void InitAsFullscreen( 99 virtual void InitAsFullscreen(
101 content::RenderWidgetHostView* reference_host_view) OVERRIDE {} 100 RenderWidgetHostView* reference_host_view) OVERRIDE {}
102 virtual void DidBecomeSelected() OVERRIDE {} 101 virtual void DidBecomeSelected() OVERRIDE {}
103 virtual void WasHidden() OVERRIDE {} 102 virtual void WasHidden() OVERRIDE {}
104 virtual void MovePluginWindows( 103 virtual void MovePluginWindows(
105 const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE {} 104 const std::vector<webkit::npapi::WebPluginGeometry>& moves) OVERRIDE {}
106 virtual void Focus() OVERRIDE {} 105 virtual void Focus() OVERRIDE {}
107 virtual void Blur() OVERRIDE {} 106 virtual void Blur() OVERRIDE {}
108 virtual void SetIsLoading(bool is_loading) OVERRIDE {} 107 virtual void SetIsLoading(bool is_loading) OVERRIDE {}
109 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE {} 108 virtual void UpdateCursor(const WebCursor& cursor) OVERRIDE {}
110 virtual void TextInputStateChanged(ui::TextInputType state, 109 virtual void TextInputStateChanged(ui::TextInputType state,
111 bool can_compose_inline) OVERRIDE {} 110 bool can_compose_inline) OVERRIDE {}
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 179
181 bool is_showing() const { return is_showing_; } 180 bool is_showing() const { return is_showing_; }
182 181
183 protected: 182 protected:
184 RenderWidgetHostImpl* rwh_; 183 RenderWidgetHostImpl* rwh_;
185 184
186 private: 185 private:
187 bool is_showing_; 186 bool is_showing_;
188 }; 187 };
189 188
190 } // namespace content
191
192 #if defined(COMPILER_MSVC) 189 #if defined(COMPILER_MSVC)
193 // See comment for same warning on RenderViewHostImpl. 190 // See comment for same warning on RenderViewHostImpl.
194 #pragma warning(push) 191 #pragma warning(push)
195 #pragma warning(disable: 4250) 192 #pragma warning(disable: 4250)
196 #endif 193 #endif
197 194
198 // TestRenderViewHost ---------------------------------------------------------- 195 // TestRenderViewHost ----------------------------------------------------------
199 196
200 // TODO(brettw) this should use a TestTabContents which should be generalized 197 // TODO(brettw) this should use a TestTabContents which should be generalized
201 // from the TabContents test. We will probably also need that class' version of 198 // from the TabContents test. We will probably also need that class' version of
202 // CreateRenderViewForRenderManager when more complicate tests start using this. 199 // CreateRenderViewForRenderManager when more complicate tests start using this.
203 class TestRenderViewHost : public RenderViewHostImpl { 200 class TestRenderViewHost : public RenderViewHostImpl {
204 public: 201 public:
205 // If the given TabContnets has a pending RVH, returns it, otherwise NULL. 202 // If the given TabContnets has a pending RVH, returns it, otherwise NULL.
206 static TestRenderViewHost* GetPendingForController( 203 static TestRenderViewHost* GetPendingForController(
207 content::NavigationController* controller); 204 NavigationController* controller);
208 205
209 TestRenderViewHost(content::SiteInstance* instance, 206 TestRenderViewHost(SiteInstance* instance,
210 content::RenderViewHostDelegate* delegate, 207 RenderViewHostDelegate* delegate,
211 int routing_id); 208 int routing_id);
212 virtual ~TestRenderViewHost(); 209 virtual ~TestRenderViewHost();
213 210
214 // Testing functions --------------------------------------------------------- 211 // Testing functions ---------------------------------------------------------
215 212
216 // Calls the RenderViewHosts' private OnMessageReceived function with the 213 // Calls the RenderViewHosts' private OnMessageReceived function with the
217 // given message. 214 // given message.
218 bool TestOnMessageReceived(const IPC::Message& msg); 215 bool TestOnMessageReceived(const IPC::Message& msg);
219 216
220 // Calls OnMsgNavigate on the RenderViewHost with the given information, 217 // Calls OnMsgNavigate on the RenderViewHost with the given information,
221 // setting the rest of the parameters in the message to the "typical" values. 218 // setting the rest of the parameters in the message to the "typical" values.
222 // This is a helper function for simulating the most common types of loads. 219 // This is a helper function for simulating the most common types of loads.
223 void SendNavigate(int page_id, const GURL& url); 220 void SendNavigate(int page_id, const GURL& url);
224 221
225 // Calls OnMsgNavigate on the RenderViewHost with the given information, 222 // Calls OnMsgNavigate on the RenderViewHost with the given information,
226 // including a custom content::PageTransition. Sets the rest of the 223 // including a custom PageTransition. Sets the rest of the
227 // parameters in the message to the "typical" values. This is a helper 224 // parameters in the message to the "typical" values. This is a helper
228 // function for simulating the most common types of loads. 225 // function for simulating the most common types of loads.
229 void SendNavigateWithTransition(int page_id, const GURL& url, 226 void SendNavigateWithTransition(int page_id, const GURL& url,
230 content::PageTransition transition); 227 PageTransition transition);
231 228
232 // Calls OnMsgShouldCloseACK on the RenderViewHost with the given parameter. 229 // Calls OnMsgShouldCloseACK on the RenderViewHost with the given parameter.
233 void SendShouldCloseACK(bool proceed); 230 void SendShouldCloseACK(bool proceed);
234 231
235 void TestOnMsgStartDragging(const WebDropData& drop_data); 232 void TestOnMsgStartDragging(const WebDropData& drop_data);
236 233
237 // If set, *delete_counter is incremented when this object destructs. 234 // If set, *delete_counter is incremented when this object destructs.
238 void set_delete_counter(int* delete_counter) { 235 void set_delete_counter(int* delete_counter) {
239 delete_counter_ = delete_counter; 236 delete_counter_ = delete_counter;
240 } 237 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // See set_contents_mime_type() above. 301 // See set_contents_mime_type() above.
305 std::string contents_mime_type_; 302 std::string contents_mime_type_;
306 303
307 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHost); 304 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHost);
308 }; 305 };
309 306
310 #if defined(COMPILER_MSVC) 307 #if defined(COMPILER_MSVC)
311 #pragma warning(pop) 308 #pragma warning(pop)
312 #endif 309 #endif
313 310
311 } // namespace content
312
314 // TestRenderViewHostFactory --------------------------------------------------- 313 // TestRenderViewHostFactory ---------------------------------------------------
315 314
316 // Manages creation of the RenderViewHosts using our special subclass. This 315 // Manages creation of the RenderViewHosts using our special subclass. This
317 // automatically registers itself when it goes in scope, and unregisters itself 316 // automatically registers itself when it goes in scope, and unregisters itself
318 // when it goes out of scope. Since you can't have more than one factory 317 // when it goes out of scope. Since you can't have more than one factory
319 // registered at a time, you can only have one of these objects at a time. 318 // registered at a time, you can only have one of these objects at a time.
320 class TestRenderViewHostFactory : public RenderViewHostFactory { 319 class TestRenderViewHostFactory : public RenderViewHostFactory {
321 public: 320 public:
322 explicit TestRenderViewHostFactory( 321 explicit TestRenderViewHostFactory(
323 content::RenderProcessHostFactory* rph_factory); 322 content::RenderProcessHostFactory* rph_factory);
324 virtual ~TestRenderViewHostFactory(); 323 virtual ~TestRenderViewHostFactory();
325 324
326 virtual void set_render_process_host_factory( 325 virtual void set_render_process_host_factory(
327 content::RenderProcessHostFactory* rph_factory); 326 content::RenderProcessHostFactory* rph_factory);
328 virtual RenderViewHost* CreateRenderViewHost( 327 virtual content::RenderViewHost* CreateRenderViewHost(
329 content::SiteInstance* instance, 328 content::SiteInstance* instance,
330 content::RenderViewHostDelegate* delegate, 329 content::RenderViewHostDelegate* delegate,
331 int routing_id, 330 int routing_id,
332 content::SessionStorageNamespace* session_storage) OVERRIDE; 331 content::SessionStorageNamespace* session_storage) OVERRIDE;
333 332
334 private: 333 private:
335 // This is a bit of a hack. With the current design of the site instances / 334 // This is a bit of a hack. With the current design of the site instances /
336 // browsing instances, it's difficult to pass a RenderProcessHostFactory 335 // browsing instances, it's difficult to pass a RenderProcessHostFactory
337 // around properly. 336 // around properly.
338 // 337 //
339 // Instead, we set it right before we create a new RenderViewHost, which 338 // Instead, we set it right before we create a new RenderViewHost, which
340 // happens before the RenderProcessHost is created. This way, the instance 339 // happens before the RenderProcessHost is created. This way, the instance
341 // has the correct factory and creates our special RenderProcessHosts. 340 // has the correct factory and creates our special RenderProcessHosts.
342 content::RenderProcessHostFactory* render_process_host_factory_; 341 content::RenderProcessHostFactory* render_process_host_factory_;
343 342
344 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); 343 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory);
345 }; 344 };
346 345
347 // RenderViewHostTestHarness --------------------------------------------------- 346 // RenderViewHostTestHarness ---------------------------------------------------
348 347
349 class RenderViewHostTestHarness : public testing::Test { 348 class RenderViewHostTestHarness : public testing::Test {
350 public: 349 public:
351 RenderViewHostTestHarness(); 350 RenderViewHostTestHarness();
352 virtual ~RenderViewHostTestHarness(); 351 virtual ~RenderViewHostTestHarness();
353 352
354 content::NavigationController& controller(); 353 content::NavigationController& controller();
355 virtual TestTabContents* contents(); 354 virtual TestTabContents* contents();
356 TestRenderViewHost* rvh(); 355 content::TestRenderViewHost* rvh();
357 TestRenderViewHost* pending_rvh(); 356 content::TestRenderViewHost* pending_rvh();
358 TestRenderViewHost* active_rvh(); 357 content::TestRenderViewHost* active_rvh();
359 content::BrowserContext* browser_context(); 358 content::BrowserContext* browser_context();
360 MockRenderProcessHost* process(); 359 MockRenderProcessHost* process();
361 360
362 // Frees the current tab contents for tests that want to test destruction. 361 // Frees the current tab contents for tests that want to test destruction.
363 void DeleteContents(); 362 void DeleteContents();
364 363
365 // Sets the current tab contents for tests that want to alter it. Takes 364 // Sets the current tab contents for tests that want to alter it. Takes
366 // ownership of the TestTabContents passed. 365 // ownership of the TestTabContents passed.
367 virtual void SetContents(TestTabContents* contents); 366 virtual void SetContents(TestTabContents* contents);
368 367
(...skipping 27 matching lines...) Expand all
396 scoped_ptr<TestTabContents> contents_; 395 scoped_ptr<TestTabContents> contents_;
397 #if defined(USE_AURA) 396 #if defined(USE_AURA)
398 scoped_ptr<aura::RootWindow> root_window_; 397 scoped_ptr<aura::RootWindow> root_window_;
399 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; 398 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
400 #endif 399 #endif
401 400
402 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); 401 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness);
403 }; 402 };
404 403
405 #endif // CONTENT_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_ 404 #endif // CONTENT_BROWSER_RENDERER_HOST_TEST_RENDER_VIEW_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/renderer_host/test_backing_store.cc ('k') | content/browser/renderer_host/test_render_view_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698