Skip to content

Commit

Permalink
Get high efficiency gauge dialog integration test working
Browse files Browse the repository at this point in the history
It turns out I forgot to add it to pixel_tests.filter and once I
did that I noticed the element ID was incorrect so I needed to
add a new once. Confirmed the golden image is generated correctly
now.

Bug: 1424230
Change-Id: Ib03f435ed5cb4e24c677647aa393dc4191e2268b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4546555
Auto-Submit: Alison Gale <agale@chromium.org>
Commit-Queue: Alison Gale <agale@chromium.org>
Reviewed-by: Joe Mason <joenotcharles@google.com>
Cr-Commit-Position: refs/heads/main@{#1146820}
  • Loading branch information
Alison Gale authored and Chromium LUCI CQ committed May 20, 2023
1 parent 751306d commit 686113e
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
Expand Up @@ -120,6 +120,11 @@ class UserPerformanceTuningManager {
return memory_footprint_estimate_;
}

void SetMemoryFootprintEstimateKbForTesting(
uint64_t memory_footprint_estimate) {
memory_footprint_estimate_ = memory_footprint_estimate;
}

::mojom::LifecycleUnitDiscardReason discard_reason() const {
return discard_reason_;
}
Expand Down
Expand Up @@ -34,6 +34,9 @@

DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(HighEfficiencyBubbleView,
kHighEfficiencyDialogBodyElementId);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(
HighEfficiencyBubbleView,
kHighEfficiencyDialogResourceViewElementId);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(HighEfficiencyBubbleView,
kHighEfficiencyDialogOkButton);
DEFINE_CLASS_ELEMENT_IDENTIFIER_VALUE(HighEfficiencyBubbleView,
Expand Down Expand Up @@ -147,7 +150,8 @@ views::BubbleDialogModelHost* HighEfficiencyBubbleView::ShowBubble(
dialog_model_builder.AddCustomField(
std::make_unique<views::BubbleDialogModelHost::CustomView>(
std::make_unique<HighEfficiencyResourceView>(memory_savings),
views::BubbleDialogModelHost::FieldType::kText));
views::BubbleDialogModelHost::FieldType::kText),
kHighEfficiencyDialogResourceViewElementId);
}

if (base::FeatureList::IsEnabled(
Expand Down
Expand Up @@ -16,6 +16,8 @@ class HighEfficiencyBubbleView {
HighEfficiencyBubbleView& operator=(const HighEfficiencyBubbleView&) = delete;

DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHighEfficiencyDialogBodyElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(
kHighEfficiencyDialogResourceViewElementId);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHighEfficiencyDialogOkButton);
DECLARE_CLASS_ELEMENT_IDENTIFIER_VALUE(kHighEfficiencyDialogCancelButton);

Expand Down
Expand Up @@ -288,9 +288,9 @@ class HighEfficiencyBubbleViewMemorySavingsImprovementsTest
base::test::ScopedFeatureList feature_list_;
};

// The memory savings should be rendered within the dialog.
// The memory savings should be rendered within the resource view.
TEST_F(HighEfficiencyBubbleViewMemorySavingsImprovementsTest,
ShouldRenderMemorySavingsInDialog) {
ShouldRenderMemorySavingsInResourceView) {
SetTabDiscardState(0, true);

ClickPageActionChip();
Expand All @@ -301,3 +301,22 @@ TEST_F(HighEfficiencyBubbleViewMemorySavingsImprovementsTest,
EXPECT_TRUE(label->GetText().find(ui::FormatBytes(
kMemorySavingsKilobytes * 1024)) != std::string::npos);
}

// The memory savings should not be rendered within the text above the resource
// view.
TEST_F(HighEfficiencyBubbleViewMemorySavingsImprovementsTest,
ShouldNotRenderMemorySavingsInDialogBodyText) {
SetTabDiscardState(0, true);

ClickPageActionChip();

views::StyledLabel* label = GetDialogLabel<views::StyledLabel>(
HighEfficiencyBubbleView::kHighEfficiencyDialogBodyElementId);
EXPECT_EQ(
label->GetText().find(ui::FormatBytes(kMemorySavingsKilobytes * 1024)),
std::string::npos);

EXPECT_NE(
label->GetText().find(u"Memory Saver freed up memory for other tasks"),
std::string::npos);
}
Expand Up @@ -755,11 +755,11 @@ INSTANTIATE_TEST_SUITE_P(All,

// Tests the new memory savings reporting improvements on the high efficiency
// dialog.
class HighEfficiencyMemorySavingsReportingImprovmentsTest
class HighEfficiencyMemorySavingsReportingImprovementsTest
: public HighEfficiencyInteractiveTest {
public:
HighEfficiencyMemorySavingsReportingImprovmentsTest() = default;
~HighEfficiencyMemorySavingsReportingImprovmentsTest() override = default;
HighEfficiencyMemorySavingsReportingImprovementsTest() = default;
~HighEfficiencyMemorySavingsReportingImprovementsTest() override = default;

void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(
Expand All @@ -779,7 +779,7 @@ class HighEfficiencyMemorySavingsReportingImprovmentsTest

// The high efficiency chip dialog renders a gauge style visualization that
// must be rendered correctly.
IN_PROC_BROWSER_TEST_F(HighEfficiencyMemorySavingsReportingImprovmentsTest,
IN_PROC_BROWSER_TEST_F(HighEfficiencyMemorySavingsReportingImprovementsTest,
RenderVisualizationInDialog) {
RunTestSequence(
SetOnIncompatibleAction(OnIncompatibleAction::kSkipTest,
Expand All @@ -788,8 +788,19 @@ IN_PROC_BROWSER_TEST_F(HighEfficiencyMemorySavingsReportingImprovmentsTest,
NavigateWebContents(kFirstTabContents, GetURL("/title1.html")),
AddInstrumentedTab(kSecondTabContents, GURL(chrome::kChromeUINewTabURL)),
ForceRefreshMemoryMetrics(), DiscardAndSelectTab(0, kFirstTabContents),
Do(base::BindLambdaForTesting([&]() {
content::WebContents* web_contents =
browser()->tab_strip_model()->GetWebContentsAt(0);
auto* pre_discard_resource_usage =
performance_manager::user_tuning::UserPerformanceTuningManager::
PreDiscardResourceUsage::FromWebContents(web_contents);
pre_discard_resource_usage->SetMemoryFootprintEstimateKbForTesting(
135 * 1024);
})),
PressButton(kHighEfficiencyChipElementId),
WaitForShow(HighEfficiencyBubbleView::kHighEfficiencyDialogBodyElementId),
Screenshot(HighEfficiencyBubbleView::kHighEfficiencyDialogBodyElementId,
"HighEfficiencyResourceView", "4497874"));
WaitForShow(
HighEfficiencyBubbleView::kHighEfficiencyDialogResourceViewElementId),
Screenshot(
HighEfficiencyBubbleView::kHighEfficiencyDialogResourceViewElementId,
"HighEfficiencyResourceView", "4546555"));
}
1 change: 1 addition & 0 deletions testing/buildbot/filters/pixel_tests.filter
Expand Up @@ -35,6 +35,7 @@ FirstRunIntroPixelTest.*
GlobalErrorBubbleTest.*
HatsBubbleTest.*
*HighEfficiencyFaviconTreatmentTest.*
*HighEfficiencyMemorySavingsReportingImprovementsTest.*
HomeButtonUiTest.*
HungRendererDialogViewBrowserTest.*
ImportLockDialogViewBrowserTest.*
Expand Down

0 comments on commit 686113e

Please sign in to comment.