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

Side by Side Diff: base/message_loop/message_loop_unittest.cc

Issue 593113004: Remove implicit HANDLE conversions from base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 3 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
« no previous file with comments | « base/files/file_win.cc ('k') | base/message_loop/message_pump_win.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 TaskList order; 326 TaskList order;
327 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); 327 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL));
328 worker.message_loop()->PostTask(FROM_HERE, 328 worker.message_loop()->PostTask(FROM_HERE,
329 Bind(&RecursiveFuncWin, 329 Bind(&RecursiveFuncWin,
330 MessageLoop::current(), 330 MessageLoop::current(),
331 event.Get(), 331 event.Get(),
332 true, 332 true,
333 &order, 333 &order,
334 false)); 334 false));
335 // Let the other thread execute. 335 // Let the other thread execute.
336 WaitForSingleObject(event, INFINITE); 336 WaitForSingleObject(event.Get(), INFINITE);
337 MessageLoop::current()->Run(); 337 MessageLoop::current()->Run();
338 338
339 ASSERT_EQ(order.Size(), 17); 339 ASSERT_EQ(order.Size(), 17);
340 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); 340 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true));
341 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); 341 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false));
342 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); 342 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true));
343 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); 343 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false));
344 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); 344 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true));
345 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false)); 345 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false));
346 // When EndDialogFunc is processed, the window is already dismissed, hence no 346 // When EndDialogFunc is processed, the window is already dismissed, hence no
(...skipping 23 matching lines...) Expand all
370 TaskList order; 370 TaskList order;
371 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); 371 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL));
372 worker.message_loop()->PostTask(FROM_HERE, 372 worker.message_loop()->PostTask(FROM_HERE,
373 Bind(&RecursiveFuncWin, 373 Bind(&RecursiveFuncWin,
374 MessageLoop::current(), 374 MessageLoop::current(),
375 event.Get(), 375 event.Get(),
376 false, 376 false,
377 &order, 377 &order,
378 true)); 378 true));
379 // Let the other thread execute. 379 // Let the other thread execute.
380 WaitForSingleObject(event, INFINITE); 380 WaitForSingleObject(event.Get(), INFINITE);
381 MessageLoop::current()->Run(); 381 MessageLoop::current()->Run();
382 382
383 ASSERT_EQ(order.Size(), 18); 383 ASSERT_EQ(order.Size(), 18);
384 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); 384 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true));
385 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); 385 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false));
386 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); 386 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true));
387 // Note that this executes in the MessageBox modal loop. 387 // Note that this executes in the MessageBox modal loop.
388 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); 388 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true));
389 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); 389 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false));
390 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); 390 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 memset(buffer_, 0, sizeof(buffer_)); 510 memset(buffer_, 0, sizeof(buffer_));
511 memset(&context_, 0, sizeof(context_)); 511 memset(&context_, 0, sizeof(context_));
512 context_.handler = this; 512 context_.handler = this;
513 513
514 file_.Set(CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 514 file_.Set(CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING,
515 FILE_FLAG_OVERLAPPED, NULL)); 515 FILE_FLAG_OVERLAPPED, NULL));
516 EXPECT_TRUE(file_.IsValid()); 516 EXPECT_TRUE(file_.IsValid());
517 } 517 }
518 518
519 void TestIOHandler::Init() { 519 void TestIOHandler::Init() {
520 MessageLoopForIO::current()->RegisterIOHandler(file_, this); 520 MessageLoopForIO::current()->RegisterIOHandler(file_.Get(), this);
521 521
522 DWORD read; 522 DWORD read;
523 EXPECT_FALSE(ReadFile(file_, buffer_, size(), &read, context())); 523 EXPECT_FALSE(ReadFile(file_.Get(), buffer_, size(), &read, context()));
524 EXPECT_EQ(ERROR_IO_PENDING, GetLastError()); 524 EXPECT_EQ(ERROR_IO_PENDING, GetLastError());
525 if (wait_) 525 if (wait_)
526 WaitForIO(); 526 WaitForIO();
527 } 527 }
528 528
529 void TestIOHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, 529 void TestIOHandler::OnIOCompleted(MessageLoopForIO::IOContext* context,
530 DWORD bytes_transfered, DWORD error) { 530 DWORD bytes_transfered, DWORD error) {
531 ASSERT_TRUE(context == &context_); 531 ASSERT_TRUE(context == &context_);
532 ASSERT_TRUE(SetEvent(signal_)); 532 ASSERT_TRUE(SetEvent(signal_));
533 } 533 }
(...skipping 13 matching lines...) Expand all
547 ASSERT_TRUE(server.IsValid()); 547 ASSERT_TRUE(server.IsValid());
548 548
549 Thread thread("IOHandler test"); 549 Thread thread("IOHandler test");
550 Thread::Options options; 550 Thread::Options options;
551 options.message_loop_type = MessageLoop::TYPE_IO; 551 options.message_loop_type = MessageLoop::TYPE_IO;
552 ASSERT_TRUE(thread.StartWithOptions(options)); 552 ASSERT_TRUE(thread.StartWithOptions(options));
553 553
554 MessageLoop* thread_loop = thread.message_loop(); 554 MessageLoop* thread_loop = thread.message_loop();
555 ASSERT_TRUE(NULL != thread_loop); 555 ASSERT_TRUE(NULL != thread_loop);
556 556
557 TestIOHandler handler(kPipeName, callback_called, false); 557 TestIOHandler handler(kPipeName, callback_called.Get(), false);
558 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 558 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init,
559 Unretained(&handler))); 559 Unretained(&handler)));
560 // Make sure the thread runs and sleeps for lack of work. 560 // Make sure the thread runs and sleeps for lack of work.
561 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); 561 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
562 562
563 const char buffer[] = "Hello there!"; 563 const char buffer[] = "Hello there!";
564 DWORD written; 564 DWORD written;
565 EXPECT_TRUE(WriteFile(server, buffer, sizeof(buffer), &written, NULL)); 565 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL));
566 566
567 DWORD result = WaitForSingleObject(callback_called, 1000); 567 DWORD result = WaitForSingleObject(callback_called.Get(), 1000);
568 EXPECT_EQ(WAIT_OBJECT_0, result); 568 EXPECT_EQ(WAIT_OBJECT_0, result);
569 569
570 thread.Stop(); 570 thread.Stop();
571 } 571 }
572 572
573 void RunTest_WaitForIO() { 573 void RunTest_WaitForIO() {
574 win::ScopedHandle callback1_called( 574 win::ScopedHandle callback1_called(
575 CreateEvent(NULL, TRUE, FALSE, NULL)); 575 CreateEvent(NULL, TRUE, FALSE, NULL));
576 win::ScopedHandle callback2_called( 576 win::ScopedHandle callback2_called(
577 CreateEvent(NULL, TRUE, FALSE, NULL)); 577 CreateEvent(NULL, TRUE, FALSE, NULL));
(...skipping 10 matching lines...) Expand all
588 ASSERT_TRUE(server2.IsValid()); 588 ASSERT_TRUE(server2.IsValid());
589 589
590 Thread thread("IOHandler test"); 590 Thread thread("IOHandler test");
591 Thread::Options options; 591 Thread::Options options;
592 options.message_loop_type = MessageLoop::TYPE_IO; 592 options.message_loop_type = MessageLoop::TYPE_IO;
593 ASSERT_TRUE(thread.StartWithOptions(options)); 593 ASSERT_TRUE(thread.StartWithOptions(options));
594 594
595 MessageLoop* thread_loop = thread.message_loop(); 595 MessageLoop* thread_loop = thread.message_loop();
596 ASSERT_TRUE(NULL != thread_loop); 596 ASSERT_TRUE(NULL != thread_loop);
597 597
598 TestIOHandler handler1(kPipeName1, callback1_called, false); 598 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false);
599 TestIOHandler handler2(kPipeName2, callback2_called, true); 599 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true);
600 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 600 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init,
601 Unretained(&handler1))); 601 Unretained(&handler1)));
602 // TODO(ajwong): Do we really need such long Sleeps in ths function? 602 // TODO(ajwong): Do we really need such long Sleeps in ths function?
603 // Make sure the thread runs and sleeps for lack of work. 603 // Make sure the thread runs and sleeps for lack of work.
604 TimeDelta delay = TimeDelta::FromMilliseconds(100); 604 TimeDelta delay = TimeDelta::FromMilliseconds(100);
605 PlatformThread::Sleep(delay); 605 PlatformThread::Sleep(delay);
606 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 606 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init,
607 Unretained(&handler2))); 607 Unretained(&handler2)));
608 PlatformThread::Sleep(delay); 608 PlatformThread::Sleep(delay);
609 609
610 // At this time handler1 is waiting to be called, and the thread is waiting 610 // At this time handler1 is waiting to be called, and the thread is waiting
611 // on the Init method of handler2, filtering only handler2 callbacks. 611 // on the Init method of handler2, filtering only handler2 callbacks.
612 612
613 const char buffer[] = "Hello there!"; 613 const char buffer[] = "Hello there!";
614 DWORD written; 614 DWORD written;
615 EXPECT_TRUE(WriteFile(server1, buffer, sizeof(buffer), &written, NULL)); 615 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL));
616 PlatformThread::Sleep(2 * delay); 616 PlatformThread::Sleep(2 * delay);
617 EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called, 0)) << 617 EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called.Get(), 0)) <<
618 "handler1 has not been called"; 618 "handler1 has not been called";
619 619
620 EXPECT_TRUE(WriteFile(server2, buffer, sizeof(buffer), &written, NULL)); 620 EXPECT_TRUE(WriteFile(server2.Get(), buffer, sizeof(buffer), &written, NULL));
621 621
622 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; 622 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() };
623 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); 623 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000);
624 EXPECT_EQ(WAIT_OBJECT_0, result); 624 EXPECT_EQ(WAIT_OBJECT_0, result);
625 625
626 thread.Stop(); 626 thread.Stop();
627 } 627 }
628 628
629 #endif // defined(OS_WIN) 629 #endif // defined(OS_WIN)
630 630
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 1007
1008 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); 1008 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1));
1009 1009
1010 loop.Run(); 1010 loop.Run();
1011 1011
1012 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); 1012 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance));
1013 } 1013 }
1014 #endif // defined(OS_WIN) 1014 #endif // defined(OS_WIN)
1015 1015
1016 } // namespace base 1016 } // namespace base
OLDNEW
« no previous file with comments | « base/files/file_win.cc ('k') | base/message_loop/message_pump_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698