| 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" |
| 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_proxy_impl.h" |
| 13 #include "base/pending_task.h" | 14 #include "base/pending_task.h" |
| 14 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 15 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
| 18 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
| 19 #include "base/threading/thread.h" | 20 #include "base/threading/thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 23 #include "base/message_loop/message_pump_win.h" | 24 #include "base/message_loop/message_pump_win.h" |
| 24 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 25 #endif | 26 #endif |
| 26 | 27 |
| 27 namespace base { | 28 namespace base { |
| 28 | 29 |
| 29 class MessageLoopLockTest { | 30 class MessageLoopLockTest { |
| 30 public: | 31 public: |
| 31 static void LockWaitUnLock(MessageLoop* loop, | 32 static void LockWaitUnLock(MessageLoop* loop, |
| 32 WaitableEvent* caller_wait, | 33 WaitableEvent* caller_wait, |
| 33 WaitableEvent* caller_signal) { | 34 WaitableEvent* caller_signal) { |
| 34 | 35 |
| 35 loop->incoming_queue_lock_.Acquire(); | 36 loop->message_loop_proxy_->incoming_queue_lock_.Acquire(); |
| 36 caller_wait->Signal(); | 37 caller_wait->Signal(); |
| 37 caller_signal->Wait(); | 38 caller_signal->Wait(); |
| 38 loop->incoming_queue_lock_.Release(); | 39 loop->message_loop_proxy_->incoming_queue_lock_.Release(); |
| 39 } | 40 } |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 // TODO(darin): Platform-specific MessageLoop tests should be grouped together | 43 // TODO(darin): Platform-specific MessageLoop tests should be grouped together |
| 43 // to avoid chopping this file up with so many #ifdefs. | 44 // to avoid chopping this file up with so many #ifdefs. |
| 44 | 45 |
| 45 namespace { | 46 namespace { |
| 46 | 47 |
| 47 class Foo : public RefCounted<Foo> { | 48 class Foo : public RefCounted<Foo> { |
| 48 public: | 49 public: |
| (...skipping 1839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1888 TEST(MessageLoopTest, WaitForIO) { | 1889 TEST(MessageLoopTest, WaitForIO) { |
| 1889 RunTest_WaitForIO(); | 1890 RunTest_WaitForIO(); |
| 1890 } | 1891 } |
| 1891 | 1892 |
| 1892 TEST(MessageLoopTest, HighResolutionTimer) { | 1893 TEST(MessageLoopTest, HighResolutionTimer) { |
| 1893 MessageLoop loop; | 1894 MessageLoop loop; |
| 1894 | 1895 |
| 1895 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); | 1896 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); |
| 1896 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); | 1897 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); |
| 1897 | 1898 |
| 1898 EXPECT_FALSE(loop.high_resolution_timers_enabled()); | 1899 EXPECT_FALSE(loop.IsHishResolutionTimersEnabledForTest()); |
| 1899 | 1900 |
| 1900 // Post a fast task to enable the high resolution timers. | 1901 // Post a fast task to enable the high resolution timers. |
| 1901 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), | 1902 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), |
| 1902 kFastTimer); | 1903 kFastTimer); |
| 1903 loop.Run(); | 1904 loop.Run(); |
| 1904 EXPECT_TRUE(loop.high_resolution_timers_enabled()); | 1905 EXPECT_TRUE(loop.IsHishResolutionTimersEnabledForTest()); |
| 1905 | 1906 |
| 1906 // Post a slow task and verify high resolution timers | 1907 // Post a slow task and verify high resolution timers |
| 1907 // are still enabled. | 1908 // are still enabled. |
| 1908 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), | 1909 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), |
| 1909 kSlowTimer); | 1910 kSlowTimer); |
| 1910 loop.Run(); | 1911 loop.Run(); |
| 1911 EXPECT_TRUE(loop.high_resolution_timers_enabled()); | 1912 EXPECT_TRUE(loop.IsHishResolutionTimersEnabledForTest()); |
| 1912 | 1913 |
| 1913 // Wait for a while so that high-resolution mode elapses. | 1914 // Wait for a while so that high-resolution mode elapses. |
| 1914 PlatformThread::Sleep(TimeDelta::FromMilliseconds( | 1915 PlatformThread::Sleep(TimeDelta::FromMilliseconds( |
| 1915 MessageLoop::kHighResolutionTimerModeLeaseTimeMs)); | 1916 MessageLoop::kHighResolutionTimerModeLeaseTimeMs)); |
| 1916 | 1917 |
| 1917 // Post a slow task to disable the high resolution timers. | 1918 // Post a slow task to disable the high resolution timers. |
| 1918 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), | 1919 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), |
| 1919 kSlowTimer); | 1920 kSlowTimer); |
| 1920 loop.Run(); | 1921 loop.Run(); |
| 1921 EXPECT_FALSE(loop.high_resolution_timers_enabled()); | 1922 EXPECT_FALSE(loop.IsHishResolutionTimersEnabledForTest()); |
| 1922 } | 1923 } |
| 1923 | 1924 |
| 1924 #endif // defined(OS_WIN) | 1925 #endif // defined(OS_WIN) |
| 1925 | 1926 |
| 1926 #if defined(OS_POSIX) && !defined(OS_NACL) | 1927 #if defined(OS_POSIX) && !defined(OS_NACL) |
| 1927 | 1928 |
| 1928 namespace { | 1929 namespace { |
| 1929 | 1930 |
| 1930 class QuitDelegate : public MessageLoopForIO::Watcher { | 1931 class QuitDelegate : public MessageLoopForIO::Watcher { |
| 1931 public: | 1932 public: |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2107 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one | 2108 // On Linux, the pipe buffer size is 64KiB by default. The bug caused one |
| 2108 // byte accumulated in the pipe per two posts, so we should repeat 128K | 2109 // byte accumulated in the pipe per two posts, so we should repeat 128K |
| 2109 // times to reproduce the bug. | 2110 // times to reproduce the bug. |
| 2110 const int kNumTimes = 1 << 17; | 2111 const int kNumTimes = 1 << 17; |
| 2111 RunTest_RecursivePosts(MessageLoop::TYPE_DEFAULT, kNumTimes); | 2112 RunTest_RecursivePosts(MessageLoop::TYPE_DEFAULT, kNumTimes); |
| 2112 RunTest_RecursivePosts(MessageLoop::TYPE_UI, kNumTimes); | 2113 RunTest_RecursivePosts(MessageLoop::TYPE_UI, kNumTimes); |
| 2113 RunTest_RecursivePosts(MessageLoop::TYPE_IO, kNumTimes); | 2114 RunTest_RecursivePosts(MessageLoop::TYPE_IO, kNumTimes); |
| 2114 } | 2115 } |
| 2115 | 2116 |
| 2116 } // namespace base | 2117 } // namespace base |
| OLD | NEW |