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

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: Ready for review, take 2 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 content::PageTransition transition_type);
49 58
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
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(content::RenderWidgetHost* rwh);
jam 2012/03/05 23:59:28 ditto
Jói 2012/03/06 16:38:55 Done.
67 virtual ~TestRenderWidgetHostView(); 66 virtual ~TestRenderWidgetHostView();
68 67
69 // RenderWidgetHostView implementation. 68 // RenderWidgetHostView implementation.
70 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE {} 69 virtual void InitAsChild(gfx::NativeView parent_view) OVERRIDE {}
71 virtual RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE; 70 virtual content::RenderWidgetHost* GetRenderWidgetHost() const OVERRIDE;
72 virtual void SetSize(const gfx::Size& size) OVERRIDE {} 71 virtual void SetSize(const gfx::Size& size) OVERRIDE {}
73 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE {} 72 virtual void SetBounds(const gfx::Rect& rect) OVERRIDE {}
74 virtual gfx::NativeView GetNativeView() const OVERRIDE; 73 virtual gfx::NativeView GetNativeView() const OVERRIDE;
75 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE; 74 virtual gfx::NativeViewId GetNativeViewId() const OVERRIDE;
76 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; 75 virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
77 virtual bool HasFocus() const OVERRIDE; 76 virtual bool HasFocus() const OVERRIDE;
78 virtual void Show() OVERRIDE; 77 virtual void Show() OVERRIDE;
79 virtual void Hide() OVERRIDE; 78 virtual void Hide() OVERRIDE;
80 virtual bool IsShowing() OVERRIDE; 79 virtual bool IsShowing() OVERRIDE;
81 virtual gfx::Rect GetViewBounds() const OVERRIDE; 80 virtual gfx::Rect GetViewBounds() const OVERRIDE;
(...skipping 26 matching lines...) Expand all
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 {}
112 virtual void ImeCancelComposition() OVERRIDE {} 111 virtual void ImeCancelComposition() OVERRIDE {}
113 virtual void DidUpdateBackingStore( 112 virtual void DidUpdateBackingStore(
114 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy, 113 const gfx::Rect& scroll_rect, int scroll_dx, int scroll_dy,
115 const std::vector<gfx::Rect>& rects) OVERRIDE {} 114 const std::vector<gfx::Rect>& rects) OVERRIDE {}
116 virtual void RenderViewGone(base::TerminationStatus status, 115 virtual void RenderViewGone(base::TerminationStatus status,
117 int error_code) OVERRIDE; 116 int error_code) OVERRIDE;
118 virtual void WillDestroyRenderWidget(RenderWidgetHost* rwh) { } 117 virtual void WillDestroyRenderWidget(content::RenderWidgetHost* rwh) { }
119 virtual void Destroy() OVERRIDE {} 118 virtual void Destroy() OVERRIDE {}
120 virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE {} 119 virtual void SetTooltipText(const string16& tooltip_text) OVERRIDE {}
121 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE; 120 virtual BackingStore* AllocBackingStore(const gfx::Size& size) OVERRIDE;
122 virtual void OnAcceleratedCompositingStateChange() OVERRIDE; 121 virtual void OnAcceleratedCompositingStateChange() OVERRIDE;
123 virtual void AcceleratedSurfaceBuffersSwapped( 122 virtual void AcceleratedSurfaceBuffersSwapped(
124 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, 123 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params,
125 int gpu_host_id) OVERRIDE; 124 int gpu_host_id) OVERRIDE;
126 virtual void AcceleratedSurfacePostSubBuffer( 125 virtual void AcceleratedSurfacePostSubBuffer(
127 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, 126 const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params,
128 int gpu_host_id) OVERRIDE; 127 int gpu_host_id) OVERRIDE;
(...skipping 51 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
(...skipping 102 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

Powered by Google App Engine
This is Rietveld 408576698