Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / application / public / cpp / tests / service_registry_unittest.cc
blob4a9f28a497eaa0a7bd499c334548f3a1c8754de6
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.
5 #include "mojo/application/public/cpp/lib/service_registry.h"
7 #include "mojo/application/public/cpp/service_connector.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace mojo {
11 namespace internal {
12 namespace {
14 class TestConnector : public ServiceConnector {
15 public:
16 explicit TestConnector(int* delete_count) : delete_count_(delete_count) {}
17 ~TestConnector() override { (*delete_count_)++; }
18 void ConnectToService(ApplicationConnection* application_connection,
19 const std::string& interface_name,
20 ScopedMessagePipeHandle client_handle) override {}
22 private:
23 int* delete_count_;
26 TEST(ServiceRegistryTest, Ownership) {
27 int delete_count = 0;
29 // Destruction.
31 ServiceRegistry* registry = new ServiceRegistry;
32 registry->SetServiceConnectorForName(new TestConnector(&delete_count),
33 "TC1");
34 registry->CloseConnection();
36 EXPECT_EQ(1, delete_count);
38 // Removal.
40 ServiceRegistry* registry = new ServiceRegistry;
41 ServiceConnector* c = new TestConnector(&delete_count);
42 registry->SetServiceConnectorForName(c, "TC1");
43 registry->RemoveServiceConnectorForName("TC1");
44 registry->CloseConnection();
45 EXPECT_EQ(2, delete_count);
48 // Multiple.
50 ServiceRegistry* registry = new ServiceRegistry;
51 registry->SetServiceConnectorForName(new TestConnector(&delete_count),
52 "TC1");
53 registry->SetServiceConnectorForName(new TestConnector(&delete_count),
54 "TC2");
55 registry->CloseConnection();
57 EXPECT_EQ(4, delete_count);
59 // Re-addition.
61 ServiceRegistry* registry = new ServiceRegistry;
62 registry->SetServiceConnectorForName(new TestConnector(&delete_count),
63 "TC1");
64 registry->SetServiceConnectorForName(new TestConnector(&delete_count),
65 "TC1");
66 EXPECT_EQ(5, delete_count);
67 registry->CloseConnection();
69 EXPECT_EQ(6, delete_count);
72 } // namespace
73 } // namespace internal
74 } // namespace mojo