| OLD | NEW |
| 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 "services/shell/public/cpp/interface_registry.h" | 5 #include "services/shell/public/cpp/interface_registry.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "services/shell/public/cpp/interface_binder.h" | 8 #include "services/shell/public/cpp/interface_binder.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 private: | 23 private: |
| 24 int* delete_count_; | 24 int* delete_count_; |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 TEST(InterfaceRegistryTest, Ownership) { | 27 TEST(InterfaceRegistryTest, Ownership) { |
| 28 base::MessageLoop message_loop_; | 28 base::MessageLoop message_loop_; |
| 29 int delete_count = 0; | 29 int delete_count = 0; |
| 30 | 30 |
| 31 // Destruction. | 31 // Destruction. |
| 32 { | 32 { |
| 33 InterfaceRegistry registry(nullptr); | 33 InterfaceRegistry registry; |
| 34 InterfaceRegistry::TestApi test_api(®istry); | 34 InterfaceRegistry::TestApi test_api(®istry); |
| 35 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | 35 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); |
| 36 } | 36 } |
| 37 EXPECT_EQ(1, delete_count); | 37 EXPECT_EQ(1, delete_count); |
| 38 | 38 |
| 39 // Removal. | 39 // Removal. |
| 40 { | 40 { |
| 41 std::unique_ptr<InterfaceRegistry> registry(new InterfaceRegistry(nullptr)); | 41 std::unique_ptr<InterfaceRegistry> registry(new InterfaceRegistry); |
| 42 InterfaceBinder* b = new TestBinder(&delete_count); | 42 InterfaceBinder* b = new TestBinder(&delete_count); |
| 43 InterfaceRegistry::TestApi test_api(registry.get()); | 43 InterfaceRegistry::TestApi test_api(registry.get()); |
| 44 test_api.SetInterfaceBinderForName(b, "TC1"); | 44 test_api.SetInterfaceBinderForName(b, "TC1"); |
| 45 registry->RemoveInterface("TC1"); | 45 registry->RemoveInterface("TC1"); |
| 46 registry.reset(); | 46 registry.reset(); |
| 47 EXPECT_EQ(2, delete_count); | 47 EXPECT_EQ(2, delete_count); |
| 48 } | 48 } |
| 49 | 49 |
| 50 // Multiple. | 50 // Multiple. |
| 51 { | 51 { |
| 52 InterfaceRegistry registry(nullptr); | 52 InterfaceRegistry registry; |
| 53 InterfaceRegistry::TestApi test_api(®istry); | 53 InterfaceRegistry::TestApi test_api(®istry); |
| 54 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | 54 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); |
| 55 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2"); | 55 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2"); |
| 56 } | 56 } |
| 57 EXPECT_EQ(4, delete_count); | 57 EXPECT_EQ(4, delete_count); |
| 58 | 58 |
| 59 // Re-addition. | 59 // Re-addition. |
| 60 { | 60 { |
| 61 InterfaceRegistry registry(nullptr); | 61 InterfaceRegistry registry; |
| 62 InterfaceRegistry::TestApi test_api(®istry); | 62 InterfaceRegistry::TestApi test_api(®istry); |
| 63 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | 63 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); |
| 64 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); | 64 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1"); |
| 65 EXPECT_EQ(5, delete_count); | 65 EXPECT_EQ(5, delete_count); |
| 66 } | 66 } |
| 67 EXPECT_EQ(6, delete_count); | 67 EXPECT_EQ(6, delete_count); |
| 68 } | 68 } |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 } // namespace internal | 71 } // namespace internal |
| 72 } // namespace shell | 72 } // namespace shell |
| OLD | NEW |