This source file includes following definitions.
- Reset
- BeganFrame
- frame_count
- FrameRateControllerTick
- TEST
- TEST
- TEST
- TEST
#include "cc/scheduler/frame_rate_controller.h"
#include "base/test/test_simple_task_runner.h"
#include "cc/test/scheduler_test_common.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
class FakeFrameRateControllerClient : public FrameRateControllerClient {
public:
FakeFrameRateControllerClient() { Reset(); }
void Reset() { frame_count_ = 0; }
bool BeganFrame() const { return frame_count_ > 0; }
int frame_count() const { return frame_count_; }
virtual void FrameRateControllerTick(
bool throttled, const BeginFrameArgs& args) OVERRIDE {
frame_count_ += throttled ? 0 : 1;
}
protected:
int frame_count_;
};
TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) {
scoped_refptr<base::TestSimpleTaskRunner> task_runner =
new base::TestSimpleTaskRunner;
FakeFrameRateControllerClient client;
base::TimeDelta interval = base::TimeDelta::FromMicroseconds(
base::Time::kMicrosecondsPerSecond / 60);
scoped_refptr<FakeDelayBasedTimeSource> time_source =
FakeDelayBasedTimeSource::Create(interval, task_runner.get());
FrameRateController controller(time_source);
controller.SetClient(&client);
controller.SetActive(true);
base::TimeTicks elapsed;
elapsed += task_runner->NextPendingTaskDelay();
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
controller.DidSwapBuffers();
time_source->SetNow(time_source->Now() +
base::TimeDelta::FromMilliseconds(5));
controller.DidSwapBuffersComplete();
elapsed += task_runner->NextPendingTaskDelay();
EXPECT_GE(elapsed, time_source->Now());
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
}
TEST(FrameRateControllerTest, TestFrameThrottling_TwoFramesInFlight) {
scoped_refptr<base::TestSimpleTaskRunner> task_runner =
new base::TestSimpleTaskRunner;
FakeFrameRateControllerClient client;
base::TimeDelta interval = base::TimeDelta::FromMicroseconds(
base::Time::kMicrosecondsPerSecond / 60);
scoped_refptr<FakeDelayBasedTimeSource> time_source =
FakeDelayBasedTimeSource::Create(interval, task_runner.get());
FrameRateController controller(time_source);
controller.SetClient(&client);
controller.SetActive(true);
controller.SetMaxSwapsPending(2);
base::TimeTicks elapsed;
elapsed += task_runner->NextPendingTaskDelay();
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
controller.DidSwapBuffers();
elapsed += task_runner->NextPendingTaskDelay();
EXPECT_GE(elapsed, time_source->Now());
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
controller.DidSwapBuffers();
elapsed += task_runner->NextPendingTaskDelay();
EXPECT_GE(elapsed, time_source->Now());
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_FALSE(client.BeganFrame());
time_source->SetNow(time_source->Now() +
base::TimeDelta::FromMilliseconds(5));
controller.DidSwapBuffersComplete();
EXPECT_FALSE(client.BeganFrame());
elapsed += task_runner->NextPendingTaskDelay();
EXPECT_GE(elapsed, time_source->Now());
time_source->SetNow(elapsed);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
}
TEST(FrameRateControllerTest, TestFrameThrottling_Unthrottled) {
scoped_refptr<base::TestSimpleTaskRunner> task_runner =
new base::TestSimpleTaskRunner;
FakeFrameRateControllerClient client;
FrameRateController controller(task_runner.get());
controller.SetClient(&client);
controller.SetMaxSwapsPending(2);
controller.SetActive(true);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
controller.DidSwapBuffers();
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
controller.DidSwapBuffers();
task_runner->RunPendingTasks();
EXPECT_FALSE(client.BeganFrame());
client.Reset();
EXPECT_FALSE(task_runner->HasPendingTask());
controller.DidSwapBuffersComplete();
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
}
TEST(FrameRateControllerTest, TestFrameThrottling_NoDoubleTicking) {
scoped_refptr<base::TestSimpleTaskRunner> task_runner =
new base::TestSimpleTaskRunner;
FakeFrameRateControllerClient client;
FrameRateController controller(task_runner.get());
controller.SetClient(&client);
controller.SetActive(true);
task_runner->RunPendingTasks();
EXPECT_TRUE(client.BeganFrame());
client.Reset();
EXPECT_TRUE(task_runner->HasPendingTask());
controller.DidSwapBuffers();
controller.DidSwapBuffersComplete();
task_runner->RunPendingTasks();
EXPECT_EQ(1, client.frame_count());
}
}
}