diff options
author | huangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-13 06:07:39 +0000 |
---|---|---|
committer | huangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-13 06:07:39 +0000 |
commit | 091fde9f0eb0276083aeacf3066d8752424c26a3 (patch) | |
tree | e47f91060a4f35596861994607f01a88d9ff3148 | |
parent | 10c5025f3f00b024d6915e4c12d47d15a20fb004 (diff) | |
download | chromium_src-091fde9f0eb0276083aeacf3066d8752424c26a3.zip chromium_src-091fde9f0eb0276083aeacf3066d8752424c26a3.tar.gz chromium_src-091fde9f0eb0276083aeacf3066d8752424c26a3.tar.bz2 |
Add documentation and a unit test for ObjectWatcher.
This documentation clarifies the expected behaviour when a watched PROCESS finishes before observation using ObjectWatcher begins. A unit-test confirms that the behaviour is as expected.
BUG=None
TEST=base_unittests --gtest_filter=ObjectWatcherTest.*
Review URL: https://chromiumcodereview.appspot.com/10979071
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161735 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/win/object_watcher.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | base/win/object_watcher_unittest.cc | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/base/win/object_watcher.h b/base/win/object_watcher.h index 6a570b2..742f2b0 100644 --- a/base/win/object_watcher.h +++ b/base/win/object_watcher.h @@ -42,6 +42,8 @@ namespace win { // signaled. ObjectWatcher makes this task easy. When MyClass goes out of // scope, the watcher_ will be destroyed, and there is no need to worry about // OnObjectSignaled being called on a deleted MyClass pointer. Easy! +// If the object is already signaled before being watched, OnObjectSignaled is +// still called after (but not necessarily immediately after) watch is started. // class BASE_EXPORT ObjectWatcher : public MessageLoop::DestructionObserver { public: diff --git a/base/win/object_watcher_unittest.cc b/base/win/object_watcher_unittest.cc index fe151d9..b4e0255 100644..100755 --- a/base/win/object_watcher_unittest.cc +++ b/base/win/object_watcher_unittest.cc @@ -70,7 +70,6 @@ void RunTest_BasicCancel(MessageLoop::Type message_loop_type) { CloseHandle(event); } - void RunTest_CancelAfterSet(MessageLoop::Type message_loop_type) { MessageLoop message_loop(message_loop_type); @@ -79,7 +78,7 @@ void RunTest_CancelAfterSet(MessageLoop::Type message_loop_type) { int counter = 1; DecrementCountDelegate delegate(&counter); - // A manual-reset event that is not yet signaled. + // A manual-reset event that is not yet signaled. HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); bool ok = watcher.StartWatching(event, &delegate); @@ -100,6 +99,24 @@ void RunTest_CancelAfterSet(MessageLoop::Type message_loop_type) { CloseHandle(event); } +void RunTest_SignalBeforeWatch(MessageLoop::Type message_loop_type) { + MessageLoop message_loop(message_loop_type); + + ObjectWatcher watcher; + + // A manual-reset event that is signaled before we begin watching. + HANDLE event = CreateEvent(NULL, TRUE, TRUE, NULL); + + QuitDelegate delegate; + bool ok = watcher.StartWatching(event, &delegate); + EXPECT_TRUE(ok); + + MessageLoop::current()->Run(); + + EXPECT_EQ(NULL, watcher.GetWatchedObject()); + CloseHandle(event); +} + void RunTest_OutlivesMessageLoop(MessageLoop::Type message_loop_type) { // Simulate a MessageLoop that dies before an ObjectWatcher. This ordinarily // doesn't happen when people use the Thread class, but it can happen when @@ -139,6 +156,12 @@ TEST(ObjectWatcherTest, CancelAfterSet) { RunTest_CancelAfterSet(MessageLoop::TYPE_UI); } +TEST(ObjectWatcherTest, SignalBeforeWatch) { + RunTest_SignalBeforeWatch(MessageLoop::TYPE_DEFAULT); + RunTest_SignalBeforeWatch(MessageLoop::TYPE_IO); + RunTest_SignalBeforeWatch(MessageLoop::TYPE_UI); +} + TEST(ObjectWatcherTest, OutlivesMessageLoop) { RunTest_OutlivesMessageLoop(MessageLoop::TYPE_DEFAULT); RunTest_OutlivesMessageLoop(MessageLoop::TYPE_IO); |