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

Side by Side Diff: base/message_loop/message_loop_unittest.cc

Issue 998063002: base: Make it possible to replace the MessageLoop's task runner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix data race (see https://codereview.chromium.org/1232573002/) Created 5 years, 5 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
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/message_loop/message_loop_test.h" 13 #include "base/message_loop/message_loop_test.h"
14 #include "base/pending_task.h" 14 #include "base/pending_task.h"
15 #include "base/posix/eintr_wrapper.h" 15 #include "base/posix/eintr_wrapper.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/test/test_simple_task_runner.h"
18 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
19 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
20 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 #if defined(OS_WIN) 24 #if defined(OS_WIN)
24 #include "base/message_loop/message_pump_dispatcher.h" 25 #include "base/message_loop/message_pump_dispatcher.h"
25 #include "base/message_loop/message_pump_win.h" 26 #include "base/message_loop/message_pump_win.h"
26 #include "base/process/memory.h" 27 #include "base/process/memory.h"
27 #include "base/strings/string16.h" 28 #include "base/strings/string16.h"
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 ASSERT_TRUE(message_hwnd) << GetLastError(); 1005 ASSERT_TRUE(message_hwnd) << GetLastError();
1005 1006
1006 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); 1007 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1));
1007 1008
1008 loop.Run(); 1009 loop.Run();
1009 1010
1010 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); 1011 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance));
1011 } 1012 }
1012 #endif // defined(OS_WIN) 1013 #endif // defined(OS_WIN)
1013 1014
1015 TEST(MessageLoopTest, SetTaskRunner) {
1016 MessageLoop loop;
1017 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner());
1018
1019 loop.SetTaskRunner(new_runner);
1020 EXPECT_EQ(new_runner, loop.task_runner());
1021 EXPECT_EQ(new_runner, ThreadTaskRunnerHandle::Get());
1022 }
1023
1024 TEST(MessageLoopTest, OriginalRunnerWorks) {
1025 MessageLoop loop;
1026 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner());
1027 scoped_refptr<SingleThreadTaskRunner> original_runner(loop.task_runner());
1028 loop.SetTaskRunner(new_runner);
1029
1030 scoped_refptr<Foo> foo(new Foo());
1031 original_runner->PostTask(FROM_HERE,
1032 Bind(&Foo::Test1ConstRef, foo.get(), "a"));
1033 loop.RunUntilIdle();
1034 EXPECT_EQ(1, foo->test_count());
1035 }
1036
1014 } // namespace base 1037 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698