1 // Copyright 2014 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/browser/content_browser_client.h" 6 #include "content/public/common/content_client.h" 7 #include "content/public/renderer/content_renderer_client.h" 8 #include "content/renderer/render_process_impl.h" 9 #include "content/renderer/render_thread_impl.h" 10 #include "content/renderer/scheduler_proxy_task_runner.h" 11 #include "content/test/mock_render_process.h" 12 #include "testing/gtest/include/gtest/gtest.h" 13 14 namespace content { 15 namespace { 16 17 void TestTask(int value, int* result) { 18 *result = (*result << 4) | value; 19 } 20 21 } // namespace 22 23 class DummyListener : public IPC::Listener { 24 public: 25 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { 26 return true; 27 } 28 }; 29 30 TEST(SchedulerProxyTaskRunnerBrowserTest, TestTaskPosting) { 31 ContentClient content_client; 32 ContentBrowserClient content_browser_client; 33 ContentRendererClient content_renderer_client; 34 SetContentClient(&content_client); 35 SetBrowserClientForTesting(&content_browser_client); 36 SetRendererClientForTesting(&content_renderer_client); 37 base::MessageLoopForIO message_loop; 38 39 std::string channel_id = 40 IPC::Channel::GenerateVerifiedChannelID(std::string()); 41 DummyListener dummy_listener; 42 scoped_ptr<IPC::Channel> channel( 43 IPC::Channel::CreateServer(channel_id, &dummy_listener)); 44 EXPECT_TRUE(channel->Connect()); 45 46 scoped_ptr<MockRenderProcess> mock_process(new MockRenderProcess); 47 // Owned by mock_process. 48 RenderThreadImpl* thread = new RenderThreadImpl(channel_id); 49 thread->EnsureWebKitInitialized(); 50 51 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner = 52 thread->main_thread_compositor_task_runner(); 53 54 EXPECT_TRUE(compositor_task_runner->BelongsToCurrentThread()); 55 56 int compositor_order = 0; 57 compositor_task_runner->PostTask(FROM_HERE, 58 base::Bind(&TestTask, 1, &compositor_order)); 59 compositor_task_runner->PostTask(FROM_HERE, 60 base::Bind(&TestTask, 2, &compositor_order)); 61 compositor_task_runner->PostTask(FROM_HERE, 62 base::Bind(&TestTask, 3, &compositor_order)); 63 compositor_task_runner->PostTask(FROM_HERE, 64 base::Bind(&TestTask, 4, &compositor_order)); 65 66 message_loop.RunUntilIdle(); 67 68 EXPECT_EQ(0x1234, compositor_order); 69 } 70 71 } // namespace content 72