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

Side by Side Diff: content/test/test_renderer_host.h

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. 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
« no previous file with comments | « content/content_tests.gypi ('k') | content/test/test_renderer_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_TEST_TEST_RENDERER_HOST_H_ 5 #ifndef CONTENT_TEST_TEST_RENDERER_HOST_H_
6 #define CONTENT_TEST_TEST_RENDERER_HOST_H_ 6 #define CONTENT_TEST_TEST_RENDERER_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/common/page_transition_types.h" 12 #include "content/public/common/page_transition_types.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 class TestTabContents;
16
17 #if defined(USE_AURA) 15 #if defined(USE_AURA)
18 namespace aura { 16 namespace aura {
19 class RootWindow; 17 class RootWindow;
20 namespace test { 18 namespace test {
21 class TestStackingClient; 19 class TestStackingClient;
22 } 20 }
23 } 21 }
24 #endif 22 #endif
25 23
26 namespace content { 24 namespace content {
27 25
28 class BrowserContext; 26 class BrowserContext;
29 class MockRenderProcessHost; 27 class MockRenderProcessHost;
30 class MockRenderProcessHostFactory; 28 class MockRenderProcessHostFactory;
31 class NavigationController; 29 class NavigationController;
32 class RenderProcessHostFactory; 30 class RenderProcessHostFactory;
33 class RenderViewHostDelegate; 31 class RenderViewHostDelegate;
34 class TestRenderViewHostFactory; 32 class TestRenderViewHostFactory;
33 class WebContents;
35 34
36 // An interface and utility for driving tests of RenderViewHost. 35 // An interface and utility for driving tests of RenderViewHost.
37 class RenderViewHostTester { 36 class RenderViewHostTester {
38 public: 37 public:
39 // Retrieves the RenderViewHostTester that drives the specified 38 // Retrieves the RenderViewHostTester that drives the specified
40 // RenderViewHost. The RenderViewHost must have been created while 39 // RenderViewHost. The RenderViewHost must have been created while
41 // RenderViewHost testing was enabled; use a 40 // RenderViewHost testing was enabled; use a
42 // RenderViewHostTestEnabler instance (see below) to do this. 41 // RenderViewHostTestEnabler instance (see below) to do this.
43 static RenderViewHostTester* For(RenderViewHost* host); 42 static RenderViewHostTester* For(RenderViewHost* host);
44 43
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 scoped_ptr<TestRenderViewHostFactory> rvh_factory_; 112 scoped_ptr<TestRenderViewHostFactory> rvh_factory_;
114 }; 113 };
115 114
116 // RenderViewHostTestHarness --------------------------------------------------- 115 // RenderViewHostTestHarness ---------------------------------------------------
117 class RenderViewHostTestHarness : public testing::Test { 116 class RenderViewHostTestHarness : public testing::Test {
118 public: 117 public:
119 RenderViewHostTestHarness(); 118 RenderViewHostTestHarness();
120 virtual ~RenderViewHostTestHarness(); 119 virtual ~RenderViewHostTestHarness();
121 120
122 NavigationController& controller(); 121 NavigationController& controller();
123 virtual TestTabContents* contents(); 122 virtual WebContents* web_contents();
124 RenderViewHost* rvh(); 123 RenderViewHost* rvh();
125 RenderViewHost* pending_rvh(); 124 RenderViewHost* pending_rvh();
126 RenderViewHost* active_rvh(); 125 RenderViewHost* active_rvh();
127 BrowserContext* browser_context(); 126 BrowserContext* browser_context();
128 MockRenderProcessHost* process(); 127 MockRenderProcessHost* process();
129 128
130 // Frees the current tab contents for tests that want to test destruction. 129 // Frees the current tab contents for tests that want to test destruction.
131 void DeleteContents(); 130 void DeleteContents();
132 131
133 // Sets the current tab contents for tests that want to alter it. Takes 132 // Sets the current tab contents for tests that want to alter it. Takes
134 // ownership of the TestTabContents passed. 133 // ownership of the WebContents passed.
135 virtual void SetContents(TestTabContents* contents); 134 virtual void SetContents(WebContents* contents);
136 135
137 // Creates a new TestTabContents. Ownership passes to the caller. 136 // Creates a new test-enabled WebContents. Ownership passes to the
138 TestTabContents* CreateTestTabContents(); 137 // caller.
138 WebContents* CreateTestWebContents();
139 139
140 // Cover for |contents()->NavigateAndCommit(url)|. See 140 // Cover for |contents()->NavigateAndCommit(url)|. See
141 // TestTabContents::NavigateAndCommit for details. 141 // WebContentsTester::NavigateAndCommit for details.
142 void NavigateAndCommit(const GURL& url); 142 void NavigateAndCommit(const GURL& url);
143 143
144 // Simulates a reload of the current page. 144 // Simulates a reload of the current page.
145 void Reload(); 145 void Reload();
146 146
147 protected: 147 protected:
148 // testing::Test 148 // testing::Test
149 virtual void SetUp() OVERRIDE; 149 virtual void SetUp() OVERRIDE;
150 virtual void TearDown() OVERRIDE; 150 virtual void TearDown() OVERRIDE;
151 151
152 #if defined(USE_AURA) 152 #if defined(USE_AURA)
153 aura::RootWindow* root_window() const { return root_window_.get(); } 153 aura::RootWindow* root_window() const { return root_window_.get(); }
154 #endif 154 #endif
155 155
156 // Replaces the RPH being used. 156 // Replaces the RPH being used.
157 void SetRenderProcessHostFactory(RenderProcessHostFactory* factory); 157 void SetRenderProcessHostFactory(RenderProcessHostFactory* factory);
158 158
159 // This browser context will be created in SetUp if it has not already been 159 // This browser context will be created in SetUp if it has not already been
160 // created. This allows tests to override the browser context if they so 160 // created. This allows tests to override the browser context if they so
161 // choose in their own SetUp function before calling the base class's (us) 161 // choose in their own SetUp function before calling the base class's (us)
162 // SetUp(). 162 // SetUp().
163 scoped_ptr<BrowserContext> browser_context_; 163 scoped_ptr<BrowserContext> browser_context_;
164 164
165 MessageLoopForUI message_loop_; 165 MessageLoopForUI message_loop_;
166 166
167 private: 167 private:
168 scoped_ptr<TestTabContents> contents_; 168 // It is important not to use this directly in the implementation as
169 // web_contents() and SetContents() are virtual and may be
170 // overridden by subclasses.
171 scoped_ptr<WebContents> contents_;
169 #if defined(USE_AURA) 172 #if defined(USE_AURA)
170 scoped_ptr<aura::RootWindow> root_window_; 173 scoped_ptr<aura::RootWindow> root_window_;
171 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; 174 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
172 #endif 175 #endif
173 RenderViewHostTestEnabler rvh_test_enabler_; 176 RenderViewHostTestEnabler rvh_test_enabler_;
174 177
175 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness); 178 DISALLOW_COPY_AND_ASSIGN(RenderViewHostTestHarness);
176 }; 179 };
177 180
178 } // namespace content 181 } // namespace content
179 182
180 // TODO(joi): Remove this after converting all clients. 183 // TODO(joi): Remove this after converting all clients.
181 using content::RenderViewHostTestHarness; 184 using content::RenderViewHostTestHarness;
182 185
183 #endif // CONTENT_TEST_TEST_RENDERER_HOST_H_ 186 #endif // CONTENT_TEST_TEST_RENDERER_HOST_H_
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/test/test_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698