chromium/chrome/browser/performance_manager/user_tuning/cpu_health_tracker_unittest.cc

// Copyright 2024 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/performance_manager/user_tuning/cpu_health_tracker.h"

#include <memory>
#include <optional>
#include <tuple>
#include <utility>
#include <vector>

#include "base/check_op.h"
#include "base/containers/flat_map.h"
#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/run_loop.h"
#include "base/system/sys_info.h"
#include "base/task/bind_post_task.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "base/time/time.h"
#include "chrome/browser/performance_manager/policies/page_discarding_helper.h"
#include "chrome/browser/performance_manager/public/user_tuning/performance_detection_manager.h"
#include "chrome/browser/performance_manager/test_support/page_discarding_utils.h"
#include "chrome/browser/performance_manager/user_tuning/profile_discard_opt_out_list_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "components/performance_manager/public/features.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/performance_manager.h"
#include "components/performance_manager/public/resource_attribution/page_context.h"
#include "components/performance_manager/public/resource_attribution/query_results.h"
#include "components/performance_manager/public/resource_attribution/resource_contexts.h"
#include "components/performance_manager/public/user_tuning/prefs.h"
#include "components/performance_manager/test_support/run_in_graph.h"
#include "components/performance_manager/test_support/test_harness_helper.h"
#include "components/system_cpu/cpu_sample.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace performance_manager::user_tuning {

namespace {

// Number of times to see a health status consecutively for the health status to
// change
const int kNumHealthStatusForChange =;

const CpuHealthTracker::CpuPercent kUnhealthySystemCpuUsagePercentage{};
const CpuHealthTracker::CpuPercent kDegradedSystemCpuUsagePercentage{};

class StatusWaiter : public PerformanceDetectionManager::StatusObserver {};

class ActionabilityWaiter
    : public PerformanceDetectionManager::ActionableTabsObserver {};
}  // namespace

class CpuHealthTrackerTestHelper {};

class CpuHealthTrackerTest : public ChromeRenderViewHostTestHarness,
                             public CpuHealthTrackerTestHelper {};

TEST_F(CpuHealthTrackerTest, RecordCpuAndUpdateHealthStatus) {}

TEST_F(CpuHealthTrackerTest, CpuStatusUpdates) {}

TEST_F(CpuHealthTrackerTest, HealthyCpuUsageFromProbe) {}

class CpuHealthTrackerBrowserTest : public BrowserWithTestWindowTest,
                                    public CpuHealthTrackerTestHelper {};

TEST_F(CpuHealthTrackerBrowserTest, HealthStatusUpdates) {}

TEST_F(CpuHealthTrackerBrowserTest, PagesMeetMinimumCpuUsage) {}

// The PerformanceDetectionManager should properly notify observers
// when a tab is actionable.
TEST_F(CpuHealthTrackerBrowserTest, UpdateActionableTabs) {}

// When multiple tabs are eligible to improve CPU health, the tab with the
// higher CPU usage is sent to observers
TEST_F(CpuHealthTrackerBrowserTest, HigherCPUTabIsActionable) {}

// Verify that the PerformanceDetectionManager notifies observers when the
// actionable tab list changes from having actionable tabs to no tabs are
// actionable.
TEST_F(CpuHealthTrackerBrowserTest, NotifyWhenNoTabsAreActionable) {}

TEST_F(CpuHealthTrackerBrowserTest, NeedMultipleTabsToBeActionable) {}

// Tabs on the discard exceptions list should not be actionable
TEST_F(CpuHealthTrackerBrowserTest, ActionableTabsRespectExceptionsList) {}

TEST_F(CpuHealthTrackerBrowserTest, ActionableTabsIgnoreIncognitoTabs) {}

}  // namespace performance_manager::user_tuning