OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/logging.h" | 10 #include "base/logging.h" |
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 // posts tasks on that message loop. | 900 // posts tasks on that message loop. |
901 TEST(MessageLoopTest, ThreadMainTaskRunner) { | 901 TEST(MessageLoopTest, ThreadMainTaskRunner) { |
902 MessageLoop loop; | 902 MessageLoop loop; |
903 | 903 |
904 scoped_refptr<Foo> foo(new Foo()); | 904 scoped_refptr<Foo> foo(new Foo()); |
905 std::string a("a"); | 905 std::string a("a"); |
906 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, Bind( | 906 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, Bind( |
907 &Foo::Test1ConstRef, foo.get(), a)); | 907 &Foo::Test1ConstRef, foo.get(), a)); |
908 | 908 |
909 // Post quit task; | 909 // Post quit task; |
910 MessageLoop::current()->PostTask(FROM_HERE, Bind( | 910 MessageLoop::current()->PostTask( |
911 &MessageLoop::Quit, Unretained(MessageLoop::current()))); | 911 FROM_HERE, |
| 912 Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); |
912 | 913 |
913 // Now kick things off | 914 // Now kick things off |
914 MessageLoop::current()->Run(); | 915 MessageLoop::current()->Run(); |
915 | 916 |
916 EXPECT_EQ(foo->test_count(), 1); | 917 EXPECT_EQ(foo->test_count(), 1); |
917 EXPECT_EQ(foo->result(), "a"); | 918 EXPECT_EQ(foo->result(), "a"); |
918 } | 919 } |
919 | 920 |
920 TEST(MessageLoopTest, IsType) { | 921 TEST(MessageLoopTest, IsType) { |
921 MessageLoop loop(MessageLoop::TYPE_UI); | 922 MessageLoop loop(MessageLoop::TYPE_UI); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 while (GetMessage(&msg, 0, 0, 0)) { | 977 while (GetMessage(&msg, 0, 0, 0)) { |
977 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) | 978 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) |
978 DispatchMessage(&msg); | 979 DispatchMessage(&msg); |
979 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting | 980 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting |
980 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats | 981 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats |
981 // WM_QUIT messages even when running inside a modal loop. | 982 // WM_QUIT messages even when running inside a modal loop. |
982 if (msg.message == WM_CLOSE) | 983 if (msg.message == WM_CLOSE) |
983 break; | 984 break; |
984 } | 985 } |
985 EXPECT_TRUE(did_run); | 986 EXPECT_TRUE(did_run); |
986 MessageLoop::current()->Quit(); | 987 MessageLoop::current()->QuitWhenIdle(); |
987 break; | 988 break; |
988 } | 989 } |
989 return 0; | 990 return 0; |
990 } | 991 } |
991 | 992 |
992 TEST(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) { | 993 TEST(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) { |
993 MessageLoop loop(MessageLoop::TYPE_UI); | 994 MessageLoop loop(MessageLoop::TYPE_UI); |
994 HINSTANCE instance = GetModuleFromAddress(&TestWndProcThunk); | 995 HINSTANCE instance = GetModuleFromAddress(&TestWndProcThunk); |
995 WNDCLASSEX wc = {0}; | 996 WNDCLASSEX wc = {0}; |
996 wc.cbSize = sizeof(wc); | 997 wc.cbSize = sizeof(wc); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 loop.SetTaskRunner(new_runner); | 1029 loop.SetTaskRunner(new_runner); |
1029 | 1030 |
1030 scoped_refptr<Foo> foo(new Foo()); | 1031 scoped_refptr<Foo> foo(new Foo()); |
1031 original_runner->PostTask(FROM_HERE, | 1032 original_runner->PostTask(FROM_HERE, |
1032 Bind(&Foo::Test1ConstRef, foo.get(), "a")); | 1033 Bind(&Foo::Test1ConstRef, foo.get(), "a")); |
1033 loop.RunUntilIdle(); | 1034 loop.RunUntilIdle(); |
1034 EXPECT_EQ(1, foo->test_count()); | 1035 EXPECT_EQ(1, foo->test_count()); |
1035 } | 1036 } |
1036 | 1037 |
1037 } // namespace base | 1038 } // namespace base |
OLD | NEW |