OLD | NEW |
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" |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 base::Bind(&DestructionObserverProbe::Run, | 1682 base::Bind(&DestructionObserverProbe::Run, |
1683 new DestructionObserverProbe(&task_destroyed, | 1683 new DestructionObserverProbe(&task_destroyed, |
1684 &destruction_observer_called)), | 1684 &destruction_observer_called)), |
1685 kDelay); | 1685 kDelay); |
1686 delete loop; | 1686 delete loop; |
1687 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); | 1687 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); |
1688 // The task should have been destroyed when we deleted the loop. | 1688 // The task should have been destroyed when we deleted the loop. |
1689 EXPECT_TRUE(task_destroyed); | 1689 EXPECT_TRUE(task_destroyed); |
1690 EXPECT_TRUE(destruction_observer_called); | 1690 EXPECT_TRUE(destruction_observer_called); |
1691 } | 1691 } |
| 1692 |
| 1693 // Verify that MessageLoop sets ThreadMainTaskRunner::current() and it |
| 1694 // posts tasks on that message loop. |
| 1695 TEST(MessageLoopTest, ThreadMainTaskRunner) { |
| 1696 MessageLoop loop; |
| 1697 |
| 1698 scoped_refptr<Foo> foo(new Foo()); |
| 1699 std::string a("a"); |
| 1700 base::ThreadMainTaskRunner::current()->PostTask(FROM_HERE, base::Bind( |
| 1701 &Foo::Test1ConstRef, foo.get(), a)); |
| 1702 |
| 1703 // Post quit task; |
| 1704 MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| 1705 &MessageLoop::Quit, base::Unretained(MessageLoop::current()))); |
| 1706 |
| 1707 // Now kick things off |
| 1708 MessageLoop::current()->Run(); |
| 1709 |
| 1710 EXPECT_EQ(foo->test_count(), 1); |
| 1711 EXPECT_EQ(foo->result(), "a"); |
| 1712 } |
OLD | NEW |