Commit afab57f1 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Chromium LUCI CQ

[PM] Remove the FakePageLiveStateData class.

This extra complexity isn't needed.

Bug: 1144025
Change-Id: I0eaf083401469d1a512b75fb146c9c424d907923
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2584707Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835864}
parent 7bcaf25e
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "build/chromeos_buildflags.h" #include "build/chromeos_buildflags.h"
#include "chrome/browser/performance_manager/policies/policy_features.h" #include "chrome/browser/performance_manager/policies/policy_features.h"
#include "chrome/browser/performance_manager/test_support/page_discarding_utils.h" #include "chrome/browser/performance_manager/test_support/page_discarding_utils.h"
#include "components/performance_manager/public/decorators/page_live_state_decorator.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -118,48 +119,48 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageWithInvalidURL) { ...@@ -118,48 +119,48 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageWithInvalidURL) {
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageProtectedByExtension) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageProtectedByExtension) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_auto_discardable_ = false; ->SetIsAutoDiscardableForTesting(false);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingVideo) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingVideo) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_capturing_video_ = true; ->SetIsCapturingVideoForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingAudio) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingAudio) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_capturing_audio_ = true; ->SetIsCapturingAudioForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageBeingMirrored) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageBeingMirrored) {
testing::FakePageLiveStateData::GetOrCreate(page_node())->is_being_mirrored_ = PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
true; ->SetIsBeingMirroredForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingWindow) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingWindow) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_capturing_window_ = true; ->SetIsCapturingWindowForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingDisplay) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingDisplay) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_capturing_display_ = true; ->SetIsCapturingDisplayForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
...@@ -167,16 +168,16 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingDisplay) { ...@@ -167,16 +168,16 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageCapturingDisplay) {
TEST_F(PageDiscardingHelperTest, TEST_F(PageDiscardingHelperTest,
TestCannotDiscardPageConnectedToBluetoothDevice) { TestCannotDiscardPageConnectedToBluetoothDevice) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_connected_to_bluetooth_device_ = true; ->SetIsConnectedToBluetoothDeviceForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
} }
TEST_F(PageDiscardingHelperTest, TestCannotDiscardIsConnectedToUSBDevice) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardIsConnectedToUSBDevice) {
testing::FakePageLiveStateData::GetOrCreate(page_node()) PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
->is_connected_to_usb_device_ = true; ->SetIsConnectedToUSBDeviceForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
...@@ -184,8 +185,8 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardIsConnectedToUSBDevice) { ...@@ -184,8 +185,8 @@ TEST_F(PageDiscardingHelperTest, TestCannotDiscardIsConnectedToUSBDevice) {
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageMultipleTimes) { TEST_F(PageDiscardingHelperTest, TestCannotDiscardPageMultipleTimes) {
testing::FakePageLiveStateData::GetOrCreate(page_node())->was_discarded_ = PageLiveStateDecorator::Data::GetOrCreateForTesting(page_node())
true; ->SetWasDiscardedForTesting(true);
EXPECT_FALSE( EXPECT_FALSE(
PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting( PageDiscardingHelper::GetFromGraph(graph())->CanUrgentlyDiscardForTesting(
page_node())); page_node()));
......
...@@ -7,69 +7,16 @@ ...@@ -7,69 +7,16 @@
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/performance_manager/decorators/page_aggregator.h" #include "chrome/browser/performance_manager/decorators/page_aggregator.h"
#include "chrome/browser/performance_manager/policies/page_discarding_helper.h" #include "chrome/browser/performance_manager/policies/page_discarding_helper.h"
#include "components/performance_manager/decorators/freezing_vote_decorator.h"
#include "components/performance_manager/freezing/freezing_vote_aggregator.h"
#include "components/performance_manager/graph/frame_node_impl.h" #include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/page_node_impl.h" #include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/decorators/page_live_state_decorator.h"
#include "components/performance_manager/test_support/graph_test_harness.h" #include "components/performance_manager/test_support/graph_test_harness.h"
namespace performance_manager { namespace performance_manager {
namespace testing { namespace testing {
namespace {
// Test version of the PageDiscardingHelper.
class TestPageDiscardingHelper : public policies::PageDiscardingHelper {
public:
TestPageDiscardingHelper();
~TestPageDiscardingHelper() override;
TestPageDiscardingHelper(const TestPageDiscardingHelper& other) = delete;
TestPageDiscardingHelper& operator=(const TestPageDiscardingHelper&) = delete;
protected:
const PageLiveStateDecorator::Data* GetPageNodeLiveStateData(
const PageNode* page_node) const override {
// Returns a fake version of the PageLiveStateDecorator::Data, create it if
// it doesn't exist. Tests that want to set some fake live state data should
// call |FakePageLiveStateData::GetOrCreate|.
return FakePageLiveStateData::GetOrCreate(
PageNodeImpl::FromNode(page_node));
}
};
} // namespace
FakePageLiveStateData::~FakePageLiveStateData() = default;
// PageLiveStateDecorator::Data:
bool FakePageLiveStateData::IsConnectedToUSBDevice() const {
return is_connected_to_usb_device_;
}
bool FakePageLiveStateData::IsConnectedToBluetoothDevice() const {
return is_connected_to_bluetooth_device_;
}
bool FakePageLiveStateData::IsCapturingVideo() const {
return is_capturing_video_;
}
bool FakePageLiveStateData::IsCapturingAudio() const {
return is_capturing_audio_;
}
bool FakePageLiveStateData::IsBeingMirrored() const {
return is_being_mirrored_;
}
bool FakePageLiveStateData::IsCapturingWindow() const {
return is_capturing_window_;
}
bool FakePageLiveStateData::IsCapturingDisplay() const {
return is_capturing_display_;
}
bool FakePageLiveStateData::IsAutoDiscardable() const {
return is_auto_discardable_;
}
bool FakePageLiveStateData::WasDiscarded() const {
return was_discarded_;
}
FakePageLiveStateData::FakePageLiveStateData(const PageNodeImpl* page_node) {}
LenientMockPageDiscarder::LenientMockPageDiscarder() = default; LenientMockPageDiscarder::LenientMockPageDiscarder() = default;
LenientMockPageDiscarder::~LenientMockPageDiscarder() = default; LenientMockPageDiscarder::~LenientMockPageDiscarder() = default;
...@@ -79,9 +26,6 @@ void LenientMockPageDiscarder::DiscardPageNode( ...@@ -79,9 +26,6 @@ void LenientMockPageDiscarder::DiscardPageNode(
std::move(post_discard_cb).Run(DiscardPageNodeImpl(page_node)); std::move(post_discard_cb).Run(DiscardPageNodeImpl(page_node));
} }
TestPageDiscardingHelper::TestPageDiscardingHelper() = default;
TestPageDiscardingHelper::~TestPageDiscardingHelper() = default;
GraphTestHarnessWithMockDiscarder::GraphTestHarnessWithMockDiscarder() { GraphTestHarnessWithMockDiscarder::GraphTestHarnessWithMockDiscarder() {
// Some tests depends on the existence of the PageAggregator. // Some tests depends on the existence of the PageAggregator.
graph()->PassToGraph(std::make_unique<PageAggregator>()); graph()->PassToGraph(std::make_unique<PageAggregator>());
...@@ -97,8 +41,12 @@ void GraphTestHarnessWithMockDiscarder::SetUp() { ...@@ -97,8 +41,12 @@ void GraphTestHarnessWithMockDiscarder::SetUp() {
auto mock_discarder = std::make_unique<MockPageDiscarder>(); auto mock_discarder = std::make_unique<MockPageDiscarder>();
mock_discarder_ = mock_discarder.get(); mock_discarder_ = mock_discarder.get();
// The discarding logic relies on the existance of the page live state data.
graph()->PassToGraph(std::make_unique<PageLiveStateDecorator>());
// Create the helper and pass it to the graph. // Create the helper and pass it to the graph.
auto page_discarding_helper = std::make_unique<TestPageDiscardingHelper>(); auto page_discarding_helper =
std::make_unique<policies::PageDiscardingHelper>();
page_discarding_helper->SetMockDiscarderForTesting(std::move(mock_discarder)); page_discarding_helper->SetMockDiscarderForTesting(std::move(mock_discarder));
graph()->PassToGraph(std::move(page_discarding_helper)); graph()->PassToGraph(std::move(page_discarding_helper));
......
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#include "chrome/browser/performance_manager/mechanisms/page_discarder.h" #include "chrome/browser/performance_manager/mechanisms/page_discarder.h"
#include "chrome/browser/performance_manager/policies/page_discarding_helper.h" #include "chrome/browser/performance_manager/policies/page_discarding_helper.h"
#include "components/performance_manager/graph/node_attached_data_impl.h"
#include "components/performance_manager/public/decorators/page_live_state_decorator.h"
#include "components/performance_manager/test_support/graph_test_harness.h" #include "components/performance_manager/test_support/graph_test_harness.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -21,44 +19,6 @@ class ProcessNodeImpl; ...@@ -21,44 +19,6 @@ class ProcessNodeImpl;
namespace testing { namespace testing {
// Class allowing setting some fake PageLiveStateDecorator::Data for a PageNode.
class FakePageLiveStateData
: public PageLiveStateDecorator::Data,
public NodeAttachedDataImpl<FakePageLiveStateData> {
public:
struct Traits : public NodeAttachedDataInMap<PageNodeImpl> {};
~FakePageLiveStateData() override;
FakePageLiveStateData(const FakePageLiveStateData& other) = delete;
FakePageLiveStateData& operator=(const FakePageLiveStateData&) = delete;
// PageLiveStateDecorator::Data:
bool IsConnectedToUSBDevice() const override;
bool IsConnectedToBluetoothDevice() const override;
bool IsCapturingVideo() const override;
bool IsCapturingAudio() const override;
bool IsBeingMirrored() const override;
bool IsCapturingWindow() const override;
bool IsCapturingDisplay() const override;
bool IsAutoDiscardable() const override;
bool WasDiscarded() const override;
bool is_connected_to_usb_device_ = false;
bool is_connected_to_bluetooth_device_ = false;
bool is_capturing_video_ = false;
bool is_capturing_audio_ = false;
bool is_being_mirrored_ = false;
bool is_capturing_window_ = false;
bool is_capturing_display_ = false;
bool is_auto_discardable_ = true;
bool was_discarded_ = false;
private:
friend class ::performance_manager::NodeAttachedDataImpl<
FakePageLiveStateData>;
explicit FakePageLiveStateData(const PageNodeImpl* page_node);
};
// Mock version of a performance_manager::mechanism::PageDiscarder. // Mock version of a performance_manager::mechanism::PageDiscarder.
class LenientMockPageDiscarder class LenientMockPageDiscarder
: public performance_manager::mechanism::PageDiscarder { : public performance_manager::mechanism::PageDiscarder {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "components/performance_manager/public/decorators/page_live_state_decorator.h" #include "components/performance_manager/public/decorators/page_live_state_decorator.h"
#include "components/performance_manager/decorators/decorators_utils.h" #include "components/performance_manager/decorators/decorators_utils.h"
#include "components/performance_manager/freezing/freezing_vote_aggregator.h"
#include "components/performance_manager/graph/node_attached_data_impl.h" #include "components/performance_manager/graph/node_attached_data_impl.h"
#include "components/performance_manager/graph/page_node_impl.h" #include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h" #include "components/performance_manager/public/graph/node_data_describer_registry.h"
...@@ -41,6 +42,34 @@ class PageLiveStateDataImpl ...@@ -41,6 +42,34 @@ class PageLiveStateDataImpl
bool IsAutoDiscardable() const override { return is_auto_discardable_; } bool IsAutoDiscardable() const override { return is_auto_discardable_; }
bool WasDiscarded() const override { return was_discarded_; } bool WasDiscarded() const override { return was_discarded_; }
void SetIsConnectedToUSBDeviceForTesting(bool value) override {
set_is_connected_to_usb_device(value);
}
void SetIsConnectedToBluetoothDeviceForTesting(bool value) override {
set_is_connected_to_bluetooth_device(value);
}
void SetIsCapturingVideoForTesting(bool value) override {
set_is_capturing_video(value);
}
void SetIsCapturingAudioForTesting(bool value) override {
set_is_capturing_audio(value);
}
void SetIsBeingMirroredForTesting(bool value) override {
set_is_being_mirrored(value);
}
void SetIsCapturingWindowForTesting(bool value) override {
set_is_capturing_window(value);
}
void SetIsCapturingDisplayForTesting(bool value) override {
set_is_capturing_display(value);
}
void SetIsAutoDiscardableForTesting(bool value) override {
set_is_auto_discardable(value);
}
void SetWasDiscardedForTesting(bool value) override {
set_was_discarded(value);
}
void set_is_connected_to_usb_device(bool is_connected_to_usb_device) { void set_is_connected_to_usb_device(bool is_connected_to_usb_device) {
is_connected_to_usb_device_ = is_connected_to_usb_device; is_connected_to_usb_device_ = is_connected_to_usb_device;
} }
......
...@@ -89,6 +89,16 @@ class PageLiveStateDecorator::Data { ...@@ -89,6 +89,16 @@ class PageLiveStateDecorator::Data {
static const Data* FromPageNode(const PageNode* page_node); static const Data* FromPageNode(const PageNode* page_node);
static Data* GetOrCreateForTesting(PageNode* page_node); static Data* GetOrCreateForTesting(PageNode* page_node);
virtual void SetIsConnectedToUSBDeviceForTesting(bool value) = 0;
virtual void SetIsConnectedToBluetoothDeviceForTesting(bool value) = 0;
virtual void SetIsCapturingVideoForTesting(bool value) = 0;
virtual void SetIsCapturingAudioForTesting(bool value) = 0;
virtual void SetIsBeingMirroredForTesting(bool value) = 0;
virtual void SetIsCapturingWindowForTesting(bool value) = 0;
virtual void SetIsCapturingDisplayForTesting(bool value) = 0;
virtual void SetIsAutoDiscardableForTesting(bool value) = 0;
virtual void SetWasDiscardedForTesting(bool value) = 0;
}; };
} // namespace performance_manager } // namespace performance_manager
......
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