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

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

#include "base/callback_list.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/simple_test_tick_clock.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/performance_manager/public/user_tuning/user_performance_tuning_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/resource_coordinator/utils.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/performance_controls/test_support/memory_saver_interactive_test_mixin.h"
#include "chrome/browser/ui/recently_audible_helper.h"
#include "chrome/browser/ui/views/frame/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/performance_controls/memory_saver_bubble_view.h"
#include "chrome/browser/ui/views/performance_controls/memory_saver_chip_view.h"
#include "chrome/browser/ui/views/performance_controls/memory_saver_resource_view.h"
#include "chrome/browser/ui/views/tabs/tab_icon.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/webui/test_support/webui_interactive_test_mixin.h"
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/interaction/interactive_browser_test.h"
#include "chrome/test/user_education/interactive_feature_promo_test.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/feature_engagement/public/feature_list.h"
#include "components/feature_engagement/test/scoped_iph_feature_list.h"
#include "components/performance_manager/public/decorators/process_metrics_decorator.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/prefs/pref_service.h"
#include "components/user_education/views/help_bubble_view.h"
#include "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"
#include "third_party/blink/public/common/switches.h"
#include "ui/base/interaction/element_identifier.h"
#include "ui/base/interaction/element_tracker.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/text/bytes_formatting.h"
#include "ui/gfx/animation/animation.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/interaction/element_tracker_views.h"
#include "url/gurl.h"

namespace {
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_ELEMENT_IDENTIFIER_VALUE();
DEFINE_LOCAL_CUSTOM_ELEMENT_EVENT_TYPE();

constexpr char kSkipPixelTestsReason[] =;

}  // namespace


// Tests Discarding on pages with various types of content
class MemorySaverDiscardPolicyInteractiveTest
    : public MemorySaverInteractiveTestMixin<InteractiveBrowserTest> {};

// Check that a tab playing a video in the background won't be discarded
IN_PROC_BROWSER_TEST_F(MemorySaverDiscardPolicyInteractiveTest,
                       TabWithVideoNotDiscarded) {}

// Check that a tab playing audio in the background won't be discarded
IN_PROC_BROWSER_TEST_F(MemorySaverDiscardPolicyInteractiveTest,
                       TabWithAudioNotDiscarded) {}

// Check that a form in the background but was interacted with by the user
// won't be discarded
IN_PROC_BROWSER_TEST_F(MemorySaverDiscardPolicyInteractiveTest,
                       TabWithFormNotDiscarded) {}

// Check that tabs with enabled notifications won't be discarded
IN_PROC_BROWSER_TEST_F(MemorySaverDiscardPolicyInteractiveTest,
                       TabWithNotificationNotDiscarded) {}

// Tests the functionality of the Memory Saver page action chip
class MemorySaverChipInteractiveTest
    : public MemorySaverInteractiveTestMixin<InteractiveBrowserTest> {};

// Page Action Chip should appear expanded the first three times a tab is
// discarded and collapse all subsequent times
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest, PageActionChipShows) {}

// Page Action chip should collapses after navigating to a tab without a chip
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       PageActionChipCollapseOnTabSwitch) {}

// Page Action chip should stay collapsed when navigating between two
// discarded tabs
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       ChipCollapseRemainCollapse) {}

// Page Action chip should only show on discarded non-chrome pages
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       ChipShowsOnNonChromeSites) {}

// Memory Saver Dialog bubble should close after clicking the "OK" button
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       CloseBubbleOnOkButtonClick) {}

// Memory Saver dialog bubble should close after clicking on the "X"
// close button
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       CloseBubbleOnCloseButtonClick) {}

// Memory Saver Dialog bubble should close after clicking on
// the page action chip again
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest, CloseBubbleOnChipClick) {}

// Memory Saver dialog bubble should close when clicking to navigate to
// another tab
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest, CloseBubbleOnTabSwitch) {}

IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       BubbleCorrectlyReportingMemorySaved) {}

// Memory Saver Dialog bubble should add the site it is currently on
// to the exceptions list if the cancel button of the dialog bubble is clicked.
// Opening the dialog button again will cause the cancel button to give users
// the option to go to settings instead.
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       ModifyExceptionsListOnCancelButtonClick) {}

// Memory Saver Dialog bubble's cancel button's state should be preserved
// for that tab even when navigating to another tab.
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       CancelButtonStatePreseveredWhenSwitchingTabs) {}

// The memory saver chip dialog renders a gauge style visualization that
// must be rendered correctly.
IN_PROC_BROWSER_TEST_F(MemorySaverChipInteractiveTest,
                       RenderVisualizationInDialog) {}

class MemorySaverDiscardIndicatorIPHTest
    : public MemorySaverInteractiveTestMixin<InteractiveFeaturePromoTest> {};

IN_PROC_BROWSER_TEST_F(MemorySaverDiscardIndicatorIPHTest,
                       IPHAppearsWhenTabIsDiscarded) {}

class MemorySaverImprovedFaviconTreatmentTest
    : public WebUiInteractiveTestMixin<
          MemorySaverInteractiveTestMixin<InteractiveBrowserTest>> {};

IN_PROC_BROWSER_TEST_F(MemorySaverImprovedFaviconTreatmentTest,
                       FaviconTreatmentOnDiscard) {}

IN_PROC_BROWSER_TEST_F(MemorySaverImprovedFaviconTreatmentTest,
                       DiscardRingTreatmentSetting) {}