| 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 "base/message_loop/message_loop_test.h" | 5 #include "base/message_loop/message_loop_test.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 } // namespace | 92 } // namespace |
| 93 | 93 |
| 94 void RunTest_PostTask(MessagePumpFactory factory) { | 94 void RunTest_PostTask(MessagePumpFactory factory) { |
| 95 std::unique_ptr<MessagePump> pump(factory()); | 95 std::unique_ptr<MessagePump> pump(factory()); |
| 96 MessageLoop loop(std::move(pump)); | 96 MessageLoop loop(std::move(pump)); |
| 97 // Add tests to message loop | 97 // Add tests to message loop |
| 98 scoped_refptr<Foo> foo(new Foo()); | 98 scoped_refptr<Foo> foo(new Foo()); |
| 99 std::string a("a"), b("b"), c("c"), d("d"); | 99 std::string a("a"), b("b"), c("c"), d("d"); |
| 100 MessageLoop::current()->task_runner()->PostTask(FROM_HERE, | 100 MessageLoop::current()->task_runner()->PostTask(FROM_HERE, |
| 101 Bind(&Foo::Test0, foo.get())); | 101 Bind(&Foo::Test0, foo)); |
| 102 MessageLoop::current()->task_runner()->PostTask( | 102 MessageLoop::current()->task_runner()->PostTask( |
| 103 FROM_HERE, Bind(&Foo::Test1ConstRef, foo.get(), a)); | 103 FROM_HERE, Bind(&Foo::Test1ConstRef, foo, a)); |
| 104 MessageLoop::current()->task_runner()->PostTask( | 104 MessageLoop::current()->task_runner()->PostTask( |
| 105 FROM_HERE, Bind(&Foo::Test1Ptr, foo.get(), &b)); | 105 FROM_HERE, Bind(&Foo::Test1Ptr, foo, &b)); |
| 106 MessageLoop::current()->task_runner()->PostTask( | 106 MessageLoop::current()->task_runner()->PostTask( |
| 107 FROM_HERE, Bind(&Foo::Test1Int, foo.get(), 100)); | 107 FROM_HERE, Bind(&Foo::Test1Int, foo, 100)); |
| 108 MessageLoop::current()->task_runner()->PostTask( | 108 MessageLoop::current()->task_runner()->PostTask( |
| 109 FROM_HERE, Bind(&Foo::Test2Ptr, foo.get(), &a, &c)); | 109 FROM_HERE, Bind(&Foo::Test2Ptr, foo, &a, &c)); |
| 110 MessageLoop::current()->task_runner()->PostTask( | 110 MessageLoop::current()->task_runner()->PostTask( |
| 111 FROM_HERE, Bind(&Foo::Test2Mixed, foo.get(), a, &d)); | 111 FROM_HERE, Bind(&Foo::Test2Mixed, foo, a, &d)); |
| 112 // After all tests, post a message that will shut down the message loop | 112 // After all tests, post a message that will shut down the message loop |
| 113 MessageLoop::current()->task_runner()->PostTask( | 113 MessageLoop::current()->task_runner()->PostTask( |
| 114 FROM_HERE, | 114 FROM_HERE, |
| 115 Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); | 115 Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); |
| 116 | 116 |
| 117 // Now kick things off | 117 // Now kick things off |
| 118 RunLoop().Run(); | 118 RunLoop().Run(); |
| 119 | 119 |
| 120 EXPECT_EQ(foo->test_count(), 105); | 120 EXPECT_EQ(foo->test_count(), 105); |
| 121 EXPECT_EQ(foo->result(), "abacad"); | 121 EXPECT_EQ(foo->result(), "abacad"); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 296 } |
| 297 void Run() {} | 297 void Run() {} |
| 298 | 298 |
| 299 private: | 299 private: |
| 300 friend class RefCounted<RecordDeletionProbe>; | 300 friend class RefCounted<RecordDeletionProbe>; |
| 301 | 301 |
| 302 ~RecordDeletionProbe() { | 302 ~RecordDeletionProbe() { |
| 303 *was_deleted_ = true; | 303 *was_deleted_ = true; |
| 304 if (post_on_delete_.get()) | 304 if (post_on_delete_.get()) |
| 305 MessageLoop::current()->task_runner()->PostTask( | 305 MessageLoop::current()->task_runner()->PostTask( |
| 306 FROM_HERE, Bind(&RecordDeletionProbe::Run, post_on_delete_.get())); | 306 FROM_HERE, Bind(&RecordDeletionProbe::Run, post_on_delete_)); |
| 307 } | 307 } |
| 308 | 308 |
| 309 scoped_refptr<RecordDeletionProbe> post_on_delete_; | 309 scoped_refptr<RecordDeletionProbe> post_on_delete_; |
| 310 bool* was_deleted_; | 310 bool* was_deleted_; |
| 311 }; | 311 }; |
| 312 | 312 |
| 313 void RunTest_EnsureDeletion(MessagePumpFactory factory) { | 313 void RunTest_EnsureDeletion(MessagePumpFactory factory) { |
| 314 bool a_was_deleted = false; | 314 bool a_was_deleted = false; |
| 315 bool b_was_deleted = false; | 315 bool b_was_deleted = false; |
| 316 { | 316 { |
| (...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 void RunTest_RecursivePosts(MessagePumpFactory factory) { | 1046 void RunTest_RecursivePosts(MessagePumpFactory factory) { |
| 1047 const int kNumTimes = 1 << 17; | 1047 const int kNumTimes = 1 << 17; |
| 1048 std::unique_ptr<MessagePump> pump(factory()); | 1048 std::unique_ptr<MessagePump> pump(factory()); |
| 1049 MessageLoop loop(std::move(pump)); | 1049 MessageLoop loop(std::move(pump)); |
| 1050 loop.task_runner()->PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); | 1050 loop.task_runner()->PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); |
| 1051 RunLoop().Run(); | 1051 RunLoop().Run(); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 } // namespace test | 1054 } // namespace test |
| 1055 } // namespace base | 1055 } // namespace base |
| OLD | NEW |