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

Side by Side Diff: content/renderer/render_thread_impl_browsertest.cc

Issue 2226403002: Remove Channel token from InProcessChildThreadParams (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moar-channels
Patch Set: . Created 4 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
« no previous file with comments | « content/renderer/DEPS ('k') | content/test/BUILD.gn » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
Ben Goodger (Google) 2016/08/10 14:24:04 this test seems like it'll be completely re-done/i
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 #include "content/renderer/render_thread_impl.h" 5 #include "content/renderer/render_thread_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/discardable_memory.h" 14 #include "base/memory/discardable_memory.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
19 #include "cc/output/buffer_to_texture_target_map.h" 19 #include "cc/output/buffer_to_texture_target_map.h"
20 #include "components/scheduler/renderer/renderer_scheduler.h" 20 #include "components/scheduler/renderer/renderer_scheduler.h"
21 #include "content/app/mojo/mojo_init.h" 21 #include "content/app/mojo/mojo_init.h"
22 #include "content/browser/mojo/mojo_child_connection.h"
22 #include "content/common/in_process_child_thread_params.h" 23 #include "content/common/in_process_child_thread_params.h"
24 #include "content/common/mojo/constants.h"
23 #include "content/common/resource_messages.h" 25 #include "content/common/resource_messages.h"
24 #include "content/common/websocket_messages.h" 26 #include "content/common/websocket_messages.h"
27 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/content_browser_client.h" 28 #include "content/public/browser/content_browser_client.h"
26 #include "content/public/common/content_client.h" 29 #include "content/public/common/content_client.h"
27 #include "content/public/common/content_switches.h" 30 #include "content/public/common/content_switches.h"
31 #include "content/public/common/mojo_shell_connection.h"
28 #include "content/public/renderer/content_renderer_client.h" 32 #include "content/public/renderer/content_renderer_client.h"
33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "content/public/test/test_content_client_initializer.h"
35 #include "content/public/test/test_mojo_shell_context.h"
29 #include "content/renderer/render_process_impl.h" 36 #include "content/renderer/render_process_impl.h"
30 #include "content/test/mock_render_process.h" 37 #include "content/test/mock_render_process.h"
31 #include "content/test/render_thread_impl_browser_test_ipc_helper.h"
32 #include "gpu/GLES2/gl2extchromium.h" 38 #include "gpu/GLES2/gl2extchromium.h"
39 #include "ipc/ipc.mojom.h"
40 #include "ipc/ipc_channel_mojo.h"
41 #include "mojo/edk/embedder/embedder.h"
42 #include "mojo/edk/test/scoped_ipc_support.h"
33 #include "testing/gtest/include/gtest/gtest.h" 43 #include "testing/gtest/include/gtest/gtest.h"
34 44
35 // IPC messages for testing ---------------------------------------------------- 45 // IPC messages for testing ----------------------------------------------------
36 46
37 // TODO(mdempsky): Fix properly by moving into a separate 47 // TODO(mdempsky): Fix properly by moving into a separate
38 // browsertest_message_generator.cc file. 48 // browsertest_message_generator.cc file.
39 #undef IPC_IPC_MESSAGE_MACROS_H_ 49 #undef IPC_IPC_MESSAGE_MACROS_H_
40 #undef IPC_MESSAGE_EXTRA 50 #undef IPC_MESSAGE_EXTRA
41 #define IPC_MESSAGE_IMPL 51 #define IPC_MESSAGE_IMPL
42 #include "ipc/ipc_message_macros.h" 52 #include "ipc/ipc_message_macros.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 113
104 class RenderThreadImplForTest : public RenderThreadImpl { 114 class RenderThreadImplForTest : public RenderThreadImpl {
105 public: 115 public:
106 RenderThreadImplForTest( 116 RenderThreadImplForTest(
107 const InProcessChildThreadParams& params, 117 const InProcessChildThreadParams& params,
108 std::unique_ptr<scheduler::RendererScheduler> scheduler, 118 std::unique_ptr<scheduler::RendererScheduler> scheduler,
109 scoped_refptr<base::SingleThreadTaskRunner>& test_task_counter) 119 scoped_refptr<base::SingleThreadTaskRunner>& test_task_counter)
110 : RenderThreadImpl(params, std::move(scheduler), test_task_counter) {} 120 : RenderThreadImpl(params, std::move(scheduler), test_task_counter) {}
111 121
112 ~RenderThreadImplForTest() override {} 122 ~RenderThreadImplForTest() override {}
123 };
113 124
114 using ChildThreadImpl::OnMessageReceived; 125 class DummyListener : public IPC::Listener {
126 public:
127 ~DummyListener() override {}
115 128
116 private: 129 bool OnMessageReceived(const IPC::Message& message) override { return true; }
117 }; 130 };
118 131
119 #if defined(COMPILER_MSVC) 132 #if defined(COMPILER_MSVC)
120 #pragma warning(pop) 133 #pragma warning(pop)
121 #endif 134 #endif
122 135
123 void QuitTask(base::MessageLoop* message_loop) { 136 void QuitTask(base::MessageLoop* message_loop) {
124 message_loop->QuitWhenIdle(); 137 message_loop->QuitWhenIdle();
125 } 138 }
126 139
(...skipping 17 matching lines...) Expand all
144 157
145 private: 158 private:
146 ~QuitOnTestMsgFilter() override {} 159 ~QuitOnTestMsgFilter() override {}
147 160
148 base::MessageLoop* message_loop_; 161 base::MessageLoop* message_loop_;
149 }; 162 };
150 163
151 class RenderThreadImplBrowserTest : public testing::Test { 164 class RenderThreadImplBrowserTest : public testing::Test {
152 public: 165 public:
153 void SetUp() override { 166 void SetUp() override {
154 content_client_.reset(new ContentClient());
155 content_browser_client_.reset(new ContentBrowserClient());
156 content_renderer_client_.reset(new ContentRendererClient()); 167 content_renderer_client_.reset(new ContentRendererClient());
157 SetContentClient(content_client_.get());
158 SetBrowserClientForTesting(content_browser_client_.get());
159 SetRendererClientForTesting(content_renderer_client_.get()); 168 SetRendererClientForTesting(content_renderer_client_.get());
160 169
161 test_helper_.reset(new RenderThreadImplBrowserIPCTestHelper()); 170 browser_threads_.reset(
171 new TestBrowserThreadBundle(TestBrowserThreadBundle::IO_MAINLOOP));
172 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
173 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
174
175 InitializeMojo();
176 ipc_support_.reset(new mojo::edk::test::ScopedIPCSupport(io_task_runner));
177 shell_context_.reset(new TestMojoShellContext);
178 child_connection_.reset(new MojoChildConnection(
179 kRendererMojoApplicationName, "test", mojo::edk::GenerateRandomToken(),
180 MojoShellConnection::GetForProcess()->GetConnector(), io_task_runner));
181
182 mojo::MessagePipe pipe;
183 IPC::mojom::ChannelBootstrapPtr channel_bootstrap;
184 child_connection_->GetRemoteInterfaces()->GetInterface(&channel_bootstrap);
185
186 dummy_listener_.reset(new DummyListener);
187 channel_ = IPC::ChannelProxy::Create(
188 IPC::ChannelMojo::CreateServerFactory(
189 channel_bootstrap.PassInterface().PassHandle(), io_task_runner),
190 dummy_listener_.get(), io_task_runner);
162 191
163 mock_process_.reset(new MockRenderProcess); 192 mock_process_.reset(new MockRenderProcess);
164 test_task_counter_ = make_scoped_refptr(new TestTaskCounter()); 193 test_task_counter_ = make_scoped_refptr(new TestTaskCounter());
165 194
166 // RenderThreadImpl expects the browser to pass these flags. 195 // RenderThreadImpl expects the browser to pass these flags.
167 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); 196 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
168 base::CommandLine::StringVector old_argv = cmd->argv(); 197 base::CommandLine::StringVector old_argv = cmd->argv();
169 198
170 cmd->AppendSwitchASCII(switches::kNumRasterThreads, "1"); 199 cmd->AppendSwitchASCII(switches::kNumRasterThreads, "1");
171 cmd->AppendSwitchASCII( 200 cmd->AppendSwitchASCII(
172 switches::kContentImageTextureTarget, 201 switches::kContentImageTextureTarget,
173 cc::BufferToTextureTargetMapToString( 202 cc::BufferToTextureTargetMapToString(
174 cc::DefaultBufferToTextureTargetMapForTesting())); 203 cc::DefaultBufferToTextureTargetMapForTesting()));
175 204
176 std::unique_ptr<scheduler::RendererScheduler> renderer_scheduler = 205 std::unique_ptr<scheduler::RendererScheduler> renderer_scheduler =
177 scheduler::RendererScheduler::Create(); 206 scheduler::RendererScheduler::Create();
178 InitializeMojo();
179 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter( 207 scoped_refptr<base::SingleThreadTaskRunner> test_task_counter(
180 test_task_counter_.get()); 208 test_task_counter_.get());
181 thread_ = new RenderThreadImplForTest( 209 thread_ = new RenderThreadImplForTest(
182 InProcessChildThreadParams(test_helper_->GetChannelId(), 210 InProcessChildThreadParams("", io_task_runner,
183 test_helper_->GetIOTaskRunner(), 211 child_connection_->service_token()),
184 test_helper_->GetMojoIpcToken(),
185 test_helper_->GetMojoApplicationToken()),
186 std::move(renderer_scheduler), test_task_counter); 212 std::move(renderer_scheduler), test_task_counter);
187 cmd->InitFromArgv(old_argv); 213 cmd->InitFromArgv(old_argv);
188 214
189 test_msg_filter_ = make_scoped_refptr( 215 test_msg_filter_ = make_scoped_refptr(
190 new QuitOnTestMsgFilter(test_helper_->GetMessageLoop())); 216 new QuitOnTestMsgFilter(base::MessageLoop::current()));
191 thread_->AddFilter(test_msg_filter_.get()); 217 thread_->AddFilter(test_msg_filter_.get());
192 } 218 }
193 219
220 IPC::Sender* sender() { return channel_.get(); }
221
194 scoped_refptr<TestTaskCounter> test_task_counter_; 222 scoped_refptr<TestTaskCounter> test_task_counter_;
195 std::unique_ptr<ContentClient> content_client_; 223 TestContentClientInitializer content_client_initializer_;
196 std::unique_ptr<ContentBrowserClient> content_browser_client_;
197 std::unique_ptr<ContentRendererClient> content_renderer_client_; 224 std::unique_ptr<ContentRendererClient> content_renderer_client_;
198 std::unique_ptr<RenderThreadImplBrowserIPCTestHelper> test_helper_; 225
226 std::unique_ptr<TestBrowserThreadBundle> browser_threads_;
227 std::unique_ptr<mojo::edk::test::ScopedIPCSupport> ipc_support_;
228 std::unique_ptr<TestMojoShellContext> shell_context_;
229 std::unique_ptr<MojoChildConnection> child_connection_;
230 std::unique_ptr<DummyListener> dummy_listener_;
231 std::unique_ptr<IPC::ChannelProxy> channel_;
232
199 std::unique_ptr<MockRenderProcess> mock_process_; 233 std::unique_ptr<MockRenderProcess> mock_process_;
200 scoped_refptr<QuitOnTestMsgFilter> test_msg_filter_; 234 scoped_refptr<QuitOnTestMsgFilter> test_msg_filter_;
201 RenderThreadImplForTest* thread_; // Owned by mock_process_. 235 RenderThreadImplForTest* thread_; // Owned by mock_process_.
202 std::string channel_id_;
203 }; 236 };
204 237
205 void CheckRenderThreadInputHandlerManager(RenderThreadImpl* thread) { 238 void CheckRenderThreadInputHandlerManager(RenderThreadImpl* thread) {
206 ASSERT_TRUE(thread->input_handler_manager()); 239 ASSERT_TRUE(thread->input_handler_manager());
207 } 240 }
208 241
209 // Check that InputHandlerManager outlives compositor thread because it uses 242 // Check that InputHandlerManager outlives compositor thread because it uses
210 // raw pointers to post tasks. 243 // raw pointers to post tasks.
211 // Disabled under LeakSanitizer due to memory leaks. http://crbug.com/348994 244 // Disabled under LeakSanitizer due to memory leaks. http://crbug.com/348994
212 TEST_F(RenderThreadImplBrowserTest, 245 TEST_F(RenderThreadImplBrowserTest,
213 WILL_LEAK(InputHandlerManagerDestroyedAfterCompositorThread)) { 246 WILL_LEAK(InputHandlerManagerDestroyedAfterCompositorThread)) {
214 ASSERT_TRUE(thread_->input_handler_manager()); 247 ASSERT_TRUE(thread_->input_handler_manager());
215 248
216 thread_->compositor_task_runner()->PostTask( 249 thread_->compositor_task_runner()->PostTask(
217 FROM_HERE, base::Bind(&CheckRenderThreadInputHandlerManager, thread_)); 250 FROM_HERE, base::Bind(&CheckRenderThreadInputHandlerManager, thread_));
218 } 251 }
219 252
220 // Disabled under LeakSanitizer due to memory leaks. 253 // Disabled under LeakSanitizer due to memory leaks.
221 TEST_F(RenderThreadImplBrowserTest, 254 TEST_F(RenderThreadImplBrowserTest,
222 WILL_LEAK(ResourceDispatchIPCTasksGoThroughScheduler)) { 255 WILL_LEAK(ResourceDispatchIPCTasksGoThroughScheduler)) {
223 test_helper_->Sender()->Send(new ResourceHostMsg_FollowRedirect(0)); 256 sender()->Send(new ResourceHostMsg_FollowRedirect(0));
224 test_helper_->Sender()->Send(new TestMsg_QuitRunLoop()); 257 sender()->Send(new TestMsg_QuitRunLoop());
225 258
226 base::RunLoop().Run(); 259 base::RunLoop().Run();
227 EXPECT_EQ(1, test_task_counter_->NumTasksPosted()); 260 EXPECT_EQ(1, test_task_counter_->NumTasksPosted());
228 } 261 }
229 262
230 // Disabled under LeakSanitizer due to memory leaks. 263 // Disabled under LeakSanitizer due to memory leaks.
231 TEST_F(RenderThreadImplBrowserTest, 264 TEST_F(RenderThreadImplBrowserTest,
232 WILL_LEAK(NonResourceDispatchIPCTasksDontGoThroughScheduler)) { 265 WILL_LEAK(NonResourceDispatchIPCTasksDontGoThroughScheduler)) {
233 // NOTE other than not being a resource message, the actual message is 266 // NOTE other than not being a resource message, the actual message is
234 // unimportant. 267 // unimportant.
235 test_helper_->Sender()->Send(new WebSocketMsg_NotifyFailure(1, "")); 268 sender()->Send(new WebSocketMsg_NotifyFailure(1, ""));
236 test_helper_->Sender()->Send(new TestMsg_QuitRunLoop()); 269 sender()->Send(new TestMsg_QuitRunLoop());
237 270
238 base::RunLoop().Run(); 271 base::RunLoop().Run();
239 272
240 EXPECT_EQ(0, test_task_counter_->NumTasksPosted()); 273 EXPECT_EQ(0, test_task_counter_->NumTasksPosted());
241 } 274 }
242 275
243 } // namespace 276 } // namespace
244 } // namespace content 277 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/DEPS ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698