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

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

Issue 2537683002: cc: Add image decode queue functionality to image manager. (Closed)
Patch Set: test fix Created 3 years, 11 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
« no previous file with comments | « cc/tiles/decoded_image_tracker.cc ('k') | cc/tiles/gpu_image_decode_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "base/bind.h"
8 #include "cc/tiles/decoded_image_tracker.h"
9 #include "cc/tiles/image_controller.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace cc {
13
14 class TestImageController : public ImageController {
15 public:
16 TestImageController() : ImageController(nullptr, nullptr) {}
17
18 void UnlockImageDecode(ImageDecodeRequestId id) override {
19 auto it = std::find(locked_ids_.begin(), locked_ids_.end(), id);
20 ASSERT_FALSE(it == locked_ids_.end());
21 locked_ids_.erase(it);
22 }
23
24 ImageDecodeRequestId QueueImageDecode(
25 sk_sp<const SkImage> image,
26 const ImageDecodedCallback& callback) override {
27 auto id = next_id_++;
28 locked_ids_.push_back(id);
29 callback.Run(id);
30 return id;
31 }
32
33 size_t num_locked_images() { return locked_ids_.size(); }
34
35 private:
36 ImageDecodeRequestId next_id_ = 1;
37 std::vector<ImageDecodeRequestId> locked_ids_;
38 };
39
40 class DecodedImageTrackerTest : public testing::Test {
41 public:
42 void SetUp() override {
43 decoded_image_tracker_.set_image_controller(image_controller());
44 }
45
46 TestImageController* image_controller() { return &image_controller_; }
47 DecodedImageTracker* decoded_image_tracker() {
48 return &decoded_image_tracker_;
49 }
50
51 private:
52 TestImageController image_controller_;
53 DecodedImageTracker decoded_image_tracker_;
54 };
55
56 TEST_F(DecodedImageTrackerTest, QueueImageLocksImages) {
57 bool locked = false;
58 decoded_image_tracker()->QueueImageDecode(
59 nullptr, base::Bind([](bool* locked) { *locked = true; },
60 base::Unretained(&locked)));
61 EXPECT_TRUE(locked);
62 EXPECT_EQ(1u, image_controller()->num_locked_images());
63 }
64
65 TEST_F(DecodedImageTrackerTest, NotifyFrameFinishedUnlocksImages) {
66 bool locked = false;
67 decoded_image_tracker()->QueueImageDecode(
68 nullptr, base::Bind([](bool* locked) { *locked = true; },
69 base::Unretained(&locked)));
70 EXPECT_TRUE(locked);
71 EXPECT_EQ(1u, image_controller()->num_locked_images());
72
73 decoded_image_tracker()->NotifyFrameFinished();
74 EXPECT_EQ(1u, image_controller()->num_locked_images());
75
76 locked = false;
77 decoded_image_tracker()->QueueImageDecode(
78 nullptr, base::Bind([](bool* locked) { *locked = true; },
79 base::Unretained(&locked)));
80 EXPECT_TRUE(locked);
81 EXPECT_EQ(2u, image_controller()->num_locked_images());
82
83 decoded_image_tracker()->NotifyFrameFinished();
84 EXPECT_EQ(1u, image_controller()->num_locked_images());
85
86 decoded_image_tracker()->NotifyFrameFinished();
87 EXPECT_EQ(0u, image_controller()->num_locked_images());
88 }
89
90 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/decoded_image_tracker.cc ('k') | cc/tiles/gpu_image_decode_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698