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

Side by Side Diff: components/favicon/core/large_icon_service_unittest.cc

Issue 1122103003: [Large Icon Service] Move icon resizing into worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment cleanup; making ResizeLargeIconOnBackgroundThreadIfValid() a member function. Created 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/favicon/core/large_icon_service.h" 5 #include "components/favicon/core/large_icon_service.h"
6 6
7 #include <deque> 7 #include <deque>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 void InjectResult(const favicon_base::FaviconRawBitmapResult& mock_result) { 76 void InjectResult(const favicon_base::FaviconRawBitmapResult& mock_result) {
77 mock_result_queue_.push_back(mock_result); 77 mock_result_queue_.push_back(mock_result);
78 } 78 }
79 79
80 bool HasUnusedResults() { 80 bool HasUnusedResults() {
81 return !mock_result_queue_.empty(); 81 return !mock_result_queue_.empty();
82 } 82 }
83 83
84 private: 84 private:
85 std::deque<favicon_base::FaviconRawBitmapResult> mock_result_queue_;
86
85 DISALLOW_COPY_AND_ASSIGN(MockFaviconService); 87 DISALLOW_COPY_AND_ASSIGN(MockFaviconService);
86
87 std::deque<favicon_base::FaviconRawBitmapResult> mock_result_queue_;
88 }; 88 };
89 89
90 // This class provides access to LargeIconService internals. 90 // This class provides access to LargeIconService internals.
91 class TestLargeIconService : public LargeIconService { 91 class TestLargeIconService : public LargeIconService {
92 public: 92 public:
93 explicit TestLargeIconService(MockFaviconService* mock_favicon_service) 93 explicit TestLargeIconService(MockFaviconService* mock_favicon_service)
94 : LargeIconService(mock_favicon_service) { 94 : LargeIconService(mock_favicon_service) {
95 } 95 }
96 ~TestLargeIconService() override { 96 ~TestLargeIconService() override {
97 } 97 }
98 98
99 // Using the current thread's task runner for testing.
100 scoped_refptr<base::TaskRunner> GetBackgroundTaskRunner() override {
101 return base::MessageLoop::current()->task_runner();
102 }
103
99 private: 104 private:
100 DISALLOW_COPY_AND_ASSIGN(TestLargeIconService); 105 DISALLOW_COPY_AND_ASSIGN(TestLargeIconService);
101 }; 106 };
102 107
103 class LargeIconServiceTest : public testing::Test { 108 class LargeIconServiceTest : public testing::Test {
104 public: 109 public:
105 LargeIconServiceTest() : is_callback_invoked_(false) { 110 LargeIconServiceTest() : is_callback_invoked_(false) {
106 } 111 }
107 112
108 ~LargeIconServiceTest() override { 113 ~LargeIconServiceTest() override {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 favicon_base::FaviconRawBitmapResult expected_bitmap_; 150 favicon_base::FaviconRawBitmapResult expected_bitmap_;
146 scoped_ptr<favicon_base::FallbackIconStyle> expected_fallback_icon_style_; 151 scoped_ptr<favicon_base::FallbackIconStyle> expected_fallback_icon_style_;
147 152
148 bool is_callback_invoked_; 153 bool is_callback_invoked_;
149 154
150 private: 155 private:
151 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest); 156 DISALLOW_COPY_AND_ASSIGN(LargeIconServiceTest);
152 }; 157 };
153 158
154 TEST_F(LargeIconServiceTest, SameSize) { 159 TEST_F(LargeIconServiceTest, SameSize) {
155
156 mock_favicon_service_->InjectResult(CreateTestBitmap(24, 24, kTestColor)); 160 mock_favicon_service_->InjectResult(CreateTestBitmap(24, 24, kTestColor));
157 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor); 161 expected_bitmap_ = CreateTestBitmap(24, 24, kTestColor);
158 large_icon_service_->GetLargeIconOrFallbackStyle( 162 large_icon_service_->GetLargeIconOrFallbackStyle(
159 GURL(kDummyUrl), 163 GURL(kDummyUrl),
160 24, // |min_source_size_in_pixel| 164 24, // |min_source_size_in_pixel|
161 24, // |desired_size_in_pixel| 165 24, // |desired_size_in_pixel|
162 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), 166 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)),
163 &cancelable_task_tracker_); 167 &cancelable_task_tracker_);
164 base::MessageLoop::current()->RunUntilIdle(); 168 base::MessageLoop::current()->RunUntilIdle();
165 EXPECT_TRUE(is_callback_invoked_); 169 EXPECT_TRUE(is_callback_invoked_);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 32, 276 32,
273 24, 277 24,
274 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)), 278 base::Bind(&LargeIconServiceTest::ResultCallback, base::Unretained(this)),
275 &cancelable_task_tracker_); 279 &cancelable_task_tracker_);
276 base::MessageLoop::current()->RunUntilIdle(); 280 base::MessageLoop::current()->RunUntilIdle();
277 EXPECT_TRUE(is_callback_invoked_); 281 EXPECT_TRUE(is_callback_invoked_);
278 } 282 }
279 283
280 } // namespace 284 } // namespace
281 } // namespace favicon 285 } // namespace favicon
OLDNEW
« components/favicon/core/DEPS ('K') | « components/favicon/core/large_icon_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698