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

Unified Diff: base/message_loop_proxy_impl_unittest.cc

Issue 1837003: Created a stock implementation of the MessageLoopProxy interface than can be ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Rearranged header files Created 10 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/thread.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop_proxy_impl_unittest.cc
===================================================================
--- base/message_loop_proxy_impl_unittest.cc (revision 0)
+++ base/message_loop_proxy_impl_unittest.cc (revision 0)
@@ -0,0 +1,131 @@
+// Copyright (c) 2010 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 "base/message_loop.h"
+#include "base/message_loop_proxy_impl.h"
+#include "base/thread.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+
+class MessageLoopProxyImplTest : public testing::Test {
+ public:
+ void Release() {
+ AssertOnIOThread();
+ Quit();
+ }
+
+ void Quit() {
+ loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask);
+ }
+
+ void AssertOnIOThread() {
+ ASSERT_TRUE(io_thread_->message_loop_proxy()->BelongsToCurrentThread());
+ }
+
+ void AssertOnFileThread() {
+ ASSERT_TRUE(file_thread_->message_loop_proxy()->BelongsToCurrentThread());
+ }
+
+ protected:
+ virtual void SetUp() {
+ io_thread_.reset(new base::Thread("MessageLoopProxyImplTest_IO"));
+ file_thread_.reset(new base::Thread("MessageLoopProxyImplTest_File"));
+ io_thread_->Start();
+ file_thread_->Start();
+ }
+
+ virtual void TearDown() {
+ io_thread_->Stop();
+ file_thread_->Stop();
+ }
+
+ static void BasicFunction(MessageLoopProxyImplTest* test) {
+ test->AssertOnFileThread();
+ test->Quit();
+ }
+
+ class DummyTask : public Task {
+ public:
+ explicit DummyTask(bool* deleted) : deleted_(deleted) { }
+ ~DummyTask() {
+ *deleted_ = true;
+ }
+
+ void Run() {
+ FAIL();
+ }
+
+ private:
+ bool* deleted_;
+ };
+
+ class DeletedOnFile {
+ public:
+ explicit DeletedOnFile(MessageLoopProxyImplTest* test) : test_(test) {}
+
+ ~DeletedOnFile() {
+ test_->AssertOnFileThread();
+ test_->Quit();
+ }
+
+ private:
+ MessageLoopProxyImplTest* test_;
+ };
+
+ scoped_ptr<base::Thread> io_thread_;
+ scoped_ptr<base::Thread> file_thread_;
+
+ private:
+ MessageLoop loop_;
+};
+
+
+TEST_F(MessageLoopProxyImplTest, PostTask) {
+ EXPECT_TRUE(file_thread_->message_loop_proxy()->PostTask(
+ FROM_HERE, NewRunnableFunction(&BasicFunction, this)));
+ MessageLoop::current()->Run();
+}
+
+TEST_F(MessageLoopProxyImplTest, Release) {
+ EXPECT_TRUE(io_thread_->message_loop_proxy()->ReleaseSoon(FROM_HERE, this));
+ MessageLoop::current()->Run();
+}
+
+TEST_F(MessageLoopProxyImplTest, Delete) {
+ DeletedOnFile* deleted_on_file = new DeletedOnFile(this);
+ EXPECT_TRUE(file_thread_->message_loop_proxy()->DeleteSoon(
+ FROM_HERE, deleted_on_file));
+ MessageLoop::current()->Run();
+}
+
+TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadExits) {
+ scoped_ptr<base::Thread> test_thread(
+ new base::Thread("MessageLoopProxyImplTest_Dummy"));
+ test_thread->Start();
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy =
+ test_thread->message_loop_proxy();
+ test_thread->Stop();
+
+ bool deleted = false;
+ bool ret = message_loop_proxy->PostTask(
+ FROM_HERE, new DummyTask(&deleted));
+ EXPECT_FALSE(ret);
+ EXPECT_TRUE(deleted);
+}
+
+TEST_F(MessageLoopProxyImplTest, PostTaskAfterThreadIsDeleted) {
+ scoped_refptr<base::MessageLoopProxy> message_loop_proxy;
+ {
+ scoped_ptr<base::Thread> test_thread(
+ new base::Thread("MessageLoopProxyImplTest_Dummy"));
+ test_thread->Start();
+ message_loop_proxy = test_thread->message_loop_proxy();
+ }
+ bool deleted = false;
+ bool ret = message_loop_proxy->PostTask(FROM_HERE, new DummyTask(&deleted));
+ EXPECT_FALSE(ret);
+ EXPECT_TRUE(deleted);
+}
+
Property changes on: base\message_loop_proxy_impl_unittest.cc
___________________________________________________________________
Added: svn:eol-style
+ LF
« no previous file with comments | « base/message_loop_proxy_impl.cc ('k') | base/thread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698