chromium/chrome/browser/ui/views/performance_controls/memory_saver_chip_view_unittest.cc

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/performance_controls/memory_saver_chip_view.h"

#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/performance_manager/test_support/test_user_performance_tuning_manager_environment.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-shared.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/performance_controls/memory_saver_chip_tab_helper.h"
#include "chrome/browser/ui/performance_controls/performance_controls_metrics.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/test_with_browser_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_controller.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/browser/ui/views/performance_controls/memory_saver_bubble_view.h"
#include "chrome/browser/ui/views/performance_controls/memory_saver_resource_view.h"
#include "chrome/browser/ui/views/performance_controls/test_support/memory_saver_unit_test_mixin.h"
#include "chrome/browser/ui/views/side_panel/side_panel.h"
#include "chrome/browser/ui/views/side_panel/side_panel_coordinator.h"
#include "chrome/browser/ui/views/side_panel/side_panel_entry.h"
#include "chrome/browser/ui/views/side_panel/side_panel_ui.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_profile.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_navigation_handle.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/events/event_utils.h"
#include "ui/events/types/event_type.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "ui/views/test/button_test_api.h"

namespace {
constexpr int64_t kMemorySavingsKilobytes =;
constexpr int64_t kHighMemorySavingsKilobytes =;
constexpr int64_t kVeryHighMemorySavingsKilobytes =;
}  // namespace

class MemorySaverChipViewTest
    : public MemorySaverUnitTestMixin<TestWithBrowserView> {};

// When the previous page has a tab discard state of true, when the icon is
// updated it should be visible.
TEST_F(MemorySaverChipViewTest, ShouldShowChipForProactivelyDiscardedPage) {}

TEST_F(MemorySaverChipViewTest,
       ShouldNotShowChipWhenNonProactivelyDiscardPage) {}

// If a discard is triggered when the user doesn't have memory saver mode
// enabled, we don't show the chip.
TEST_F(MemorySaverChipViewTest, ShouldNotShowWhenPrefIsFalse) {}

// When the collapsed chip is shown, UMA metrics should be logged.
TEST_F(MemorySaverChipViewTest, ShouldLogMetricsForCollapsedChip) {}

// When the educational expanded chip is shown, UMA metrics should be logged.
TEST_F(MemorySaverChipViewTest, ShouldLogMetricsForInformationalExpandedChip) {}

// When the previous page was not previously discarded, the icon should not be
// visible.
TEST_F(MemorySaverChipViewTest, ShouldNotShowForRegularPage) {}

// When the previous page was not previously discarded, the icon should not be
// visible.
TEST_F(MemorySaverChipViewTest, ShouldHideLabelAfterMultipleDiscards) {}

TEST_F(MemorySaverChipViewTest, ShouldCollapseChipAfterNavigatingTabs) {}

// When the savings are above the threshold then the chip is
// eligible to expand.
TEST_F(MemorySaverChipViewTest, ShouldExpandChipWhenConditionsAreMet) {}

// When the savings are below the threshold then the chip won't
// expand.
TEST_F(MemorySaverChipViewTest, ShouldNotExpandForSavingsBelowThreshold) {}

// When the savings chip has been expanded recently then it does not show in
// the expanded mode.
TEST_F(MemorySaverChipViewTest, ShouldNotExpandWhenChipHasExpandedRecently) {}

// When the tab has been expanded recently then the chip does not show in the
// expanded mode.
TEST_F(MemorySaverChipViewTest, ShouldNotExpandWhenTabWasDiscardedRecently) {}

// When the celebratory expanded chip is shown, UMA metrics should be logged.
TEST_F(MemorySaverChipViewTest, ShouldLogMetricsForCelebratoryExpandedChip) {}

// When a tab is proactively discarded with >2Gb memory saving, we should show
// the expanded chip with savings, and not crash.
TEST_F(MemorySaverChipViewTest, MoreThan2GbMemorySavings) {}