OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/favicon_handler.h" | 5 #include "components/favicon/core/favicon_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <list> | |
10 #include <map> | |
9 #include <memory> | 11 #include <memory> |
10 #include <set> | 12 #include <set> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/macros.h" | 15 #include "base/macros.h" |
14 #include "components/favicon/core/favicon_driver.h" | 16 #include "components/favicon/core/favicon_driver.h" |
15 #include "components/favicon/core/test/mock_favicon_service.h" | 17 #include "components/favicon/core/test/mock_favicon_service.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
19 #include "ui/base/layout.h" | 21 #include "ui/base/layout.h" |
20 #include "ui/gfx/codec/png_codec.h" | 22 #include "ui/gfx/codec/png_codec.h" |
21 #include "ui/gfx/favicon_size.h" | 23 #include "ui/gfx/favicon_size.h" |
22 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
23 | 25 |
24 namespace favicon { | 26 namespace favicon { |
25 namespace { | 27 namespace { |
26 | 28 |
27 // Fill the given bmp with valid png data. | 29 using favicon_base::FaviconRawBitmapResult; |
28 void FillDataToBitmap(int w, int h, SkBitmap* bmp) { | 30 using testing::Contains; |
29 bmp->allocN32Pixels(w, h); | 31 using testing::InSequence; |
32 using testing::Invoke; | |
33 using testing::Key; | |
34 using testing::Return; | |
35 using testing::SaveArg; | |
36 using testing::WithArg; | |
37 using testing::_; | |
38 | |
39 using URLVector = std::vector<GURL>; | |
40 | |
41 MATCHER_P2(ImageSizeIs, width, height, "") { | |
42 return arg.Size() == gfx::Size(width, height); | |
43 } | |
44 | |
45 // Fill the given bmp with some test data. | |
46 SkBitmap CreateBitmap(int w, int h) { | |
47 SkBitmap bmp; | |
48 bmp.allocN32Pixels(w, h); | |
30 | 49 |
31 unsigned char* src_data = | 50 unsigned char* src_data = |
32 reinterpret_cast<unsigned char*>(bmp->getAddr32(0, 0)); | 51 reinterpret_cast<unsigned char*>(bmp.getAddr32(0, 0)); |
33 for (int i = 0; i < w * h; i++) { | 52 for (int i = 0; i < w * h; i++) { |
34 src_data[i * 4 + 0] = static_cast<unsigned char>(i % 255); | 53 src_data[i * 4 + 0] = static_cast<unsigned char>(i % 255); |
35 src_data[i * 4 + 1] = static_cast<unsigned char>(i % 255); | 54 src_data[i * 4 + 1] = static_cast<unsigned char>(i % 255); |
36 src_data[i * 4 + 2] = static_cast<unsigned char>(i % 255); | 55 src_data[i * 4 + 2] = static_cast<unsigned char>(i % 255); |
37 src_data[i * 4 + 3] = static_cast<unsigned char>(i % 255); | 56 src_data[i * 4 + 3] = static_cast<unsigned char>(i % 255); |
38 } | 57 } |
58 return bmp; | |
39 } | 59 } |
40 | 60 |
41 // Fill the given data buffer with valid png data. | 61 // Fill the given data buffer with valid png data. |
42 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { | 62 void FillBitmap(int w, int h, std::vector<unsigned char>* output) { |
43 SkBitmap bitmap; | 63 SkBitmap bitmap = CreateBitmap(w, h); |
44 FillDataToBitmap(w, h, &bitmap); | |
45 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); | 64 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, output); |
46 } | 65 } |
47 | 66 |
48 void SetFaviconRawBitmapResult( | 67 std::vector<FaviconRawBitmapResult> CreateFaviconRawBitmapResult( |
49 const GURL& icon_url, | 68 const GURL& icon_url, |
50 favicon_base::IconType icon_type, | 69 favicon_base::IconType icon_type, |
51 bool expired, | 70 bool expired) { |
52 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | |
53 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | 71 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); |
54 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); | 72 FillBitmap(gfx::kFaviconSize, gfx::kFaviconSize, &data->data()); |
55 favicon_base::FaviconRawBitmapResult bitmap_result; | 73 FaviconRawBitmapResult bitmap_result; |
56 bitmap_result.expired = expired; | 74 bitmap_result.expired = expired; |
57 bitmap_result.bitmap_data = data; | 75 bitmap_result.bitmap_data = data; |
58 // Use a pixel size other than (0,0) as (0,0) has a special meaning. | 76 // Use a pixel size other than (0,0) as (0,0) has a special meaning. |
59 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 77 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
60 bitmap_result.icon_type = icon_type; | 78 bitmap_result.icon_type = icon_type; |
61 bitmap_result.icon_url = icon_url; | 79 bitmap_result.icon_url = icon_url; |
62 | 80 return {bitmap_result}; |
63 favicon_bitmap_results->push_back(bitmap_result); | |
64 } | 81 } |
65 | 82 |
66 void SetFaviconRawBitmapResult( | 83 // Convenience class to queue image download requests. MockDelegate below will |
67 const GURL& icon_url, | 84 // forward all download requests to this class. |
68 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { | 85 class ImageDownloadTester { |
69 SetFaviconRawBitmapResult(icon_url, | 86 public: |
70 favicon_base::FAVICON, | 87 using ImageDownloadCallback = FaviconHandler::Delegate::ImageDownloadCallback; |
71 false /* expired */, | |
72 favicon_bitmap_results); | |
73 } | |
74 | 88 |
75 // This class is used to save the download request for verifying with test case. | 89 ImageDownloadTester() : download_id_(0) {} |
76 class DownloadHandler { | |
77 public: | |
78 DownloadHandler() : callback_invoked_(false) {} | |
79 ~DownloadHandler() {} | |
80 | 90 |
81 void Reset() { | 91 int DownloadImage(const GURL& url, |
82 download_.reset(); | 92 int max_image_size, |
83 callback_invoked_ = false; | 93 ImageDownloadCallback callback) { |
84 // Does not affect |should_fail_download_icon_urls_| and | 94 ++download_id_; |
85 // |failed_download_icon_urls_|. | 95 pending_downloads_[url].emplace_back(download_id_, callback); |
86 } | 96 LOG(INFO) << "Returning download id " << download_id_; |
87 | |
88 // Make downloads for any of |icon_urls| fail. | |
89 void FailDownloadForIconURLs(const std::set<GURL>& icon_urls) { | |
90 should_fail_download_icon_urls_ = icon_urls; | |
91 } | |
92 | |
93 // Returns whether a download for |icon_url| did fail. | |
94 bool DidFailDownloadForIconURL(const GURL& icon_url) const { | |
95 return failed_download_icon_urls_.count(icon_url); | |
96 } | |
97 | |
98 void AddDownload(int download_id, | |
99 const GURL& image_url, | |
100 const std::vector<int>& image_sizes, | |
101 int max_image_size, | |
102 FaviconHandler::Delegate::ImageDownloadCallback callback) { | |
103 download_.reset(new Download(download_id, image_url, image_sizes, | |
104 max_image_size, callback)); | |
105 } | |
106 | |
107 void InvokeCallback(); | |
108 | |
109 bool HasDownload() const { return download_.get(); } | |
110 const GURL& GetImageUrl() const { return download_->image_url; } | |
111 void SetImageSizes(const std::vector<int>& sizes) { | |
112 download_->image_sizes = sizes; } | |
113 | |
114 private: | |
115 struct Download { | |
116 Download(int id, | |
117 GURL url, | |
118 const std::vector<int>& sizes, | |
119 int max_size, | |
120 FaviconHandler::Delegate::ImageDownloadCallback callback) | |
121 : download_id(id), | |
122 image_url(url), | |
123 image_sizes(sizes), | |
124 max_image_size(max_size), | |
125 callback(callback) {} | |
126 ~Download() {} | |
127 int download_id; | |
128 GURL image_url; | |
129 std::vector<int> image_sizes; | |
130 int max_image_size; | |
131 FaviconHandler::Delegate::ImageDownloadCallback callback; | |
132 }; | |
133 | |
134 std::unique_ptr<Download> download_; | |
135 bool callback_invoked_; | |
136 | |
137 // The icon URLs for which the download should fail. | |
138 std::set<GURL> should_fail_download_icon_urls_; | |
139 | |
140 // The icon URLs for which the download did fail. This should be a subset of | |
141 // |should_fail_download_icon_urls_|. | |
142 std::set<GURL> failed_download_icon_urls_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(DownloadHandler); | |
145 }; | |
146 | |
147 // This class is used to save the history request for verifying with test case. | |
148 // It also will be used to simulate the history response. | |
149 class HistoryRequestHandler { | |
150 public: | |
151 HistoryRequestHandler(const GURL& page_url, | |
152 const GURL& icon_url, | |
153 int icon_type, | |
154 const favicon_base::FaviconResultsCallback& callback) | |
155 : page_url_(page_url), | |
156 icon_url_(icon_url), | |
157 icon_type_(icon_type), | |
158 callback_(callback) { | |
159 } | |
160 | |
161 HistoryRequestHandler(const GURL& page_url, | |
162 const GURL& icon_url, | |
163 int icon_type, | |
164 const std::vector<unsigned char>& bitmap_data, | |
165 const gfx::Size& size) | |
166 : page_url_(page_url), | |
167 icon_url_(icon_url), | |
168 icon_type_(icon_type), | |
169 bitmap_data_(bitmap_data), | |
170 size_(size) { | |
171 } | |
172 | |
173 ~HistoryRequestHandler() {} | |
174 void InvokeCallback(); | |
175 | |
176 const GURL page_url_; | |
177 const GURL icon_url_; | |
178 const int icon_type_; | |
179 const std::vector<unsigned char> bitmap_data_; | |
180 const gfx::Size size_; | |
181 std::vector<favicon_base::FaviconRawBitmapResult> history_results_; | |
182 favicon_base::FaviconResultsCallback callback_; | |
183 | |
184 private: | |
185 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | |
186 }; | |
187 | |
188 class TestDelegate : public FaviconHandler::Delegate { | |
189 public: | |
190 TestDelegate() : num_notifications_(0), download_id_(0) {} | |
191 | |
192 int DownloadImage(const GURL& image_url, | |
193 int max_bitmap_size, | |
194 ImageDownloadCallback callback) override { | |
195 // Do not do a download if downloading |image_url| failed previously. This | |
196 // emulates the behavior of FaviconDriver::StartDownload() | |
197 if (download_handler_.DidFailDownloadForIconURL(image_url)) { | |
198 download_handler_.AddDownload(download_id_, image_url, std::vector<int>(), | |
199 0, callback); | |
200 return 0; | |
201 } | |
202 | |
203 download_id_++; | |
204 std::vector<int> sizes; | |
205 sizes.push_back(0); | |
206 download_handler_.AddDownload(download_id_, image_url, sizes, | |
207 max_bitmap_size, callback); | |
208 return download_id_; | 97 return download_id_; |
209 } | 98 } |
210 | 99 |
211 bool IsOffTheRecord() override { return false; } | 100 // Causes the first queued download for |image_url| to be finished. Returns |
212 | 101 // false if none was queued. |
213 bool IsBookmarked(const GURL& url) override { return false; } | 102 bool TestDownloadFinished(int http_status_code, |
214 | 103 const GURL& url, |
215 void OnFaviconUpdated( | 104 const std::vector<SkBitmap>& bitmaps, |
216 const GURL& page_url, | 105 const std::vector<gfx::Size>& original_bitmap_sizes) |
217 FaviconDriverObserver::NotificationIconType notification_icon_type, | 106 WARN_UNUSED_RESULT { |
218 const GURL& icon_url, | 107 if (pending_downloads_[url].empty()) { |
219 bool icon_url_changed, | 108 EXPECT_THAT(pending_downloads_, Contains(Key(url))); |
220 const gfx::Image& image) override { | 109 return false; |
221 ++num_notifications_; | 110 } |
222 icon_url_ = icon_url; | 111 int id = pending_downloads_[url].front().first; |
223 image_ = image; | 112 ImageDownloadCallback callback = pending_downloads_[url].front().second; |
113 pending_downloads_[url].pop_front(); | |
114 LOG(INFO) << "Returning bitmaps " << bitmaps.size(); | |
115 callback.Run(id, http_status_code, url, bitmaps, original_bitmap_sizes); | |
116 return true; | |
224 } | 117 } |
225 | 118 |
226 DownloadHandler* download_handler() { return &download_handler_; } | 119 private: |
227 const GURL& icon_url() const { return icon_url_; } | 120 int download_id_; |
228 const gfx::Image& image() const { return image_; } | 121 // Map keyed by image URL. Values are <id, callback> pairs. |
229 size_t num_notifications() const { return num_notifications_; } | 122 std::map<GURL, std::list<std::pair<int, ImageDownloadCallback>>> |
230 void ResetNumNotifications() { num_notifications_ = 0; } | 123 pending_downloads_; |
124 }; | |
125 | |
126 // Convenience class to "queue" requestes to FaviconService. MockFaviconService | |
127 // will forward requests to this class. | |
128 class FaviconServiceTester { | |
129 public: | |
130 base::CancelableTaskTracker::TaskId SaveCallback( | |
131 favicon_base::FaviconResultsCallback callback) { | |
132 EXPECT_TRUE(callback); | |
133 EXPECT_FALSE(callback_) << "Single in-flight FaviconRequest expected"; | |
134 callback_ = callback; | |
135 return 1; | |
136 } | |
137 | |
138 // Runs a previously saved callback. Returns false if none was saved. | |
139 bool TestRunCallback(const std::vector<FaviconRawBitmapResult>& results) | |
140 WARN_UNUSED_RESULT { | |
141 if (!callback_) | |
142 return false; | |
143 favicon_base::FaviconResultsCallback callback_copy = callback_; | |
144 callback_.Reset(); | |
145 callback_copy.Run(results); | |
146 return true; | |
147 } | |
231 | 148 |
232 private: | 149 private: |
233 GURL icon_url_; | 150 // We actually support one single request in flight; |
234 gfx::Image image_; | 151 favicon_base::FaviconResultsCallback callback_; |
235 size_t num_notifications_; | |
236 | |
237 // The unique id of a download request. It will be returned to a | |
238 // FaviconHandler. | |
239 int download_id_; | |
240 DownloadHandler download_handler_; | |
241 | |
242 DISALLOW_COPY_AND_ASSIGN(TestDelegate); | |
243 }; | 152 }; |
244 | 153 |
245 } // namespace | 154 class MockDelegate : public FaviconHandler::Delegate { |
246 | |
247 // This class is used to catch the FaviconHandler's download and history | |
248 // request, and also provide the methods to access the FaviconHandler | |
249 // internals. | |
250 class TestFaviconHandler : public FaviconHandler { | |
251 public: | 155 public: |
252 static int GetMaximalIconSize(favicon_base::IconType icon_type) { | 156 MOCK_METHOD3(DownloadImage, |
253 return FaviconHandler::GetMaximalIconSize(icon_type); | 157 int(const GURL& url, |
254 } | 158 int max_image_size, |
255 | 159 ImageDownloadCallback callback)); |
256 TestFaviconHandler(FaviconService* service, | 160 // TODO(mastiz): Consider parameterizing tests to cover incognito. |
257 FaviconHandler::Delegate* delegate, | 161 MOCK_METHOD0(IsOffTheRecord, bool()); |
258 FaviconDriverObserver::NotificationIconType handler_type) | 162 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); |
259 : FaviconHandler(service, delegate, handler_type) {} | 163 MOCK_METHOD5(OnFaviconUpdated, |
260 | 164 void(const GURL& page_url, |
261 ~TestFaviconHandler() override {} | 165 FaviconDriverObserver::NotificationIconType type, |
262 | 166 const GURL& icon_url, |
263 HistoryRequestHandler* history_handler() { | 167 bool icon_url_changed, |
264 return history_handler_.get(); | 168 const gfx::Image& image)); |
265 } | |
266 | |
267 // This method will take the ownership of the given handler. | |
268 void set_history_handler(HistoryRequestHandler* handler) { | |
269 history_handler_.reset(handler); | |
270 } | |
271 | |
272 FaviconURL* current_candidate() { | |
273 return FaviconHandler::current_candidate(); | |
274 } | |
275 | |
276 size_t current_candidate_index() const { | |
277 return current_candidate_index_; | |
278 } | |
279 | |
280 const FaviconCandidate& best_favicon_candidate() { | |
281 return best_favicon_candidate_; | |
282 } | |
283 | |
284 protected: | |
285 void UpdateFaviconMappingAndFetch( | |
286 const GURL& page_url, | |
287 const GURL& icon_url, | |
288 favicon_base::IconType icon_type, | |
289 const favicon_base::FaviconResultsCallback& callback, | |
290 base::CancelableTaskTracker* tracker) override { | |
291 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | |
292 icon_type, callback)); | |
293 } | |
294 | |
295 void GetFaviconFromFaviconService( | |
296 const GURL& icon_url, | |
297 favicon_base::IconType icon_type, | |
298 const favicon_base::FaviconResultsCallback& callback, | |
299 base::CancelableTaskTracker* tracker) override { | |
300 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, | |
301 icon_type, callback)); | |
302 } | |
303 | |
304 void GetFaviconForURLFromFaviconService( | |
305 const GURL& page_url, | |
306 int icon_types, | |
307 const favicon_base::FaviconResultsCallback& callback, | |
308 base::CancelableTaskTracker* tracker) override { | |
309 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | |
310 icon_types, callback)); | |
311 } | |
312 | |
313 void SetHistoryFavicons(const GURL& page_url, | |
314 const GURL& icon_url, | |
315 favicon_base::IconType icon_type, | |
316 const gfx::Image& image) override { | |
317 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | |
318 std::vector<unsigned char> bitmap_data(bytes->front(), | |
319 bytes->front() + bytes->size()); | |
320 history_handler_.reset(new HistoryRequestHandler( | |
321 page_url, icon_url, icon_type, bitmap_data, image.Size())); | |
322 } | |
323 | |
324 bool ShouldSaveFavicon() override { return true; } | |
325 | |
326 GURL page_url_; | |
327 | |
328 private: | |
329 std::unique_ptr<HistoryRequestHandler> history_handler_; | |
330 | |
331 DISALLOW_COPY_AND_ASSIGN(TestFaviconHandler); | |
332 }; | 169 }; |
333 | 170 |
334 namespace { | |
335 | |
336 void HistoryRequestHandler::InvokeCallback() { | |
337 if (!callback_.is_null()) { | |
338 callback_.Run(history_results_); | |
339 } | |
340 } | |
341 | |
342 void DownloadHandler::InvokeCallback() { | |
343 if (callback_invoked_) | |
344 return; | |
345 | |
346 std::vector<gfx::Size> original_bitmap_sizes; | |
347 std::vector<SkBitmap> bitmaps; | |
348 if (should_fail_download_icon_urls_.count(download_->image_url)) { | |
349 failed_download_icon_urls_.insert(download_->image_url); | |
350 } else { | |
351 for (std::vector<int>::const_iterator i = download_->image_sizes.begin(); | |
352 i != download_->image_sizes.end(); ++i) { | |
353 int original_size = (*i > 0) ? *i : gfx::kFaviconSize; | |
354 int downloaded_size = original_size; | |
355 if (download_->max_image_size != 0 && | |
356 downloaded_size > download_->max_image_size) { | |
357 downloaded_size = download_->max_image_size; | |
358 } | |
359 SkBitmap bitmap; | |
360 FillDataToBitmap(downloaded_size, downloaded_size, &bitmap); | |
361 bitmaps.push_back(bitmap); | |
362 original_bitmap_sizes.push_back(gfx::Size(original_size, original_size)); | |
363 } | |
364 } | |
365 download_->callback.Run(download_->download_id, | |
366 /*=status_code=*/200, download_->image_url, bitmaps, | |
367 original_bitmap_sizes); | |
368 callback_invoked_ = true; | |
369 } | |
370 | |
371 class FaviconHandlerTest : public testing::Test { | 171 class FaviconHandlerTest : public testing::Test { |
372 protected: | 172 protected: |
173 const std::vector<gfx::Size> kEmptySizes; | |
174 const std::vector<FaviconRawBitmapResult> kEmptyBitmapResult; | |
175 | |
373 FaviconHandlerTest() { | 176 FaviconHandlerTest() { |
177 // Forward ImageDownload calls to ImageDownloadTester where they get queued. | |
178 ON_CALL(delegate_, DownloadImage(_, _, _)) | |
179 .WillByDefault(Invoke(&image_download_tester_, | |
180 &ImageDownloadTester::DownloadImage)); | |
181 // Forward FaviconService calls to FaviconServiceTester. | |
182 ON_CALL(favicon_service_, GetFaviconForPageURL(_, _, _, _, _)) | |
183 .WillByDefault(WithArg<3>(Invoke(&favicon_service_tester_, | |
184 &FaviconServiceTester::SaveCallback))); | |
185 ON_CALL(favicon_service_, GetFavicon(_, _, _, _, _)) | |
186 .WillByDefault(WithArg<3>(Invoke(&favicon_service_tester_, | |
187 &FaviconServiceTester::SaveCallback))); | |
188 ON_CALL(favicon_service_, UpdateFaviconMappingsAndFetch(_, _, _, _, _, _)) | |
189 .WillByDefault(WithArg<4>(Invoke(&favicon_service_tester_, | |
190 &FaviconServiceTester::SaveCallback))); | |
374 } | 191 } |
375 | 192 |
376 ~FaviconHandlerTest() override {} | |
377 | |
378 // Simulates requesting a favicon for |page_url| given: | 193 // Simulates requesting a favicon for |page_url| given: |
379 // - We have not previously cached anything in history for |page_url| or for | 194 // - We have not previously cached anything in history for |page_url| or for |
380 // any of |candidates|. | 195 // any of |candidates|. |
381 // - The page provides favicons at |candidate_icons|. | 196 // - The page provides favicons at |candidate_icons|. |
382 // - The favicons at |candidate_icons| have edge pixel sizes of | 197 // - The favicons at |candidate_icons| have edge pixel sizes of |
383 // |candidate_icon_sizes|. | 198 // |candidate_icon_sizes|. |
384 void DownloadTillDoneIgnoringHistory( | 199 void DownloadTillDoneIgnoringHistory( |
385 TestDelegate* delegate, | 200 MockDelegate* delegate, |
386 TestFaviconHandler* favicon_handler, | 201 FaviconHandler* favicon_handler, |
387 const GURL& page_url, | 202 const GURL& page_url, |
388 const std::vector<FaviconURL>& candidate_icons, | 203 const std::vector<FaviconURL>& candidate_icons, |
389 const int* candidate_icon_sizes) { | 204 const int* candidate_icon_sizes) { |
205 /* | |
206 EXPECT_CALL(favicon_service_, | |
207 GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, _)) | |
208 .WillOnce(SaveArg<3>(&get_favicon_callback)); | |
209 | |
390 size_t old_num_notifications = delegate->num_notifications(); | 210 size_t old_num_notifications = delegate->num_notifications(); |
391 | 211 |
392 UpdateFaviconURL(delegate, favicon_handler, page_url, candidate_icons); | 212 UpdateFaviconURL(delegate, favicon_handler, page_url, candidate_icons); |
393 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); | 213 EXPECT_EQ(candidate_icons.size(), favicon_handler->image_urls().size()); |
394 | 214 |
395 DownloadHandler* download_handler = delegate->download_handler(); | 215 DownloadHandler* download_handler = delegate->download_handler(); |
396 for (size_t i = 0; i < candidate_icons.size(); ++i) { | 216 for (size_t i = 0; i < candidate_icons.size(); ++i) { |
397 favicon_handler->history_handler()->history_results_.clear(); | 217 favicon_handler->history_handler()->history_results_.clear(); |
398 favicon_handler->history_handler()->InvokeCallback(); | 218 favicon_handler->history_handler()->InvokeCallback(); |
399 ASSERT_TRUE(download_handler->HasDownload()); | 219 ASSERT_TRUE(download_handler->HasDownload()); |
400 EXPECT_EQ(download_handler->GetImageUrl(), | 220 EXPECT_EQ(download_handler->GetImageUrl(), |
401 candidate_icons[i].icon_url); | 221 candidate_icons[i].icon_url); |
402 std::vector<int> sizes; | 222 std::vector<int> sizes; |
403 sizes.push_back(candidate_icon_sizes[i]); | 223 sizes.push_back(candidate_icon_sizes[i]); |
404 download_handler->SetImageSizes(sizes); | 224 download_handler->SetImageSizes(sizes); |
405 download_handler->InvokeCallback(); | 225 download_handler->InvokeCallback(); |
406 | 226 |
407 download_handler->Reset(); | 227 download_handler->Reset(); |
408 | 228 |
409 if (delegate->num_notifications() > old_num_notifications) | 229 if (delegate->num_notifications() > old_num_notifications) |
410 return; | 230 return; |
411 } | 231 } |
232 */ | |
412 } | 233 } |
413 | 234 |
414 void UpdateFaviconURL(TestDelegate* delegate, | 235 void UpdateFaviconURL(FaviconHandler* favicon_handler, |
415 TestFaviconHandler* favicon_handler, | |
416 const GURL& page_url, | 236 const GURL& page_url, |
417 const std::vector<FaviconURL>& candidate_icons) { | 237 const std::vector<FaviconURL>& candidate_icons) { |
418 delegate->ResetNumNotifications(); | 238 EXPECT_CALL(favicon_service_, WasUnableToDownloadFavicon(_)) |
239 .Times(candidate_icons.size()) | |
240 .WillRepeatedly(Return(false)); | |
241 | |
242 favicon_base::FaviconResultsCallback get_favicon_callback; | |
243 // EXPECT_CALL(favicon_service_, | |
244 // GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, | |
245 // _)) | |
246 // .WillOnce(SaveArg<3>(&get_favicon_callback)); | |
419 | 247 |
420 favicon_handler->FetchFavicon(page_url); | 248 favicon_handler->FetchFavicon(page_url); |
421 favicon_handler->history_handler()->InvokeCallback(); | 249 get_favicon_callback.Run(std::vector<FaviconRawBitmapResult>()); |
422 | 250 |
423 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); | 251 favicon_handler->OnUpdateFaviconURL(page_url, candidate_icons); |
424 } | 252 } |
425 | 253 |
426 void SetUp() override { | 254 void SetUp() override { |
427 // The score computed by SelectFaviconFrames() is dependent on the supported | 255 // The score computed by SelectFaviconFrames() is dependent on the supported |
428 // scale factors of the platform. It is used for determining the goodness of | 256 // scale factors of the platform. It is used for determining the goodness of |
429 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 257 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
430 // Force the values of the scale factors so that the tests produce the same | 258 // Force the values of the scale factors so that the tests produce the same |
431 // results on all platforms. | 259 // results on all platforms. |
432 std::vector<ui::ScaleFactor> scale_factors; | 260 std::vector<ui::ScaleFactor> scale_factors; |
433 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 261 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
434 scoped_set_supported_scale_factors_.reset( | 262 scoped_set_supported_scale_factors_.reset( |
435 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 263 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
436 testing::Test::SetUp(); | 264 testing::Test::SetUp(); |
437 } | 265 } |
438 | 266 |
439 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 267 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
440 scoped_set_supported_scale_factors_; | 268 scoped_set_supported_scale_factors_; |
441 testing::StrictMock<MockFaviconService> favicon_service_; | 269 testing::StrictMock<MockFaviconService> favicon_service_; |
442 | 270 ImageDownloadTester image_download_tester_; |
443 private: | 271 FaviconServiceTester favicon_service_tester_; |
444 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 272 testing::NiceMock<MockDelegate> delegate_; |
445 }; | 273 }; |
446 | 274 |
447 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 275 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
448 const GURL page_url("http://www.google.com"); | 276 const GURL page_url("http://www.google.com"); |
449 const GURL icon_url("http://www.google.com/favicon"); | 277 const GURL icon_url("http://www.google.com/favicon"); |
450 | 278 |
451 TestDelegate delegate; | 279 // Favicon shouldn't request to download icon. |
452 TestFaviconHandler helper(&favicon_service_, &delegate, | 280 EXPECT_CALL(delegate_, DownloadImage(_, _, _)).Times(0); |
453 FaviconDriverObserver::NON_TOUCH_16_DIP); | |
454 | 281 |
455 helper.FetchFavicon(page_url); | 282 InSequence seq; |
456 HistoryRequestHandler* history_handler = helper.history_handler(); | 283 EXPECT_CALL(favicon_service_, |
457 // Ensure the data given to history is correct. | 284 GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, _)); |
pkotwicz
2017/02/16 16:36:17
I don't think that which FaviconService method got
mastiz
2017/02/21 16:22:16
I propose as follows: I'll try to finalize these p
| |
458 ASSERT_TRUE(history_handler); | 285 EXPECT_CALL(delegate_, OnFaviconUpdated( |
459 EXPECT_EQ(page_url, history_handler->page_url_); | 286 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, |
460 EXPECT_EQ(GURL(), history_handler->icon_url_); | 287 icon_url, /*icon_url_changed=*/true, _)); |
461 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
462 | 288 |
463 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 289 FaviconHandler handler(&favicon_service_, &delegate_, |
464 | 290 FaviconDriverObserver::NON_TOUCH_16_DIP); |
291 handler.FetchFavicon(page_url); | |
465 // Send history response. | 292 // Send history response. |
466 history_handler->InvokeCallback(); | 293 EXPECT_TRUE( |
467 // Verify FaviconHandler status | 294 favicon_service_tester_.TestRunCallback(CreateFaviconRawBitmapResult( |
468 EXPECT_EQ(1u, delegate.num_notifications()); | 295 icon_url, favicon_base::FAVICON, /*expired=*/false))); |
pkotwicz
2017/02/17 15:46:24
The test right now tests the order of the db reque
mastiz
2017/02/21 16:22:15
I agree that this is a implementation detail.
How
| |
469 EXPECT_EQ(icon_url, delegate.icon_url()); | |
470 | |
471 // Simulates update favicon url. | 296 // Simulates update favicon url. |
472 std::vector<FaviconURL> urls; | 297 handler.OnUpdateFaviconURL( |
473 urls.push_back( | 298 page_url, { |
474 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 299 FaviconURL(icon_url, favicon_base::FAVICON, kEmptySizes), |
475 helper.OnUpdateFaviconURL(page_url, urls); | 300 }); |
476 | |
477 // Verify FaviconHandler status | |
478 EXPECT_EQ(1u, helper.image_urls().size()); | |
479 ASSERT_TRUE(helper.current_candidate()); | |
480 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | |
481 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | |
482 | |
483 // Favicon shouldn't request to download icon. | |
484 EXPECT_FALSE(delegate.download_handler()->HasDownload()); | |
485 } | 301 } |
486 | 302 |
487 TEST_F(FaviconHandlerTest, DownloadFavicon) { | 303 TEST_F(FaviconHandlerTest, RedownloadExpiredFavicon) { |
488 const GURL page_url("http://www.google.com"); | 304 const GURL page_url("http://www.google.com"); |
489 const GURL icon_url("http://www.google.com/favicon"); | 305 const GURL icon_url("http://www.google.com/favicon"); |
490 | 306 |
491 TestDelegate delegate; | 307 InSequence seq; |
492 TestFaviconHandler helper(&favicon_service_, &delegate, | 308 EXPECT_CALL(favicon_service_, |
493 FaviconDriverObserver::NON_TOUCH_16_DIP); | 309 GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, _)); |
310 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
311 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
312 icon_url, /*icon_url_changed=*/true, _)); | |
pkotwicz
2017/02/16 16:36:17
This method should have been called twice
mastiz
2017/02/21 16:22:15
There's one more occurrence below, with a differen
| |
313 EXPECT_CALL(delegate_, DownloadImage(icon_url, _, _)); | |
314 // New icon should be saved to favicon service. | |
315 EXPECT_CALL(favicon_service_, | |
316 SetFavicons(page_url, icon_url, favicon_base::FAVICON, | |
317 ImageSizeIs(16, 16))); | |
318 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
319 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
320 icon_url, /*icon_url_changed=*/false, _)); | |
494 | 321 |
495 helper.FetchFavicon(page_url); | 322 FaviconHandler handler(&favicon_service_, &delegate_, |
496 HistoryRequestHandler* history_handler = helper.history_handler(); | 323 FaviconDriverObserver::NON_TOUCH_16_DIP); |
497 // Ensure the data given to history is correct. | 324 handler.FetchFavicon(page_url); |
498 ASSERT_TRUE(history_handler); | 325 // Send history response with expired icon data. |
499 EXPECT_EQ(page_url, history_handler->page_url_); | 326 EXPECT_TRUE( |
500 EXPECT_EQ(GURL(), history_handler->icon_url_); | 327 favicon_service_tester_.TestRunCallback(CreateFaviconRawBitmapResult( |
501 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 328 icon_url, favicon_base::FAVICON, /*expired=*/true))); |
502 | |
503 // Set icon data expired | |
504 SetFaviconRawBitmapResult(icon_url, | |
505 favicon_base::FAVICON, | |
506 true /* expired */, | |
507 &history_handler->history_results_); | |
508 // Send history response. | |
509 history_handler->InvokeCallback(); | |
510 // Verify FaviconHandler status | |
511 EXPECT_EQ(1u, delegate.num_notifications()); | |
512 EXPECT_EQ(icon_url, delegate.icon_url()); | |
513 | |
514 // Simulates update favicon url. | 329 // Simulates update favicon url. |
515 std::vector<FaviconURL> urls; | 330 handler.OnUpdateFaviconURL( |
516 urls.push_back( | 331 page_url, { |
517 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 332 FaviconURL(icon_url, favicon_base::FAVICON, kEmptySizes), |
518 helper.OnUpdateFaviconURL(page_url, urls); | 333 }); |
519 | 334 // Simulates download done. |
520 // Verify FaviconHandler status | 335 EXPECT_TRUE(image_download_tester_.TestDownloadFinished( |
521 EXPECT_EQ(1u, helper.image_urls().size()); | 336 200, icon_url, {CreateBitmap(16, 16)}, {gfx::Size(16, 16)})); |
pkotwicz
2017/02/16 16:36:17
Doesn't this duplicate the check on line 313?
mastiz
2017/02/21 16:22:15
This is the price you pay for controlling when exa
| |
522 ASSERT_TRUE(helper.current_candidate()); | |
523 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | |
524 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | |
525 | |
526 // Favicon should request to download icon now. | |
527 DownloadHandler* download_handler = delegate.download_handler(); | |
528 EXPECT_TRUE(download_handler->HasDownload()); | |
529 | |
530 // Verify the download request. | |
531 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | |
532 | |
533 // Reset the history_handler to verify whether favicon is set. | |
534 helper.set_history_handler(nullptr); | |
535 | |
536 // Smulates download done. | |
537 download_handler->InvokeCallback(); | |
538 | |
539 // New icon should be saved to history backend and navigation entry. | |
540 history_handler = helper.history_handler(); | |
541 ASSERT_TRUE(history_handler); | |
542 EXPECT_EQ(icon_url, history_handler->icon_url_); | |
543 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
544 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | |
545 EXPECT_EQ(page_url, history_handler->page_url_); | |
546 | |
547 // Verify NavigationEntry. | |
548 EXPECT_EQ(2u, delegate.num_notifications()); | |
549 EXPECT_EQ(icon_url, delegate.icon_url()); | |
550 EXPECT_FALSE(delegate.image().IsEmpty()); | |
551 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); | |
552 } | 337 } |
553 | 338 |
554 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { | 339 TEST_F(FaviconHandlerTest, UpdateAndDownloadFavicon) { |
555 const GURL page_url("http://www.google.com"); | 340 const GURL page_url("http://www.google.com"); |
556 const GURL icon_url("http://www.google.com/favicon"); | 341 const GURL icon_url("http://www.google.com/favicon"); |
557 const GURL new_icon_url("http://www.google.com/new_favicon"); | 342 const GURL new_icon_url("http://www.google.com/new_favicon"); |
558 | 343 |
559 TestDelegate delegate; | 344 InSequence seq; |
560 TestFaviconHandler helper(&favicon_service_, &delegate, | 345 EXPECT_CALL(favicon_service_, |
561 FaviconDriverObserver::NON_TOUCH_16_DIP); | 346 GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, _)); |
347 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
348 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
349 icon_url, /*icon_url_changed=*/true, _)); | |
350 EXPECT_CALL(favicon_service_, | |
351 UpdateFaviconMappingsAndFetch(page_url, URLVector{new_icon_url}, | |
352 favicon_base::FAVICON, _, _, _)); | |
353 EXPECT_CALL(delegate_, DownloadImage(new_icon_url, _, _)); | |
354 // New icon should be saved to favicon service. | |
355 EXPECT_CALL(favicon_service_, | |
356 SetFavicons(page_url, new_icon_url, favicon_base::FAVICON, | |
357 ImageSizeIs(16, 16))); | |
358 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
359 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
360 new_icon_url, /*icon_url_changed=*/true, _)); | |
562 | 361 |
563 helper.FetchFavicon(page_url); | 362 FaviconHandler handler(&favicon_service_, &delegate_, |
564 HistoryRequestHandler* history_handler = helper.history_handler(); | 363 FaviconDriverObserver::NON_TOUCH_16_DIP); |
565 // Ensure the data given to history is correct. | 364 handler.FetchFavicon(page_url); |
566 ASSERT_TRUE(history_handler); | |
567 EXPECT_EQ(page_url, history_handler->page_url_); | |
568 EXPECT_EQ(GURL(), history_handler->icon_url_); | |
569 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
570 | |
571 // Set valid icon data. | |
572 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | |
573 | |
574 // Send history response. | 365 // Send history response. |
575 history_handler->InvokeCallback(); | 366 EXPECT_TRUE( |
576 // Verify FaviconHandler status. | 367 favicon_service_tester_.TestRunCallback(CreateFaviconRawBitmapResult( |
577 EXPECT_EQ(1u, delegate.num_notifications()); | 368 icon_url, favicon_base::FAVICON, /*expired=*/false))); |
578 EXPECT_EQ(icon_url, delegate.icon_url()); | |
579 | |
580 // Reset the history_handler to verify whether new icon is requested from | |
581 // history. | |
582 helper.set_history_handler(nullptr); | |
583 | |
584 // Simulates update with the different favicon url. | 369 // Simulates update with the different favicon url. |
585 std::vector<FaviconURL> urls; | 370 handler.OnUpdateFaviconURL( |
586 urls.push_back(FaviconURL( | 371 page_url, |
587 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 372 { |
588 helper.OnUpdateFaviconURL(page_url, urls); | 373 FaviconURL(new_icon_url, favicon_base::FAVICON, kEmptySizes), |
589 | 374 }); |
590 // Verify FaviconHandler status. | |
591 EXPECT_EQ(1u, helper.image_urls().size()); | |
592 ASSERT_TRUE(helper.current_candidate()); | |
593 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | |
594 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | |
595 | |
596 // Favicon should be requested from history. | |
597 history_handler = helper.history_handler(); | |
598 ASSERT_TRUE(history_handler); | |
599 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | |
600 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
601 EXPECT_EQ(page_url, history_handler->page_url_); | |
602 | |
603 // Simulate not find icon. | 375 // Simulate not find icon. |
604 history_handler->history_results_.clear(); | 376 EXPECT_TRUE(favicon_service_tester_.TestRunCallback(kEmptyBitmapResult)); |
605 history_handler->InvokeCallback(); | 377 // Simulates download done. |
606 | 378 EXPECT_TRUE(image_download_tester_.TestDownloadFinished( |
607 // Favicon should request to download icon now. | 379 200, new_icon_url, {CreateBitmap(16, 16)}, {gfx::Size(16, 16)})); |
608 DownloadHandler* download_handler = delegate.download_handler(); | |
609 EXPECT_TRUE(download_handler->HasDownload()); | |
610 | |
611 // Verify the download request. | |
612 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | |
613 | |
614 // Reset the history_handler to verify whether favicon is set. | |
615 helper.set_history_handler(nullptr); | |
616 | |
617 // Smulates download done. | |
618 download_handler->InvokeCallback(); | |
619 | |
620 // New icon should be saved to history backend and navigation entry. | |
621 history_handler = helper.history_handler(); | |
622 ASSERT_TRUE(history_handler); | |
623 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | |
624 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
625 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | |
626 EXPECT_EQ(page_url, history_handler->page_url_); | |
627 | |
628 // Verify NavigationEntry. | |
629 EXPECT_EQ(2u, delegate.num_notifications()); | |
630 EXPECT_EQ(new_icon_url, delegate.icon_url()); | |
631 EXPECT_FALSE(delegate.image().IsEmpty()); | |
632 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); | |
633 } | 380 } |
634 | 381 |
635 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { | 382 TEST_F(FaviconHandlerTest, FaviconInHistoryInvalid) { |
636 const GURL page_url("http://www.google.com"); | 383 const GURL page_url("http://www.google.com"); |
637 const GURL icon_url("http://www.google.com/favicon"); | 384 const GURL icon_url("http://www.google.com/favicon"); |
638 | 385 |
639 TestDelegate delegate; | 386 InSequence seq; |
640 TestFaviconHandler helper(&favicon_service_, &delegate, | 387 EXPECT_CALL(favicon_service_, |
641 FaviconDriverObserver::NON_TOUCH_16_DIP); | 388 GetFaviconForPageURL(page_url, favicon_base::FAVICON, _, _, _)); |
389 EXPECT_CALL(delegate_, DownloadImage(icon_url, _, _)); | |
390 // Icon should be saved to favicon service. | |
391 EXPECT_CALL(favicon_service_, | |
392 SetFavicons(page_url, icon_url, favicon_base::FAVICON, | |
393 ImageSizeIs(16, 16))); | |
394 EXPECT_CALL(delegate_, OnFaviconUpdated( | |
395 page_url, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
396 icon_url, /*icon_url_changed=*/true, _)); | |
642 | 397 |
643 helper.FetchFavicon(page_url); | 398 FaviconHandler handler(&favicon_service_, &delegate_, |
644 HistoryRequestHandler* history_handler = helper.history_handler(); | 399 FaviconDriverObserver::NON_TOUCH_16_DIP); |
645 // Ensure the data given to history is correct. | 400 handler.FetchFavicon(page_url); |
646 ASSERT_TRUE(history_handler); | |
647 EXPECT_EQ(page_url, history_handler->page_url_); | |
648 EXPECT_EQ(GURL(), history_handler->icon_url_); | |
649 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
650 | |
651 // Set non empty but invalid data. | 401 // Set non empty but invalid data. |
652 favicon_base::FaviconRawBitmapResult bitmap_result; | 402 FaviconRawBitmapResult bitmap_result; |
653 bitmap_result.expired = false; | 403 bitmap_result.expired = false; |
654 // Empty bitmap data is invalid. | 404 // Empty bitmap data is invalid. |
655 bitmap_result.bitmap_data = new base::RefCountedBytes(); | 405 bitmap_result.bitmap_data = new base::RefCountedBytes(); |
656 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); | 406 bitmap_result.pixel_size = gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize); |
657 bitmap_result.icon_type = favicon_base::FAVICON; | 407 bitmap_result.icon_type = favicon_base::FAVICON; |
658 bitmap_result.icon_url = icon_url; | 408 bitmap_result.icon_url = icon_url; |
659 history_handler->history_results_.clear(); | 409 EXPECT_TRUE(favicon_service_tester_.TestRunCallback( |
660 history_handler->history_results_.push_back(bitmap_result); | 410 std::vector<FaviconRawBitmapResult>{bitmap_result})); |
411 // Simulates update favicon url. | |
412 handler.OnUpdateFaviconURL( | |
413 page_url, { | |
414 FaviconURL(icon_url, favicon_base::FAVICON, kEmptySizes), | |
415 }); | |
416 // Simulates download done. | |
417 EXPECT_TRUE(image_download_tester_.TestDownloadFinished( | |
418 200, icon_url, {CreateBitmap(16, 16)}, {gfx::Size(16, 16)})); | |
419 } | |
661 | 420 |
662 // Send history response. | 421 #ifdef MASTIZ_WIP |
663 history_handler->InvokeCallback(); | |
664 // The NavigationEntry should not be set yet as the history data is invalid. | |
665 EXPECT_EQ(0u, delegate.num_notifications()); | |
666 EXPECT_EQ(GURL(), delegate.icon_url()); | |
667 | |
668 // Reset the history_handler to verify whether new icon is requested from | |
669 // history. | |
670 helper.set_history_handler(nullptr); | |
671 | |
672 // Simulates update with matching favicon URL. | |
673 std::vector<FaviconURL> urls; | |
674 urls.push_back( | |
675 FaviconURL(icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | |
676 helper.OnUpdateFaviconURL(page_url, urls); | |
677 | |
678 // A download for the favicon should be requested, and we should not do | |
679 // another history request. | |
680 DownloadHandler* download_handler = delegate.download_handler(); | |
681 EXPECT_TRUE(download_handler->HasDownload()); | |
682 EXPECT_EQ(nullptr, helper.history_handler()); | |
683 | |
684 // Verify the download request. | |
685 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | |
686 | |
687 // Simulates download done. | |
688 download_handler->InvokeCallback(); | |
689 | |
690 // New icon should be saved to history backend and navigation entry. | |
691 history_handler = helper.history_handler(); | |
692 ASSERT_TRUE(history_handler); | |
693 EXPECT_EQ(icon_url, history_handler->icon_url_); | |
694 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | |
695 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | |
696 EXPECT_EQ(page_url, history_handler->page_url_); | |
697 | |
698 // Verify NavigationEntry. | |
699 EXPECT_EQ(1u, delegate.num_notifications()); | |
700 EXPECT_EQ(icon_url, delegate.icon_url()); | |
701 EXPECT_FALSE(delegate.image().IsEmpty()); | |
702 EXPECT_EQ(gfx::kFaviconSize, delegate.image().Width()); | |
703 } | |
704 | 422 |
705 TEST_F(FaviconHandlerTest, UpdateFavicon) { | 423 TEST_F(FaviconHandlerTest, UpdateFavicon) { |
706 const GURL page_url("http://www.google.com"); | 424 const GURL page_url("http://www.google.com"); |
707 const GURL icon_url("http://www.google.com/favicon"); | 425 const GURL icon_url("http://www.google.com/favicon"); |
708 const GURL new_icon_url("http://www.google.com/new_favicon"); | 426 const GURL new_icon_url("http://www.google.com/new_favicon"); |
709 | 427 |
710 TestDelegate delegate; | 428 MockDelegate_ delegate_; |
711 TestFaviconHandler helper(&favicon_service_, &delegate, | 429 FaviconHandler handler(&favicon_service_, &delegate_, |
712 FaviconDriverObserver::NON_TOUCH_16_DIP); | 430 FaviconDriverObserver::NON_TOUCH_16_DIP); |
713 | 431 |
714 helper.FetchFavicon(page_url); | 432 handler.FetchFavicon(page_url); |
715 HistoryRequestHandler* history_handler = helper.history_handler(); | 433 HistoryRequestHandler* history_handler = handler.history_handler(); |
716 // Ensure the data given to history is correct. | 434 // Ensure the data given to history is correct. |
717 ASSERT_TRUE(history_handler); | 435 ASSERT_TRUE(history_handler); |
718 EXPECT_EQ(page_url, history_handler->page_url_); | 436 EXPECT_EQ(page_url, history_handler->page_url_); |
719 EXPECT_EQ(GURL(), history_handler->icon_url_); | 437 EXPECT_EQ(GURL(), history_handler->icon_url_); |
720 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 438 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
721 | 439 |
722 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); | 440 SetFaviconRawBitmapResult(icon_url, &history_handler->history_results_); |
723 | 441 |
724 // Send history response. | 442 // Send history response. |
725 history_handler->InvokeCallback(); | 443 history_handler->InvokeCallback(); |
726 // Verify FaviconHandler status. | 444 // Verify FaviconHandler status. |
727 EXPECT_EQ(1u, delegate.num_notifications()); | 445 EXPECT_EQ(1u, delegate_.num_notifications()); |
728 EXPECT_EQ(icon_url, delegate.icon_url()); | 446 EXPECT_EQ(icon_url, delegate_.icon_url()); |
729 | 447 |
730 // Reset the history_handler to verify whether new icon is requested from | 448 // Reset the history_handler to verify whether new icon is requested from |
731 // history. | 449 // history. |
732 helper.set_history_handler(nullptr); | 450 handler.set_history_handler(nullptr); |
733 | 451 |
734 // Simulates update with the different favicon url. | 452 // Simulates update with the different favicon url. |
735 std::vector<FaviconURL> urls; | 453 std::vector<FaviconURL> urls; |
736 urls.push_back(FaviconURL( | 454 urls.push_back(FaviconURL(new_icon_url, favicon_base::FAVICON, kEmptySizes)); |
737 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | 455 handler.OnUpdateFaviconURL(page_url, urls); |
738 helper.OnUpdateFaviconURL(page_url, urls); | |
739 | 456 |
740 // Verify FaviconHandler status. | 457 // Verify FaviconHandler status. |
741 EXPECT_EQ(1u, helper.image_urls().size()); | 458 EXPECT_EQ(1u, handler.image_urls().size()); |
742 ASSERT_TRUE(helper.current_candidate()); | 459 ASSERT_TRUE(handler.current_candidate()); |
743 ASSERT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 460 ASSERT_EQ(new_icon_url, handler.current_candidate()->icon_url); |
744 ASSERT_EQ(favicon_base::FAVICON, helper.current_candidate()->icon_type); | 461 ASSERT_EQ(favicon_base::FAVICON, handler.current_candidate()->icon_type); |
745 | 462 |
746 // Favicon should be requested from history. | 463 // Favicon should be requested from history. |
747 history_handler = helper.history_handler(); | 464 history_handler = handler.history_handler(); |
748 ASSERT_TRUE(history_handler); | 465 ASSERT_TRUE(history_handler); |
749 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 466 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
750 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); | 467 EXPECT_EQ(favicon_base::FAVICON, history_handler->icon_type_); |
751 EXPECT_EQ(page_url, history_handler->page_url_); | 468 EXPECT_EQ(page_url, history_handler->page_url_); |
752 | 469 |
753 // Simulate find icon. | 470 // Simulate find icon. |
754 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); | 471 SetFaviconRawBitmapResult(new_icon_url, &history_handler->history_results_); |
755 history_handler->InvokeCallback(); | 472 history_handler->InvokeCallback(); |
756 | 473 |
757 // Shouldn't request download favicon | 474 // Shouldn't request download favicon |
758 EXPECT_FALSE(delegate.download_handler()->HasDownload()); | 475 EXPECT_FALSE(delegate_.download_handler()->HasDownload()); |
759 | 476 |
760 // Verify the favicon status. | 477 // Verify the favicon status. |
761 EXPECT_EQ(2u, delegate.num_notifications()); | 478 EXPECT_EQ(2u, delegate_.num_notifications()); |
762 EXPECT_EQ(new_icon_url, delegate.icon_url()); | 479 EXPECT_EQ(new_icon_url, delegate_.icon_url()); |
763 EXPECT_FALSE(delegate.image().IsEmpty()); | 480 EXPECT_FALSE(delegate_.image().IsEmpty()); |
764 } | 481 } |
765 | 482 |
766 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { | 483 TEST_F(FaviconHandlerTest, Download2ndFaviconURLCandidate) { |
767 const GURL page_url("http://www.google.com"); | 484 const GURL page_url("http://www.google.com"); |
768 const GURL icon_url("http://www.google.com/favicon"); | 485 const GURL icon_url("http://www.google.com/favicon"); |
769 const GURL new_icon_url("http://www.google.com/new_favicon"); | 486 const GURL new_icon_url("http://www.google.com/new_favicon"); |
770 | 487 |
771 TestDelegate delegate; | 488 MockDelegate_ delegate_; |
772 TestFaviconHandler helper(&favicon_service_, &delegate, | 489 FaviconHandler handler(&favicon_service_, &delegate_, |
773 FaviconDriverObserver::TOUCH_LARGEST); | 490 FaviconDriverObserver::TOUCH_LARGEST); |
774 std::set<GURL> fail_downloads; | 491 std::set<GURL> fail_downloads; |
775 fail_downloads.insert(icon_url); | 492 fail_downloads.insert(icon_url); |
776 delegate.download_handler()->FailDownloadForIconURLs(fail_downloads); | 493 delegate_.download_handler()->FailDownloadForIconURLs(fail_downloads); |
777 | 494 |
778 helper.FetchFavicon(page_url); | 495 handler.FetchFavicon(page_url); |
779 HistoryRequestHandler* history_handler = helper.history_handler(); | 496 HistoryRequestHandler* history_handler = handler.history_handler(); |
780 // Ensure the data given to history is correct. | 497 // Ensure the data given to history is correct. |
781 ASSERT_TRUE(history_handler); | 498 ASSERT_TRUE(history_handler); |
782 EXPECT_EQ(page_url, history_handler->page_url_); | 499 EXPECT_EQ(page_url, history_handler->page_url_); |
783 EXPECT_EQ(GURL(), history_handler->icon_url_); | 500 EXPECT_EQ(GURL(), history_handler->icon_url_); |
784 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 501 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
785 history_handler->icon_type_); | 502 history_handler->icon_type_); |
786 | 503 |
787 // Icon not found. | 504 // Icon not found. |
788 history_handler->history_results_.clear(); | 505 history_handler->history_results_.clear(); |
789 // Send history response. | 506 // Send history response. |
790 history_handler->InvokeCallback(); | 507 history_handler->InvokeCallback(); |
791 // Verify FaviconHandler status. | 508 // Verify FaviconHandler status. |
792 EXPECT_EQ(0u, delegate.num_notifications()); | 509 EXPECT_EQ(0u, delegate_.num_notifications()); |
793 EXPECT_EQ(GURL(), delegate.icon_url()); | 510 EXPECT_EQ(GURL(), delegate_.icon_url()); |
794 | 511 |
795 // Reset the history_handler to verify whether new icon is requested from | 512 // Reset the history_handler to verify whether new icon is requested from |
796 // history. | 513 // history. |
797 helper.set_history_handler(nullptr); | 514 handler.set_history_handler(nullptr); |
798 | 515 |
799 // Simulates update with the different favicon url. | 516 // Simulates update with the different favicon url. |
800 std::vector<FaviconURL> urls; | 517 std::vector<FaviconURL> urls; |
801 urls.push_back(FaviconURL(icon_url, | 518 urls.push_back( |
802 favicon_base::TOUCH_PRECOMPOSED_ICON, | 519 FaviconURL(icon_url, favicon_base::TOUCH_PRECOMPOSED_ICON, kEmptySizes)); |
803 std::vector<gfx::Size>())); | 520 urls.push_back( |
804 urls.push_back(FaviconURL( | 521 FaviconURL(new_icon_url, favicon_base::TOUCH_ICON, kEmptySizes)); |
805 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); | 522 urls.push_back(FaviconURL(new_icon_url, favicon_base::FAVICON, kEmptySizes)); |
806 urls.push_back(FaviconURL( | 523 handler.OnUpdateFaviconURL(page_url, urls); |
807 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | |
808 helper.OnUpdateFaviconURL(page_url, urls); | |
809 | 524 |
810 // Verify FaviconHandler status. | 525 // Verify FaviconHandler status. |
811 EXPECT_EQ(2u, helper.image_urls().size()); | 526 EXPECT_EQ(2u, handler.image_urls().size()); |
812 EXPECT_EQ(0u, helper.current_candidate_index()); | 527 EXPECT_EQ(0u, handler.current_candidate_index()); |
813 ASSERT_TRUE(helper.current_candidate()); | 528 ASSERT_TRUE(handler.current_candidate()); |
814 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 529 ASSERT_EQ(icon_url, handler.current_candidate()->icon_url); |
815 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, | 530 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, |
816 helper.current_candidate()->icon_type); | 531 handler.current_candidate()->icon_type); |
817 | 532 |
818 // Favicon should be requested from history. | 533 // Favicon should be requested from history. |
819 history_handler = helper.history_handler(); | 534 history_handler = handler.history_handler(); |
820 ASSERT_TRUE(history_handler); | 535 ASSERT_TRUE(history_handler); |
821 EXPECT_EQ(icon_url, history_handler->icon_url_); | 536 EXPECT_EQ(icon_url, history_handler->icon_url_); |
822 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 537 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
823 EXPECT_EQ(page_url, history_handler->page_url_); | 538 EXPECT_EQ(page_url, history_handler->page_url_); |
824 | 539 |
825 // Simulate not find icon. | 540 // Simulate not find icon. |
826 history_handler->history_results_.clear(); | 541 history_handler->history_results_.clear(); |
827 history_handler->InvokeCallback(); | 542 history_handler->InvokeCallback(); |
828 | 543 |
829 // Should request download favicon. | 544 // Should request download favicon. |
830 DownloadHandler* download_handler = delegate.download_handler(); | 545 DownloadHandler* download_handler = delegate_.download_handler(); |
831 EXPECT_TRUE(download_handler->HasDownload()); | 546 EXPECT_TRUE(download_handler->HasDownload()); |
832 | 547 |
833 // Verify the download request. | 548 // Verify the download request. |
834 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 549 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
835 | 550 |
836 // Reset the history_handler to verify whether favicon is request from | 551 // Reset the history_handler to verify whether favicon is request from |
837 // history. | 552 // history. |
838 helper.set_history_handler(nullptr); | 553 handler.set_history_handler(nullptr); |
839 download_handler->InvokeCallback(); | 554 download_handler->InvokeCallback(); |
840 | 555 |
841 // Left 1 url. | 556 // Left 1 url. |
842 EXPECT_EQ(1u, helper.current_candidate_index()); | 557 EXPECT_EQ(1u, handler.current_candidate_index()); |
843 ASSERT_TRUE(helper.current_candidate()); | 558 ASSERT_TRUE(handler.current_candidate()); |
844 EXPECT_EQ(new_icon_url, helper.current_candidate()->icon_url); | 559 EXPECT_EQ(new_icon_url, handler.current_candidate()->icon_url); |
845 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); | 560 EXPECT_EQ(favicon_base::TOUCH_ICON, handler.current_candidate()->icon_type); |
846 | 561 |
847 // Favicon should be requested from history. | 562 // Favicon should be requested from history. |
848 history_handler = helper.history_handler(); | 563 history_handler = handler.history_handler(); |
849 ASSERT_TRUE(history_handler); | 564 ASSERT_TRUE(history_handler); |
850 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 565 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
851 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 566 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
852 EXPECT_EQ(page_url, history_handler->page_url_); | 567 EXPECT_EQ(page_url, history_handler->page_url_); |
853 | 568 |
854 // Reset download handler | 569 // Reset download handler |
855 download_handler->Reset(); | 570 download_handler->Reset(); |
856 | 571 |
857 // Simulates getting a expired icon from history. | 572 // Simulates getting a expired icon from history. |
858 SetFaviconRawBitmapResult(new_icon_url, | 573 SetFaviconRawBitmapResult(new_icon_url, |
859 favicon_base::TOUCH_ICON, | 574 favicon_base::TOUCH_ICON, |
860 true /* expired */, | 575 true /* expired */, |
861 &history_handler->history_results_); | 576 &history_handler->history_results_); |
862 history_handler->InvokeCallback(); | 577 history_handler->InvokeCallback(); |
863 | 578 |
864 // Verify the download request. | 579 // Verify the download request. |
865 EXPECT_TRUE(delegate.download_handler()->HasDownload()); | 580 EXPECT_TRUE(delegate_.download_handler()->HasDownload()); |
866 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); | 581 EXPECT_EQ(new_icon_url, download_handler->GetImageUrl()); |
867 | 582 |
868 helper.set_history_handler(nullptr); | 583 handler.set_history_handler(nullptr); |
869 | 584 |
870 // Simulates icon being downloaded. | 585 // Simulates icon being downloaded. |
871 download_handler->InvokeCallback(); | 586 download_handler->InvokeCallback(); |
872 | 587 |
873 // New icon should be saved to history backend. | 588 // New icon should be saved to history backend. |
874 history_handler = helper.history_handler(); | 589 history_handler = handler.history_handler(); |
875 ASSERT_TRUE(history_handler); | 590 ASSERT_TRUE(history_handler); |
876 EXPECT_EQ(new_icon_url, history_handler->icon_url_); | 591 EXPECT_EQ(new_icon_url, history_handler->icon_url_); |
877 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 592 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
878 EXPECT_LT(0U, history_handler->bitmap_data_.size()); | 593 EXPECT_LT(0U, history_handler->bitmap_data_.size()); |
879 EXPECT_EQ(page_url, history_handler->page_url_); | 594 EXPECT_EQ(page_url, history_handler->page_url_); |
880 } | 595 } |
881 | 596 |
882 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { | 597 TEST_F(FaviconHandlerTest, UpdateDuringDownloading) { |
883 const GURL page_url("http://www.google.com"); | 598 const GURL page_url("http://www.google.com"); |
884 const GURL icon_url("http://www.google.com/favicon"); | 599 const GURL icon_url("http://www.google.com/favicon"); |
885 const GURL new_icon_url("http://www.google.com/new_favicon"); | 600 const GURL new_icon_url("http://www.google.com/new_favicon"); |
886 | 601 |
887 TestDelegate delegate; | 602 MockDelegate_ delegate_; |
888 TestFaviconHandler helper(&favicon_service_, &delegate, | 603 FaviconHandler handler(&favicon_service_, &delegate_, |
889 FaviconDriverObserver::TOUCH_LARGEST); | 604 FaviconDriverObserver::TOUCH_LARGEST); |
890 | 605 |
891 helper.FetchFavicon(page_url); | 606 handler.FetchFavicon(page_url); |
892 HistoryRequestHandler* history_handler = helper.history_handler(); | 607 HistoryRequestHandler* history_handler = handler.history_handler(); |
893 // Ensure the data given to history is correct. | 608 // Ensure the data given to history is correct. |
894 ASSERT_TRUE(history_handler); | 609 ASSERT_TRUE(history_handler); |
895 EXPECT_EQ(page_url, history_handler->page_url_); | 610 EXPECT_EQ(page_url, history_handler->page_url_); |
896 EXPECT_EQ(GURL(), history_handler->icon_url_); | 611 EXPECT_EQ(GURL(), history_handler->icon_url_); |
897 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, | 612 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON | favicon_base::TOUCH_ICON, |
898 history_handler->icon_type_); | 613 history_handler->icon_type_); |
899 | 614 |
900 // Icon not found. | 615 // Icon not found. |
901 history_handler->history_results_.clear(); | 616 history_handler->history_results_.clear(); |
902 // Send history response. | 617 // Send history response. |
903 history_handler->InvokeCallback(); | 618 history_handler->InvokeCallback(); |
904 // Verify FaviconHandler status. | 619 // Verify FaviconHandler status. |
905 EXPECT_EQ(0u, delegate.num_notifications()); | 620 EXPECT_EQ(0u, delegate_.num_notifications()); |
906 EXPECT_EQ(GURL(), delegate.icon_url()); | 621 EXPECT_EQ(GURL(), delegate_.icon_url()); |
907 | 622 |
908 // Reset the history_handler to verify whether new icon is requested from | 623 // Reset the history_handler to verify whether new icon is requested from |
909 // history. | 624 // history. |
910 helper.set_history_handler(nullptr); | 625 handler.set_history_handler(nullptr); |
911 | 626 |
912 // Simulates update with the different favicon url. | 627 // Simulates update with the different favicon url. |
913 std::vector<FaviconURL> urls; | 628 std::vector<FaviconURL> urls; |
914 urls.push_back(FaviconURL(icon_url, | 629 urls.push_back( |
915 favicon_base::TOUCH_PRECOMPOSED_ICON, | 630 FaviconURL(icon_url, favicon_base::TOUCH_PRECOMPOSED_ICON, kEmptySizes)); |
916 std::vector<gfx::Size>())); | 631 urls.push_back( |
917 urls.push_back(FaviconURL( | 632 FaviconURL(new_icon_url, favicon_base::TOUCH_ICON, kEmptySizes)); |
918 new_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); | 633 urls.push_back(FaviconURL(new_icon_url, favicon_base::FAVICON, kEmptySizes)); |
919 urls.push_back(FaviconURL( | 634 handler.OnUpdateFaviconURL(page_url, urls); |
920 new_icon_url, favicon_base::FAVICON, std::vector<gfx::Size>())); | |
921 helper.OnUpdateFaviconURL(page_url, urls); | |
922 | 635 |
923 // Verify FaviconHandler status. | 636 // Verify FaviconHandler status. |
924 EXPECT_EQ(2u, helper.image_urls().size()); | 637 EXPECT_EQ(2u, handler.image_urls().size()); |
925 ASSERT_EQ(0u, helper.current_candidate_index()); | 638 ASSERT_EQ(0u, handler.current_candidate_index()); |
926 ASSERT_EQ(icon_url, helper.current_candidate()->icon_url); | 639 ASSERT_EQ(icon_url, handler.current_candidate()->icon_url); |
927 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, | 640 ASSERT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, |
928 helper.current_candidate()->icon_type); | 641 handler.current_candidate()->icon_type); |
929 | 642 |
930 // Favicon should be requested from history. | 643 // Favicon should be requested from history. |
931 history_handler = helper.history_handler(); | 644 history_handler = handler.history_handler(); |
932 ASSERT_TRUE(history_handler); | 645 ASSERT_TRUE(history_handler); |
933 EXPECT_EQ(icon_url, history_handler->icon_url_); | 646 EXPECT_EQ(icon_url, history_handler->icon_url_); |
934 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); | 647 EXPECT_EQ(favicon_base::TOUCH_PRECOMPOSED_ICON, history_handler->icon_type_); |
935 EXPECT_EQ(page_url, history_handler->page_url_); | 648 EXPECT_EQ(page_url, history_handler->page_url_); |
936 | 649 |
937 // Simulate not find icon. | 650 // Simulate not find icon. |
938 history_handler->history_results_.clear(); | 651 history_handler->history_results_.clear(); |
939 history_handler->InvokeCallback(); | 652 history_handler->InvokeCallback(); |
940 | 653 |
941 // Should request download favicon. | 654 // Should request download favicon. |
942 DownloadHandler* download_handler = delegate.download_handler(); | 655 DownloadHandler* download_handler = delegate_.download_handler(); |
943 EXPECT_TRUE(download_handler->HasDownload()); | 656 EXPECT_TRUE(download_handler->HasDownload()); |
944 | 657 |
945 // Verify the download request. | 658 // Verify the download request. |
946 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); | 659 EXPECT_EQ(icon_url, download_handler->GetImageUrl()); |
947 | 660 |
948 // Reset the history_handler to verify whether favicon is request from | 661 // Reset the history_handler to verify whether favicon is request from |
949 // history. | 662 // history. |
950 helper.set_history_handler(nullptr); | 663 handler.set_history_handler(nullptr); |
951 const GURL latest_icon_url("http://www.google.com/latest_favicon"); | 664 const GURL latest_icon_url("http://www.google.com/latest_favicon"); |
952 std::vector<FaviconURL> latest_urls; | 665 std::vector<FaviconURL> latest_urls; |
953 latest_urls.push_back(FaviconURL( | 666 latest_urls.push_back( |
954 latest_icon_url, favicon_base::TOUCH_ICON, std::vector<gfx::Size>())); | 667 FaviconURL(latest_icon_url, favicon_base::TOUCH_ICON, kEmptySizes)); |
955 helper.OnUpdateFaviconURL(page_url, latest_urls); | 668 handler.OnUpdateFaviconURL(page_url, latest_urls); |
956 | 669 |
957 EXPECT_EQ(1u, helper.image_urls().size()); | 670 EXPECT_EQ(1u, handler.image_urls().size()); |
958 EXPECT_EQ(0u, helper.current_candidate_index()); | 671 EXPECT_EQ(0u, handler.current_candidate_index()); |
959 EXPECT_EQ(latest_icon_url, helper.current_candidate()->icon_url); | 672 EXPECT_EQ(latest_icon_url, handler.current_candidate()->icon_url); |
960 EXPECT_EQ(favicon_base::TOUCH_ICON, helper.current_candidate()->icon_type); | 673 EXPECT_EQ(favicon_base::TOUCH_ICON, handler.current_candidate()->icon_type); |
961 | 674 |
962 // Whether new icon is requested from history | 675 // Whether new icon is requested from history |
963 history_handler = helper.history_handler(); | 676 history_handler = handler.history_handler(); |
964 ASSERT_TRUE(history_handler); | 677 ASSERT_TRUE(history_handler); |
965 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); | 678 EXPECT_EQ(latest_icon_url, history_handler->icon_url_); |
966 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); | 679 EXPECT_EQ(favicon_base::TOUCH_ICON, history_handler->icon_type_); |
967 EXPECT_EQ(page_url, history_handler->page_url_); | 680 EXPECT_EQ(page_url, history_handler->page_url_); |
968 | 681 |
969 // Reset the history_handler to verify whether favicon is request from | 682 // Reset the history_handler to verify whether favicon is request from |
970 // history. | 683 // history. |
971 // Save the callback for late use. | 684 // Save the callback for late use. |
972 favicon_base::FaviconResultsCallback callback = history_handler->callback_; | 685 favicon_base::FaviconResultsCallback callback = history_handler->callback_; |
973 helper.set_history_handler(nullptr); | 686 handler.set_history_handler(nullptr); |
974 | 687 |
975 // Simulates download succeed. | 688 // Simulates download succeed. |
976 download_handler->InvokeCallback(); | 689 download_handler->InvokeCallback(); |
977 // The downloaded icon should be thrown away as there is favicon update. | 690 // The downloaded icon should be thrown away as there is favicon update. |
978 EXPECT_FALSE(helper.history_handler()); | 691 EXPECT_FALSE(handler.history_handler()); |
979 | 692 |
980 download_handler->Reset(); | 693 download_handler->Reset(); |
981 | 694 |
982 // Simulates getting the icon from history. | 695 // Simulates getting the icon from history. |
983 std::unique_ptr<HistoryRequestHandler> handler; | 696 std::unique_ptr<HistoryRequestHandler> handler; |
984 handler.reset(new HistoryRequestHandler( | 697 handler.reset(new HistoryRequestHandler( |
985 page_url, latest_icon_url, favicon_base::TOUCH_ICON, callback)); | 698 page_url, latest_icon_url, favicon_base::TOUCH_ICON, callback)); |
986 SetFaviconRawBitmapResult(latest_icon_url, | 699 SetFaviconRawBitmapResult(latest_icon_url, |
987 favicon_base::TOUCH_ICON, | 700 favicon_base::TOUCH_ICON, |
988 false /* expired */, | 701 false /* expired */, |
989 &handler->history_results_); | 702 &handler->history_results_); |
990 handler->InvokeCallback(); | 703 handler->InvokeCallback(); |
991 | 704 |
992 // No download request. | 705 // No download request. |
993 EXPECT_FALSE(download_handler->HasDownload()); | 706 EXPECT_FALSE(download_handler->HasDownload()); |
994 } | 707 } |
995 | 708 |
996 // Test that sending an icon URL update identical to the previous icon URL | 709 // Test that sending an icon URL update identical to the previous icon URL |
997 // update is a no-op. | 710 // update is a no-op. |
998 TEST_F(FaviconHandlerTest, UpdateSameIconURLs) { | 711 TEST_F(FaviconHandlerTest, UpdateSameIconURLs) { |
999 const GURL page_url("http://www.google.com"); | 712 const GURL page_url("http://www.google.com"); |
1000 const GURL icon_url1("http://www.google.com/favicon1"); | 713 const GURL icon_url1("http://www.google.com/favicon1"); |
1001 const GURL icon_url2("http://www.google.com/favicon2"); | 714 const GURL icon_url2("http://www.google.com/favicon2"); |
1002 std::vector<FaviconURL> favicon_urls; | 715 std::vector<FaviconURL> favicon_urls; |
1003 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), | 716 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon1"), |
1004 favicon_base::FAVICON, | 717 favicon_base::FAVICON, kEmptySizes)); |
1005 std::vector<gfx::Size>())); | |
1006 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), | 718 favicon_urls.push_back(FaviconURL(GURL("http://www.google.com/favicon2"), |
1007 favicon_base::FAVICON, | 719 favicon_base::FAVICON, kEmptySizes)); |
1008 std::vector<gfx::Size>())); | |
1009 | 720 |
1010 TestDelegate delegate; | 721 MockDelegate_ delegate_; |
1011 TestFaviconHandler helper(&favicon_service_, &delegate, | 722 FaviconHandler handler(&favicon_service_, &delegate_, |
1012 FaviconDriverObserver::NON_TOUCH_16_DIP); | 723 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1013 | 724 |
1014 // Initiate a request for favicon data for |page_url|. History does not know | 725 // Initiate a request for favicon data for |page_url|. History does not know |
1015 // about the page URL or the icon URLs. | 726 // about the page URL or the icon URLs. |
1016 helper.FetchFavicon(page_url); | 727 handler.FetchFavicon(page_url); |
1017 helper.history_handler()->InvokeCallback(); | 728 handler.history_handler()->InvokeCallback(); |
1018 helper.set_history_handler(nullptr); | 729 handler.set_history_handler(nullptr); |
1019 | 730 |
1020 // Got icon URLs. | 731 // Got icon URLs. |
1021 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 732 handler.OnUpdateFaviconURL(page_url, favicon_urls); |
1022 | 733 |
1023 // There should be an ongoing history request for |icon_url1|. | 734 // There should be an ongoing history request for |icon_url1|. |
1024 ASSERT_EQ(2u, helper.image_urls().size()); | 735 ASSERT_EQ(2u, handler.image_urls().size()); |
1025 ASSERT_EQ(0u, helper.current_candidate_index()); | 736 ASSERT_EQ(0u, handler.current_candidate_index()); |
1026 HistoryRequestHandler* history_handler = helper.history_handler(); | 737 HistoryRequestHandler* history_handler = handler.history_handler(); |
1027 ASSERT_TRUE(history_handler); | 738 ASSERT_TRUE(history_handler); |
1028 | 739 |
1029 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 740 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
1030 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 741 handler.OnUpdateFaviconURL(page_url, favicon_urls); |
1031 EXPECT_EQ(history_handler, helper.history_handler()); | 742 EXPECT_EQ(history_handler, handler.history_handler()); |
1032 | 743 |
1033 // Complete history request for |icon_url1| and do download. | 744 // Complete history request for |icon_url1| and do download. |
1034 helper.history_handler()->InvokeCallback(); | 745 handler.history_handler()->InvokeCallback(); |
1035 helper.set_history_handler(nullptr); | 746 handler.set_history_handler(nullptr); |
1036 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 747 delegate_.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
1037 delegate.download_handler()->InvokeCallback(); | 748 delegate_.download_handler()->InvokeCallback(); |
1038 delegate.download_handler()->Reset(); | 749 delegate_.download_handler()->Reset(); |
1039 | 750 |
1040 // There should now be an ongoing history request for |icon_url2|. | 751 // There should now be an ongoing history request for |icon_url2|. |
1041 ASSERT_EQ(1u, helper.current_candidate_index()); | 752 ASSERT_EQ(1u, handler.current_candidate_index()); |
1042 history_handler = helper.history_handler(); | 753 history_handler = handler.history_handler(); |
1043 ASSERT_TRUE(history_handler); | 754 ASSERT_TRUE(history_handler); |
1044 | 755 |
1045 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. | 756 // Calling OnUpdateFaviconURL() with the same icon URLs should have no effect. |
1046 helper.OnUpdateFaviconURL(page_url, favicon_urls); | 757 handler.OnUpdateFaviconURL(page_url, favicon_urls); |
1047 EXPECT_EQ(history_handler, helper.history_handler()); | 758 EXPECT_EQ(history_handler, handler.history_handler()); |
1048 } | 759 } |
1049 | 760 |
1050 // Fixes crbug.com/544560 | 761 // Fixes crbug.com/544560 |
1051 TEST_F(FaviconHandlerTest, | 762 TEST_F(FaviconHandlerTest, |
1052 OnFaviconAvailableNotificationSentAfterIconURLChange) { | 763 OnFaviconAvailableNotificationSentAfterIconURLChange) { |
1053 const GURL kPageURL("http://www.page_which_animates_favicon.com"); | 764 const GURL kPageURL("http://www.page_which_animates_favicon.com"); |
1054 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ; | 765 const GURL kIconURL1("http://wwww.page_which_animates_favicon.com/frame1.png") ; |
1055 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ; | 766 const GURL kIconURL2("http://wwww.page_which_animates_favicon.com/frame2.png") ; |
1056 | 767 |
1057 TestDelegate delegate; | 768 MockDelegate_ delegate_; |
1058 TestFaviconHandler helper(&favicon_service_, &delegate, | 769 FaviconHandler handler(&favicon_service_, &delegate_, |
1059 FaviconDriverObserver::NON_TOUCH_16_DIP); | 770 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1060 | 771 |
1061 // Initial state: | 772 // Initial state: |
1062 // - The database does not know about |kPageURL|. | 773 // - The database does not know about |kPageURL|. |
1063 // - The page uses |kIconURL1| and |kIconURL2|. | 774 // - The page uses |kIconURL1| and |kIconURL2|. |
1064 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons | 775 // - The database knows about both |kIconURL1| and |kIconURl2|. Both icons |
1065 // are expired in the database. | 776 // are expired in the database. |
1066 helper.FetchFavicon(kPageURL); | 777 handler.FetchFavicon(kPageURL); |
1067 ASSERT_TRUE(helper.history_handler()); | 778 ASSERT_TRUE(handler.history_handler()); |
1068 helper.history_handler()->InvokeCallback(); | 779 handler.history_handler()->InvokeCallback(); |
1069 { | 780 { |
1070 std::vector<FaviconURL> icon_urls; | 781 std::vector<FaviconURL> icon_urls; |
1071 icon_urls.push_back( | 782 icon_urls.push_back( |
1072 FaviconURL(kIconURL1, favicon_base::FAVICON, std::vector<gfx::Size>())); | 783 FaviconURL(kIconURL1, favicon_base::FAVICON, kEmptySizes)); |
1073 icon_urls.push_back( | 784 icon_urls.push_back( |
1074 FaviconURL(kIconURL2, favicon_base::FAVICON, std::vector<gfx::Size>())); | 785 FaviconURL(kIconURL2, favicon_base::FAVICON, kEmptySizes)); |
1075 helper.OnUpdateFaviconURL(kPageURL, icon_urls); | 786 handler.OnUpdateFaviconURL(kPageURL, icon_urls); |
1076 } | 787 } |
1077 | 788 |
1078 // FaviconHandler should request from history and download |kIconURL1| and | 789 // FaviconHandler should request from history and download |kIconURL1| and |
1079 // |kIconURL2|. |kIconURL1| is the better match. A | 790 // |kIconURL2|. |kIconURL1| is the better match. A |
1080 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 791 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1081 // |kIconURL1|. | 792 // |kIconURL1|. |
1082 ASSERT_EQ(0u, delegate.num_notifications()); | 793 ASSERT_EQ(0u, delegate_.num_notifications()); |
1083 ASSERT_TRUE(helper.history_handler()); | 794 ASSERT_TRUE(handler.history_handler()); |
1084 SetFaviconRawBitmapResult(kIconURL1, | 795 SetFaviconRawBitmapResult(kIconURL1, favicon_base::FAVICON, |
1085 favicon_base::FAVICON, | |
1086 true /* expired */, | 796 true /* expired */, |
1087 &helper.history_handler()->history_results_); | 797 &handler.history_handler()->history_results_); |
1088 helper.history_handler()->InvokeCallback(); | 798 handler.history_handler()->InvokeCallback(); |
1089 helper.set_history_handler(nullptr); | 799 handler.set_history_handler(nullptr); |
1090 ASSERT_TRUE(delegate.download_handler()->HasDownload()); | 800 ASSERT_TRUE(delegate_.download_handler()->HasDownload()); |
1091 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); | 801 delegate_.download_handler()->SetImageSizes(std::vector<int>(1u, 15)); |
1092 delegate.download_handler()->InvokeCallback(); | 802 delegate_.download_handler()->InvokeCallback(); |
1093 delegate.download_handler()->Reset(); | 803 delegate_.download_handler()->Reset(); |
1094 | 804 |
1095 ASSERT_TRUE(helper.history_handler()); | 805 ASSERT_TRUE(handler.history_handler()); |
1096 helper.history_handler()->InvokeCallback(); | 806 handler.history_handler()->InvokeCallback(); |
1097 SetFaviconRawBitmapResult(kIconURL2, | 807 SetFaviconRawBitmapResult(kIconURL2, favicon_base::FAVICON, |
1098 favicon_base::FAVICON, | |
1099 true /* expired */, | 808 true /* expired */, |
1100 &helper.history_handler()->history_results_); | 809 &handler.history_handler()->history_results_); |
1101 helper.history_handler()->InvokeCallback(); | 810 handler.history_handler()->InvokeCallback(); |
1102 helper.set_history_handler(nullptr); | 811 handler.set_history_handler(nullptr); |
1103 ASSERT_TRUE(delegate.download_handler()->HasDownload()); | 812 ASSERT_TRUE(delegate_.download_handler()->HasDownload()); |
1104 delegate.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); | 813 delegate_.download_handler()->SetImageSizes(std::vector<int>(1u, 10)); |
1105 delegate.download_handler()->InvokeCallback(); | 814 delegate_.download_handler()->InvokeCallback(); |
1106 delegate.download_handler()->Reset(); | 815 delegate_.download_handler()->Reset(); |
1107 | 816 |
1108 ASSERT_LT(0u, delegate.num_notifications()); | 817 ASSERT_LT(0u, delegate_.num_notifications()); |
1109 ASSERT_EQ(kIconURL1, delegate.icon_url()); | 818 ASSERT_EQ(kIconURL1, delegate_.icon_url()); |
1110 | 819 |
1111 // Clear the history handler because SetHistoryFavicons() sets it. | 820 // Clear the history handler because SetHistoryFavicons() sets it. |
1112 helper.set_history_handler(nullptr); | 821 handler.set_history_handler(nullptr); |
1113 | 822 |
1114 // Simulate the page changing it's icon URL to just |kIconURL2| via | 823 // Simulate the page changing it's icon URL to just |kIconURL2| via |
1115 // Javascript. | 824 // Javascript. |
1116 helper.OnUpdateFaviconURL( | 825 handler.OnUpdateFaviconURL( |
1117 kPageURL, | 826 kPageURL, |
1118 std::vector<FaviconURL>(1u, FaviconURL(kIconURL2, favicon_base::FAVICON, | 827 std::vector<FaviconURL>( |
1119 std::vector<gfx::Size>()))); | 828 1u, FaviconURL(kIconURL2, favicon_base::FAVICON, kEmptySizes))); |
1120 | 829 |
1121 // FaviconHandler should request from history and download |kIconURL2|. A | 830 // FaviconHandler should request from history and download |kIconURL2|. A |
1122 // FaviconDriver::OnFaviconUpdated() notification should be sent for | 831 // FaviconDriver::OnFaviconUpdated() notification should be sent for |
1123 // |kIconURL2|. | 832 // |kIconURL2|. |
1124 delegate.ResetNumNotifications(); | 833 delegate_.ResetNumNotifications(); |
1125 ASSERT_TRUE(helper.history_handler()); | 834 ASSERT_TRUE(handler.history_handler()); |
1126 SetFaviconRawBitmapResult(kIconURL2, | 835 SetFaviconRawBitmapResult(kIconURL2, favicon_base::FAVICON, |
1127 favicon_base::FAVICON, | |
1128 true /* expired */, | 836 true /* expired */, |
1129 &helper.history_handler()->history_results_); | 837 &handler.history_handler()->history_results_); |
1130 helper.history_handler()->InvokeCallback(); | 838 handler.history_handler()->InvokeCallback(); |
1131 helper.set_history_handler(nullptr); | 839 handler.set_history_handler(nullptr); |
1132 ASSERT_TRUE(delegate.download_handler()->HasDownload()); | 840 ASSERT_TRUE(delegate_.download_handler()->HasDownload()); |
1133 delegate.download_handler()->InvokeCallback(); | 841 delegate_.download_handler()->InvokeCallback(); |
1134 delegate.download_handler()->Reset(); | 842 delegate_.download_handler()->Reset(); |
1135 ASSERT_LT(0u, delegate.num_notifications()); | 843 ASSERT_LT(0u, delegate_.num_notifications()); |
1136 EXPECT_EQ(kIconURL2, delegate.icon_url()); | 844 EXPECT_EQ(kIconURL2, delegate_.icon_url()); |
1137 } | 845 } |
1138 | 846 |
1139 // Test the favicon which is selected when the web page provides several | 847 // Test the favicon which is selected when the web page provides several |
1140 // favicons and none of the favicons are cached in history. | 848 // favicons and none of the favicons are cached in history. |
1141 // The goal of this test is to be more of an integration test than | 849 // The goal of this test is to be more of an integration test than |
1142 // SelectFaviconFramesTest.*. | 850 // SelectFaviconFramesTest.*. |
1143 TEST_F(FaviconHandlerTest, MultipleFavicons) { | 851 TEST_F(FaviconHandlerTest, MultipleFavicons) { |
1144 const GURL kPageURL("http://www.google.com"); | 852 const GURL kPageURL("http://www.google.com"); |
1145 const FaviconURL kSourceIconURLs[] = { | 853 const FaviconURL kSourceIconURLs[] = { |
1146 FaviconURL(GURL("http://www.google.com/a"), | 854 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, |
1147 favicon_base::FAVICON, | 855 kEmptySizes), |
1148 std::vector<gfx::Size>()), | 856 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, |
1149 FaviconURL(GURL("http://www.google.com/b"), | 857 kEmptySizes), |
1150 favicon_base::FAVICON, | 858 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, |
1151 std::vector<gfx::Size>()), | 859 kEmptySizes), |
1152 FaviconURL(GURL("http://www.google.com/c"), | 860 FaviconURL(GURL("http://www.google.com/d"), favicon_base::FAVICON, |
1153 favicon_base::FAVICON, | 861 kEmptySizes), |
1154 std::vector<gfx::Size>()), | 862 FaviconURL(GURL("http://www.google.com/e"), favicon_base::FAVICON, |
1155 FaviconURL(GURL("http://www.google.com/d"), | 863 kEmptySizes)}; |
1156 favicon_base::FAVICON, | |
1157 std::vector<gfx::Size>()), | |
1158 FaviconURL(GURL("http://www.google.com/e"), | |
1159 favicon_base::FAVICON, | |
1160 std::vector<gfx::Size>())}; | |
1161 | 864 |
1162 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 865 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
1163 // SelectFaviconFrames(). | 866 // SelectFaviconFrames(). |
1164 std::vector<ui::ScaleFactor> scale_factors; | 867 std::vector<ui::ScaleFactor> scale_factors; |
1165 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 868 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
1166 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 869 scale_factors.push_back(ui::SCALE_FACTOR_200P); |
1167 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 870 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); |
1168 | 871 |
1169 // 1) Test that if there are several single resolution favicons to choose from | 872 // 1) Test that if there are several single resolution favicons to choose from |
1170 // that the largest exact match is chosen. | 873 // that the largest exact match is chosen. |
1171 TestDelegate delegate1; | 874 MockDelegate_ delegate_1; |
1172 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 875 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1173 FaviconDriverObserver::NON_TOUCH_16_DIP); | 876 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1174 | 877 |
1175 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 878 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
1176 std::vector<FaviconURL> urls1(kSourceIconURLs, | 879 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1177 kSourceIconURLs + arraysize(kSizes1)); | 880 kSourceIconURLs + arraysize(kSizes1)); |
1178 DownloadTillDoneIgnoringHistory(&delegate1, &handler1, kPageURL, urls1, | 881 DownloadTillDoneIgnoringHistory(&delegate_1, &handler1, kPageURL, urls1, |
1179 kSizes1); | 882 kSizes1); |
1180 | 883 |
1181 EXPECT_EQ(nullptr, handler1.current_candidate()); | 884 EXPECT_EQ(nullptr, handler1.current_candidate()); |
1182 EXPECT_EQ(1u, delegate1.num_notifications()); | 885 EXPECT_EQ(1u, delegate_1.num_notifications()); |
1183 EXPECT_FALSE(delegate1.image().IsEmpty()); | 886 EXPECT_FALSE(delegate_1.image().IsEmpty()); |
1184 EXPECT_EQ(gfx::kFaviconSize, delegate1.image().Width()); | 887 EXPECT_EQ(gfx::kFaviconSize, delegate_1.image().Width()); |
1185 | 888 |
1186 size_t expected_index = 2u; | 889 size_t expected_index = 2u; |
1187 EXPECT_EQ(32, kSizes1[expected_index]); | 890 EXPECT_EQ(32, kSizes1[expected_index]); |
1188 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate1.icon_url()); | 891 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate_1.icon_url()); |
1189 | 892 |
1190 // 2) Test that if there are several single resolution favicons to choose | 893 // 2) Test that if there are several single resolution favicons to choose |
1191 // from, the exact match is preferred even if it results in upsampling. | 894 // from, the exact match is preferred even if it results in upsampling. |
1192 TestDelegate delegate2; | 895 MockDelegate_ delegate_2; |
1193 TestFaviconHandler handler2(&favicon_service_, &delegate2, | 896 FaviconHandler handler2(&favicon_service_, &delegate_2, |
1194 FaviconDriverObserver::NON_TOUCH_16_DIP); | 897 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1195 | 898 |
1196 const int kSizes2[] = { 16, 24, 48, 256 }; | 899 const int kSizes2[] = { 16, 24, 48, 256 }; |
1197 std::vector<FaviconURL> urls2(kSourceIconURLs, | 900 std::vector<FaviconURL> urls2(kSourceIconURLs, |
1198 kSourceIconURLs + arraysize(kSizes2)); | 901 kSourceIconURLs + arraysize(kSizes2)); |
1199 DownloadTillDoneIgnoringHistory(&delegate2, &handler2, kPageURL, urls2, | 902 DownloadTillDoneIgnoringHistory(&delegate_2, &handler2, kPageURL, urls2, |
1200 kSizes2); | 903 kSizes2); |
1201 EXPECT_EQ(1u, delegate2.num_notifications()); | 904 EXPECT_EQ(1u, delegate_2.num_notifications()); |
1202 expected_index = 0u; | 905 expected_index = 0u; |
1203 EXPECT_EQ(16, kSizes2[expected_index]); | 906 EXPECT_EQ(16, kSizes2[expected_index]); |
1204 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate2.icon_url()); | 907 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate_2.icon_url()); |
1205 | 908 |
1206 // 3) Test that favicons which need to be upsampled a little or downsampled | 909 // 3) Test that favicons which need to be upsampled a little or downsampled |
1207 // a little are preferred over huge favicons. | 910 // a little are preferred over huge favicons. |
1208 TestDelegate delegate3; | 911 MockDelegate_ delegate_3; |
1209 TestFaviconHandler handler3(&favicon_service_, &delegate3, | 912 FaviconHandler handler3(&favicon_service_, &delegate_3, |
1210 FaviconDriverObserver::NON_TOUCH_16_DIP); | 913 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1211 | 914 |
1212 const int kSizes3[] = { 256, 48 }; | 915 const int kSizes3[] = { 256, 48 }; |
1213 std::vector<FaviconURL> urls3(kSourceIconURLs, | 916 std::vector<FaviconURL> urls3(kSourceIconURLs, |
1214 kSourceIconURLs + arraysize(kSizes3)); | 917 kSourceIconURLs + arraysize(kSizes3)); |
1215 DownloadTillDoneIgnoringHistory(&delegate3, &handler3, kPageURL, urls3, | 918 DownloadTillDoneIgnoringHistory(&delegate_3, &handler3, kPageURL, urls3, |
1216 kSizes3); | 919 kSizes3); |
1217 EXPECT_EQ(1u, delegate3.num_notifications()); | 920 EXPECT_EQ(1u, delegate_3.num_notifications()); |
1218 expected_index = 1u; | 921 expected_index = 1u; |
1219 EXPECT_EQ(48, kSizes3[expected_index]); | 922 EXPECT_EQ(48, kSizes3[expected_index]); |
1220 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate3.icon_url()); | 923 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate_3.icon_url()); |
1221 | 924 |
1222 TestDelegate delegate4; | 925 MockDelegate_ delegate_4; |
1223 TestFaviconHandler handler4(&favicon_service_, &delegate4, | 926 FaviconHandler handler4(&favicon_service_, &delegate_4, |
1224 FaviconDriverObserver::NON_TOUCH_16_DIP); | 927 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1225 | 928 |
1226 const int kSizes4[] = { 17, 256 }; | 929 const int kSizes4[] = { 17, 256 }; |
1227 std::vector<FaviconURL> urls4(kSourceIconURLs, | 930 std::vector<FaviconURL> urls4(kSourceIconURLs, |
1228 kSourceIconURLs + arraysize(kSizes4)); | 931 kSourceIconURLs + arraysize(kSizes4)); |
1229 DownloadTillDoneIgnoringHistory(&delegate4, &handler4, kPageURL, urls4, | 932 DownloadTillDoneIgnoringHistory(&delegate_4, &handler4, kPageURL, urls4, |
1230 kSizes4); | 933 kSizes4); |
1231 EXPECT_EQ(1u, delegate4.num_notifications()); | 934 EXPECT_EQ(1u, delegate_4.num_notifications()); |
1232 expected_index = 0u; | 935 expected_index = 0u; |
1233 EXPECT_EQ(17, kSizes4[expected_index]); | 936 EXPECT_EQ(17, kSizes4[expected_index]); |
1234 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate4.icon_url()); | 937 EXPECT_EQ(kSourceIconURLs[expected_index].icon_url, delegate_4.icon_url()); |
1235 } | 938 } |
1236 | 939 |
1237 // Test that the best favicon is selected when: | 940 // Test that the best favicon is selected when: |
1238 // - The page provides several favicons. | 941 // - The page provides several favicons. |
1239 // - Downloading one of the page's icon URLs previously returned a 404. | 942 // - Downloading one of the page's icon URLs previously returned a 404. |
1240 // - None of the favicons are cached in the Favicons database. | 943 // - None of the favicons are cached in the Favicons database. |
1241 TEST_F(FaviconHandlerTest, MultipleFavicons404) { | 944 TEST_F(FaviconHandlerTest, MultipleFavicons404) { |
1242 const GURL kPageURL("http://www.google.com"); | 945 const GURL kPageURL("http://www.google.com"); |
1243 const GURL k404IconURL("http://www.google.com/404.png"); | 946 const GURL k404IconURL("http://www.google.com/404.png"); |
1244 const FaviconURL k404FaviconURL( | 947 const FaviconURL k404FaviconURL(k404IconURL, favicon_base::FAVICON, |
1245 k404IconURL, favicon_base::FAVICON, std::vector<gfx::Size>()); | 948 kEmptySizes); |
1246 const FaviconURL kFaviconURLs[] = { | 949 const FaviconURL kFaviconURLs[] = { |
1247 FaviconURL(GURL("http://www.google.com/a"), | 950 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, |
1248 favicon_base::FAVICON, | 951 kEmptySizes), |
1249 std::vector<gfx::Size>()), | 952 k404FaviconURL, FaviconURL(GURL("http://www.google.com/c"), |
1250 k404FaviconURL, | 953 favicon_base::FAVICON, kEmptySizes), |
1251 FaviconURL(GURL("http://www.google.com/c"), | |
1252 favicon_base::FAVICON, | |
1253 std::vector<gfx::Size>()), | |
1254 }; | 954 }; |
1255 | 955 |
1256 TestDelegate delegate; | 956 MockDelegate_ delegate_; |
1257 TestFaviconHandler handler(&favicon_service_, &delegate, | 957 FaviconHandler handler(&favicon_service_, &delegate_, |
1258 FaviconDriverObserver::NON_TOUCH_16_DIP); | 958 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1259 DownloadHandler* download_handler = delegate.download_handler(); | 959 DownloadHandler* download_handler = delegate_.download_handler(); |
1260 | 960 |
1261 std::set<GURL> k404URLs; | 961 std::set<GURL> k404URLs; |
1262 k404URLs.insert(k404IconURL); | 962 k404URLs.insert(k404IconURL); |
1263 download_handler->FailDownloadForIconURLs(k404URLs); | 963 download_handler->FailDownloadForIconURLs(k404URLs); |
1264 | 964 |
1265 // Make the initial download for |k404IconURL| fail. | 965 // Make the initial download for |k404IconURL| fail. |
1266 const int kSizes1[] = { 0 }; | 966 const int kSizes1[] = { 0 }; |
1267 std::vector<FaviconURL> urls1(1u, k404FaviconURL); | 967 std::vector<FaviconURL> urls1(1u, k404FaviconURL); |
1268 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls1, | 968 DownloadTillDoneIgnoringHistory(&delegate_, &handler, kPageURL, urls1, |
1269 kSizes1); | 969 kSizes1); |
1270 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); | 970 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL)); |
1271 | 971 |
1272 // Do a fetch now that the initial download for |k404IconURL| has failed. The | 972 // Do a fetch now that the initial download for |k404IconURL| has failed. The |
1273 // behavior is different because OnDidDownloadFavicon() is invoked | 973 // behavior is different because OnDidDownloadFavicon() is invoked |
1274 // synchronously from DownloadFavicon(). | 974 // synchronously from DownloadFavicon(). |
1275 const int kSizes2[] = { 10, 0, 16 }; | 975 const int kSizes2[] = { 10, 0, 16 }; |
1276 std::vector<FaviconURL> urls2(kFaviconURLs, | 976 std::vector<FaviconURL> urls2(kFaviconURLs, |
1277 kFaviconURLs + arraysize(kFaviconURLs)); | 977 kFaviconURLs + arraysize(kFaviconURLs)); |
1278 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls2, | 978 DownloadTillDoneIgnoringHistory(&delegate_, &handler, kPageURL, urls2, |
1279 kSizes2); | 979 kSizes2); |
1280 | 980 |
1281 EXPECT_EQ(nullptr, handler.current_candidate()); | 981 EXPECT_EQ(nullptr, handler.current_candidate()); |
1282 EXPECT_EQ(1u, delegate.num_notifications()); | 982 EXPECT_EQ(1u, delegate_.num_notifications()); |
1283 EXPECT_FALSE(delegate.image().IsEmpty()); | 983 EXPECT_FALSE(delegate_.image().IsEmpty()); |
1284 int expected_index = 2u; | 984 int expected_index = 2u; |
1285 EXPECT_EQ(16, kSizes2[expected_index]); | 985 EXPECT_EQ(16, kSizes2[expected_index]); |
1286 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, delegate.icon_url()); | 986 EXPECT_EQ(kFaviconURLs[expected_index].icon_url, delegate_.icon_url()); |
1287 } | 987 } |
1288 | 988 |
1289 // Test that no favicon is selected when: | 989 // Test that no favicon is selected when: |
1290 // - The page provides several favicons. | 990 // - The page provides several favicons. |
1291 // - Downloading the page's icons has previously returned a 404. | 991 // - Downloading the page's icons has previously returned a 404. |
1292 // - None of the favicons are cached in the Favicons database. | 992 // - None of the favicons are cached in the Favicons database. |
1293 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { | 993 TEST_F(FaviconHandlerTest, MultipleFaviconsAll404) { |
1294 const GURL kPageURL("http://www.google.com"); | 994 const GURL kPageURL("http://www.google.com"); |
1295 const GURL k404IconURL1("http://www.google.com/4041.png"); | 995 const GURL k404IconURL1("http://www.google.com/4041.png"); |
1296 const GURL k404IconURL2("http://www.google.com/4042.png"); | 996 const GURL k404IconURL2("http://www.google.com/4042.png"); |
1297 const FaviconURL kFaviconURLs[] = { | 997 const FaviconURL kFaviconURLs[] = { |
1298 FaviconURL(k404IconURL1, | 998 FaviconURL(k404IconURL1, favicon_base::FAVICON, kEmptySizes), |
1299 favicon_base::FAVICON, | 999 FaviconURL(k404IconURL2, favicon_base::FAVICON, kEmptySizes), |
1300 std::vector<gfx::Size>()), | |
1301 FaviconURL(k404IconURL2, | |
1302 favicon_base::FAVICON, | |
1303 std::vector<gfx::Size>()), | |
1304 }; | 1000 }; |
1305 | 1001 |
1306 TestDelegate delegate; | 1002 MockDelegate_ delegate_; |
1307 TestFaviconHandler handler(&favicon_service_, &delegate, | 1003 FaviconHandler handler(&favicon_service_, &delegate_, |
1308 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1004 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1309 DownloadHandler* download_handler = delegate.download_handler(); | 1005 DownloadHandler* download_handler = delegate_.download_handler(); |
1310 | 1006 |
1311 std::set<GURL> k404URLs; | 1007 std::set<GURL> k404URLs; |
1312 k404URLs.insert(k404IconURL1); | 1008 k404URLs.insert(k404IconURL1); |
1313 k404URLs.insert(k404IconURL2); | 1009 k404URLs.insert(k404IconURL2); |
1314 download_handler->FailDownloadForIconURLs(k404URLs); | 1010 download_handler->FailDownloadForIconURLs(k404URLs); |
1315 | 1011 |
1316 // Make the initial downloads for |kFaviconURLs| fail. | 1012 // Make the initial downloads for |kFaviconURLs| fail. |
1317 for (const FaviconURL& favicon_url : kFaviconURLs) { | 1013 for (const FaviconURL& favicon_url : kFaviconURLs) { |
1318 const int kSizes[] = { 0 }; | 1014 const int kSizes[] = { 0 }; |
1319 std::vector<FaviconURL> urls(1u, favicon_url); | 1015 std::vector<FaviconURL> urls(1u, favicon_url); |
1320 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, | 1016 DownloadTillDoneIgnoringHistory(&delegate_, &handler, kPageURL, urls, |
1321 kSizes); | 1017 kSizes); |
1322 } | 1018 } |
1323 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); | 1019 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL1)); |
1324 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); | 1020 EXPECT_TRUE(download_handler->DidFailDownloadForIconURL(k404IconURL2)); |
1325 | 1021 |
1326 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. | 1022 // Do a fetch now that the initial downloads for |kFaviconURLs| have failed. |
1327 // The behavior is different because OnDidDownloadFavicon() is invoked | 1023 // The behavior is different because OnDidDownloadFavicon() is invoked |
1328 // synchronously from DownloadFavicon(). | 1024 // synchronously from DownloadFavicon(). |
1329 const int kSizes[] = { 0, 0 }; | 1025 const int kSizes[] = { 0, 0 }; |
1330 std::vector<FaviconURL> urls(kFaviconURLs, | 1026 std::vector<FaviconURL> urls(kFaviconURLs, |
1331 kFaviconURLs + arraysize(kFaviconURLs)); | 1027 kFaviconURLs + arraysize(kFaviconURLs)); |
1332 DownloadTillDoneIgnoringHistory(&delegate, &handler, kPageURL, urls, kSizes); | 1028 DownloadTillDoneIgnoringHistory(&delegate_, &handler, kPageURL, urls, kSizes); |
1333 | 1029 |
1334 EXPECT_EQ(nullptr, handler.current_candidate()); | 1030 EXPECT_EQ(nullptr, handler.current_candidate()); |
1335 EXPECT_EQ(0u, delegate.num_notifications()); | 1031 EXPECT_EQ(0u, delegate_.num_notifications()); |
1336 EXPECT_TRUE(delegate.image().IsEmpty()); | 1032 EXPECT_TRUE(delegate_.image().IsEmpty()); |
1337 } | 1033 } |
1338 | 1034 |
1339 // Test that no favicon is selected when the page's only icon uses an invalid | 1035 // Test that no favicon is selected when the page's only icon uses an invalid |
1340 // URL syntax. | 1036 // URL syntax. |
1341 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { | 1037 TEST_F(FaviconHandlerTest, FaviconInvalidURL) { |
1342 const GURL kPageURL("http://www.google.com"); | 1038 const GURL kPageURL("http://www.google.com"); |
1343 const GURL kInvalidFormatURL("invalid"); | 1039 const GURL kInvalidFormatURL("invalid"); |
1344 ASSERT_TRUE(kInvalidFormatURL.is_empty()); | 1040 ASSERT_TRUE(kInvalidFormatURL.is_empty()); |
1345 | 1041 |
1346 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, | 1042 FaviconURL favicon_url(kInvalidFormatURL, favicon_base::FAVICON, kEmptySizes); |
1347 std::vector<gfx::Size>()); | |
1348 | 1043 |
1349 TestDelegate delegate; | 1044 MockDelegate_ delegate_; |
1350 TestFaviconHandler handler(&favicon_service_, &delegate, | 1045 FaviconHandler handler(&favicon_service_, &delegate_, |
1351 FaviconDriverObserver::NON_TOUCH_16_DIP); | 1046 FaviconDriverObserver::NON_TOUCH_16_DIP); |
1352 UpdateFaviconURL(&delegate, &handler, kPageURL, | 1047 UpdateFaviconURL(&delegate_, &handler, kPageURL, |
1353 std::vector<FaviconURL>(1u, favicon_url)); | 1048 std::vector<FaviconURL>(1u, favicon_url)); |
1354 EXPECT_EQ(0u, handler.image_urls().size()); | 1049 EXPECT_EQ(0u, handler.image_urls().size()); |
1355 } | 1050 } |
1356 | 1051 |
1357 TEST_F(FaviconHandlerTest, TestSortFavicon) { | 1052 TEST_F(FaviconHandlerTest, TestSortFavicon) { |
1358 const GURL kPageURL("http://www.google.com"); | 1053 const GURL kPageURL("http://www.google.com"); |
1359 std::vector<gfx::Size> icon1; | 1054 kEmptySizes icon1; |
1360 icon1.push_back(gfx::Size(1024, 1024)); | 1055 icon1.push_back(gfx::Size(1024, 1024)); |
1361 icon1.push_back(gfx::Size(512, 512)); | 1056 icon1.push_back(gfx::Size(512, 512)); |
1362 | 1057 |
1363 std::vector<gfx::Size> icon2; | 1058 kEmptySizes icon2; |
1364 icon2.push_back(gfx::Size(15, 15)); | 1059 icon2.push_back(gfx::Size(15, 15)); |
1365 icon2.push_back(gfx::Size(16, 16)); | 1060 icon2.push_back(gfx::Size(16, 16)); |
1366 | 1061 |
1367 std::vector<gfx::Size> icon3; | 1062 kEmptySizes icon3; |
1368 icon3.push_back(gfx::Size(16, 16)); | 1063 icon3.push_back(gfx::Size(16, 16)); |
1369 icon3.push_back(gfx::Size(14, 14)); | 1064 icon3.push_back(gfx::Size(14, 14)); |
1370 | 1065 |
1371 const FaviconURL kSourceIconURLs[] = { | 1066 const FaviconURL kSourceIconURLs[] = { |
1372 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), | 1067 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), |
1373 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1068 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
1374 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1069 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1375 FaviconURL(GURL("http://www.google.com/d"), | 1070 FaviconURL(GURL("http://www.google.com/d"), favicon_base::FAVICON, |
1376 favicon_base::FAVICON, | 1071 kEmptySizes), |
1377 std::vector<gfx::Size>()), | 1072 FaviconURL(GURL("http://www.google.com/e"), favicon_base::FAVICON, |
1378 FaviconURL(GURL("http://www.google.com/e"), | 1073 kEmptySizes)}; |
1379 favicon_base::FAVICON, | |
1380 std::vector<gfx::Size>())}; | |
1381 | 1074 |
1382 TestDelegate delegate1; | 1075 MockDelegate_ delegate_1; |
1383 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 1076 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1384 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1077 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1385 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1078 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1386 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1079 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1387 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); | 1080 UpdateFaviconURL(&delegate_1, &handler1, kPageURL, urls1); |
1388 | 1081 |
1389 struct ExpectedResult { | 1082 struct ExpectedResult { |
1390 // The favicon's index in kSourceIconURLs. | 1083 // The favicon's index in kSourceIconURLs. |
1391 size_t favicon_index; | 1084 size_t favicon_index; |
1392 // Width of largest bitmap. | 1085 // Width of largest bitmap. |
1393 int width; | 1086 int width; |
1394 } results[] = { | 1087 } results[] = { |
1395 // First is icon1, though its size larger than maximal. | 1088 // First is icon1, though its size larger than maximal. |
1396 {0, 1024}, | 1089 {0, 1024}, |
1397 // Second is icon2 | 1090 // Second is icon2 |
(...skipping 11 matching lines...) Expand all Loading... | |
1409 for (size_t i = 0; i < icons.size(); ++i) { | 1102 for (size_t i = 0; i < icons.size(); ++i) { |
1410 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1103 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, |
1411 icons[i].icon_url); | 1104 icons[i].icon_url); |
1412 if (results[i].width != -1) | 1105 if (results[i].width != -1) |
1413 EXPECT_EQ(results[i].width, icons[i].icon_sizes[0].width()); | 1106 EXPECT_EQ(results[i].width, icons[i].icon_sizes[0].width()); |
1414 } | 1107 } |
1415 } | 1108 } |
1416 | 1109 |
1417 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { | 1110 TEST_F(FaviconHandlerTest, TestDownloadLargestFavicon) { |
1418 const GURL kPageURL("http://www.google.com"); | 1111 const GURL kPageURL("http://www.google.com"); |
1419 std::vector<gfx::Size> icon1; | 1112 kEmptySizes icon1; |
1420 icon1.push_back(gfx::Size(1024, 1024)); | 1113 icon1.push_back(gfx::Size(1024, 1024)); |
1421 icon1.push_back(gfx::Size(512, 512)); | 1114 icon1.push_back(gfx::Size(512, 512)); |
1422 | 1115 |
1423 std::vector<gfx::Size> icon2; | 1116 kEmptySizes icon2; |
1424 icon2.push_back(gfx::Size(15, 15)); | 1117 icon2.push_back(gfx::Size(15, 15)); |
1425 icon2.push_back(gfx::Size(14, 14)); | 1118 icon2.push_back(gfx::Size(14, 14)); |
1426 | 1119 |
1427 std::vector<gfx::Size> icon3; | 1120 kEmptySizes icon3; |
1428 icon3.push_back(gfx::Size(16, 16)); | 1121 icon3.push_back(gfx::Size(16, 16)); |
1429 icon3.push_back(gfx::Size(512, 512)); | 1122 icon3.push_back(gfx::Size(512, 512)); |
1430 | 1123 |
1431 const FaviconURL kSourceIconURLs[] = { | 1124 const FaviconURL kSourceIconURLs[] = { |
1432 FaviconURL( | 1125 FaviconURL(GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), |
1433 GURL("http://www.google.com/a"), favicon_base::FAVICON, icon1), | 1126 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), |
1434 FaviconURL( | 1127 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), |
1435 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon2), | 1128 FaviconURL(GURL("http://www.google.com/d"), favicon_base::FAVICON, |
1436 FaviconURL( | 1129 kEmptySizes), |
1437 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon3), | 1130 FaviconURL(GURL("http://www.google.com/e"), favicon_base::FAVICON, |
1438 FaviconURL(GURL("http://www.google.com/d"), | 1131 kEmptySizes)}; |
1439 favicon_base::FAVICON, | |
1440 std::vector<gfx::Size>()), | |
1441 FaviconURL(GURL("http://www.google.com/e"), | |
1442 favicon_base::FAVICON, | |
1443 std::vector<gfx::Size>())}; | |
1444 | 1132 |
1445 TestDelegate delegate1; | 1133 MockDelegate_ delegate_1; |
1446 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 1134 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1447 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1135 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1448 | 1136 |
1449 std::set<GURL> fail_icon_urls; | 1137 std::set<GURL> fail_icon_urls; |
1450 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { | 1138 for (size_t i = 0; i < arraysize(kSourceIconURLs); ++i) { |
1451 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); | 1139 fail_icon_urls.insert(kSourceIconURLs[i].icon_url); |
1452 } | 1140 } |
1453 delegate1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); | 1141 delegate_1.download_handler()->FailDownloadForIconURLs(fail_icon_urls); |
1454 | 1142 |
1455 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1143 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1456 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1144 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1457 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); | 1145 UpdateFaviconURL(&delegate_1, &handler1, kPageURL, urls1); |
1458 | 1146 |
1459 // Simulate the download failed, to check whether the icons were requested | 1147 // Simulate the download failed, to check whether the icons were requested |
1460 // to download according their size. | 1148 // to download according their size. |
1461 struct ExpectedResult { | 1149 struct ExpectedResult { |
1462 // The favicon's index in kSourceIconURLs. | 1150 // The favicon's index in kSourceIconURLs. |
1463 size_t favicon_index; | 1151 size_t favicon_index; |
1464 // Width of largest bitmap. | 1152 // Width of largest bitmap. |
1465 int width; | 1153 int width; |
1466 } results[] = { | 1154 } results[] = { |
1467 {0, 1024}, | 1155 {0, 1024}, |
(...skipping 10 matching lines...) Expand all Loading... | |
1478 if (results[i].width != -1) { | 1166 if (results[i].width != -1) { |
1479 EXPECT_EQ(results[i].width, handler1.current_candidate()-> | 1167 EXPECT_EQ(results[i].width, handler1.current_candidate()-> |
1480 icon_sizes[0].width()); | 1168 icon_sizes[0].width()); |
1481 } | 1169 } |
1482 | 1170 |
1483 // Simulate no favicon from history. | 1171 // Simulate no favicon from history. |
1484 handler1.history_handler()->history_results_.clear(); | 1172 handler1.history_handler()->history_results_.clear(); |
1485 handler1.history_handler()->InvokeCallback(); | 1173 handler1.history_handler()->InvokeCallback(); |
1486 | 1174 |
1487 // Verify download request | 1175 // Verify download request |
1488 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); | 1176 ASSERT_TRUE(delegate_1.download_handler()->HasDownload()); |
1489 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, | 1177 EXPECT_EQ(kSourceIconURLs[results[i].favicon_index].icon_url, |
1490 delegate1.download_handler()->GetImageUrl()); | 1178 delegate_1.download_handler()->GetImageUrl()); |
1491 | 1179 |
1492 delegate1.download_handler()->InvokeCallback(); | 1180 delegate_1.download_handler()->InvokeCallback(); |
1493 delegate1.download_handler()->Reset(); | 1181 delegate_1.download_handler()->Reset(); |
1494 } | 1182 } |
1495 } | 1183 } |
1496 | 1184 |
1497 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { | 1185 TEST_F(FaviconHandlerTest, TestSelectLargestFavicon) { |
1498 const GURL kPageURL("http://www.google.com"); | 1186 const GURL kPageURL("http://www.google.com"); |
1499 | 1187 |
1500 std::vector<gfx::Size> one_icon; | 1188 kEmptySizes one_icon; |
1501 one_icon.push_back(gfx::Size(15, 15)); | 1189 one_icon.push_back(gfx::Size(15, 15)); |
1502 | 1190 |
1503 std::vector<gfx::Size> two_icons; | 1191 kEmptySizes two_icons; |
1504 two_icons.push_back(gfx::Size(14, 14)); | 1192 two_icons.push_back(gfx::Size(14, 14)); |
1505 two_icons.push_back(gfx::Size(16, 16)); | 1193 two_icons.push_back(gfx::Size(16, 16)); |
1506 | 1194 |
1507 const FaviconURL kSourceIconURLs[] = { | 1195 const FaviconURL kSourceIconURLs[] = { |
1508 FaviconURL( | 1196 FaviconURL( |
1509 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), | 1197 GURL("http://www.google.com/b"), favicon_base::FAVICON, one_icon), |
1510 FaviconURL( | 1198 FaviconURL( |
1511 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; | 1199 GURL("http://www.google.com/c"), favicon_base::FAVICON, two_icons)}; |
1512 | 1200 |
1513 TestDelegate delegate1; | 1201 MockDelegate_ delegate_1; |
1514 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 1202 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1515 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1203 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1516 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1204 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1517 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1205 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1518 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); | 1206 UpdateFaviconURL(&delegate_1, &handler1, kPageURL, urls1); |
1519 | 1207 |
1520 ASSERT_EQ(2u, handler1.image_urls().size()); | 1208 ASSERT_EQ(2u, handler1.image_urls().size()); |
1521 | 1209 |
1522 // Index of largest favicon in kSourceIconURLs. | 1210 // Index of largest favicon in kSourceIconURLs. |
1523 size_t i = 1; | 1211 size_t i = 1; |
1524 // The largest bitmap's index in Favicon . | 1212 // The largest bitmap's index in Favicon . |
1525 int b = 1; | 1213 int b = 1; |
1526 | 1214 |
1527 // Verify the icon_bitmaps_ was initialized correctly. | 1215 // Verify the icon_bitmaps_ was initialized correctly. |
1528 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1216 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1529 handler1.current_candidate()->icon_url); | 1217 handler1.current_candidate()->icon_url); |
1530 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1218 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1531 handler1.current_candidate()->icon_sizes[0]); | 1219 handler1.current_candidate()->icon_sizes[0]); |
1532 | 1220 |
1533 // Simulate no favicon from history. | 1221 // Simulate no favicon from history. |
1534 handler1.history_handler()->history_results_.clear(); | 1222 handler1.history_handler()->history_results_.clear(); |
1535 handler1.history_handler()->InvokeCallback(); | 1223 handler1.history_handler()->InvokeCallback(); |
1536 | 1224 |
1537 // Verify download request | 1225 // Verify download request |
1538 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); | 1226 ASSERT_TRUE(delegate_1.download_handler()->HasDownload()); |
1539 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1227 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1540 delegate1.download_handler()->GetImageUrl()); | 1228 delegate_1.download_handler()->GetImageUrl()); |
1541 | 1229 |
1542 // Give the correct download result. | 1230 // Give the correct download result. |
1543 std::vector<int> sizes; | 1231 std::vector<int> sizes; |
1544 for (std::vector<gfx::Size>::const_iterator j = | 1232 for (kEmptySizes::const_iterator j = kSourceIconURLs[i].icon_sizes.begin(); |
1545 kSourceIconURLs[i].icon_sizes.begin(); | |
1546 j != kSourceIconURLs[i].icon_sizes.end(); ++j) | 1233 j != kSourceIconURLs[i].icon_sizes.end(); ++j) |
1547 sizes.push_back(j->width()); | 1234 sizes.push_back(j->width()); |
1548 | 1235 |
1549 delegate1.download_handler()->SetImageSizes(sizes); | 1236 delegate_1.download_handler()->SetImageSizes(sizes); |
1550 delegate1.download_handler()->InvokeCallback(); | 1237 delegate_1.download_handler()->InvokeCallback(); |
1551 | 1238 |
1552 // Verify the largest bitmap has been saved into history. | 1239 // Verify the largest bitmap has been saved into history. |
1553 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1240 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1554 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1241 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1555 handler1.history_handler()->size_); | 1242 handler1.history_handler()->size_); |
1556 // Verify NotifyFaviconAvailable(). | 1243 // Verify NotifyFaviconAvailable(). |
1557 EXPECT_EQ(1u, delegate1.num_notifications()); | 1244 EXPECT_EQ(1u, delegate_1.num_notifications()); |
1558 EXPECT_EQ(kSourceIconURLs[i].icon_url, delegate1.icon_url()); | 1245 EXPECT_EQ(kSourceIconURLs[i].icon_url, delegate_1.icon_url()); |
1559 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], delegate1.image().Size()); | 1246 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], delegate_1.image().Size()); |
1560 } | 1247 } |
1561 | 1248 |
1562 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { | 1249 TEST_F(FaviconHandlerTest, TestFaviconWasScaledAfterDownload) { |
1563 const GURL kPageURL("http://www.google.com"); | 1250 const GURL kPageURL("http://www.google.com"); |
1564 const int kMaximalSize = | 1251 const int kMaximalSize = |
1565 TestFaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); | 1252 FaviconHandler::GetMaximalIconSize(favicon_base::FAVICON); |
1566 | 1253 |
1567 std::vector<gfx::Size> icon1; | 1254 kEmptySizes icon1; |
1568 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); | 1255 icon1.push_back(gfx::Size(kMaximalSize + 1, kMaximalSize + 1)); |
1569 | 1256 |
1570 std::vector<gfx::Size> icon2; | 1257 kEmptySizes icon2; |
1571 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); | 1258 icon2.push_back(gfx::Size(kMaximalSize + 2, kMaximalSize + 2)); |
1572 | 1259 |
1573 const FaviconURL kSourceIconURLs[] = { | 1260 const FaviconURL kSourceIconURLs[] = { |
1574 FaviconURL( | 1261 FaviconURL( |
1575 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1262 GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1576 FaviconURL( | 1263 FaviconURL( |
1577 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; | 1264 GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2)}; |
1578 | 1265 |
1579 TestDelegate delegate1; | 1266 MockDelegate_ delegate_1; |
1580 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 1267 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1581 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1268 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1582 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1269 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1583 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1270 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1584 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); | 1271 UpdateFaviconURL(&delegate_1, &handler1, kPageURL, urls1); |
1585 | 1272 |
1586 ASSERT_EQ(2u, handler1.image_urls().size()); | 1273 ASSERT_EQ(2u, handler1.image_urls().size()); |
1587 | 1274 |
1588 // Index of largest favicon in kSourceIconURLs. | 1275 // Index of largest favicon in kSourceIconURLs. |
1589 size_t i = 1; | 1276 size_t i = 1; |
1590 // The largest bitmap's index in Favicon . | 1277 // The largest bitmap's index in Favicon . |
1591 int b = 0; | 1278 int b = 0; |
1592 | 1279 |
1593 // Verify the icon_bitmaps_ was initialized correctly. | 1280 // Verify the icon_bitmaps_ was initialized correctly. |
1594 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1281 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1595 handler1.current_candidate()->icon_url); | 1282 handler1.current_candidate()->icon_url); |
1596 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], | 1283 EXPECT_EQ(kSourceIconURLs[i].icon_sizes[b], |
1597 handler1.current_candidate()->icon_sizes[0]); | 1284 handler1.current_candidate()->icon_sizes[0]); |
1598 | 1285 |
1599 // Simulate no favicon from history. | 1286 // Simulate no favicon from history. |
1600 handler1.history_handler()->history_results_.clear(); | 1287 handler1.history_handler()->history_results_.clear(); |
1601 handler1.history_handler()->InvokeCallback(); | 1288 handler1.history_handler()->InvokeCallback(); |
1602 | 1289 |
1603 // Verify download request | 1290 // Verify download request |
1604 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); | 1291 ASSERT_TRUE(delegate_1.download_handler()->HasDownload()); |
1605 EXPECT_EQ(kSourceIconURLs[i].icon_url, | 1292 EXPECT_EQ(kSourceIconURLs[i].icon_url, |
1606 delegate1.download_handler()->GetImageUrl()); | 1293 delegate_1.download_handler()->GetImageUrl()); |
1607 | 1294 |
1608 // Give the scaled download bitmap. | 1295 // Give the scaled download bitmap. |
1609 std::vector<int> sizes; | 1296 std::vector<int> sizes; |
1610 sizes.push_back(kMaximalSize); | 1297 sizes.push_back(kMaximalSize); |
1611 | 1298 |
1612 delegate1.download_handler()->SetImageSizes(sizes); | 1299 delegate_1.download_handler()->SetImageSizes(sizes); |
1613 delegate1.download_handler()->InvokeCallback(); | 1300 delegate_1.download_handler()->InvokeCallback(); |
1614 | 1301 |
1615 // Verify the largest bitmap has been saved into history though it was | 1302 // Verify the largest bitmap has been saved into history though it was |
1616 // scaled down to maximal size and smaller than icon1 now. | 1303 // scaled down to maximal size and smaller than icon1 now. |
1617 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); | 1304 EXPECT_EQ(kSourceIconURLs[i].icon_url, handler1.history_handler()->icon_url_); |
1618 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), | 1305 EXPECT_EQ(gfx::Size(kMaximalSize, kMaximalSize), |
1619 handler1.history_handler()->size_); | 1306 handler1.history_handler()->size_); |
1620 } | 1307 } |
1621 | 1308 |
1622 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { | 1309 TEST_F(FaviconHandlerTest, TestKeepDownloadedLargestFavicon) { |
1623 const GURL kPageURL("http://www.google.com"); | 1310 const GURL kPageURL("http://www.google.com"); |
1624 | 1311 |
1625 std::vector<gfx::Size> icon1; | 1312 kEmptySizes icon1; |
1626 icon1.push_back(gfx::Size(16, 16)); | 1313 icon1.push_back(gfx::Size(16, 16)); |
1627 const int actual_size1 = 10; | 1314 const int actual_size1 = 10; |
1628 | 1315 |
1629 std::vector<gfx::Size> icon2; | 1316 kEmptySizes icon2; |
1630 icon2.push_back(gfx::Size(15, 15)); | 1317 icon2.push_back(gfx::Size(15, 15)); |
1631 const int actual_size2 = 12; | 1318 const int actual_size2 = 12; |
1632 | 1319 |
1633 const FaviconURL kSourceIconURLs[] = { | 1320 const FaviconURL kSourceIconURLs[] = { |
1634 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), | 1321 FaviconURL(GURL("http://www.google.com/b"), favicon_base::FAVICON, icon1), |
1635 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), | 1322 FaviconURL(GURL("http://www.google.com/c"), favicon_base::FAVICON, icon2), |
1636 FaviconURL(GURL("http://www.google.com/d"), | 1323 FaviconURL(GURL("http://www.google.com/d"), favicon_base::FAVICON, |
1637 favicon_base::FAVICON, | 1324 kEmptySizes)}; |
1638 std::vector<gfx::Size>())}; | |
1639 | 1325 |
1640 TestDelegate delegate1; | 1326 MockDelegate_ delegate_1; |
1641 TestFaviconHandler handler1(&favicon_service_, &delegate1, | 1327 FaviconHandler handler1(&favicon_service_, &delegate_1, |
1642 FaviconDriverObserver::NON_TOUCH_LARGEST); | 1328 FaviconDriverObserver::NON_TOUCH_LARGEST); |
1643 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1329 std::vector<FaviconURL> urls1(kSourceIconURLs, |
1644 kSourceIconURLs + arraysize(kSourceIconURLs)); | 1330 kSourceIconURLs + arraysize(kSourceIconURLs)); |
1645 UpdateFaviconURL(&delegate1, &handler1, kPageURL, urls1); | 1331 UpdateFaviconURL(&delegate_1, &handler1, kPageURL, urls1); |
1646 ASSERT_EQ(3u, handler1.image_urls().size()); | 1332 ASSERT_EQ(3u, handler1.image_urls().size()); |
1647 | 1333 |
1648 // Simulate no favicon from history. | 1334 // Simulate no favicon from history. |
1649 handler1.history_handler()->history_results_.clear(); | 1335 handler1.history_handler()->history_results_.clear(); |
1650 handler1.history_handler()->InvokeCallback(); | 1336 handler1.history_handler()->InvokeCallback(); |
1651 | 1337 |
1652 // Verify the first icon was request to download | 1338 // Verify the first icon was request to download |
1653 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); | 1339 ASSERT_TRUE(delegate_1.download_handler()->HasDownload()); |
1654 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1340 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1655 delegate1.download_handler()->GetImageUrl()); | 1341 delegate_1.download_handler()->GetImageUrl()); |
1656 | 1342 |
1657 // Give the incorrect size. | 1343 // Give the incorrect size. |
1658 std::vector<int> sizes; | 1344 std::vector<int> sizes; |
1659 sizes.push_back(actual_size1); | 1345 sizes.push_back(actual_size1); |
1660 delegate1.download_handler()->SetImageSizes(sizes); | 1346 delegate_1.download_handler()->SetImageSizes(sizes); |
1661 delegate1.download_handler()->InvokeCallback(); | 1347 delegate_1.download_handler()->InvokeCallback(); |
1662 delegate1.download_handler()->Reset(); | 1348 delegate_1.download_handler()->Reset(); |
1663 | 1349 |
1664 // Simulate no favicon from history. | 1350 // Simulate no favicon from history. |
1665 handler1.history_handler()->history_results_.clear(); | 1351 handler1.history_handler()->history_results_.clear(); |
1666 handler1.history_handler()->InvokeCallback(); | 1352 handler1.history_handler()->InvokeCallback(); |
1667 | 1353 |
1668 // Verify the 2nd icon was request to download | 1354 // Verify the 2nd icon was request to download |
1669 ASSERT_TRUE(delegate1.download_handler()->HasDownload()); | 1355 ASSERT_TRUE(delegate_1.download_handler()->HasDownload()); |
1670 EXPECT_EQ(kSourceIconURLs[1].icon_url, | 1356 EXPECT_EQ(kSourceIconURLs[1].icon_url, |
1671 delegate1.download_handler()->GetImageUrl()); | 1357 delegate_1.download_handler()->GetImageUrl()); |
1672 | 1358 |
1673 // Very the best candidate is icon1 | 1359 // Very the best candidate is icon1 |
1674 EXPECT_EQ(kSourceIconURLs[0].icon_url, | 1360 EXPECT_EQ(kSourceIconURLs[0].icon_url, |
1675 handler1.best_favicon_candidate().image_url); | 1361 handler1.best_favicon_candidate().image_url); |
1676 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), | 1362 EXPECT_EQ(gfx::Size(actual_size1, actual_size1), |
1677 handler1.best_favicon_candidate().image.Size()); | 1363 handler1.best_favicon_candidate().image.Size()); |
1678 | 1364 |
1679 // Give the incorrect size. | 1365 // Give the incorrect size. |
1680 sizes.clear(); | 1366 sizes.clear(); |
1681 sizes.push_back(actual_size2); | 1367 sizes.push_back(actual_size2); |
1682 delegate1.download_handler()->SetImageSizes(sizes); | 1368 delegate_1.download_handler()->SetImageSizes(sizes); |
1683 delegate1.download_handler()->InvokeCallback(); | 1369 delegate_1.download_handler()->InvokeCallback(); |
1684 delegate1.download_handler()->Reset(); | 1370 delegate_1.download_handler()->Reset(); |
1685 | 1371 |
1686 // Verify icon2 has been saved into history. | 1372 // Verify icon2 has been saved into history. |
1687 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); | 1373 EXPECT_EQ(kSourceIconURLs[1].icon_url, handler1.history_handler()->icon_url_); |
1688 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), | 1374 EXPECT_EQ(gfx::Size(actual_size2, actual_size2), |
1689 handler1.history_handler()->size_); | 1375 handler1.history_handler()->size_); |
1690 } | 1376 } |
1691 | 1377 |
1378 #endif | |
1379 | |
1692 } // namespace | 1380 } // namespace |
1693 } // namespace favicon | 1381 } // namespace favicon |
OLD | NEW |