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

Unified Diff: services/resource_coordinator/memory/coordinator/process_map_unittest.cc

Issue 2883693002: [Memory-UMA] Implement basic working prototype. (Closed)
Patch Set: Tests working. 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 side-by-side diff with in-line comments
Download patch
Index: services/resource_coordinator/memory/coordinator/process_map_unittest.cc
diff --git a/services/resource_coordinator/memory/coordinator/process_map_unittest.cc b/services/resource_coordinator/memory/coordinator/process_map_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..337f210e2caf69a3c3ae381b81d7db904ec935e1
--- /dev/null
+++ b/services/resource_coordinator/memory/coordinator/process_map_unittest.cc
@@ -0,0 +1,61 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/resource_coordinator/memory/coordinator/process_map.h"
+#include "services/service_manager/public/cpp/identity.h"
+#include "services/service_manager/public/interfaces/service_manager.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace memory_instrumentation {
+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.
+using ServiceManagerListenerRequest =
+ service_manager::mojom::ServiceManagerListenerRequest;
+
+class ProcessMapTest : public testing::Test {
+ public:
+ ProcessMapTest() {}
+
+ protected:
+ ProcessMap process_map_;
+};
+
+TEST_F(ProcessMapTest, TypicalCase) {
+ service_manager::Identity id1("id1");
+ EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
+ process_map_.OnInit(std::vector<RunningServiceInfoPtr>());
+ EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
+
+ RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New());
+ info->identity = id1;
+ info->pid = 1;
+ process_map_.OnServiceCreated(info.Clone());
+ EXPECT_EQ(1, process_map_.GetProcessId(id1));
+
+ // Adding a separate service with a different identity should have no effect.
+ info->identity = service_manager::Identity("id2");
+ info->pid = 2;
+ process_map_.OnServiceCreated(info.Clone());
+ EXPECT_EQ(1, process_map_.GetProcessId(id1));
+
+ // Once the service is stopped, searching for its id should return a null pid.
+ process_map_.OnServiceStopped(id1);
+ EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
+}
+
+TEST_F(ProcessMapTest, PresentInInit) {
+ service_manager::Identity id1("id1");
+ RunningServiceInfoPtr info(service_manager::mojom::RunningServiceInfo::New());
+ info->identity = id1;
+ info->pid = 1;
+
+ std::vector<RunningServiceInfoPtr> v;
+ v.push_back(std::move(info));
+ process_map_.OnInit(std::move(v));
dcheng 2017/05/13 20:22:37 Nit: #include <utility>
erikchen 2017/05/14 04:49:16 Done.
+ EXPECT_EQ(1, process_map_.GetProcessId(id1));
+
+ process_map_.OnServiceStopped(id1);
+ EXPECT_EQ(base::kNullProcessId, process_map_.GetProcessId(id1));
+}
+
+} // namespace memory_instrumentation

Powered by Google App Engine
This is Rietveld 408576698