Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4519)

Unified Diff: cc/tiles/gpu_image_decode_controller_unittest.cc

Issue 1997743002: cc: Implement test task runner for tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@remove_schedule_complete
Patch Set: extended to SoftwareImageDecodeControllerTest Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/tiles/gpu_image_decode_controller_unittest.cc
diff --git a/cc/tiles/gpu_image_decode_controller_unittest.cc b/cc/tiles/gpu_image_decode_controller_unittest.cc
index 7d19d8dd86fd2ffe592017d13e6b39498f2e4c71..9ce9db04272afe17805a48dfa244e976197879e4 100644
--- a/cc/tiles/gpu_image_decode_controller_unittest.cc
+++ b/cc/tiles/gpu_image_decode_controller_unittest.cc
@@ -5,7 +5,7 @@
#include "cc/tiles/gpu_image_decode_controller.h"
#include "cc/playback/draw_image.h"
-#include "cc/raster/tile_task.h"
+#include "cc/test/simple_task_runner.h"
#include "cc/test/test_context_provider.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkRefCnt.h"
@@ -31,33 +31,6 @@ SkMatrix CreateMatrix(const SkSize& scale, bool is_decomposable) {
return matrix;
}
-void ScheduleTask(TileTask* task) {
- task->state().DidSchedule();
-}
-
-// Before running the task it must be scheduled. Call ScheduleTask() before
-// calling this function.
-void RunTask(TileTask* task) {
- task->state().DidStart();
- task->RunOnWorkerThread();
- task->state().DidFinish();
-}
-
-void CompleteTask(TileTask* task) {
- DCHECK(task->state().IsFinished() || task->state().IsCanceled());
- task->OnTaskCompleted();
-}
-
-void CancelTask(TileTask* task) {
- task->state().DidCancel();
-}
-
-void ProcessTask(TileTask* task) {
- ScheduleTask(task);
- RunTask(task);
- CompleteTask(task);
-}
-
TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) {
auto context_provider = TestContextProvider::Create();
context_provider->BindToCurrentThread();
@@ -85,8 +58,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageSameImage) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task.get() == another_task.get());
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task.get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -122,10 +95,10 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageDifferentImage) {
EXPECT_TRUE(second_task);
EXPECT_TRUE(first_task.get() != second_task.get());
- ProcessTask(first_task->dependencies()[0].get());
- ProcessTask(first_task.get());
- ProcessTask(second_task->dependencies()[0].get());
- ProcessTask(second_task.get());
+ SimpleTaskRunner::ProcessTask(first_task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(first_task.get());
+ SimpleTaskRunner::ProcessTask(second_task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(second_task.get());
controller.UnrefImage(first_draw_image);
controller.UnrefImage(second_draw_image);
@@ -152,12 +125,12 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) {
EXPECT_TRUE(task->dependencies()[0]);
// Run the decode but don't complete it (this will keep the decode locked).
- ScheduleTask(task->dependencies()[0].get());
- RunTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ScheduleTask(task->dependencies()[0].get());
+ SimpleTaskRunner::RunTask(task->dependencies()[0].get());
// Cancel the upload.
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
// Get the image again - we should have an upload task, but no dependent
// decode task, as the decode was already locked.
@@ -168,10 +141,10 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedAndLocked) {
EXPECT_TRUE(another_task);
EXPECT_EQ(another_task->dependencies().size(), 0u);
- ProcessTask(another_task.get());
+ SimpleTaskRunner::ProcessTask(another_task.get());
// Finally, complete the original decode task.
- CompleteTask(task->dependencies()[0].get());
+ SimpleTaskRunner::CompleteTask(task->dependencies()[0].get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -198,11 +171,11 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) {
EXPECT_TRUE(task->dependencies()[0]);
// Run the decode.
- ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
// Cancel the upload.
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
// Unref the image.
controller.UnrefImage(draw_image);
@@ -217,8 +190,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyDecodedNotLocked) {
EXPECT_EQ(another_task->dependencies().size(), 1u);
EXPECT_TRUE(task->dependencies()[0]);
- ProcessTask(another_task->dependencies()[0].get());
- ProcessTask(another_task.get());
+ SimpleTaskRunner::ProcessTask(another_task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(another_task.get());
controller.UnrefImage(draw_image);
}
@@ -243,9 +216,9 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) {
EXPECT_EQ(task->dependencies().size(), 1u);
EXPECT_TRUE(task->dependencies()[0]);
- ProcessTask(task->dependencies()[0].get());
- ScheduleTask(task.get());
- RunTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ScheduleTask(task.get());
+ SimpleTaskRunner::RunTask(task.get());
scoped_refptr<TileTask> another_task;
need_unref = controller.GetTaskForImageAndRef(
@@ -253,7 +226,7 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageAlreadyUploaded) {
EXPECT_TRUE(need_unref);
EXPECT_FALSE(another_task);
- CompleteTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
controller.UnrefImage(draw_image);
controller.UnrefImage(draw_image);
@@ -277,7 +250,7 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
scoped_refptr<TileTask> another_task;
need_unref = controller.GetTaskForImageAndRef(
@@ -286,8 +259,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(another_task.get() == task.get());
// Didn't run the task, so cancel it.
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
// Fully cancel everything (so the raster would unref things).
controller.UnrefImage(draw_image);
@@ -301,8 +274,8 @@ TEST(GpuImageDecodeControllerTest, GetTaskForImageCanceledGetsNewTask) {
EXPECT_TRUE(third_task);
EXPECT_FALSE(third_task.get() == task.get());
- ProcessTask(third_task->dependencies()[0].get());
- ProcessTask(third_task.get());
+ SimpleTaskRunner::ProcessTask(third_task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(third_task.get());
controller.UnrefImage(draw_image);
}
@@ -326,7 +299,7 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
scoped_refptr<TileTask> another_task;
need_unref = controller.GetTaskForImageAndRef(
@@ -335,8 +308,8 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(another_task.get() == task.get());
// Didn't run the task, so cancel it.
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
// Note that here, everything is reffed, but a new task is created. This is
// possible with repeated schedule/cancel operations.
@@ -347,8 +320,8 @@ TEST(GpuImageDecodeControllerTest,
EXPECT_TRUE(third_task);
EXPECT_FALSE(third_task.get() == task.get());
- ProcessTask(third_task->dependencies()[0].get());
- ProcessTask(third_task.get());
+ SimpleTaskRunner::ProcessTask(third_task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(third_task.get());
// 3 Unrefs!
controller.UnrefImage(draw_image);
@@ -374,10 +347,10 @@ TEST(GpuImageDecodeControllerTest, NoTaskForImageAlreadyFailedDecoding) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
// Didn't run the task, so cancel it.
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
controller.SetImageDecodingFailedForTesting(draw_image);
@@ -408,8 +381,8 @@ TEST(GpuImageDecodeControllerTest, GetDecodedImageForDraw) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -442,8 +415,8 @@ TEST(GpuImageDecodeControllerTest, GetLargeDecodedImageForDraw) {
EXPECT_TRUE(need_unref);
EXPECT_TRUE(task);
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task.get());
// Must hold context lock before calling GetDecodedImageForDraw /
// DrawWithImageFinished.
@@ -651,10 +624,10 @@ TEST(GpuImageDecodeControllerTest, CanceledTasksDoNotCountAgainstBudget) {
EXPECT_TRUE(task);
EXPECT_TRUE(need_unref);
- CancelTask(task->dependencies()[0].get());
- CompleteTask(task->dependencies()[0].get());
- CancelTask(task.get());
- CompleteTask(task.get());
+ SimpleTaskRunner::CancelTask(task->dependencies()[0].get());
+ SimpleTaskRunner::CompleteTask(task->dependencies()[0].get());
+ SimpleTaskRunner::CancelTask(task.get());
+ SimpleTaskRunner::CompleteTask(task.get());
controller.UnrefImage(draw_image);
EXPECT_EQ(0u, controller.GetBytesUsedForTesting());
@@ -680,8 +653,8 @@ TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) {
EXPECT_TRUE(task);
}
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task.get());
controller.UnrefImage(draw_image);
@@ -710,8 +683,8 @@ TEST(GpuImageDecodeControllerTest, ShouldAggressivelyFreeResources) {
EXPECT_TRUE(task);
}
- ProcessTask(task->dependencies()[0].get());
- ProcessTask(task.get());
+ SimpleTaskRunner::ProcessTask(task->dependencies()[0].get());
+ SimpleTaskRunner::ProcessTask(task.get());
// The image should be in our cache after un-ref.
controller.UnrefImage(draw_image);

Powered by Google App Engine
This is Rietveld 408576698