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

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

Issue 10826311: Move the corresponding cc files from content\test to be alongside their headers in content\public\t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 4 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/test/test_notification_tracker.cc ('k') | content/test/test_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/public/test/test_renderer_host.h"
6
7 #include "content/browser/renderer_host/render_view_host_factory.h"
8 #include "content/browser/renderer_host/render_widget_host_impl.h"
9 #include "content/browser/renderer_host/test_render_view_host.h"
10 #include "content/browser/site_instance_impl.h"
11 #include "content/browser/web_contents/navigation_entry_impl.h"
12 #include "content/browser/web_contents/test_web_contents.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/mock_render_process_host.h"
15 #include "content/public/test/test_browser_context.h"
16 #include "content/test/test_render_view_host_factory.h"
17
18 #if defined(USE_AURA)
19 #include "ui/aura/test/aura_test_helper.h"
20 #endif
21
22 namespace content {
23
24 // static
25 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) {
26 return static_cast<TestRenderViewHost*>(host);
27 }
28
29 // static
30 void RenderViewHostTester::EnableAccessibilityUpdatedNotifications(
31 RenderViewHost* host) {
32 static_cast<RenderViewHostImpl*>(
33 host)->set_send_accessibility_updated_notifications(true);
34 }
35
36 // static
37 RenderViewHost* RenderViewHostTester::GetPendingForController(
38 NavigationController* controller) {
39 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
40 controller->GetWebContents());
41 return web_contents->GetRenderManagerForTesting()->pending_render_view_host();
42 }
43
44 // static
45 bool RenderViewHostTester::IsRenderViewHostSwappedOut(RenderViewHost* rvh) {
46 return static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out();
47 }
48
49 // static
50 bool RenderViewHostTester::TestOnMessageReceived(RenderViewHost* rvh,
51 const IPC::Message& msg) {
52 return static_cast<RenderViewHostImpl*>(rvh)->OnMessageReceived(msg);
53 }
54
55 // static
56 bool RenderViewHostTester::HasTouchEventHandler(RenderViewHost* rvh) {
57 RenderWidgetHostImpl* host_impl = RenderWidgetHostImpl::From(rvh);
58 return host_impl->has_touch_handler();
59 }
60
61 RenderViewHostTestEnabler::RenderViewHostTestEnabler()
62 : rph_factory_(new MockRenderProcessHostFactory()),
63 rvh_factory_(new TestRenderViewHostFactory(rph_factory_.get())) {
64 }
65
66 RenderViewHostTestEnabler::~RenderViewHostTestEnabler() {
67 }
68
69 RenderViewHostTestHarness::RenderViewHostTestHarness()
70 : contents_(NULL) {
71 }
72
73 RenderViewHostTestHarness::~RenderViewHostTestHarness() {
74 }
75
76 NavigationController& RenderViewHostTestHarness::controller() {
77 return web_contents()->GetController();
78 }
79
80 WebContents* RenderViewHostTestHarness::web_contents() {
81 return contents_.get();
82 }
83
84 RenderViewHost* RenderViewHostTestHarness::rvh() {
85 return web_contents()->GetRenderViewHost();
86 }
87
88 RenderViewHost* RenderViewHostTestHarness::pending_rvh() {
89 return static_cast<TestWebContents*>(web_contents())->
90 GetRenderManagerForTesting()->pending_render_view_host();
91 }
92
93 RenderViewHost* RenderViewHostTestHarness::active_rvh() {
94 return pending_rvh() ? pending_rvh() : rvh();
95 }
96
97 BrowserContext* RenderViewHostTestHarness::browser_context() {
98 return browser_context_.get();
99 }
100
101 MockRenderProcessHost* RenderViewHostTestHarness::process() {
102 return static_cast<MockRenderProcessHost*>(active_rvh()->GetProcess());
103 }
104
105 void RenderViewHostTestHarness::DeleteContents() {
106 SetContents(NULL);
107 }
108
109 void RenderViewHostTestHarness::SetContents(WebContents* contents) {
110 contents_.reset(contents);
111 }
112
113 WebContents* RenderViewHostTestHarness::CreateTestWebContents() {
114 // See comment above browser_context_ decl for why we check for NULL here.
115 if (!browser_context_.get())
116 browser_context_.reset(new content::TestBrowserContext());
117
118 // This will be deleted when the WebContentsImpl goes away.
119 SiteInstance* instance = SiteInstance::Create(browser_context_.get());
120
121 return TestWebContents::Create(browser_context_.get(), instance);
122 }
123
124 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
125 static_cast<TestWebContents*>(web_contents())->NavigateAndCommit(url);
126 }
127
128 void RenderViewHostTestHarness::Reload() {
129 NavigationEntry* entry = controller().GetLastCommittedEntry();
130 DCHECK(entry);
131 controller().Reload(false);
132 static_cast<TestRenderViewHost*>(
133 rvh())->SendNavigate(entry->GetPageID(), entry->GetURL());
134 }
135
136 void RenderViewHostTestHarness::SetUp() {
137 #if defined(USE_AURA)
138 aura_test_helper_.reset(new aura::test::AuraTestHelper(&message_loop_));
139 aura_test_helper_->SetUp();
140 #endif
141 SetContents(CreateTestWebContents());
142 }
143
144 void RenderViewHostTestHarness::TearDown() {
145 SetContents(NULL);
146 #if defined(USE_AURA)
147 aura_test_helper_->TearDown();
148 #endif
149 // Make sure that we flush any messages related to WebContentsImpl destruction
150 // before we destroy the browser context.
151 MessageLoop::current()->RunAllPending();
152
153 // Delete any RenderProcessHosts before the BrowserContext goes away.
154 if (rvh_test_enabler_.rph_factory_.get())
155 rvh_test_enabler_.rph_factory_.reset();
156
157 // Release the browser context on the UI thread.
158 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
159 message_loop_.RunAllPending();
160 }
161
162 void RenderViewHostTestHarness::SetRenderProcessHostFactory(
163 RenderProcessHostFactory* factory) {
164 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory);
165 }
166
167 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_notification_tracker.cc ('k') | content/test/test_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698