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

Unified Diff: services/resource_coordinator/coordination_unit/web_contents_coordination_unit_impl_unittest.cc

Issue 2964103002: [GRC] Decouple Render Process CPU Measurement from CU Graph (Closed)
Patch Set: Rebase Created 3 years, 6 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/coordination_unit/web_contents_coordination_unit_impl_unittest.cc
diff --git a/services/resource_coordinator/coordination_unit/web_contents_coordination_unit_impl_unittest.cc b/services/resource_coordinator/coordination_unit/web_contents_coordination_unit_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c6504263ae9ca9aaabf83fb64167a88673e8f99a
--- /dev/null
+++ b/services/resource_coordinator/coordination_unit/web_contents_coordination_unit_impl_unittest.cc
@@ -0,0 +1,74 @@
+// 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 "base/run_loop.h"
+#include "services/resource_coordinator/coordination_unit/coordination_unit_impl.h"
+#include "services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest_util.h"
+#include "services/resource_coordinator/coordination_unit/mock_coordination_unit_graphs.h"
+#include "services/resource_coordinator/public/cpp/coordination_unit_types.h"
+#include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace resource_coordinator {
+
+namespace {
+
+class WebContentsCoordinationUnitImplTest
+ : public CoordinationUnitImplTestBase {};
+
+} // namespace
+
+TEST_F(WebContentsCoordinationUnitImplTest,
+ CalculateTabCPUUsageForSingleTabInSingleProcess) {
+ MockSingleTabInSingleProcessCoordinationUnitGraph cu_graph;
+
+ cu_graph.process->SetPropertyAndPropagate(mojom::PropertyType::kCPUUsage,
+ base::Value(40.0));
+
+ EXPECT_EQ(base::Value(40.0),
+ cu_graph.tab->GetProperty(mojom::PropertyType::kCPUUsage));
+}
+
+TEST_F(WebContentsCoordinationUnitImplTest,
+ CalculateTabCPUUsageForMultipleTabsInSingleProcess) {
+ MockMultipleTabsInSingleProcessCoordinationUnitGraph cu_graph;
+
+ cu_graph.process->SetPropertyAndPropagate(mojom::PropertyType::kCPUUsage,
+ base::Value(40.0));
+
+ EXPECT_EQ(base::Value(20.0),
+ cu_graph.tab->GetProperty(mojom::PropertyType::kCPUUsage));
+ EXPECT_EQ(base::Value(20.0),
+ cu_graph.tab->GetProperty(mojom::PropertyType::kCPUUsage));
+}
+
+TEST_F(WebContentsCoordinationUnitImplTest,
+ CalculateTabCPUUsageForSingleTabWithMultipleProcesses) {
+ MockSingleTabWithMultipleProcessesCoordinationUnitGraph cu_graph;
+
+ cu_graph.process->SetPropertyAndPropagate(mojom::PropertyType::kCPUUsage,
+ base::Value(40.0));
+ cu_graph.other_process->SetPropertyAndPropagate(
+ mojom::PropertyType::kCPUUsage, base::Value(30.0));
+
+ EXPECT_EQ(base::Value(70.0),
+ cu_graph.tab->GetProperty(mojom::PropertyType::kCPUUsage));
+}
+
+TEST_F(WebContentsCoordinationUnitImplTest,
+ CalculateTabCPUUsageForMultipleTabsWithMultipleProcesses) {
+ MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph cu_graph;
+
+ cu_graph.process->SetPropertyAndPropagate(mojom::PropertyType::kCPUUsage,
+ base::Value(40.0));
+ cu_graph.other_process->SetPropertyAndPropagate(
+ mojom::PropertyType::kCPUUsage, base::Value(30.0));
+
+ EXPECT_EQ(base::Value(20.0),
+ cu_graph.tab->GetProperty(mojom::PropertyType::kCPUUsage));
+ EXPECT_EQ(base::Value(50.0),
+ cu_graph.other_tab->GetProperty(mojom::PropertyType::kCPUUsage));
+}
+
+} // namespace resource_coordinator

Powered by Google App Engine
This is Rietveld 408576698