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

Side by Side Diff: mojo/shell/public/cpp/tests/interface_registry_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
« no previous file with comments | « mojo/shell/public/cpp/tests/connection_impl_unittest.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 2014 The Chromium Authors. All rights reserved. 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 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/shell/public/cpp/lib/connection_impl.h" 5 #include "mojo/shell/public/cpp/interface_registry.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "mojo/shell/public/cpp/interface_binder.h" 8 #include "mojo/shell/public/cpp/interface_binder.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 namespace internal { 12 namespace internal {
13 namespace { 13 namespace {
14 14
15 class TestBinder : public InterfaceBinder { 15 class TestBinder : public InterfaceBinder {
16 public: 16 public:
17 explicit TestBinder(int* delete_count) : delete_count_(delete_count) {} 17 explicit TestBinder(int* delete_count) : delete_count_(delete_count) {}
18 ~TestBinder() override { (*delete_count_)++; } 18 ~TestBinder() override { (*delete_count_)++; }
19 void BindInterface(Connection* connection, 19 void BindInterface(Connection* connection,
20 const std::string& interface_name, 20 const std::string& interface_name,
21 ScopedMessagePipeHandle client_handle) override {} 21 ScopedMessagePipeHandle client_handle) override {}
22 22
23 private: 23 private:
24 int* delete_count_; 24 int* delete_count_;
25 }; 25 };
26 26
27 TEST(ConnectionImplTest, Ownership) { 27 TEST(InterfaceRegistryTest, Ownership) {
28 int delete_count = 0; 28 int delete_count = 0;
29 29
30 // Destruction. 30 // Destruction.
31 { 31 {
32 ConnectionImpl connection; 32 shell::mojom::InterfaceProviderRequest ir;
33 ConnectionImpl::TestApi test_api(&connection); 33 InterfaceRegistry registry(std::move(ir), nullptr);
34 InterfaceRegistry::TestApi test_api(&registry);
34 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); 35 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
35 } 36 }
36 EXPECT_EQ(1, delete_count); 37 EXPECT_EQ(1, delete_count);
37 38
38 // Removal. 39 // Removal.
39 { 40 {
40 scoped_ptr<ConnectionImpl> connection(new ConnectionImpl); 41 shell::mojom::InterfaceProviderRequest ir;
42 scoped_ptr<InterfaceRegistry> registry(
43 new InterfaceRegistry(std::move(ir), nullptr));
41 InterfaceBinder* b = new TestBinder(&delete_count); 44 InterfaceBinder* b = new TestBinder(&delete_count);
42 ConnectionImpl::TestApi test_api(connection.get()); 45 InterfaceRegistry::TestApi test_api(registry.get());
43 test_api.SetInterfaceBinderForName(b, "TC1"); 46 test_api.SetInterfaceBinderForName(b, "TC1");
44 test_api.RemoveInterfaceBinderForName("TC1"); 47 test_api.RemoveInterfaceBinderForName("TC1");
45 connection.reset(); 48 registry.reset();
46 EXPECT_EQ(2, delete_count); 49 EXPECT_EQ(2, delete_count);
47 } 50 }
48 51
49 // Multiple. 52 // Multiple.
50 { 53 {
51 ConnectionImpl connection; 54 shell::mojom::InterfaceProviderRequest ir;
52 ConnectionImpl::TestApi test_api(&connection); 55 InterfaceRegistry registry(std::move(ir), nullptr);
56 InterfaceRegistry::TestApi test_api(&registry);
53 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); 57 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
54 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2"); 58 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2");
55 } 59 }
56 EXPECT_EQ(4, delete_count); 60 EXPECT_EQ(4, delete_count);
57 61
58 // Re-addition. 62 // Re-addition.
59 { 63 {
60 ConnectionImpl connection; 64 shell::mojom::InterfaceProviderRequest ir;
61 ConnectionImpl::TestApi test_api(&connection); 65 InterfaceRegistry registry(std::move(ir), nullptr);
66 InterfaceRegistry::TestApi test_api(&registry);
62 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); 67 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
63 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); 68 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
64 EXPECT_EQ(5, delete_count); 69 EXPECT_EQ(5, delete_count);
65 } 70 }
66 EXPECT_EQ(6, delete_count); 71 EXPECT_EQ(6, delete_count);
67 } 72 }
68 73
69 } // namespace 74 } // namespace
70 } // namespace internal 75 } // namespace internal
71 } // namespace mojo 76 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/tests/connection_impl_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698