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

Side by Side Diff: mojo/shell/public/cpp/tests/connection_impl_unittest.cc

Issue 1681933005: Extracts InterfaceRegistry from ConnectionImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nested
Patch Set: . Created 4 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/shell/public/cpp/lib/connection_impl.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "mojo/shell/public/cpp/interface_binder.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace mojo {
12 namespace internal {
13 namespace {
14
15 class TestBinder : public InterfaceBinder {
16 public:
17 explicit TestBinder(int* delete_count) : delete_count_(delete_count) {}
18 ~TestBinder() override { (*delete_count_)++; }
19 void BindInterface(Connection* connection,
20 const std::string& interface_name,
21 ScopedMessagePipeHandle client_handle) override {}
22
23 private:
24 int* delete_count_;
25 };
26
27 TEST(ConnectionImplTest, Ownership) {
28 int delete_count = 0;
29
30 // Destruction.
31 {
32 ConnectionImpl connection;
33 ConnectionImpl::TestApi test_api(&connection);
34 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
35 }
36 EXPECT_EQ(1, delete_count);
37
38 // Removal.
39 {
40 scoped_ptr<ConnectionImpl> connection(new ConnectionImpl);
41 InterfaceBinder* b = new TestBinder(&delete_count);
42 ConnectionImpl::TestApi test_api(connection.get());
43 test_api.SetInterfaceBinderForName(b, "TC1");
44 test_api.RemoveInterfaceBinderForName("TC1");
45 connection.reset();
46 EXPECT_EQ(2, delete_count);
47 }
48
49 // Multiple.
50 {
51 ConnectionImpl connection;
52 ConnectionImpl::TestApi test_api(&connection);
53 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
54 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2");
55 }
56 EXPECT_EQ(4, delete_count);
57
58 // Re-addition.
59 {
60 ConnectionImpl connection;
61 ConnectionImpl::TestApi test_api(&connection);
62 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
63 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
64 EXPECT_EQ(5, delete_count);
65 }
66 EXPECT_EQ(6, delete_count);
67 }
68
69 } // namespace
70 } // namespace internal
71 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/tests/BUILD.gn ('k') | mojo/shell/public/cpp/tests/interface_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698