Commit b3c9a824 authored by Matthew Halpern's avatar Matthew Halpern Committed by Commit Bot

[GRC] Add Tab-level CPU Usage Attribution Tests

This CL adds tab-level CPU usage attribution tests for GRC. Tab-level CPU usage attribution is tested under a variety of different coordination unit graph topologies.

A set of mock coordination unit graph topologies has also been added to the code base as a common set of coordination unit graph topologies has emerged across the coordination unit unittests. 

Bug: 691886
Change-Id: I2e9178ca5454846320add15f9f004ba0d9df2a9f
Reviewed-on: https://chromium-review.googlesource.com/562549
Commit-Queue: Matthew Halpern <matthalp@google.com>
Reviewed-by: default avatarZhen Wang <zhenw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485024}
parent 0bafc424
...@@ -73,7 +73,10 @@ source_set("tests") { ...@@ -73,7 +73,10 @@ source_set("tests") {
"coordination_unit/coordination_unit_impl_unittest.cc", "coordination_unit/coordination_unit_impl_unittest.cc",
"coordination_unit/coordination_unit_impl_unittest_util.cc", "coordination_unit/coordination_unit_impl_unittest_util.cc",
"coordination_unit/coordination_unit_impl_unittest_util.h", "coordination_unit/coordination_unit_impl_unittest_util.h",
"coordination_unit/mock_coordination_unit_graphs.cc",
"coordination_unit/mock_coordination_unit_graphs.h",
"coordination_unit/process_coordination_unit_impl_unittest.cc", "coordination_unit/process_coordination_unit_impl_unittest.cc",
"coordination_unit/web_contents_coordination_unit_impl_unittest.cc",
"memory_instrumentation/coordinator_impl_unittest.cc", "memory_instrumentation/coordinator_impl_unittest.cc",
"memory_instrumentation/process_map_unittest.cc", "memory_instrumentation/process_map_unittest.cc",
"public/cpp/memory_instrumentation/os_metrics_unittest.cc", "public/cpp/memory_instrumentation/os_metrics_unittest.cc",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "services/resource_coordinator/coordination_unit/coordination_unit_impl.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/coordination_unit_impl_unittest_util.h"
#include "services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.h" #include "services/resource_coordinator/coordination_unit/coordination_unit_provider_impl.h"
#include "services/resource_coordinator/coordination_unit/mock_coordination_unit_graphs.h"
#include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h" #include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h"
#include "services/service_manager/public/cpp/service_context_ref.h" #include "services/service_manager/public/cpp/service_context_ref.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -222,231 +223,102 @@ TEST_F(CoordinationUnitImplTest, GetSetProperty) { ...@@ -222,231 +223,102 @@ TEST_F(CoordinationUnitImplTest, GetSetProperty) {
TEST_F(CoordinationUnitImplTest, TEST_F(CoordinationUnitImplTest,
GetAssociatedCoordinationUnitsForSingleTabInSingleProcess) { GetAssociatedCoordinationUnitsForSingleTabInSingleProcess) {
// The following coordination unit graph topology is created to emulate a MockSingleTabInSingleProcessCoordinationUnitGraph cu_graph;
// scenario when a single tab are executes in a single process:
//
// T P
// \ /
// F
//
// Where:
// T: tab_coordination_unit
// F: frame_coordination_unit
// P: process_coordination_unit
auto frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
tab_coordination_unit->AddChild(frame_coordination_unit->id());
process_coordination_unit->AddChild(frame_coordination_unit->id());
auto tabs_associated_with_process = auto tabs_associated_with_process =
process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(1u, tabs_associated_with_process.size()); EXPECT_EQ(1u, tabs_associated_with_process.size());
EXPECT_EQ(1u, EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.tab.get()));
tabs_associated_with_process.count(tab_coordination_unit.get()));
auto processes_associated_with_tab = auto processes_associated_with_tab =
tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(1u, processes_associated_with_tab.size()); EXPECT_EQ(1u, processes_associated_with_tab.size());
EXPECT_EQ( EXPECT_EQ(1u, processes_associated_with_tab.count(cu_graph.process.get()));
1u, processes_associated_with_tab.count(process_coordination_unit.get()));
} }
TEST_F(CoordinationUnitImplTest, TEST_F(CoordinationUnitImplTest,
GetAssociatedCoordinationUnitsForMultipleTabsInSingleProcess) { GetAssociatedCoordinationUnitsForMultipleTabsInSingleProcess) {
// The following coordination unit graph topology is created to emulate a MockMultipleTabsInSingleProcessCoordinationUnitGraph cu_graph;
// scenario where multiple tabs are executing in a single process:
//
// T P OT
// \ / \ /
// F OF
//
// Where:
// T: tab_coordination_unit
// OT: other_tab_coordination_unit
// F: frame_coordination_unit
// OF: other_frame_coordination_unit
// P: process_coordination_unit
auto frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto other_frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
auto other_tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
tab_coordination_unit->AddChild(frame_coordination_unit->id());
other_tab_coordination_unit->AddChild(other_frame_coordination_unit->id());
process_coordination_unit->AddChild(frame_coordination_unit->id());
process_coordination_unit->AddChild(other_frame_coordination_unit->id());
auto tabs_associated_with_process = auto tabs_associated_with_process =
process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(2u, tabs_associated_with_process.size()); EXPECT_EQ(2u, tabs_associated_with_process.size());
EXPECT_EQ(1u, EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.tab.get()));
tabs_associated_with_process.count(tab_coordination_unit.get())); EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.other_tab.get()));
EXPECT_EQ(1u, tabs_associated_with_process.count(
other_tab_coordination_unit.get()));
auto processes_associated_with_tab = auto processes_associated_with_tab =
tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(1u, processes_associated_with_tab.size()); EXPECT_EQ(1u, processes_associated_with_tab.size());
EXPECT_EQ( EXPECT_EQ(1u, processes_associated_with_tab.count(cu_graph.process.get()));
1u, processes_associated_with_tab.count(process_coordination_unit.get()));
auto processes_associated_with_other_tab = auto processes_associated_with_other_tab =
other_tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.other_tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(1u, processes_associated_with_other_tab.size()); EXPECT_EQ(1u, processes_associated_with_other_tab.size());
EXPECT_EQ( EXPECT_EQ(1u, processes_associated_with_tab.count(cu_graph.process.get()));
1u, processes_associated_with_tab.count(process_coordination_unit.get()));
} }
TEST_F(CoordinationUnitImplTest, TEST_F(CoordinationUnitImplTest,
GetAssociatedCoordinationUnitsForSingleTabWithMultipleProcesses) { GetAssociatedCoordinationUnitsForSingleTabWithMultipleProcesses) {
// The following coordination unit graph topology is created to emulate a MockSingleTabWithMultipleProcessesCoordinationUnitGraph cu_graph;
// scenario where a single tab that has frames executing in different
// processes (e.g. out-of-process iFrames):
//
// T P
// \ /
// F OP
// \ /
// OF
//
// Where:
// T: tab_coordination_unit
// F: frame_coordination_unit
// OF: other_frame_coordination_unit
// P: process_coordination_unit
// OP: other_process_coordination_unit
auto frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto other_frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto other_process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
frame_coordination_unit->AddChild(other_frame_coordination_unit->id());
tab_coordination_unit->AddChild(frame_coordination_unit->id());
tab_coordination_unit->AddChild(other_frame_coordination_unit->id());
process_coordination_unit->AddChild(frame_coordination_unit->id());
other_process_coordination_unit->AddChild(
other_frame_coordination_unit->id());
auto tabs_associated_with_process = auto tabs_associated_with_process =
process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(1u, tabs_associated_with_process.size()); EXPECT_EQ(1u, tabs_associated_with_process.size());
EXPECT_EQ(1u, EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.tab.get()));
tabs_associated_with_process.count(tab_coordination_unit.get()));
auto tabs_associated_with_other_process = auto tabs_associated_with_other_process =
other_process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.other_process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(1u, tabs_associated_with_other_process.size()); EXPECT_EQ(1u, tabs_associated_with_other_process.size());
EXPECT_EQ(1u, tabs_associated_with_other_process.count( EXPECT_EQ(1u, tabs_associated_with_other_process.count(cu_graph.tab.get()));
tab_coordination_unit.get()));
auto processes_associated_with_tab = auto processes_associated_with_tab =
tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(2u, processes_associated_with_tab.size()); EXPECT_EQ(2u, processes_associated_with_tab.size());
EXPECT_EQ( EXPECT_EQ(1u, processes_associated_with_tab.count(cu_graph.process.get()));
1u, processes_associated_with_tab.count(process_coordination_unit.get())); EXPECT_EQ(1u,
EXPECT_EQ(1u, processes_associated_with_tab.count( processes_associated_with_tab.count(cu_graph.other_process.get()));
other_process_coordination_unit.get()));
} }
TEST_F(CoordinationUnitImplTest, TEST_F(CoordinationUnitImplTest,
GetAssociatedCoordinationUnitsForMultipeTabsWithMultipleProcesses) { GetAssociatedCoordinationUnitsForMultipleTabsWithMultipleProcesses) {
// The following coordination unit graph topology is created to emulate a MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph cu_graph;
// scenario where multiple tabs are utilizing multiple processes (e.g.
// out-of-process iFrames and multiple tabs in a process):
//
// OT P T
// \ / \ /
// OF F OP
// \ /
// AF
//
// Where:
// T: tab_coordination_unit
// OT: other_tab_coordination_unit
// F: frame_coordination_unit
// OF: other_frame_coordination_unit
// AF: another_frame_coordination_unit
// P: process_coordination_unit
// OP: other_process_coordination_unit
auto frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto other_frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto another_frame_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kFrame);
auto process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto other_process_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kProcess);
auto tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
auto other_tab_coordination_unit =
CreateCoordinationUnit(CoordinationUnitType::kWebContents);
frame_coordination_unit->AddChild(another_frame_coordination_unit->id());
tab_coordination_unit->AddChild(frame_coordination_unit->id());
other_tab_coordination_unit->AddChild(other_frame_coordination_unit->id());
process_coordination_unit->AddChild(frame_coordination_unit->id());
process_coordination_unit->AddChild(other_frame_coordination_unit->id());
other_process_coordination_unit->AddChild(
another_frame_coordination_unit->id());
auto tabs_associated_with_process = auto tabs_associated_with_process =
process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(2u, tabs_associated_with_process.size()); EXPECT_EQ(2u, tabs_associated_with_process.size());
EXPECT_EQ(1u, EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.tab.get()));
tabs_associated_with_process.count(tab_coordination_unit.get())); EXPECT_EQ(1u, tabs_associated_with_process.count(cu_graph.other_tab.get()));
EXPECT_EQ(1u, tabs_associated_with_process.count(
other_tab_coordination_unit.get()));
auto tabs_associated_with_other_process = auto tabs_associated_with_other_process =
other_process_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.other_process->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kWebContents); CoordinationUnitType::kWebContents);
EXPECT_EQ(1u, tabs_associated_with_other_process.size()); EXPECT_EQ(1u, tabs_associated_with_other_process.size());
EXPECT_EQ(1u, tabs_associated_with_other_process.count( EXPECT_EQ(1u,
tab_coordination_unit.get())); tabs_associated_with_other_process.count(cu_graph.other_tab.get()));
auto processes_associated_with_tab = auto processes_associated_with_tab =
tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(2u, processes_associated_with_tab.size()); EXPECT_EQ(1u, processes_associated_with_tab.size());
EXPECT_EQ( EXPECT_EQ(1u, processes_associated_with_tab.count(cu_graph.process.get()));
1u, processes_associated_with_tab.count(process_coordination_unit.get()));
EXPECT_EQ(1u, processes_associated_with_tab.count(
other_process_coordination_unit.get()));
auto processes_associated_with_other_tab = auto processes_associated_with_other_tab =
other_tab_coordination_unit->GetAssociatedCoordinationUnitsOfType( cu_graph.other_tab->GetAssociatedCoordinationUnitsOfType(
CoordinationUnitType::kProcess); CoordinationUnitType::kProcess);
EXPECT_EQ(1u, processes_associated_with_other_tab.size()); EXPECT_EQ(2u, processes_associated_with_other_tab.size());
EXPECT_EQ(1u,
processes_associated_with_other_tab.count(cu_graph.process.get()));
EXPECT_EQ(1u, processes_associated_with_other_tab.count( EXPECT_EQ(1u, processes_associated_with_other_tab.count(
process_coordination_unit.get())); cu_graph.other_process.get()));
} }
} // namespace resource_coordinator } // namespace resource_coordinator
// 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/coordination_unit/mock_coordination_unit_graphs.h"
#include <string>
#include "services/resource_coordinator/coordination_unit/coordination_unit_factory.h"
#include "services/resource_coordinator/public/cpp/coordination_unit_id.h"
#include "services/resource_coordinator/public/cpp/coordination_unit_types.h"
namespace service_manager {
class ServiceContextRef;
}
namespace resource_coordinator {
namespace {
std::unique_ptr<CoordinationUnitImpl> CreateCoordinationUnit(
CoordinationUnitType type) {
CoordinationUnitID cu_id(type, std::string());
return coordination_unit_factory::CreateCoordinationUnit(
cu_id, std::unique_ptr<service_manager::ServiceContextRef>(nullptr));
} // namespace
} // namespace
MockSingleTabInSingleProcessCoordinationUnitGraph::
MockSingleTabInSingleProcessCoordinationUnitGraph() {
frame = CreateCoordinationUnit(CoordinationUnitType::kFrame);
process = CreateCoordinationUnit(CoordinationUnitType::kProcess);
tab = CreateCoordinationUnit(CoordinationUnitType::kWebContents);
tab->AddChild(frame->id());
process->AddChild(frame->id());
}
MockSingleTabInSingleProcessCoordinationUnitGraph::
~MockSingleTabInSingleProcessCoordinationUnitGraph() = default;
MockMultipleTabsInSingleProcessCoordinationUnitGraph::
MockMultipleTabsInSingleProcessCoordinationUnitGraph() {
other_frame = CreateCoordinationUnit(CoordinationUnitType::kFrame);
other_tab = CreateCoordinationUnit(CoordinationUnitType::kWebContents);
other_tab->AddChild(other_frame->id());
process->AddChild(other_frame->id());
}
MockMultipleTabsInSingleProcessCoordinationUnitGraph::
~MockMultipleTabsInSingleProcessCoordinationUnitGraph() = default;
MockSingleTabWithMultipleProcessesCoordinationUnitGraph::
MockSingleTabWithMultipleProcessesCoordinationUnitGraph() {
child_frame = CreateCoordinationUnit(CoordinationUnitType::kFrame);
other_process = CreateCoordinationUnit(CoordinationUnitType::kProcess);
frame->AddChild(child_frame->id());
other_process->AddChild(child_frame->id());
}
MockSingleTabWithMultipleProcessesCoordinationUnitGraph::
~MockSingleTabWithMultipleProcessesCoordinationUnitGraph() = default;
MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph::
MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph() {
child_frame = CreateCoordinationUnit(CoordinationUnitType::kFrame);
other_process = CreateCoordinationUnit(CoordinationUnitType::kProcess);
other_frame->AddChild(child_frame->id());
other_process->AddChild(child_frame->id());
}
MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph::
~MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph() = default;
} // namespace resource_coordinator
// 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.
#ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_MOCK_COORDINATION_UNIT_GRAPHS_H_
#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_MOCK_COORDINATION_UNIT_GRAPHS_H_
#include <memory>
namespace resource_coordinator {
class CoordinationUnitImpl;
// The following coordination unit graph topology is created to emulate a
// scenario when a single tab are executes in a single process:
//
// T P
// \ /
// F
//
// Where:
// T: tab
// F: frame
// P: process
struct MockSingleTabInSingleProcessCoordinationUnitGraph {
MockSingleTabInSingleProcessCoordinationUnitGraph();
~MockSingleTabInSingleProcessCoordinationUnitGraph();
std::unique_ptr<CoordinationUnitImpl> frame;
std::unique_ptr<CoordinationUnitImpl> process;
std::unique_ptr<CoordinationUnitImpl> tab;
};
// The following coordination unit graph topology is created to emulate a
// scenario where multiple tabs are executing in a single process:
//
// T P OT
// \ / \ /
// F OF
//
// Where:
// T: tab
// OT: other_tab
// F: frame
// OF: other_frame
// P: process
struct MockMultipleTabsInSingleProcessCoordinationUnitGraph
: public MockSingleTabInSingleProcessCoordinationUnitGraph {
MockMultipleTabsInSingleProcessCoordinationUnitGraph();
~MockMultipleTabsInSingleProcessCoordinationUnitGraph();
std::unique_ptr<CoordinationUnitImpl> other_frame;
std::unique_ptr<CoordinationUnitImpl> other_tab;
};
// The following coordination unit graph topology is created to emulate a
// scenario where a single tab that has frames executing in different
// processes (e.g. out-of-process iFrames):
//
// T P
// \ /
// F OP
// \ /
// CF
//
// Where:
// T: tab
// F: frame
// CF: chid_frame
// P: process
// OP: other_process
struct MockSingleTabWithMultipleProcessesCoordinationUnitGraph
: public MockSingleTabInSingleProcessCoordinationUnitGraph {
MockSingleTabWithMultipleProcessesCoordinationUnitGraph();
~MockSingleTabWithMultipleProcessesCoordinationUnitGraph();
std::unique_ptr<CoordinationUnitImpl> child_frame;
std::unique_ptr<CoordinationUnitImpl> other_process;
};
// The following coordination unit graph topology is created to emulate a
// scenario where multiple tabs are utilizing multiple processes (e.g.
// out-of-process iFrames and multiple tabs in a process):
//
// T P OT
// \ / \ /
// F OF OP
// \ /
// CF
//
// Where:
// T: tab_coordination_unit
// OT: other_tab_coordination_unit
// F: frame_coordination_unit
// OF: other_frame_coordination_unit
// CF: another_frame_coordination_unit
// P: process_coordination_unit
// OP: other_process_coordination_unit
struct MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph
: public MockMultipleTabsInSingleProcessCoordinationUnitGraph {
MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph();
~MockMultipleTabsWithMultipleProcessesCoordinationUnitGraph();
std::unique_ptr<CoordinationUnitImpl> child_frame;
std::unique_ptr<CoordinationUnitImpl> other_process;
};
} // namespace resource_coordinator
#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_MOCK_COORDINATION_UNIT_GRAPHS_H_
// 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->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<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->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<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->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<base::Value>(40.0));
cu_graph.other_process->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<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->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<base::Value>(40.0));
cu_graph.other_process->SetProperty(mojom::PropertyType::kCPUUsage,
base::MakeUnique<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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment