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

Side by Side Diff: services/resource_coordinator/memory/coordinator/process_map_unittest.cc

Issue 2883693002: [Memory-UMA] Implement basic working prototype. (Closed)
Patch Set: Fix test. Created 3 years, 7 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
OLDNEW
(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 <utility>
6
7 #include "services/resource_coordinator/memory/coordinator/process_map.h"
8 #include "services/service_manager/public/cpp/identity.h"
9 #include "services/service_manager/public/interfaces/service_manager.mojom.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace memory_instrumentation {
13
14 using RunningServiceInfoPtr = service_manager::mojom::RunningServiceInfoPtr;
15 using ServiceManagerListenerRequest =
16 service_manager::mojom::ServiceManagerListenerRequest;
17
18 class ProcessMapTest : public testing::Test {
19 public:
20 ProcessMapTest() : process_map_(nullptr) {}
21
22 protected:
23 ProcessMap process_map_;
24 };
25
26 TEST_F(ProcessMapTest, TypicalCase) {
27 service_manager::Identity id1("id1");
28 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
29 process_map_.OnInit(std::vector<RunningServiceInfoPtr>());
30 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
31
32 RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New());
33 info->identity = id1;
34 info->pid = 1;
35 process_map_.OnServiceCreated(info.Clone());
36 EXPECT_EQ(static_cast<base::ProcessId>(1), process_map_.GetProcessId(id1));
37
38 // Adding a separate service with a different identity should have no effect.
39 info->identity = service_manager::Identity("id2");
40 info->pid = 2;
41 process_map_.OnServiceCreated(info.Clone());
42 EXPECT_EQ(static_cast<base::ProcessId>(1), process_map_.GetProcessId(id1));
43
44 // Once the service is stopped, searching for its id should return a null pid.
45 process_map_.OnServiceStopped(id1);
46 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
47 }
48
49 TEST_F(ProcessMapTest, PresentInInit) {
50 service_manager::Identity id1("id1");
51 RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New());
52 info->identity = id1;
53 info->pid = 1;
54
55 std::vector<RunningServiceInfoPtr> v;
56 v.push_back(std::move(info));
57 process_map_.OnInit(std::move(v));
58 EXPECT_EQ(static_cast<base::ProcessId>(1), process_map_.GetProcessId(id1));
59
60 process_map_.OnServiceStopped(id1);
61 EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
62 }
63
64 } // namespace memory_instrumentation
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698