| Index: services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest.cc
|
| diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest.cc b/services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest.cc
|
| index bec8c8e7b3a0bc100597ad4bc4a6e60e134cc908..fd21706a3dbcb2185a82da8e5693681dce71864d 100644
|
| --- a/services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest.cc
|
| +++ b/services/resource_coordinator/coordination_unit/coordination_unit_impl_unittest.cc
|
| @@ -11,7 +11,6 @@
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| #include "base/values.h"
|
| -#include "services/resource_coordinator/coordination_unit/coordination_unit_factory.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_provider_impl.h"
|
| @@ -142,15 +141,10 @@ TEST_F(CoordinationUnitImplTest, AddChild) {
|
| }
|
|
|
| TEST_F(CoordinationUnitImplTest, RemoveChild) {
|
| - CoordinationUnitID parent_cu_id(CoordinationUnitType::kFrame, std::string());
|
| - CoordinationUnitID child_cu_id(CoordinationUnitType::kFrame, std::string());
|
| -
|
| - std::unique_ptr<CoordinationUnitImpl> parent_coordination_unit =
|
| - coordination_unit_factory::CreateCoordinationUnit(
|
| - parent_cu_id, service_context_ref_factory()->CreateRef());
|
| - std::unique_ptr<CoordinationUnitImpl> child_coordination_unit =
|
| - coordination_unit_factory::CreateCoordinationUnit(
|
| - child_cu_id, service_context_ref_factory()->CreateRef());
|
| + auto parent_coordination_unit =
|
| + CreateCoordinationUnit(CoordinationUnitType::kFrame);
|
| + auto child_coordination_unit =
|
| + CreateCoordinationUnit(CoordinationUnitType::kFrame);
|
|
|
| // Parent-child relationships have not been established yet.
|
| EXPECT_EQ(0u, parent_coordination_unit->children().size());
|
| @@ -214,11 +208,8 @@ TEST_F(CoordinationUnitImplTest, CyclicGraphUnits) {
|
| }
|
|
|
| TEST_F(CoordinationUnitImplTest, GetSetProperty) {
|
| - CoordinationUnitID cu_id(CoordinationUnitType::kWebContents, std::string());
|
| -
|
| - std::unique_ptr<CoordinationUnitImpl> coordination_unit =
|
| - coordination_unit_factory::CreateCoordinationUnit(
|
| - cu_id, service_context_ref_factory()->CreateRef());
|
| + auto coordination_unit =
|
| + CreateCoordinationUnit(CoordinationUnitType::kWebContents);
|
|
|
| // An empty value should be returned if property is not found
|
| EXPECT_EQ(base::Value(),
|
| @@ -240,4 +231,233 @@ TEST_F(CoordinationUnitImplTest, GetSetProperty) {
|
| EXPECT_EQ(0u, coordination_unit->property_store_for_testing().size());
|
| }
|
|
|
| +TEST_F(CoordinationUnitImplTest,
|
| + GetAssociatedCoordinationUnitsForSingleTabInSingleProcess) {
|
| + // 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_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 =
|
| + process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(1u, tabs_associated_with_process.size());
|
| + EXPECT_EQ(1u,
|
| + tabs_associated_with_process.count(tab_coordination_unit.get()));
|
| +
|
| + auto processes_associated_with_tab =
|
| + tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(1u, processes_associated_with_tab.size());
|
| + EXPECT_EQ(
|
| + 1u, processes_associated_with_tab.count(process_coordination_unit.get()));
|
| +}
|
| +
|
| +TEST_F(CoordinationUnitImplTest,
|
| + GetAssociatedCoordinationUnitsForMultipleTabsInSingleProcess) {
|
| + // 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_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 =
|
| + process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(2u, tabs_associated_with_process.size());
|
| + EXPECT_EQ(1u,
|
| + tabs_associated_with_process.count(tab_coordination_unit.get()));
|
| + EXPECT_EQ(1u, tabs_associated_with_process.count(
|
| + other_tab_coordination_unit.get()));
|
| +
|
| + auto processes_associated_with_tab =
|
| + tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(1u, processes_associated_with_tab.size());
|
| + EXPECT_EQ(
|
| + 1u, processes_associated_with_tab.count(process_coordination_unit.get()));
|
| +
|
| + auto processes_associated_with_other_tab =
|
| + other_tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(1u, processes_associated_with_other_tab.size());
|
| + EXPECT_EQ(
|
| + 1u, processes_associated_with_tab.count(process_coordination_unit.get()));
|
| +}
|
| +
|
| +TEST_F(CoordinationUnitImplTest,
|
| + GetAssociatedCoordinationUnitsForSingleTabWithMultipleProcesses) {
|
| + // 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
|
| + // \ /
|
| + // 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 =
|
| + process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(1u, tabs_associated_with_process.size());
|
| + EXPECT_EQ(1u,
|
| + tabs_associated_with_process.count(tab_coordination_unit.get()));
|
| +
|
| + auto tabs_associated_with_other_process =
|
| + other_process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(1u, tabs_associated_with_other_process.size());
|
| + EXPECT_EQ(1u, tabs_associated_with_other_process.count(
|
| + tab_coordination_unit.get()));
|
| +
|
| + auto processes_associated_with_tab =
|
| + tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(2u, processes_associated_with_tab.size());
|
| + EXPECT_EQ(
|
| + 1u, processes_associated_with_tab.count(process_coordination_unit.get()));
|
| + EXPECT_EQ(1u, processes_associated_with_tab.count(
|
| + other_process_coordination_unit.get()));
|
| +}
|
| +
|
| +TEST_F(CoordinationUnitImplTest,
|
| + GetAssociatedCoordinationUnitsForMultipeTabsWithMultipleProcesses) {
|
| + // 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):
|
| + //
|
| + // 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 =
|
| + process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(2u, tabs_associated_with_process.size());
|
| + EXPECT_EQ(1u,
|
| + tabs_associated_with_process.count(tab_coordination_unit.get()));
|
| + EXPECT_EQ(1u, tabs_associated_with_process.count(
|
| + other_tab_coordination_unit.get()));
|
| +
|
| + auto tabs_associated_with_other_process =
|
| + other_process_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kWebContents);
|
| + EXPECT_EQ(1u, tabs_associated_with_other_process.size());
|
| + EXPECT_EQ(1u, tabs_associated_with_other_process.count(
|
| + tab_coordination_unit.get()));
|
| +
|
| + auto processes_associated_with_tab =
|
| + tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(2u, processes_associated_with_tab.size());
|
| + EXPECT_EQ(
|
| + 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 =
|
| + other_tab_coordination_unit->GetAssociatedCoordinationUnitsOfType(
|
| + CoordinationUnitType::kProcess);
|
| + EXPECT_EQ(1u, processes_associated_with_other_tab.size());
|
| + EXPECT_EQ(1u, processes_associated_with_other_tab.count(
|
| + process_coordination_unit.get()));
|
| +}
|
| +
|
| } // namespace resource_coordinator
|
|
|