summaryrefslogtreecommitdiffstats
path: root/content/renderer/scheduler_proxy_task_runner_browsertest.cc
blob: d2088e11bfebee9cba0609fe703e891d736daae5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/public/browser/content_browser_client.h"
#include "content/public/common/content_client.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/render_process_impl.h"
#include "content/renderer/render_thread_impl.h"
#include "content/renderer/scheduler_proxy_task_runner.h"
#include "content/test/mock_render_process.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {
namespace {

void TestTask(int value, int* result) {
  *result = (*result << 4) | value;
}

}  // namespace

class DummyListener : public IPC::Listener {
 public:
  virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE {
    return true;
  }
};

TEST(SchedulerProxyTaskRunnerBrowserTest, TestTaskPosting) {
  ContentClient content_client;
  ContentBrowserClient content_browser_client;
  ContentRendererClient content_renderer_client;
  SetContentClient(&content_client);
  SetBrowserClientForTesting(&content_browser_client);
  SetRendererClientForTesting(&content_renderer_client);
  base::MessageLoopForIO message_loop;

  std::string channel_id =
      IPC::Channel::GenerateVerifiedChannelID(std::string());
  DummyListener dummy_listener;
  scoped_ptr<IPC::Channel> channel(
      IPC::Channel::CreateServer(channel_id, &dummy_listener));
  EXPECT_TRUE(channel->Connect());

  scoped_ptr<MockRenderProcess> mock_process(new MockRenderProcess);
  // Owned by mock_process.
  RenderThreadImpl* thread = new RenderThreadImpl(channel_id);
  thread->EnsureWebKitInitialized();

  scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner =
      thread->main_thread_compositor_task_runner();

  EXPECT_TRUE(compositor_task_runner->BelongsToCurrentThread());

  int compositor_order = 0;
  compositor_task_runner->PostTask(FROM_HERE,
                                   base::Bind(&TestTask, 1, &compositor_order));
  compositor_task_runner->PostTask(FROM_HERE,
                                   base::Bind(&TestTask, 2, &compositor_order));
  compositor_task_runner->PostTask(FROM_HERE,
                                   base::Bind(&TestTask, 3, &compositor_order));
  compositor_task_runner->PostTask(FROM_HERE,
                                   base::Bind(&TestTask, 4, &compositor_order));

  message_loop.RunUntilIdle();

  EXPECT_EQ(0x1234, compositor_order);
}

}  // namespace content