#include "content/browser/scheduler/responsiveness/calculator.h"
#include <optional>
#include "base/test/metrics/histogram_tester.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "content/public/browser/responsiveness_calculator_delegate.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace content {
namespace responsiveness {
CongestionType;
StartupStage;
_;
namespace {
constexpr int kMeasurementIntervalInMs = …;
constexpr int kCongestionThresholdInMs = …;
class FakeCalculator : public Calculator { … };
}
class MockDelegate : public ResponsivenessCalculatorDelegate { … };
class ResponsivenessCalculatorTest : public testing::Test { … };
#define EXPECT_EXECUTION_CONGESTED_SLICES(num_slices, phase) …
#define EXPECT_CONGESTED_SLICES(num_slices, phase) …
TEST_F(ResponsivenessCalculatorTest, ShortExecutionCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, ShortQueueCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, ShortCombinedQueueAndExecutionCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, LongExecutionCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, LongQueueCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, NoExecutionCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, NoQueueCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, OverlappingExecutionCongestion) { … }
TEST_F(ResponsivenessCalculatorTest, OverlappingQueueCongestion) { … }
TEST_F(ResponsivenessCalculatorTest,
OverlappingExecutionCongestionMultipleThreads) { … }
TEST_F(ResponsivenessCalculatorTest,
OverlappingQueueCongestionMultipleThreads) { … }
TEST_F(ResponsivenessCalculatorTest, SeparatedExecutionCongestions) { … }
TEST_F(ResponsivenessCalculatorTest, SeparatedQueueCongestions) { … }
TEST_F(ResponsivenessCalculatorTest, MultipleTrigger) { … }
TEST_F(ResponsivenessCalculatorTest, LongDelay) { … }
TEST_F(ResponsivenessCalculatorTest, LongEvent) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(ResponsivenessCalculatorTest, ApplicationInBackground) {
constexpr int kQueueTime = 35;
constexpr int kStartTime = 40;
constexpr int kFinishTime = kStartTime + kCongestionThresholdInMs + 5;
AddEventUI(kQueueTime, kStartTime, kFinishTime);
base::android::ApplicationStatusListener::NotifyApplicationStateChange(
base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES);
base::RunLoop().RunUntilIdle();
AddEventUI(kQueueTime, kStartTime + 1, kFinishTime + 1);
EXPECT_CALL(*calculator_, EmitResponsivenessMock(_, _, _)).Times(0);
TriggerCalculation();
}
#endif
TEST_F(ResponsivenessCalculatorTest, StartupStages) { … }
TEST_F(ResponsivenessCalculatorTest, FastStartupStages) { … }
TEST_F(ResponsivenessCalculatorTest, ExecutionCrossesBoundary) { … }
TEST_F(ResponsivenessCalculatorTest, QueuingCrossesBoundary) { … }
TEST_F(ResponsivenessCalculatorTest, UnorderedEvents) { … }
TEST_F(ResponsivenessCalculatorTest, EmitResponsivenessTraceEventsEmpty) { … }
TEST_F(ResponsivenessCalculatorTest, EmitResponsivenessTraceEventsWrongMetric) { … }
TEST_F(ResponsivenessCalculatorTest, EmitResponsivenessTraceEvents) { … }
TEST_F(ResponsivenessCalculatorTest, Delegate) { … }
}
}