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

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

Issue 1877753003: Move mojo\shell to services\shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@62scan
Patch Set: . Created 4 years, 8 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/BUILD.gn ('k') | mojo/shell/public/interfaces/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/interface_registry.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/shell/public/cpp/interface_binder.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace mojo {
13 namespace internal {
14 namespace {
15
16 class TestBinder : public InterfaceBinder {
17 public:
18 explicit TestBinder(int* delete_count) : delete_count_(delete_count) {}
19 ~TestBinder() override { (*delete_count_)++; }
20 void BindInterface(Connection* connection,
21 const std::string& interface_name,
22 ScopedMessagePipeHandle client_handle) override {}
23
24 private:
25 int* delete_count_;
26 };
27
28 TEST(InterfaceRegistryTest, Ownership) {
29 base::MessageLoop message_loop_;
30 int delete_count = 0;
31
32 // Destruction.
33 {
34 InterfaceRegistry registry(nullptr);
35 InterfaceRegistry::TestApi test_api(&registry);
36 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
37 }
38 EXPECT_EQ(1, delete_count);
39
40 // Removal.
41 {
42 scoped_ptr<InterfaceRegistry> registry(new InterfaceRegistry(nullptr));
43 InterfaceBinder* b = new TestBinder(&delete_count);
44 InterfaceRegistry::TestApi test_api(registry.get());
45 test_api.SetInterfaceBinderForName(b, "TC1");
46 test_api.RemoveInterfaceBinderForName("TC1");
47 registry.reset();
48 EXPECT_EQ(2, delete_count);
49 }
50
51 // Multiple.
52 {
53 InterfaceRegistry registry(nullptr);
54 InterfaceRegistry::TestApi test_api(&registry);
55 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
56 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC2");
57 }
58 EXPECT_EQ(4, delete_count);
59
60 // Re-addition.
61 {
62 InterfaceRegistry registry(nullptr);
63 InterfaceRegistry::TestApi test_api(&registry);
64 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
65 test_api.SetInterfaceBinderForName(new TestBinder(&delete_count), "TC1");
66 EXPECT_EQ(5, delete_count);
67 }
68 EXPECT_EQ(6, delete_count);
69 }
70
71 } // namespace
72 } // namespace internal
73 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/shell/public/cpp/tests/BUILD.gn ('k') | mojo/shell/public/interfaces/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698