diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-05 23:16:41 +0000 |
commit | 2a1272586d0ab6719820ea25ac596683b33d0676 (patch) | |
tree | 3f0203f0cc289e067d9668d73265832e5ecf6742 /base/object_watcher_unittest.cc | |
parent | 836dff30efbff95f2090a024da25debe4edd2f83 (diff) | |
download | chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.zip chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.gz chromium_src-2a1272586d0ab6719820ea25ac596683b33d0676.tar.bz2 |
ObjectWatcher needs to know when the current thread's MessageLoop is being destroyed. This might also be generically useful, so I added a new API on ML to observe when the ML is being destroyed. The notification is sent to observers just prior to ML::current() being modified to return NULL.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/object_watcher_unittest.cc')
-rw-r--r-- | base/object_watcher_unittest.cc | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/base/object_watcher_unittest.cc b/base/object_watcher_unittest.cc index 51ed968..6c3fcce 100644 --- a/base/object_watcher_unittest.cc +++ b/base/object_watcher_unittest.cc @@ -27,6 +27,8 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <process.h> + #include "base/message_loop.h" #include "base/object_watcher.h" #include "testing/gtest/include/gtest/gtest.h" @@ -113,3 +115,34 @@ 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) { + HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); // not signaled + { + base::ObjectWatcher watcher; + { + MessageLoop message_loop; + + QuitDelegate delegate; + watcher.StartWatching(event, &delegate); + } + } + 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); +} |