| OLD | NEW |
| (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 "services/service_manager/public/cpp/interface_registry.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "services/service_manager/public/cpp/interface_binder.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | |
| 11 | |
| 12 namespace service_manager { | |
| 13 | |
| 14 class TestBinder : public InterfaceBinder { | |
| 15 public: | |
| 16 explicit TestBinder(int* delete_count) : delete_count_(delete_count) {} | |
| 17 ~TestBinder() override { (*delete_count_)++; } | |
| 18 void BindInterface(const Identity& remote_identity, | |
| 19 const std::string& interface_name, | |
| 20 mojo::ScopedMessagePipeHandle client_handle) override {} | |
| 21 | |
| 22 private: | |
| 23 int* delete_count_; | |
| 24 }; | |
| 25 | |
| 26 TEST(InterfaceRegistryTest, Ownership) { | |
| 27 base::MessageLoop message_loop_; | |
| 28 int delete_count = 0; | |
| 29 | |
| 30 // Destruction. | |
| 31 { | |
| 32 auto registry = base::MakeUnique<InterfaceRegistry>(std::string()); | |
| 33 InterfaceRegistry::TestApi test_api(registry.get()); | |
| 34 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | |
| 35 } | |
| 36 EXPECT_EQ(1, delete_count); | |
| 37 | |
| 38 // Removal. | |
| 39 { | |
| 40 auto registry = | |
| 41 base::MakeUnique<InterfaceRegistry>(std::string()); | |
| 42 InterfaceBinder* b = new TestBinder(&delete_count); | |
| 43 InterfaceRegistry::TestApi test_api(registry.get()); | |
| 44 test_api.SetInterfaceBinderForName(b, "TC1"); | |
| 45 registry->RemoveInterface("TC1"); | |
| 46 registry.reset(); | |
| 47 EXPECT_EQ(2, delete_count); | |
| 48 } | |
| 49 | |
| 50 // Multiple. | |
| 51 { | |
| 52 auto registry = base::MakeUnique<InterfaceRegistry>(std::string()); | |
| 53 InterfaceRegistry::TestApi test_api(registry.get()); | |
| 54 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | |
| 55 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2"); | |
| 56 } | |
| 57 EXPECT_EQ(4, delete_count); | |
| 58 | |
| 59 // Re-addition. | |
| 60 { | |
| 61 auto registry = base::MakeUnique<InterfaceRegistry>(std::string()); | |
| 62 InterfaceRegistry::TestApi test_api(registry.get()); | |
| 63 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | |
| 64 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | |
| 65 EXPECT_EQ(5, delete_count); | |
| 66 } | |
| 67 EXPECT_EQ(6, delete_count); | |
| 68 } | |
| 69 | |
| 70 } // namespace service_manager | |
| OLD | NEW |