OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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/resource_coordinator/memory/coordinator/process_map.h" | |
6 #include "services/service_manager/public/cpp/identity.h" | |
7 #include "services/service_manager/public/interfaces/service_manager.mojom.h" | |
8 #include "testing/gtest/include/gtest/gtest.h" | |
9 | |
10 namespace memory_instrumentation { | |
11 using RunningServiceInfoPtr = service_manager::mojom::RunningServiceInfoPtr; | |
dcheng
2017/05/13 20:22:37
Super duper minor nit: newline before for symmetry
erikchen
2017/05/14 04:49:16
Done.
| |
12 using ServiceManagerListenerRequest = | |
13 service_manager::mojom::ServiceManagerListenerRequest; | |
14 | |
15 class ProcessMapTest : public testing::Test { | |
16 public: | |
17 ProcessMapTest() {} | |
18 | |
19 protected: | |
20 ProcessMap process_map_; | |
21 }; | |
22 | |
23 TEST_F(ProcessMapTest, TypicalCase) { | |
24 service_manager::Identity id1("id1"); | |
25 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1)); | |
26 process_map_.OnInit(std::vector<RunningServiceInfoPtr>()); | |
27 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1)); | |
28 | |
29 RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New()); | |
30 info->identity = id1; | |
31 info->pid = 1; | |
32 process_map_.OnServiceCreated(info.Clone()); | |
33 EXPECT_EQ(1, process_map_.GetProcessId(id1)); | |
34 | |
35 // Adding a separate service with a different identity should have no effect. | |
36 info->identity = service_manager::Identity("id2"); | |
37 info->pid = 2; | |
38 process_map_.OnServiceCreated(info.Clone()); | |
39 EXPECT_EQ(1, process_map_.GetProcessId(id1)); | |
40 | |
41 // Once the service is stopped, searching for its id should return a null pid. | |
42 process_map_.OnServiceStopped(id1); | |
43 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1)); | |
44 } | |
45 | |
46 TEST_F(ProcessMapTest, PresentInInit) { | |
47 service_manager::Identity id1("id1"); | |
48 RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New()); | |
49 info->identity = id1; | |
50 info->pid = 1; | |
51 | |
52 std::vector<RunningServiceInfoPtr> v; | |
53 v.push_back(std::move(info)); | |
54 process_map_.OnInit(std::move(v)); | |
dcheng
2017/05/13 20:22:37
Nit: #include <utility>
erikchen
2017/05/14 04:49:16
Done.
| |
55 EXPECT_EQ(1, process_map_.GetProcessId(id1)); | |
56 | |
57 process_map_.OnServiceStopped(id1); | |
58 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1)); | |
59 } | |
60 | |
61 } // namespace memory_instrumentation | |
OLD | NEW |