diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 05:53:57 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-26 05:53:57 +0000 |
commit | 4d9bdfafcd1393385860bc9fe947e0c07719c0f4 (patch) | |
tree | 67c91c3fa4c658352995e22b894535e60b04f282 /base/object_watcher_unittest.cc | |
parent | 3c17b9c00d5fc28f5523ab60b0df502dd7c2a596 (diff) | |
download | chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.zip chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.tar.gz chromium_src-4d9bdfafcd1393385860bc9fe947e0c07719c0f4.tar.bz2 |
Allow consumers of MessageLoop to specify the type of MessageLoop they want.
This CL introduces a Type enum to MessageLoop, and I also created subclasses of MessageLoop corresponding to the non-default types: MessageLoopForIO and MessageLoopForUI.
I moved all of the platform-specific MessageLoop APIs onto either MessageLoopForIO or MessageLoopForUI. MessageLoopForIO gets the Watcher API, and MessageLoopForUI gets the Observer and Dispatcher APIs. Under the hood, both are implemented in terms of MessagePumpWin, but that will change in a future CL.
The Thread class is changed to allow the consumer to specify the Type of MessageLoop they want to have setup on the created thread.
I re-organized message_loop_unittest.cc and timer_unittest.cc so that I could exercise all (or most) of the tests against each type of MessageLoop.
Note: I know that "explicit MessageLoop(Type type = TYPE_DEFAULT);" is in violation to the style-guide's restriction against default arguments. I'm working on finding a decent solution to that problem. Please ignore this issue for now.
The corresponding chrome/ changes are coming in a separate CL due to Reitveld data size limitations.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1362 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/object_watcher_unittest.cc')
-rw-r--r-- | base/object_watcher_unittest.cc | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/base/object_watcher_unittest.cc b/base/object_watcher_unittest.cc index 1598d76..d830dfc 100644 --- a/base/object_watcher_unittest.cc +++ b/base/object_watcher_unittest.cc @@ -9,6 +9,7 @@ #include "testing/gtest/include/gtest/gtest.h" namespace { + typedef testing::Test ObjectWatcherTest; class QuitDelegate : public base::ObjectWatcher::Delegate { @@ -29,9 +30,11 @@ class DecrementCountDelegate : public base::ObjectWatcher::Delegate { int* counter_; }; -} +} // namespace TEST(ObjectWatcherTest, BasicSignal) { + MessageLoop message_loop; + base::ObjectWatcher watcher; // A manual-reset event that is not yet signaled. @@ -49,6 +52,8 @@ TEST(ObjectWatcherTest, BasicSignal) { } TEST(ObjectWatcherTest, BasicCancel) { + MessageLoop message_loop; + base::ObjectWatcher watcher; // A manual-reset event that is not yet signaled. @@ -65,6 +70,8 @@ TEST(ObjectWatcherTest, BasicCancel) { TEST(ObjectWatcherTest, CancelAfterSet) { + MessageLoop message_loop; + base::ObjectWatcher watcher; int counter = 1; @@ -91,10 +98,10 @@ TEST(ObjectWatcherTest, CancelAfterSet) { CloseHandle(event); } -// Used so we can simulate a MessageLoop that dies before an ObjectWatcher. -// This ordinarily doesn't happen when people use the Thread class, but it can -// happen when people use the Singleton pattern or atexit. -static unsigned __stdcall ThreadFunc(void* param) { +TEST(ObjectWatcherTest, OutlivesMessageLoop) { + // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily + // doesn't happen when people use the Thread class, but it can happen when + // people use the Singleton pattern or atexit. HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled { base::ObjectWatcher watcher; @@ -106,19 +113,4 @@ static unsigned __stdcall ThreadFunc(void* param) { } } CloseHandle(event); - return 0; } - -TEST(ObjectWatcherTest, OutlivesMessageLoop) { - unsigned int thread_id; - HANDLE thread = reinterpret_cast<HANDLE>( - _beginthreadex(NULL, - 0, - ThreadFunc, - NULL, - 0, - &thread_id)); - WaitForSingleObject(thread, INFINITE); - CloseHandle(thread); -} - |