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

Side by Side Diff: mojo/public/cpp/bindings/tests/connector_unittest.cc

Issue 2350883003: Mojo C++ bindings: fix Connector teardown. (Closed)
Patch Set: Created 4 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 | « mojo/public/cpp/bindings/lib/connector.cc ('k') | no next file » | 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 "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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/callback_helpers.h" 14 #include "base/callback_helpers.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/threading/thread.h"
17 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
18 #include "mojo/public/cpp/bindings/lib/message_builder.h" 19 #include "mojo/public/cpp/bindings/lib/message_builder.h"
19 #include "mojo/public/cpp/bindings/tests/message_queue.h" 20 #include "mojo/public/cpp/bindings/tests/message_queue.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace mojo { 23 namespace mojo {
23 namespace test { 24 namespace test {
24 namespace { 25 namespace {
25 26
26 class MessageAccumulator : public MessageReceiver { 27 class MessageAccumulator : public MessageReceiver {
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 // loop. The loop is quit when another message is received. 566 // loop. The loop is quit when another message is received.
566 accumulator.set_closure(base::Bind(&AccumulateWithNestedLoop, &accumulator, 567 accumulator.set_closure(base::Bind(&AccumulateWithNestedLoop, &accumulator,
567 run_loop.QuitClosure())); 568 run_loop.QuitClosure()));
568 connector1.set_incoming_receiver(&accumulator); 569 connector1.set_incoming_receiver(&accumulator);
569 570
570 run_loop.Run(); 571 run_loop.Run();
571 572
572 ASSERT_EQ(2u, accumulator.size()); 573 ASSERT_EQ(2u, accumulator.size());
573 } 574 }
574 575
576 TEST_F(ConnectorTest, DestroyOnDifferentThreadAfterClose) {
577 std::unique_ptr<Connector> connector(
578 new Connector(std::move(handle0_), Connector::SINGLE_THREADED_SEND,
579 base::ThreadTaskRunnerHandle::Get()));
580
581 connector->CloseMessagePipe();
582
583 base::Thread another_thread("ThreadForDestroyingConnector");
584 another_thread.Start();
585
586 base::RunLoop run_loop;
587 another_thread.task_runner()->PostTaskAndReply(
588 FROM_HERE,
589 base::Bind(
590 [](std::unique_ptr<Connector> connector) { connector.reset(); },
591 base::Passed(std::move(connector))),
592 run_loop.QuitClosure());
593
594 run_loop.Run();
595 }
596
575 } // namespace 597 } // namespace
576 } // namespace test 598 } // namespace test
577 } // namespace mojo 599 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/connector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698