Remove invocation of WebSettings::setFontRenderingNormal, which is a no-op.
[chromium-blink-merge.git] / base / message_loop / message_loop_proxy_impl_unittest.cc
blob4c88887c23185d12f3111368e185251f40950150
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.
5 #include "base/message_loop/message_loop_proxy_impl.h"
7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "base/threading/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h"
15 namespace base {
17 class MessageLoopProxyImplTest : public testing::Test {
18 public:
19 void Release() const {
20 AssertOnIOThread();
21 Quit();
24 void Quit() const {
25 loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure());
28 void AssertOnIOThread() const {
29 ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
30 ASSERT_EQ(io_thread_->message_loop_proxy(),
31 MessageLoopProxy::current());
34 void AssertOnFileThread() const {
35 ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread());
36 ASSERT_EQ(file_thread_->message_loop_proxy(),
37 MessageLoopProxy::current());
40 protected:
41 virtual void SetUp() OVERRIDE {
42 io_thread_.reset(new Thread("MessageLoopProxyImplTest_IO"));
43 file_thread_.reset(new Thread("MessageLoopProxyImplTest_File"));
44 io_thread_->Start();
45 file_thread_->Start();
48 virtual void TearDown() OVERRIDE {
49 io_thread_->Stop();
50 file_thread_->Stop();
53 static void BasicFunction(MessageLoopProxyImplTest* test) {
54 test->AssertOnFileThread();
55 test->Quit();
58 static void AssertNotRun() {
59 FAIL() << "Callback Should not get executed.";
62 class DeletedOnFile {
63 public:
64 explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {}
66 ~DeletedOnFile() {
67 test_->AssertOnFileThread();
68 test_->Quit();
71 private:
72 MessageLoopProxyImplTest* test_;
75 scoped_ptr<Thread> io_thread_;
76 scoped_ptr<Thread> file_thread_;
78 private:
79 mutable MessageLoop loop_;
82 TEST_F(MessageLoopProxyImplTest, Release) {
83 EXPECT_TRUE(io_thread_->message_loop_proxy()->ReleaseSoon(FROM_HERE, this));
84 MessageLoop::current()->Run();
87 TEST_F(MessageLoopProxyImplTest, Delete) {
88 DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
89 EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon(
90 FROM_HERE, deleted_on_file));
91 MessageLoop::current()->Run();
94 TEST_F(MessageLoopProxyImplTest, PostTask) {
95 EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
96 FROM_HERE, Bind(&MessageLoopProxyImplTest::BasicFunction,
97 Unretained(this))));
98 MessageLoop::current()->Run();
101 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
102 scoped_ptr<Thread> test_thread(
103 new Thread("MessageLoopProxyImplTest_Dummy"));
104 test_thread->Start();
105 scoped_refptr<MessageLoopProxy> message_loop_proxy =
106 test_thread->message_loop_proxy();
107 test_thread->Stop();
109 bool ret = message_loop_proxy->PostTask(
110 FROM_HERE,
111 Bind(&MessageLoopProxyImplTest::AssertNotRun));
112 EXPECT_FALSE(ret);
115 TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
116 scoped_refptr<MessageLoopProxy> message_loop_proxy;
118 scoped_ptr<Thread> test_thread(
119 new Thread("MessageLoopProxyImplTest_Dummy"));
120 test_thread->Start();
121 message_loop_proxy = test_thread->message_loop_proxy();
123 bool ret = message_loop_proxy->PostTask(
124 FROM_HERE,
125 Bind(&MessageLoopProxyImplTest::AssertNotRun));
126 EXPECT_FALSE(ret);
129 } // namespace base