Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(887)

Side by Side Diff: base/message_loop_unittest.cc

Issue 87045: Plug hole in struct event lifecycle; should fix bug 10503 (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_pump_libevent.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/logging.h" 5 #include "base/logging.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/ref_counted.h" 8 #include "base/ref_counted.h"
9 #include "base/thread.h" 9 #include "base/thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 #if defined(OS_WIN) 12 #if defined(OS_WIN)
13 #include "base/message_pump_win.h" 13 #include "base/message_pump_win.h"
14 #include "base/scoped_handle.h" 14 #include "base/scoped_handle.h"
15 #endif 15 #endif
16 #if defined(OS_POSIX)
17 #include "base/message_pump_libevent.h"
18 #endif
16 19
17 using base::Thread; 20 using base::Thread;
18 using base::Time; 21 using base::Time;
19 using base::TimeDelta; 22 using base::TimeDelta;
20 23
21 // TODO(darin): Platform-specific MessageLoop tests should be grouped together 24 // TODO(darin): Platform-specific MessageLoop tests should be grouped together
22 // to avoid chopping this file up with so many #ifdefs. 25 // to avoid chopping this file up with so many #ifdefs.
23 26
24 namespace { 27 namespace {
25 28
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 } 1377 }
1375 1378
1376 TEST(MessageLoopTest, IOHandler) { 1379 TEST(MessageLoopTest, IOHandler) {
1377 RunTest_IOHandler(); 1380 RunTest_IOHandler();
1378 } 1381 }
1379 1382
1380 TEST(MessageLoopTest, WaitForIO) { 1383 TEST(MessageLoopTest, WaitForIO) {
1381 RunTest_WaitForIO(); 1384 RunTest_WaitForIO();
1382 } 1385 }
1383 #endif // defined(OS_WIN) 1386 #endif // defined(OS_WIN)
1387
1388 #if defined(OS_POSIX)
1389
1390 namespace {
1391
1392 class QuitDelegate : public
1393 base::MessagePumpLibevent::Watcher {
1394 public:
1395 virtual void OnFileCanWriteWithoutBlocking(int fd) {
1396 MessageLoop::current()->Quit();
1397 }
1398 virtual void OnFileCanReadWithoutBlocking(int fd) {
1399 MessageLoop::current()->Quit();
1400 }
1401 };
1402
1403 } // namespace
1404
1405 TEST(MessageLoopTest, DISABLED_FileDescriptorWatcherOutlivesMessageLoop) {
1406 // Simulate a MessageLoop that dies before an FileDescriptorWatcher.
1407 // This could happen when people use the Singleton pattern or atexit.
1408 // This is disabled for now because it fails (valgrind shows
1409 // invalid reads), and it's not clear any code relies on this...
1410 // TODO(dkegel): enable if it turns out we rely on this
1411
1412 // Create a file descriptor. Doesn't need to be readable or writable,
1413 // as we don't need to actually get any notifications.
1414 // pipe() is just the easiest way to do it.
1415 int pipefds[2];
1416 int err = pipe(pipefds);
1417 ASSERT_TRUE(err == 0);
1418 int fd = pipefds[1];
1419 {
1420 // Arrange for controller to live longer than message loop.
1421 base::MessagePumpLibevent::FileDescriptorWatcher controller;
1422 {
1423 MessageLoopForIO message_loop;
1424
1425 QuitDelegate delegate;
1426 message_loop.WatchFileDescriptor(fd,
1427 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate);
1428 // and don't run the message loop, just destroy it.
1429 }
1430 }
1431 close(pipefds[0]);
1432 close(pipefds[1]);
1433 }
1434
1435 TEST(MessageLoopTest, FileDescriptorWatcherDoubleStop) {
1436 // Verify that it's ok to call StopWatchingFileDescriptor().
1437 // (Errors only showed up in valgrind.)
1438 int pipefds[2];
1439 int err = pipe(pipefds);
1440 ASSERT_TRUE(err == 0);
1441 int fd = pipefds[1];
1442 {
1443 // Arrange for message loop to live longer than controller.
1444 MessageLoopForIO message_loop;
1445 {
1446 base::MessagePumpLibevent::FileDescriptorWatcher controller;
1447
1448 QuitDelegate delegate;
1449 message_loop.WatchFileDescriptor(fd,
1450 true, MessageLoopForIO::WATCH_WRITE, &controller, &delegate);
1451 controller.StopWatchingFileDescriptor();
1452 }
1453 }
1454 close(pipefds[0]);
1455 close(pipefds[1]);
1456 }
1457
1458 #endif // defined(OS_LINUX)
OLDNEW
« no previous file with comments | « no previous file | base/message_pump_libevent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698