From 840246b68b70b0d1faa5d19d552daaa3b361189e Mon Sep 17 00:00:00 2001 From: "leng@chromium.org" Date: Wed, 18 Jul 2012 08:06:50 +0000 Subject: Change explicit usage of each type of message loop in WaitableEventWatcher tests to instead loop through an array of message loop types. This allows for easier-to-read code while including a platform that cannot run the tests on every kind of message loop. Specifically, iOS cannot run the UI loop for unit tests. Un-exclude synchronization/waitable_event_watcher_unittest.cc on ios in base.gyp. BUG=b/6825256 TEST=None Review URL: https://chromiumcodereview.appspot.com/10790028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147198 0039d316-1c4b-4281-b951-d872f2087c98 --- .../waitable_event_watcher_unittest.cc | 41 ++++++++++++++-------- 1 file changed, 26 insertions(+), 15 deletions(-) (limited to 'base/synchronization') diff --git a/base/synchronization/waitable_event_watcher_unittest.cc b/base/synchronization/waitable_event_watcher_unittest.cc index c48333a..8fa4e7b 100644 --- a/base/synchronization/waitable_event_watcher_unittest.cc +++ b/base/synchronization/waitable_event_watcher_unittest.cc @@ -12,6 +12,17 @@ namespace base { namespace { +// The message loops on which each waitable event timer should be tested. +const MessageLoop::Type testing_message_loops[] = { + MessageLoop::TYPE_DEFAULT, + MessageLoop::TYPE_IO, +#if !defined(OS_IOS) // iOS does not allow direct running of the UI loop. + MessageLoop::TYPE_UI, +#endif +}; + +const int kNumTestingMessageLoops = arraysize(testing_message_loops); + class QuitDelegate : public WaitableEventWatcher::Delegate { public: virtual void OnWaitableEventSignaled(WaitableEvent* event) OVERRIDE { @@ -127,27 +138,27 @@ void RunTest_DeleteUnder(MessageLoop::Type message_loop_type) { //----------------------------------------------------------------------------- TEST(WaitableEventWatcherTest, BasicSignal) { - RunTest_BasicSignal(MessageLoop::TYPE_DEFAULT); - RunTest_BasicSignal(MessageLoop::TYPE_IO); - RunTest_BasicSignal(MessageLoop::TYPE_UI); + for (int i = 0; i < kNumTestingMessageLoops; i++) { + RunTest_BasicSignal(testing_message_loops[i]); + } } TEST(WaitableEventWatcherTest, BasicCancel) { - RunTest_BasicCancel(MessageLoop::TYPE_DEFAULT); - RunTest_BasicCancel(MessageLoop::TYPE_IO); - RunTest_BasicCancel(MessageLoop::TYPE_UI); + for (int i = 0; i < kNumTestingMessageLoops; i++) { + RunTest_BasicCancel(testing_message_loops[i]); + } } TEST(WaitableEventWatcherTest, CancelAfterSet) { - RunTest_CancelAfterSet(MessageLoop::TYPE_DEFAULT); - RunTest_CancelAfterSet(MessageLoop::TYPE_IO); - RunTest_CancelAfterSet(MessageLoop::TYPE_UI); + for (int i = 0; i < kNumTestingMessageLoops; i++) { + RunTest_CancelAfterSet(testing_message_loops[i]); + } } TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { - RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); - RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); - RunTest_OutlivesMessageLoop(MessageLoop::TYPE_UI); + for (int i = 0; i < kNumTestingMessageLoops; i++) { + RunTest_OutlivesMessageLoop(testing_message_loops[i]); + } } #if defined(OS_WIN) @@ -157,9 +168,9 @@ TEST(WaitableEventWatcherTest, OutlivesMessageLoop) { #define MAYBE_DeleteUnder DeleteUnder #endif TEST(WaitableEventWatcherTest, MAYBE_DeleteUnder) { - RunTest_DeleteUnder(MessageLoop::TYPE_DEFAULT); - RunTest_DeleteUnder(MessageLoop::TYPE_IO); - RunTest_DeleteUnder(MessageLoop::TYPE_UI); + for (int i = 0; i < kNumTestingMessageLoops; i++) { + RunTest_DeleteUnder(testing_message_loops[i]); + } } } // namespace base -- cgit v1.1