OLD | NEW |
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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.Get(), 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(17u, order.Size()); |
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 |
347 // "end" entry. | 347 // "end" entry. |
348 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, true)); | 348 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, true)); |
349 EXPECT_EQ(order.Get(7), TaskItem(QUITMESSAGELOOP, 5, true)); | 349 EXPECT_EQ(order.Get(7), TaskItem(QUITMESSAGELOOP, 5, true)); |
(...skipping 23 matching lines...) Expand all Loading... |
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.Get(), 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(18u, order.Size()); |
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)); |
391 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); | 391 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); |
392 EXPECT_EQ(order.Get(7), TaskItem(MESSAGEBOX, 2, false)); | 392 EXPECT_EQ(order.Get(7), TaskItem(MESSAGEBOX, 2, false)); |
393 /* The order can subtly change here. The reason is that when RecursiveFunc(1) | 393 /* The order can subtly change here. The reason is that when RecursiveFunc(1) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 file_.Set(CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, | 515 file_.Set(CreateFile(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, |
516 FILE_FLAG_OVERLAPPED, NULL)); | 516 FILE_FLAG_OVERLAPPED, NULL)); |
517 EXPECT_TRUE(file_.IsValid()); | 517 EXPECT_TRUE(file_.IsValid()); |
518 } | 518 } |
519 | 519 |
520 void TestIOHandler::Init() { | 520 void TestIOHandler::Init() { |
521 MessageLoopForIO::current()->RegisterIOHandler(file_.Get(), this); | 521 MessageLoopForIO::current()->RegisterIOHandler(file_.Get(), this); |
522 | 522 |
523 DWORD read; | 523 DWORD read; |
524 EXPECT_FALSE(ReadFile(file_.Get(), buffer_, size(), &read, context())); | 524 EXPECT_FALSE(ReadFile(file_.Get(), buffer_, size(), &read, context())); |
525 EXPECT_EQ(ERROR_IO_PENDING, GetLastError()); | 525 EXPECT_EQ(static_cast<DWORD>(ERROR_IO_PENDING), GetLastError()); |
526 if (wait_) | 526 if (wait_) |
527 WaitForIO(); | 527 WaitForIO(); |
528 } | 528 } |
529 | 529 |
530 void TestIOHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, | 530 void TestIOHandler::OnIOCompleted(MessageLoopForIO::IOContext* context, |
531 DWORD bytes_transfered, DWORD error) { | 531 DWORD bytes_transfered, DWORD error) { |
532 ASSERT_TRUE(context == &context_); | 532 ASSERT_TRUE(context == &context_); |
533 ASSERT_TRUE(SetEvent(signal_)); | 533 ASSERT_TRUE(SetEvent(signal_)); |
534 } | 534 } |
535 | 535 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 Unretained(&handler2))); | 608 Unretained(&handler2))); |
609 PlatformThread::Sleep(delay); | 609 PlatformThread::Sleep(delay); |
610 | 610 |
611 // At this time handler1 is waiting to be called, and the thread is waiting | 611 // At this time handler1 is waiting to be called, and the thread is waiting |
612 // on the Init method of handler2, filtering only handler2 callbacks. | 612 // on the Init method of handler2, filtering only handler2 callbacks. |
613 | 613 |
614 const char buffer[] = "Hello there!"; | 614 const char buffer[] = "Hello there!"; |
615 DWORD written; | 615 DWORD written; |
616 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); | 616 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); |
617 PlatformThread::Sleep(2 * delay); | 617 PlatformThread::Sleep(2 * delay); |
618 EXPECT_EQ(WAIT_TIMEOUT, WaitForSingleObject(callback1_called.Get(), 0)) << | 618 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), |
619 "handler1 has not been called"; | 619 WaitForSingleObject(callback1_called.Get(), 0)) |
| 620 << "handler1 has not been called"; |
620 | 621 |
621 EXPECT_TRUE(WriteFile(server2.Get(), buffer, sizeof(buffer), &written, NULL)); | 622 EXPECT_TRUE(WriteFile(server2.Get(), buffer, sizeof(buffer), &written, NULL)); |
622 | 623 |
623 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; | 624 HANDLE objects[2] = { callback1_called.Get(), callback2_called.Get() }; |
624 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); | 625 DWORD result = WaitForMultipleObjects(2, objects, TRUE, 1000); |
625 EXPECT_EQ(WAIT_OBJECT_0, result); | 626 EXPECT_EQ(WAIT_OBJECT_0, result); |
626 | 627 |
627 thread.Stop(); | 628 thread.Stop(); |
628 } | 629 } |
629 | 630 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 loop.SetTaskRunner(new_runner); | 1030 loop.SetTaskRunner(new_runner); |
1030 | 1031 |
1031 scoped_refptr<Foo> foo(new Foo()); | 1032 scoped_refptr<Foo> foo(new Foo()); |
1032 original_runner->PostTask(FROM_HERE, | 1033 original_runner->PostTask(FROM_HERE, |
1033 Bind(&Foo::Test1ConstRef, foo.get(), "a")); | 1034 Bind(&Foo::Test1ConstRef, foo.get(), "a")); |
1034 loop.RunUntilIdle(); | 1035 loop.RunUntilIdle(); |
1035 EXPECT_EQ(1, foo->test_count()); | 1036 EXPECT_EQ(1, foo->test_count()); |
1036 } | 1037 } |
1037 | 1038 |
1038 } // namespace base | 1039 } // namespace base |
OLD | NEW |