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

Side by Side Diff: base/message_loop_unittest.cc

Issue 10380016: Add base::ThreadTaskRunner class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/eintr_wrapper.h" 10 #include "base/eintr_wrapper.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/platform_thread.h" 15 #include "base/threading/platform_thread.h"
15 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 #if defined(OS_WIN) 19 #if defined(OS_WIN)
19 #include "base/message_pump_win.h" 20 #include "base/message_pump_win.h"
20 #include "base/win/scoped_handle.h" 21 #include "base/win/scoped_handle.h"
21 #endif 22 #endif
22 23
23 using base::PlatformThread; 24 using base::PlatformThread;
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 base::Bind(&DestructionObserverProbe::Run, 1683 base::Bind(&DestructionObserverProbe::Run,
1683 new DestructionObserverProbe(&task_destroyed, 1684 new DestructionObserverProbe(&task_destroyed,
1684 &destruction_observer_called)), 1685 &destruction_observer_called)),
1685 kDelay); 1686 kDelay);
1686 delete loop; 1687 delete loop;
1687 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); 1688 EXPECT_TRUE(observer.task_destroyed_before_message_loop());
1688 // The task should have been destroyed when we deleted the loop. 1689 // The task should have been destroyed when we deleted the loop.
1689 EXPECT_TRUE(task_destroyed); 1690 EXPECT_TRUE(task_destroyed);
1690 EXPECT_TRUE(destruction_observer_called); 1691 EXPECT_TRUE(destruction_observer_called);
1691 } 1692 }
1693
1694
1695 // Verify that MessageLoop sets ThreadMainTaskRunner::current() and it
1696 // posts tasks on that message loop.
1697 TEST(MessageLoopTest, ThreadMainTaskRunner) {
1698 MessageLoop loop;
1699
1700 scoped_refptr<Foo> foo(new Foo());
1701 std::string a("a");
1702 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::Bind(
1703 &Foo::Test1ConstRef, foo.get(), a));
1704
1705 // Post quit task;
1706 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(
1707 &MessageLoop::Quit, base::Unretained(MessageLoop::current())));
1708
1709 // Now kick things off
1710 MessageLoop::current()->Run();
1711
1712 EXPECT_EQ(foo->test_count(), 1);
1713 EXPECT_EQ(foo->result(), "a");
1714 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698