#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 {
const int kNumHealthStatusForChange = …;
const CpuHealthTracker::CpuPercent kUnhealthySystemCpuUsagePercentage{ … };
const CpuHealthTracker::CpuPercent kDegradedSystemCpuUsagePercentage{ … };
class StatusWaiter : public PerformanceDetectionManager::StatusObserver { … };
class ActionabilityWaiter
: public PerformanceDetectionManager::ActionableTabsObserver { … };
}
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) { … }
TEST_F(CpuHealthTrackerBrowserTest, UpdateActionableTabs) { … }
TEST_F(CpuHealthTrackerBrowserTest, HigherCPUTabIsActionable) { … }
TEST_F(CpuHealthTrackerBrowserTest, NotifyWhenNoTabsAreActionable) { … }
TEST_F(CpuHealthTrackerBrowserTest, NeedMultipleTabsToBeActionable) { … }
TEST_F(CpuHealthTrackerBrowserTest, ActionableTabsRespectExceptionsList) { … }
TEST_F(CpuHealthTrackerBrowserTest, ActionableTabsIgnoreIncognitoTabs) { … }
}