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

Side by Side Diff: cc/tiles/image_controller_unittest.cc

Issue 2703633004: cc: Make image controller return a status with the callback. (Closed)
Patch Set: update Created 3 years, 10 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 unified diff | Download patch
« cc/tiles/image_controller.cc ('K') | « cc/tiles/image_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/tiles/image_controller.h"
5 #include "base/bind.h" 6 #include "base/bind.h"
6 #include "base/optional.h" 7 #include "base/optional.h"
7 #include "base/run_loop.h" 8 #include "base/run_loop.h"
8 #include "base/test/test_simple_task_runner.h" 9 #include "base/test/test_simple_task_runner.h"
9 #include "base/threading/sequenced_task_runner_handle.h" 10 #include "base/threading/sequenced_task_runner_handle.h"
10 #include "cc/tiles/image_controller.h" 11 #include "cc/test/skia_common.h"
11 #include "cc/tiles/image_decode_cache.h" 12 #include "cc/tiles/image_decode_cache.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 14
14 namespace cc { 15 namespace cc {
15 namespace { 16 namespace {
16 17
17 class TestWorkerThread : public base::SimpleThread { 18 class TestWorkerThread : public base::SimpleThread {
18 public: 19 public:
19 TestWorkerThread() 20 TestWorkerThread()
20 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {} 21 : base::SimpleThread("test_worker_thread"), condition_(&lock_) {}
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 private: 126 private:
126 int number_of_refs_ = 0; 127 int number_of_refs_ = 0;
127 scoped_refptr<TileTask> task_to_use_; 128 scoped_refptr<TileTask> task_to_use_;
128 }; 129 };
129 130
130 // A simple class that can receive decode callbacks. 131 // A simple class that can receive decode callbacks.
131 class DecodeClient { 132 class DecodeClient {
132 public: 133 public:
133 DecodeClient() {} 134 DecodeClient() {}
134 void Callback(const base::Closure& quit_closure, 135 void Callback(const base::Closure& quit_closure,
135 ImageController::ImageDecodeRequestId id) { 136 ImageController::ImageDecodeRequestId id,
137 ImageController::ImageDecodeResult result) {
136 id_ = id; 138 id_ = id;
137 quit_closure.Run(); 139 quit_closure.Run();
138 } 140 }
139 141
140 ImageController::ImageDecodeRequestId id() { return id_; } 142 ImageController::ImageDecodeRequestId id() { return id_; }
141 143
142 private: 144 private:
143 ImageController::ImageDecodeRequestId id_ = 0; 145 ImageController::ImageDecodeRequestId id_ = 0;
144 }; 146 };
145 147
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 }; 213 };
212 214
213 // For tests that exercise image controller's thread, this is the timeout value 215 // For tests that exercise image controller's thread, this is the timeout value
214 // to 216 // to
215 // allow the worker thread to do its work. 217 // allow the worker thread to do its work.
216 int kDefaultTimeoutSeconds = 10; 218 int kDefaultTimeoutSeconds = 10;
217 219
218 class ImageControllerTest : public testing::Test { 220 class ImageControllerTest : public testing::Test {
219 public: 221 public:
220 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) { 222 ImageControllerTest() : task_runner_(base::SequencedTaskRunnerHandle::Get()) {
221 bitmap_.allocN32Pixels(1, 1); 223 image_ = CreateDiscardableImage(gfx::Size(1, 1));
222 image_ = SkImage::MakeFromBitmap(bitmap_);
223 } 224 }
224 ~ImageControllerTest() override = default; 225 ~ImageControllerTest() override = default;
225 226
226 void SetUp() override { 227 void SetUp() override {
227 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner); 228 worker_task_runner_ = make_scoped_refptr(new WorkerTaskRunner);
228 controller_.reset( 229 controller_.reset(
229 new ImageController(task_runner_.get(), worker_task_runner_)); 230 new ImageController(task_runner_.get(), worker_task_runner_));
230 cache_ = TestableCache(); 231 cache_ = TestableCache();
231 controller_->SetImageDecodeCache(&cache_); 232 controller_->SetImageDecodeCache(&cache_);
232 } 233 }
(...skipping 21 matching lines...) Expand all
254 base::Bind(&ImageControllerTest::Timeout, base::Unretained(run_loop)), 255 base::Bind(&ImageControllerTest::Timeout, base::Unretained(run_loop)),
255 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds)); 256 base::TimeDelta::FromSeconds(kDefaultTimeoutSeconds));
256 run_loop->Run(); 257 run_loop->Run();
257 } 258 }
258 259
259 private: 260 private:
260 scoped_refptr<base::SequencedTaskRunner> task_runner_; 261 scoped_refptr<base::SequencedTaskRunner> task_runner_;
261 scoped_refptr<WorkerTaskRunner> worker_task_runner_; 262 scoped_refptr<WorkerTaskRunner> worker_task_runner_;
262 TestableCache cache_; 263 TestableCache cache_;
263 std::unique_ptr<ImageController> controller_; 264 std::unique_ptr<ImageController> controller_;
264 SkBitmap bitmap_;
265 sk_sp<const SkImage> image_; 265 sk_sp<const SkImage> image_;
266 }; 266 };
267 267
268 TEST_F(ImageControllerTest, NullControllerUnrefsImages) { 268 TEST_F(ImageControllerTest, NullControllerUnrefsImages) {
269 std::vector<DrawImage> images(10); 269 std::vector<DrawImage> images(10);
270 ImageDecodeCache::TracingInfo tracing_info; 270 ImageDecodeCache::TracingInfo tracing_info;
271 271
272 ASSERT_EQ(10u, images.size()); 272 ASSERT_EQ(10u, images.size());
273 auto tasks = 273 auto tasks =
274 controller()->SetPredecodeImages(std::move(images), tracing_info); 274 controller()->SetPredecodeImages(std::move(images), tracing_info);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 EXPECT_EQ(expected_id1, decode_client1.id()); 442 EXPECT_EQ(expected_id1, decode_client1.id());
443 EXPECT_TRUE(task->has_run()); 443 EXPECT_TRUE(task->has_run());
444 EXPECT_EQ(1, cache()->number_of_refs()); 444 EXPECT_EQ(1, cache()->number_of_refs());
445 445
446 controller()->SetImageDecodeCache(nullptr); 446 controller()->SetImageDecodeCache(nullptr);
447 EXPECT_EQ(0, cache()->number_of_refs()); 447 EXPECT_EQ(0, cache()->number_of_refs());
448 } 448 }
449 449
450 } // namespace 450 } // namespace
451 } // namespace cc 451 } // namespace cc
OLDNEW
« cc/tiles/image_controller.cc ('K') | « cc/tiles/image_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698