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

Side by Side Diff: components/ntp_tiles/icon_cacher_impl_unittest.cc

Issue 2715153006: Set desired_image_size when decoding images for NTP Tile icons. (Closed)
Patch Set: comment formatting Created 3 years, 9 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 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 "components/ntp_tiles/icon_cacher_impl.h" 5 #include "components/ntp_tiles/icon_cacher_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 21 matching lines...) Expand all
32 public: 32 public:
33 MOCK_METHOD1(SetImageFetcherDelegate, 33 MOCK_METHOD1(SetImageFetcherDelegate,
34 void(image_fetcher::ImageFetcherDelegate* delegate)); 34 void(image_fetcher::ImageFetcherDelegate* delegate));
35 MOCK_METHOD1(SetDataUseServiceName, 35 MOCK_METHOD1(SetDataUseServiceName,
36 void(image_fetcher::ImageFetcher::DataUseServiceName name)); 36 void(image_fetcher::ImageFetcher::DataUseServiceName name));
37 MOCK_METHOD3(StartOrQueueNetworkRequest, 37 MOCK_METHOD3(StartOrQueueNetworkRequest,
38 void(const std::string& id, 38 void(const std::string& id,
39 const GURL& image_url, 39 const GURL& image_url,
40 base::Callback<void(const std::string& id, 40 base::Callback<void(const std::string& id,
41 const gfx::Image& image)> callback)); 41 const gfx::Image& image)> callback));
42 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&));
42 }; 43 };
43 44
44 class IconCacherTest : public ::testing::Test { 45 class IconCacherTest : public ::testing::Test {
45 protected: 46 protected:
46 IconCacherTest() 47 IconCacherTest()
47 : site_(base::string16(), // title, unused 48 : site_(base::string16(), // title, unused
48 GURL("http://url.google/"), 49 GURL("http://url.google/"),
49 GURL("http://url.google/icon.png"), 50 GURL("http://url.google/icon.png"),
50 GURL("http://url.google/favicon.ico"), 51 GURL("http://url.google/favicon.ico"),
51 GURL()), // thumbnail, unused 52 GURL()), // thumbnail, unused
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 113
113 TEST_F(IconCacherTest, LargeCached) { 114 TEST_F(IconCacherTest, LargeCached) {
114 MockFunction<void(bool)> done; 115 MockFunction<void(bool)> done;
115 base::RunLoop loop; 116 base::RunLoop loop;
116 { 117 {
117 InSequence s; 118 InSequence s;
118 EXPECT_CALL(*image_fetcher_, 119 EXPECT_CALL(*image_fetcher_,
119 SetDataUseServiceName( 120 SetDataUseServiceName(
120 data_use_measurement::DataUseUserData::NTP_TILES)); 121 data_use_measurement::DataUseUserData::NTP_TILES));
122 EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(gfx::Size(128, 128)));
121 EXPECT_CALL(done, Call(false)).WillOnce(Quit(&loop)); 123 EXPECT_CALL(done, Call(false)).WillOnce(Quit(&loop));
122 } 124 }
123 PreloadIcon(site_.url, site_.large_icon_url, favicon_base::TOUCH_ICON, 128, 125 PreloadIcon(site_.url, site_.large_icon_url, favicon_base::TOUCH_ICON, 128,
124 128); 126 128);
125 127
126 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_)); 128 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_));
127 cacher.StartFetch(site_, BindMockFunction(&done)); 129 cacher.StartFetch(site_, BindMockFunction(&done));
128 loop.Run(); 130 loop.Run();
129 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON)); 131 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
130 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON)); 132 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
131 } 133 }
132 134
133 TEST_F(IconCacherTest, LargeNotCachedAndFetchSucceeded) { 135 TEST_F(IconCacherTest, LargeNotCachedAndFetchSucceeded) {
134 MockFunction<void(bool)> done; 136 MockFunction<void(bool)> done;
135 base::RunLoop loop; 137 base::RunLoop loop;
136 { 138 {
137 InSequence s; 139 InSequence s;
138 EXPECT_CALL(*image_fetcher_, 140 EXPECT_CALL(*image_fetcher_,
139 SetDataUseServiceName( 141 SetDataUseServiceName(
140 data_use_measurement::DataUseUserData::NTP_TILES)); 142 data_use_measurement::DataUseUserData::NTP_TILES));
143 EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(gfx::Size(128, 128)));
141 EXPECT_CALL(*image_fetcher_, 144 EXPECT_CALL(*image_fetcher_,
142 StartOrQueueNetworkRequest(_, site_.large_icon_url, _)) 145 StartOrQueueNetworkRequest(_, site_.large_icon_url, _))
143 .WillOnce(PassFetch(128, 128)); 146 .WillOnce(PassFetch(128, 128));
144 EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop)); 147 EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop));
145 } 148 }
146 149
147 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_)); 150 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_));
148 cacher.StartFetch(site_, BindMockFunction(&done)); 151 cacher.StartFetch(site_, BindMockFunction(&done));
149 loop.Run(); 152 loop.Run();
150 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON)); 153 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
151 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON)); 154 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
152 } 155 }
153 156
154 TEST_F(IconCacherTest, SmallNotCachedAndFetchSucceeded) { 157 TEST_F(IconCacherTest, SmallNotCachedAndFetchSucceeded) {
155 site_.large_icon_url = GURL(); 158 site_.large_icon_url = GURL();
156 159
157 MockFunction<void(bool)> done; 160 MockFunction<void(bool)> done;
158 base::RunLoop loop; 161 base::RunLoop loop;
159 { 162 {
160 InSequence s; 163 InSequence s;
161 EXPECT_CALL(*image_fetcher_, 164 EXPECT_CALL(*image_fetcher_,
162 SetDataUseServiceName( 165 SetDataUseServiceName(
163 data_use_measurement::DataUseUserData::NTP_TILES)); 166 data_use_measurement::DataUseUserData::NTP_TILES));
167 EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(gfx::Size(128, 128)));
164 EXPECT_CALL(*image_fetcher_, 168 EXPECT_CALL(*image_fetcher_,
165 StartOrQueueNetworkRequest(_, site_.favicon_url, _)) 169 StartOrQueueNetworkRequest(_, site_.favicon_url, _))
166 .WillOnce(PassFetch(128, 128)); 170 .WillOnce(PassFetch(128, 128));
167 EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop)); 171 EXPECT_CALL(done, Call(true)).WillOnce(Quit(&loop));
168 } 172 }
169 173
170 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_)); 174 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_));
171 cacher.StartFetch(site_, BindMockFunction(&done)); 175 cacher.StartFetch(site_, BindMockFunction(&done));
172 loop.Run(); 176 loop.Run();
173 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::FAVICON)); 177 EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
174 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON)); 178 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
175 } 179 }
176 180
177 TEST_F(IconCacherTest, LargeNotCachedAndFetchFailed) { 181 TEST_F(IconCacherTest, LargeNotCachedAndFetchFailed) {
178 MockFunction<void(bool)> done; 182 MockFunction<void(bool)> done;
179 base::RunLoop loop; 183 base::RunLoop loop;
180 { 184 {
181 InSequence s; 185 InSequence s;
182 EXPECT_CALL(*image_fetcher_, 186 EXPECT_CALL(*image_fetcher_,
183 SetDataUseServiceName( 187 SetDataUseServiceName(
184 data_use_measurement::DataUseUserData::NTP_TILES)); 188 data_use_measurement::DataUseUserData::NTP_TILES));
189 EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(gfx::Size(128, 128)));
185 EXPECT_CALL(*image_fetcher_, 190 EXPECT_CALL(*image_fetcher_,
186 StartOrQueueNetworkRequest(_, site_.large_icon_url, _)) 191 StartOrQueueNetworkRequest(_, site_.large_icon_url, _))
187 .WillOnce(FailFetch()); 192 .WillOnce(FailFetch());
188 EXPECT_CALL(done, Call(false)).WillOnce(Quit(&loop)); 193 EXPECT_CALL(done, Call(false)).WillOnce(Quit(&loop));
189 } 194 }
190 195
191 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_)); 196 IconCacherImpl cacher(&favicon_service_, std::move(image_fetcher_));
192 cacher.StartFetch(site_, BindMockFunction(&done)); 197 cacher.StartFetch(site_, BindMockFunction(&done));
193 loop.Run(); 198 loop.Run();
194 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON)); 199 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
195 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON)); 200 EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
196 } 201 }
197 202
198 } // namespace 203 } // namespace
199 } // namespace ntp_tiles 204 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/icon_cacher_impl.cc ('k') | components/suggestions/image_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698