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 "mojo/public/cpp/bindings/connector.h" | 5 #include "mojo/public/cpp/bindings/connector.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <string.h> | 9 #include <string.h> |
10 #include <utility> | 10 #include <utility> |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 connector0.Accept(&message); | 561 connector0.Accept(&message); |
562 | 562 |
563 base::RunLoop run_loop; | 563 base::RunLoop run_loop; |
564 MessageAccumulator accumulator; | 564 MessageAccumulator accumulator; |
565 // When the accumulator gets the first message it spins a nested message | 565 // When the accumulator gets the first message it spins a nested message |
566 // loop. The loop is quit when another message is received. | 566 // loop. The loop is quit when another message is received. |
567 accumulator.set_closure(base::Bind(&AccumulateWithNestedLoop, &accumulator, | 567 accumulator.set_closure(base::Bind(&AccumulateWithNestedLoop, &accumulator, |
568 run_loop.QuitClosure())); | 568 run_loop.QuitClosure())); |
569 connector1.set_incoming_receiver(&accumulator); | 569 connector1.set_incoming_receiver(&accumulator); |
570 | 570 |
571 connector1.EnableNestedDispatch(true); | |
572 run_loop.Run(); | 571 run_loop.Run(); |
573 | 572 |
574 ASSERT_EQ(2u, accumulator.size()); | 573 ASSERT_EQ(2u, accumulator.size()); |
575 } | 574 } |
576 | 575 |
577 TEST_F(ConnectorTest, DestroyOnDifferentThreadAfterClose) { | 576 TEST_F(ConnectorTest, DestroyOnDifferentThreadAfterClose) { |
578 std::unique_ptr<Connector> connector( | 577 std::unique_ptr<Connector> connector( |
579 new Connector(std::move(handle0_), Connector::SINGLE_THREADED_SEND, | 578 new Connector(std::move(handle0_), Connector::SINGLE_THREADED_SEND, |
580 base::ThreadTaskRunnerHandle::Get())); | 579 base::ThreadTaskRunnerHandle::Get())); |
581 | 580 |
582 connector->CloseMessagePipe(); | 581 connector->CloseMessagePipe(); |
583 | 582 |
584 base::Thread another_thread("ThreadForDestroyingConnector"); | 583 base::Thread another_thread("ThreadForDestroyingConnector"); |
585 another_thread.Start(); | 584 another_thread.Start(); |
586 | 585 |
587 base::RunLoop run_loop; | 586 base::RunLoop run_loop; |
588 another_thread.task_runner()->PostTaskAndReply( | 587 another_thread.task_runner()->PostTaskAndReply( |
589 FROM_HERE, | 588 FROM_HERE, |
590 base::Bind( | 589 base::Bind( |
591 [](std::unique_ptr<Connector> connector) { connector.reset(); }, | 590 [](std::unique_ptr<Connector> connector) { connector.reset(); }, |
592 base::Passed(std::move(connector))), | 591 base::Passed(std::move(connector))), |
593 run_loop.QuitClosure()); | 592 run_loop.QuitClosure()); |
594 | 593 |
595 run_loop.Run(); | 594 run_loop.Run(); |
596 } | 595 } |
597 | 596 |
598 } // namespace | 597 } // namespace |
599 } // namespace test | 598 } // namespace test |
600 } // namespace mojo | 599 } // namespace mojo |
OLD | NEW |