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 <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 #include <set> | 11 #include <set> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
19 #include "base/test/scoped_feature_list.h" | |
19 #include "base/test/scoped_task_environment.h" | 20 #include "base/test/scoped_task_environment.h" |
20 #include "base/test/test_simple_task_runner.h" | 21 #include "base/test/test_simple_task_runner.h" |
21 #include "components/favicon/core/favicon_driver.h" | 22 #include "components/favicon/core/favicon_driver.h" |
22 #include "components/favicon/core/test/mock_favicon_service.h" | 23 #include "components/favicon/core/test/mock_favicon_service.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 26 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 27 #include "third_party/skia/include/core/SkColor.h" |
27 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
28 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
29 #include "ui/gfx/favicon_size.h" | 30 #include "ui/gfx/favicon_size.h" |
30 #include "ui/gfx/image/image.h" | 31 #include "ui/gfx/image/image.h" |
31 | 32 |
32 namespace favicon { | 33 namespace favicon { |
33 namespace { | 34 namespace { |
34 | 35 |
35 using favicon_base::FAVICON; | 36 using favicon_base::FAVICON; |
36 using favicon_base::FaviconRawBitmapResult; | 37 using favicon_base::FaviconRawBitmapResult; |
37 using favicon_base::TOUCH_ICON; | 38 using favicon_base::TOUCH_ICON; |
38 using favicon_base::TOUCH_PRECOMPOSED_ICON; | 39 using favicon_base::TOUCH_PRECOMPOSED_ICON; |
40 using testing::AnyNumber; | |
39 using testing::Assign; | 41 using testing::Assign; |
42 using testing::Contains; | |
40 using testing::ElementsAre; | 43 using testing::ElementsAre; |
41 using testing::InSequence; | 44 using testing::InSequence; |
42 using testing::Invoke; | 45 using testing::Invoke; |
43 using testing::IsEmpty; | 46 using testing::IsEmpty; |
47 using testing::Not; | |
44 using testing::Return; | 48 using testing::Return; |
45 using testing::_; | 49 using testing::_; |
46 | 50 |
47 using DownloadOutcome = FaviconHandler::DownloadOutcome; | 51 using DownloadOutcome = FaviconHandler::DownloadOutcome; |
48 using IntVector = std::vector<int>; | 52 using IntVector = std::vector<int>; |
49 using URLVector = std::vector<GURL>; | 53 using URLVector = std::vector<GURL>; |
50 using BitmapVector = std::vector<SkBitmap>; | 54 using BitmapVector = std::vector<SkBitmap>; |
51 using SizeVector = std::vector<gfx::Size>; | 55 using SizeVector = std::vector<gfx::Size>; |
52 | 56 |
53 MATCHER_P2(ImageSizeIs, width, height, "") { | 57 MATCHER_P2(ImageSizeIs, width, height, "") { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 // Fake that implements the calls to FaviconHandler::Delegate's DownloadImage(), | 114 // Fake that implements the calls to FaviconHandler::Delegate's DownloadImage(), |
111 // delegated to this class through MockDelegate. | 115 // delegated to this class through MockDelegate. |
112 class FakeImageDownloader { | 116 class FakeImageDownloader { |
113 public: | 117 public: |
114 struct Response { | 118 struct Response { |
115 int http_status_code = 404; | 119 int http_status_code = 404; |
116 BitmapVector bitmaps; | 120 BitmapVector bitmaps; |
117 SizeVector original_bitmap_sizes; | 121 SizeVector original_bitmap_sizes; |
118 }; | 122 }; |
119 | 123 |
120 FakeImageDownloader() : next_download_id_(1) {} | 124 // |downloads| must not be nullptr and must outlive this object. |
125 FakeImageDownloader(URLVector* downloads) | |
126 : downloads_(downloads), next_download_id_(1) {} | |
121 | 127 |
122 // Implementation of FaviconHalder::Delegate's DownloadImage(). If a given | 128 // Implementation of FaviconHalder::Delegate's DownloadImage(). If a given |
123 // URL is not known (i.e. not previously added via Add()), it produces 404s. | 129 // URL is not known (i.e. not previously added via Add()), it produces 404s. |
124 int DownloadImage(const GURL& url, | 130 int DownloadImage(const GURL& url, |
125 int max_image_size, | 131 int max_image_size, |
126 FaviconHandler::Delegate::ImageDownloadCallback callback) { | 132 FaviconHandler::Delegate::ImageDownloadCallback callback) { |
127 downloads_.push_back(url); | 133 downloads_->push_back(url); |
128 | 134 |
129 const Response& response = responses_[url]; | 135 const Response& response = responses_[url]; |
130 int download_id = next_download_id_++; | 136 int download_id = next_download_id_++; |
131 base::Closure bound_callback = | 137 base::Closure bound_callback = |
132 base::Bind(callback, download_id, response.http_status_code, url, | 138 base::Bind(callback, download_id, response.http_status_code, url, |
133 response.bitmaps, response.original_bitmap_sizes); | 139 response.bitmaps, response.original_bitmap_sizes); |
134 if (url == manual_callback_url_) | 140 if (url == manual_callback_url_) |
135 manual_callback_ = bound_callback; | 141 manual_callbacks_.push_back(bound_callback); |
136 else | 142 else |
137 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | 143 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); |
138 return download_id; | 144 return download_id; |
139 } | 145 } |
140 | 146 |
141 void Add(const GURL& icon_url, | 147 void Add(const GURL& icon_url, |
142 const IntVector& sizes, | 148 const IntVector& sizes, |
143 const IntVector& original_sizes, | 149 const IntVector& original_sizes, |
144 SkColor color) { | 150 SkColor color) { |
145 DCHECK_EQ(sizes.size(), original_sizes.size()); | 151 DCHECK_EQ(sizes.size(), original_sizes.size()); |
(...skipping 12 matching lines...) Expand all Loading... | |
158 } | 164 } |
159 | 165 |
160 void AddError(const GURL& icon_url, int http_status_code) { | 166 void AddError(const GURL& icon_url, int http_status_code) { |
161 Response response; | 167 Response response; |
162 response.http_status_code = http_status_code; | 168 response.http_status_code = http_status_code; |
163 responses_[icon_url] = response; | 169 responses_[icon_url] = response; |
164 } | 170 } |
165 | 171 |
166 // Disables automatic callback for |url|. This is useful for emulating a | 172 // Disables automatic callback for |url|. This is useful for emulating a |
167 // download taking a long time. The callback for DownloadImage() will be | 173 // download taking a long time. The callback for DownloadImage() will be |
168 // stored in |manual_callback_|. | 174 // stored in |manual_callbacks_|. |
169 void SetRunCallbackManuallyForUrl(const GURL& url) { | 175 void SetRunCallbackManuallyForUrl(const GURL& url) { |
170 manual_callback_url_ = url; | 176 manual_callback_url_ = url; |
171 } | 177 } |
172 | 178 |
173 // Returns whether an ongoing download exists for a url previously selected | 179 // Returns whether an ongoing download exists for a url previously selected |
174 // via SetRunCallbackManuallyForUrl(). | 180 // via SetRunCallbackManuallyForUrl(). |
175 bool HasPendingManualCallback() { return !manual_callback_.is_null(); } | 181 bool HasPendingManualCallback() { return !manual_callbacks_.empty(); } |
176 | 182 |
177 // Triggers the response for a download previously selected for manual | 183 // Triggers responses for downloads previously selected for manual triggering |
178 // triggering via SetRunCallbackManuallyForUrl(). | 184 // via SetRunCallbackManuallyForUrl(). |
179 bool RunCallbackManually() { | 185 bool RunCallbackManually() { |
180 if (!HasPendingManualCallback()) | 186 if (!HasPendingManualCallback()) |
181 return false; | 187 return false; |
182 manual_callback_.Run(); | 188 for (base::Closure& callback : std::move(manual_callbacks_)) |
183 manual_callback_.Reset(); | 189 callback.Run(); |
184 return true; | 190 return true; |
185 } | 191 } |
186 | 192 |
187 // Returns pending and completed download URLs. | |
188 const URLVector& downloads() const { return downloads_; } | |
189 | |
190 void ClearDownloads() { downloads_.clear(); } | |
191 | |
192 private: | 193 private: |
194 URLVector* downloads_; | |
193 int next_download_id_; | 195 int next_download_id_; |
194 | 196 |
195 // Pending and completed download URLs. | |
196 URLVector downloads_; | |
197 | |
198 // URL to disable automatic callbacks for. | 197 // URL to disable automatic callbacks for. |
199 GURL manual_callback_url_; | 198 GURL manual_callback_url_; |
200 | 199 |
201 // Callback for DownloadImage() request for |manual_callback_url_|. | 200 // Callback for DownloadImage() request for |manual_callback_url_|. |
202 base::Closure manual_callback_; | 201 std::vector<base::Closure> manual_callbacks_; |
203 | 202 |
204 // Registered responses. | 203 // Registered responses. |
205 std::map<GURL, Response> responses_; | 204 std::map<GURL, Response> responses_; |
206 | 205 |
207 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); | 206 DISALLOW_COPY_AND_ASSIGN(FakeImageDownloader); |
208 }; | 207 }; |
209 | 208 |
209 // Fake that implements the calls to FaviconHandler::Delegate's | |
210 // DownloadManifest(), delegated to this class through MockDelegate. | |
211 class FakeManifestDownloader { | |
212 public: | |
213 struct Response { | |
214 std::vector<favicon::FaviconURL> favicon_urls; | |
215 }; | |
216 | |
217 // |downloads| must not be nullptr and must outlive this object. | |
218 FakeManifestDownloader(URLVector* downloads) : downloads_(downloads) {} | |
219 | |
220 // Implementation of FaviconHalder::Delegate's DownloadManifest(). If a given | |
221 // URL is not known (i.e. not previously added via Add()), it produces 404s. | |
222 void DownloadManifest( | |
223 const GURL& url, | |
224 FaviconHandler::Delegate::ManifestDownloadCallback callback) { | |
225 downloads_->push_back(url); | |
226 | |
227 const Response& response = responses_[url]; | |
228 base::Closure bound_callback = base::Bind(callback, response.favicon_urls); | |
229 if (url == manual_callback_url_) | |
230 manual_callbacks_.push_back(bound_callback); | |
231 else | |
232 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, bound_callback); | |
233 } | |
234 | |
235 void Add(const GURL& manifest_url, | |
236 const std::vector<favicon::FaviconURL>& favicon_urls) { | |
237 Response response; | |
238 response.favicon_urls = favicon_urls; | |
239 responses_[manifest_url] = response; | |
240 } | |
241 | |
242 void AddError(const GURL& manifest_url) { | |
243 responses_[manifest_url] = Response(); | |
244 } | |
245 | |
246 // Disables automatic callback for |url|. This is useful for emulating a | |
247 // download taking a long time. The callback for DownloadManifest() will be | |
248 // stored in |manual_callback_|. | |
249 void SetRunCallbackManuallyForUrl(const GURL& url) { | |
250 manual_callback_url_ = url; | |
251 } | |
252 | |
253 // Returns whether an ongoing download exists for a url previously selected | |
254 // via SetRunCallbackManuallyForUrl(). | |
255 bool HasPendingManualCallback() { return !manual_callbacks_.empty(); } | |
256 | |
257 // Triggers responses for downloads previously selected for manual triggering | |
258 // via SetRunCallbackManuallyForUrl(). | |
259 bool RunCallbackManually() { | |
260 if (!HasPendingManualCallback()) | |
261 return false; | |
262 for (base::Closure& callback : std::move(manual_callbacks_)) | |
263 callback.Run(); | |
264 return true; | |
265 } | |
266 | |
267 private: | |
268 URLVector* downloads_; | |
269 | |
270 // URL to disable automatic callbacks for. | |
271 GURL manual_callback_url_; | |
272 | |
273 // Callback for DownloadManifest() request for |manual_callback_url_|. | |
274 std::vector<base::Closure> manual_callbacks_; | |
275 | |
276 // Registered responses. | |
277 std::map<GURL, Response> responses_; | |
278 | |
279 DISALLOW_COPY_AND_ASSIGN(FakeManifestDownloader); | |
280 }; | |
281 | |
210 class MockDelegate : public FaviconHandler::Delegate { | 282 class MockDelegate : public FaviconHandler::Delegate { |
211 public: | 283 public: |
212 MockDelegate() { | 284 MockDelegate() |
285 : fake_image_downloader_(&downloads_), | |
286 fake_manifest_downloader_(&downloads_) { | |
213 // Delegate image downloading to FakeImageDownloader. | 287 // Delegate image downloading to FakeImageDownloader. |
214 ON_CALL(*this, DownloadImage(_, _, _)) | 288 ON_CALL(*this, DownloadImage(_, _, _)) |
215 .WillByDefault(Invoke(&fake_image_downloader_, | 289 .WillByDefault(Invoke(&fake_image_downloader_, |
216 &FakeImageDownloader::DownloadImage)); | 290 &FakeImageDownloader::DownloadImage)); |
291 // Delegate manifest downloading to FakeManifestDownloader. | |
292 ON_CALL(*this, DownloadManifest(_, _)) | |
293 .WillByDefault(Invoke(&fake_manifest_downloader_, | |
294 &FakeManifestDownloader::DownloadManifest)); | |
217 } | 295 } |
218 | 296 |
219 MOCK_METHOD3(DownloadImage, | 297 MOCK_METHOD3(DownloadImage, |
220 int(const GURL& url, | 298 int(const GURL& url, |
221 int max_image_size, | 299 int max_image_size, |
222 ImageDownloadCallback callback)); | 300 ImageDownloadCallback callback)); |
301 MOCK_METHOD2(DownloadManifest, | |
302 void(const GURL& url, ManifestDownloadCallback callback)); | |
223 MOCK_METHOD0(IsOffTheRecord, bool()); | 303 MOCK_METHOD0(IsOffTheRecord, bool()); |
224 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); | 304 MOCK_METHOD1(IsBookmarked, bool(const GURL& url)); |
225 MOCK_METHOD5(OnFaviconUpdated, | 305 MOCK_METHOD5(OnFaviconUpdated, |
226 void(const GURL& page_url, | 306 void(const GURL& page_url, |
227 FaviconDriverObserver::NotificationIconType type, | 307 FaviconDriverObserver::NotificationIconType type, |
228 const GURL& icon_url, | 308 const GURL& icon_url, |
229 bool icon_url_changed, | 309 bool icon_url_changed, |
230 const gfx::Image& image)); | 310 const gfx::Image& image)); |
231 | 311 |
232 FakeImageDownloader& fake_image_downloader() { | 312 FakeImageDownloader& fake_image_downloader() { |
233 return fake_image_downloader_; | 313 return fake_image_downloader_; |
234 } | 314 } |
235 | 315 |
236 // Convenience getter for test readability. Returns pending and completed | 316 FakeManifestDownloader& fake_manifest_downloader() { |
237 // download URLs. | 317 return fake_manifest_downloader_; |
238 const URLVector& downloads() const { | |
239 return fake_image_downloader_.downloads(); | |
240 } | 318 } |
241 | 319 |
320 // Returns pending and completed download URLs. | |
321 const URLVector& downloads() const { return downloads_; } | |
322 | |
323 void ClearDownloads() { downloads_.clear(); } | |
324 | |
242 private: | 325 private: |
326 // Pending and completed download URLs. | |
327 URLVector downloads_; | |
243 FakeImageDownloader fake_image_downloader_; | 328 FakeImageDownloader fake_image_downloader_; |
329 FakeManifestDownloader fake_manifest_downloader_; | |
244 }; | 330 }; |
245 | 331 |
246 // FakeFaviconService mimics a FaviconService backend that allows setting up | 332 // FakeFaviconService mimics a FaviconService backend that allows setting up |
247 // test data stored via Store(). If Store() has not been called for a | 333 // test data stored via Store(). If Store() has not been called for a |
248 // particular URL, the callback is called with empty database results. | 334 // particular URL, the callback is called with empty database results. |
249 class FakeFaviconService { | 335 class FakeFaviconService { |
250 public: | 336 public: |
251 FakeFaviconService() | 337 FakeFaviconService() |
252 : manual_callback_task_runner_(new base::TestSimpleTaskRunner()) {} | 338 : manual_callback_task_runner_(new base::TestSimpleTaskRunner()) {} |
253 | 339 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 483 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
398 // Force the values of the scale factors so that the tests produce the same | 484 // Force the values of the scale factors so that the tests produce the same |
399 // results on all platforms. | 485 // results on all platforms. |
400 scoped_set_supported_scale_factors_.reset( | 486 scoped_set_supported_scale_factors_.reset( |
401 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); | 487 new ui::test::ScopedSetSupportedScaleFactors({ui::SCALE_FACTOR_100P})); |
402 } | 488 } |
403 | 489 |
404 bool VerifyAndClearExpectations() { | 490 bool VerifyAndClearExpectations() { |
405 base::RunLoop().RunUntilIdle(); | 491 base::RunLoop().RunUntilIdle(); |
406 favicon_service_.fake()->ClearDbRequests(); | 492 favicon_service_.fake()->ClearDbRequests(); |
407 delegate_.fake_image_downloader().ClearDownloads(); | 493 delegate_.ClearDownloads(); |
408 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && | 494 return testing::Mock::VerifyAndClearExpectations(&favicon_service_) && |
409 testing::Mock::VerifyAndClearExpectations(&delegate_); | 495 testing::Mock::VerifyAndClearExpectations(&delegate_); |
410 } | 496 } |
411 | 497 |
412 // Creates a new handler and feeds in the page URL and the candidates. | 498 // Creates a new handler and feeds in the page URL and the candidates. |
413 // Returns the handler in case tests want to exercise further steps. | 499 // Returns the handler in case tests want to exercise further steps. |
414 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( | 500 std::unique_ptr<FaviconHandler> RunHandlerWithCandidates( |
415 FaviconDriverObserver::NotificationIconType handler_type, | 501 FaviconDriverObserver::NotificationIconType handler_type, |
416 const std::vector<favicon::FaviconURL>& candidates) { | 502 const std::vector<favicon::FaviconURL>& candidates, |
503 const GURL& manifest_url = GURL()) { | |
417 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, | 504 auto handler = base::MakeUnique<FaviconHandler>(&favicon_service_, |
418 &delegate_, handler_type); | 505 &delegate_, handler_type); |
419 handler->FetchFavicon(kPageURL); | 506 handler->FetchFavicon(kPageURL); |
420 // The first RunUntilIdle() causes the FaviconService lookups be faster than | 507 // The first RunUntilIdle() causes the FaviconService lookups be faster than |
421 // OnUpdateCandidates(), which is the most likely scenario. | 508 // OnUpdateCandidates(), which is the most likely scenario. |
422 base::RunLoop().RunUntilIdle(); | 509 base::RunLoop().RunUntilIdle(); |
423 handler->OnUpdateCandidates(kPageURL, candidates); | 510 handler->OnUpdateCandidates(kPageURL, candidates, manifest_url); |
424 base::RunLoop().RunUntilIdle(); | 511 base::RunLoop().RunUntilIdle(); |
425 return handler; | 512 return handler; |
426 } | 513 } |
427 | 514 |
428 // Same as above, but for the simplest case where all types are FAVICON and | 515 // Same as above, but for the simplest case where all types are FAVICON and |
429 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. | 516 // no sizes are provided, using a FaviconHandler of type NON_TOUCH_16_DIP. |
430 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( | 517 std::unique_ptr<FaviconHandler> RunHandlerWithSimpleFaviconCandidates( |
431 const std::vector<GURL>& urls) { | 518 const std::vector<GURL>& urls, |
519 const GURL& manifest_url = GURL()) { | |
432 std::vector<favicon::FaviconURL> candidates; | 520 std::vector<favicon::FaviconURL> candidates; |
433 for (const GURL& url : urls) { | 521 for (const GURL& url : urls) { |
434 candidates.emplace_back(url, FAVICON, kEmptySizes); | 522 candidates.emplace_back(url, FAVICON, kEmptySizes); |
435 } | 523 } |
436 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, | 524 return RunHandlerWithCandidates(FaviconDriverObserver::NON_TOUCH_16_DIP, |
437 candidates); | 525 candidates, manifest_url); |
438 } | 526 } |
439 | 527 |
440 base::test::ScopedTaskEnvironment scoped_task_environment_; | 528 base::test::ScopedTaskEnvironment scoped_task_environment_; |
441 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> | 529 std::unique_ptr<ui::test::ScopedSetSupportedScaleFactors> |
442 scoped_set_supported_scale_factors_; | 530 scoped_set_supported_scale_factors_; |
443 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; | 531 testing::NiceMock<MockFaviconServiceWithFake> favicon_service_; |
444 testing::NiceMock<MockDelegate> delegate_; | 532 testing::NiceMock<MockDelegate> delegate_; |
445 }; | 533 }; |
446 | 534 |
447 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 535 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 // Causes FaviconService lookups be faster than OnUpdateCandidates(). | 584 // Causes FaviconService lookups be faster than OnUpdateCandidates(). |
497 ASSERT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 585 ASSERT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
498 ASSERT_TRUE(VerifyAndClearExpectations()); | 586 ASSERT_TRUE(VerifyAndClearExpectations()); |
499 | 587 |
500 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 588 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
501 ImageSizeIs(16, 16))); | 589 ImageSizeIs(16, 16))); |
502 EXPECT_CALL(delegate_, OnFaviconUpdated( | 590 EXPECT_CALL(delegate_, OnFaviconUpdated( |
503 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, | 591 kPageURL, FaviconDriverObserver::NON_TOUCH_16_DIP, |
504 kIconURL16x16, /*icon_url_changed=*/true, _)); | 592 kIconURL16x16, /*icon_url_changed=*/true, _)); |
505 // Feed in favicons now that the database lookup is completed. | 593 // Feed in favicons now that the database lookup is completed. |
506 handler.OnUpdateCandidates(kPageURL, | 594 handler.OnUpdateCandidates( |
507 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 595 kPageURL, {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, GURL()); |
508 base::RunLoop().RunUntilIdle(); | 596 base::RunLoop().RunUntilIdle(); |
509 | 597 |
510 EXPECT_THAT(favicon_service_.fake()->db_requests(), | 598 EXPECT_THAT(favicon_service_.fake()->db_requests(), |
511 ElementsAre(kIconURL16x16)); | 599 ElementsAre(kIconURL16x16)); |
512 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); | 600 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL16x16)); |
513 } | 601 } |
514 | 602 |
515 // Test that the FaviconHandler process finishes when: | 603 // Test that the FaviconHandler process finishes when: |
516 // - There is data in the database for neither the page URL nor the icon URL. | 604 // - There is data in the database for neither the page URL nor the icon URL. |
517 // AND | 605 // AND |
518 // - FaviconService::GetFaviconForPageURL() callback returns after | 606 // - FaviconService::GetFaviconForPageURL() callback returns after |
519 // FaviconHandler::OnUpdateCandidates() is called. | 607 // FaviconHandler::OnUpdateCandidates() is called. |
520 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { | 608 TEST_F(FaviconHandlerTest, DownloadUnknownFaviconIfCandidatesFaster) { |
521 // Defer the database lookup completion to control the exact timing. | 609 // Defer the database lookup completion to control the exact timing. |
522 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); | 610 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kPageURL); |
523 | 611 |
524 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 612 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
525 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 613 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
526 | 614 |
527 FaviconHandler handler(&favicon_service_, &delegate_, | 615 FaviconHandler handler(&favicon_service_, &delegate_, |
528 FaviconDriverObserver::NON_TOUCH_16_DIP); | 616 FaviconDriverObserver::NON_TOUCH_16_DIP); |
529 handler.FetchFavicon(kPageURL); | 617 handler.FetchFavicon(kPageURL); |
530 base::RunLoop().RunUntilIdle(); | 618 base::RunLoop().RunUntilIdle(); |
531 // Feed in favicons before completing the database lookup. | 619 // Feed in favicons before completing the database lookup. |
532 handler.OnUpdateCandidates(kPageURL, | 620 handler.OnUpdateCandidates( |
533 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}); | 621 kPageURL, {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, GURL()); |
534 | 622 |
535 ASSERT_TRUE(VerifyAndClearExpectations()); | 623 ASSERT_TRUE(VerifyAndClearExpectations()); |
536 // Database lookup for |kPageURL| is ongoing. | 624 // Database lookup for |kPageURL| is ongoing. |
537 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 625 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
538 | 626 |
539 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, | 627 EXPECT_CALL(favicon_service_, SetFavicons(kPageURL, kIconURL16x16, FAVICON, |
540 ImageSizeIs(16, 16))); | 628 ImageSizeIs(16, 16))); |
541 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); | 629 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)); |
542 | 630 |
543 // Complete the lookup for |kPageURL|. | 631 // Complete the lookup for |kPageURL|. |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
737 std::unique_ptr<FaviconHandler> handler = | 825 std::unique_ptr<FaviconHandler> handler = |
738 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); | 826 RunHandlerWithSimpleFaviconCandidates({kIconURL1, kIconURL2}); |
739 | 827 |
740 ASSERT_TRUE(VerifyAndClearExpectations()); | 828 ASSERT_TRUE(VerifyAndClearExpectations()); |
741 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); | 829 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
742 | 830 |
743 // Favicon update should invalidate the ongoing download. | 831 // Favicon update should invalidate the ongoing download. |
744 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); | 832 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL3, _, _)); |
745 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); | 833 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL3, _, _)); |
746 | 834 |
747 handler->OnUpdateCandidates(kPageURL, | 835 handler->OnUpdateCandidates( |
748 {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}); | 836 kPageURL, {FaviconURL(kIconURL3, FAVICON, kEmptySizes)}, GURL()); |
749 | 837 |
750 // Finalizes download, which should be thrown away as the favicon URLs were | 838 // Finalizes download, which should be thrown away as the favicon URLs were |
751 // updated. | 839 // updated. |
752 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); | 840 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
753 base::RunLoop().RunUntilIdle(); | 841 base::RunLoop().RunUntilIdle(); |
754 | 842 |
755 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); | 843 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL3)); |
756 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); | 844 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL3)); |
757 } | 845 } |
758 | 846 |
(...skipping 15 matching lines...) Expand all Loading... | |
774 RunHandlerWithSimpleFaviconCandidates(URLVector{kIconURL1}); | 862 RunHandlerWithSimpleFaviconCandidates(URLVector{kIconURL1}); |
775 | 863 |
776 ASSERT_TRUE(VerifyAndClearExpectations()); | 864 ASSERT_TRUE(VerifyAndClearExpectations()); |
777 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 865 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
778 | 866 |
779 // SetFavicons() and OnFaviconUpdated() should be called for the new icon URL | 867 // SetFavicons() and OnFaviconUpdated() should be called for the new icon URL |
780 // and not |kIconURL1|. | 868 // and not |kIconURL1|. |
781 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL2, _, _)); | 869 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL2, _, _)); |
782 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); | 870 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); |
783 | 871 |
784 handler->OnUpdateCandidates(kPageURL, | 872 handler->OnUpdateCandidates( |
785 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); | 873 kPageURL, {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}, GURL()); |
786 | 874 |
787 // Finalizes the DB lookup, which should be thrown away as the favicon URLs | 875 // Finalizes the DB lookup, which should be thrown away as the favicon URLs |
788 // were updated. | 876 // were updated. |
789 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 877 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
790 base::RunLoop().RunUntilIdle(); | 878 base::RunLoop().RunUntilIdle(); |
791 | 879 |
792 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL2)); | 880 EXPECT_THAT(favicon_service_.fake()->db_requests(), ElementsAre(kIconURL2)); |
793 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); | 881 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL2)); |
794 } | 882 } |
795 | 883 |
(...skipping 16 matching lines...) Expand all Loading... | |
812 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 900 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
813 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 901 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
814 | 902 |
815 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 903 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
816 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); | 904 ElementsAre(kPageURL, kIconURL64x64, kSlowLoadingIconURL)); |
817 ASSERT_TRUE(VerifyAndClearExpectations()); | 905 ASSERT_TRUE(VerifyAndClearExpectations()); |
818 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); | 906 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); |
819 | 907 |
820 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, | 908 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, |
821 // despite the ongoing download. | 909 // despite the ongoing download. |
822 handler->OnUpdateCandidates(kPageURL, favicon_urls); | 910 handler->OnUpdateCandidates(kPageURL, favicon_urls, GURL()); |
823 base::RunLoop().RunUntilIdle(); | 911 base::RunLoop().RunUntilIdle(); |
824 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 912 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
825 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 913 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
826 | 914 |
827 // Complete the download. | 915 // Complete the download. |
828 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 916 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
829 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 917 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
830 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); | 918 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); |
831 base::RunLoop().RunUntilIdle(); | 919 base::RunLoop().RunUntilIdle(); |
832 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 920 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
(...skipping 13 matching lines...) Expand all Loading... | |
846 | 934 |
847 // Ongoing database lookup. | 935 // Ongoing database lookup. |
848 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 936 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
849 ElementsAre(kPageURL, kIconURL64x64)); | 937 ElementsAre(kPageURL, kIconURL64x64)); |
850 ASSERT_THAT(delegate_.downloads(), IsEmpty()); | 938 ASSERT_THAT(delegate_.downloads(), IsEmpty()); |
851 ASSERT_TRUE(VerifyAndClearExpectations()); | 939 ASSERT_TRUE(VerifyAndClearExpectations()); |
852 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | 940 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); |
853 | 941 |
854 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, | 942 // Calling OnUpdateCandidates() with the same icon URLs should have no effect, |
855 // despite the ongoing DB lookup. | 943 // despite the ongoing DB lookup. |
856 handler->OnUpdateCandidates(kPageURL, favicon_urls); | 944 handler->OnUpdateCandidates(kPageURL, favicon_urls, GURL()); |
857 base::RunLoop().RunUntilIdle(); | 945 base::RunLoop().RunUntilIdle(); |
858 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 946 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
859 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 947 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
860 | 948 |
861 // Complete the lookup. | 949 // Complete the lookup. |
862 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); | 950 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)); |
863 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); | 951 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)); |
864 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | 952 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); |
865 base::RunLoop().RunUntilIdle(); | 953 base::RunLoop().RunUntilIdle(); |
866 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL64x64)); | 954 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL64x64)); |
(...skipping 10 matching lines...) Expand all Loading... | |
877 | 965 |
878 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( | 966 std::unique_ptr<FaviconHandler> handler = RunHandlerWithCandidates( |
879 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); | 967 FaviconDriverObserver::NON_TOUCH_16_DIP, favicon_urls); |
880 | 968 |
881 ASSERT_TRUE(VerifyAndClearExpectations()); | 969 ASSERT_TRUE(VerifyAndClearExpectations()); |
882 | 970 |
883 // Calling OnUpdateCandidates() with identical data should be a no-op. | 971 // Calling OnUpdateCandidates() with identical data should be a no-op. |
884 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | 972 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); |
885 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | 973 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); |
886 | 974 |
887 handler->OnUpdateCandidates(kPageURL, favicon_urls); | 975 handler->OnUpdateCandidates(kPageURL, favicon_urls, GURL()); |
888 base::RunLoop().RunUntilIdle(); | 976 base::RunLoop().RunUntilIdle(); |
889 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); | 977 EXPECT_THAT(favicon_service_.fake()->db_requests(), IsEmpty()); |
890 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | 978 EXPECT_THAT(delegate_.downloads(), IsEmpty()); |
891 } | 979 } |
892 | 980 |
893 // Fixes crbug.com/544560 | 981 // Fixes crbug.com/544560 |
894 // Tests that Delegate::OnFaviconUpdated() is called if: | 982 // Tests that Delegate::OnFaviconUpdated() is called if: |
895 // - The best icon on the initial page is not the last icon. | 983 // - The best icon on the initial page is not the last icon. |
896 // - All of the initial page's icons are downloaded. | 984 // - All of the initial page's icons are downloaded. |
897 // AND | 985 // AND |
(...skipping 21 matching lines...) Expand all Loading... | |
919 // database and downloaded. |kIconURL2| should have been fetched from the | 1007 // database and downloaded. |kIconURL2| should have been fetched from the |
920 // database and downloaded last. | 1008 // database and downloaded last. |
921 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); | 1009 ASSERT_THAT(delegate_.downloads(), ElementsAre(kIconURL1, kIconURL2)); |
922 ASSERT_THAT(favicon_service_.fake()->db_requests(), | 1010 ASSERT_THAT(favicon_service_.fake()->db_requests(), |
923 ElementsAre(kPageURL, kIconURL1, kIconURL2)); | 1011 ElementsAre(kPageURL, kIconURL1, kIconURL2)); |
924 ASSERT_TRUE(VerifyAndClearExpectations()); | 1012 ASSERT_TRUE(VerifyAndClearExpectations()); |
925 | 1013 |
926 // Simulate the page changing it's icon URL to just |kIconURL2| via | 1014 // Simulate the page changing it's icon URL to just |kIconURL2| via |
927 // Javascript. | 1015 // Javascript. |
928 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); | 1016 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL2, _, _)); |
929 handler->OnUpdateCandidates(kPageURL, | 1017 handler->OnUpdateCandidates( |
930 {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}); | 1018 kPageURL, {FaviconURL(kIconURL2, FAVICON, kEmptySizes)}, GURL()); |
931 base::RunLoop().RunUntilIdle(); | 1019 base::RunLoop().RunUntilIdle(); |
932 } | 1020 } |
933 | 1021 |
934 // Test the favicon which is selected when the web page provides several | 1022 // Test the favicon which is selected when the web page provides several |
935 // favicons and none of the favicons are cached in history. | 1023 // favicons and none of the favicons are cached in history. |
936 // The goal of this test is to be more of an integration test than | 1024 // The goal of this test is to be more of an integration test than |
937 // SelectFaviconFramesTest.*. | 1025 // SelectFaviconFramesTest.*. |
938 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { | 1026 class FaviconHandlerMultipleFaviconsTest : public FaviconHandlerTest { |
939 protected: | 1027 protected: |
940 FaviconHandlerMultipleFaviconsTest() { | 1028 FaviconHandlerMultipleFaviconsTest() { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1363 .WillByDefault(Return(true)); | 1451 .WillByDefault(Return(true)); |
1364 | 1452 |
1365 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); | 1453 RunHandlerWithSimpleFaviconCandidates({k404IconURL}); |
1366 | 1454 |
1367 EXPECT_THAT( | 1455 EXPECT_THAT( |
1368 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), | 1456 histogram_tester.GetAllSamples("Favicons.DownloadOutcome"), |
1369 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), | 1457 ElementsAre(base::Bucket(static_cast<int>(DownloadOutcome::SKIPPED), |
1370 /*expected_count=*/1))); | 1458 /*expected_count=*/1))); |
1371 } | 1459 } |
1372 | 1460 |
1461 // Test that the support for Web Manifest is disabled by default, unless the | |
1462 // feature is enabled. | |
1463 TEST_F(FaviconHandlerTest, IgnoreWebManifestByDefault) { | |
1464 const GURL kManifestURL("http://www.google.com/manifest.json"); | |
1465 | |
1466 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}, kManifestURL); | |
1467 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1468 Not(Contains(kManifestURL))); | |
1469 EXPECT_THAT(delegate_.downloads(), Not(Contains(kManifestURL))); | |
1470 } | |
1471 | |
1472 class FaviconHandlerManifestsEnabledTest : public FaviconHandlerTest { | |
1473 protected: | |
1474 const GURL kManifestURL = GURL("http://www.google.com/manifest.json"); | |
1475 | |
1476 FaviconHandlerManifestsEnabledTest() { | |
1477 override_features_.InitAndEnableFeature(kFaviconsFromWebManifest); | |
1478 } | |
1479 | |
1480 private: | |
1481 base::test::ScopedFeatureList override_features_; | |
1482 | |
1483 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerManifestsEnabledTest); | |
1484 }; | |
1485 | |
1486 // Test that a favicon corresponding to a web manifest is reported when: | |
1487 // - There is data in the favicon database for the manifest URL. | |
1488 // AND | |
1489 // - FaviconService::OnFaviconDataForManifestFromFaviconService() runs before | |
1490 // FaviconHandler::OnUpdateCandidates() is called. | |
1491 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1492 GetFaviconFromManifestInHistoryIfCandidatesSlower) { | |
1493 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1494 CreateRawBitmapResult(kManifestURL)); | |
1495 | |
1496 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1497 | |
1498 EXPECT_CALL(favicon_service_, | |
1499 UpdateFaviconMappingsAndFetch(_, kManifestURL, FAVICON, | |
1500 /*desired_size_in_dip=*/16, _, _)); | |
1501 EXPECT_CALL(delegate_, | |
1502 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
1503 kManifestURL, _, _)) | |
1504 .Times(2); | |
pkotwicz
2017/05/16 06:36:37
In a follow up CL, it would be nice to decrease th
mastiz
2017/05/16 11:05:23
Done, in this CL.
| |
1505 | |
1506 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1507 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1508 ElementsAre(kPageURL, kManifestURL)); | |
1509 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | |
1510 } | |
1511 | |
1512 // Test that a favicon corresponding to a web manifest is reported when: | |
1513 // - There is data in the favicon database for the manifest URL. | |
1514 // AND | |
1515 // - FaviconHandler::OnUpdateCandidates() is called before | |
1516 // FaviconService::OnFaviconDataForManifestFromFaviconService() runs. | |
1517 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1518 GetFaviconFromManifestInHistoryIfCandidatesFaster) { | |
1519 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1520 CreateRawBitmapResult(kManifestURL)); | |
1521 // Defer the database lookup completion to control the exact timing. | |
1522 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kManifestURL); | |
1523 | |
1524 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1525 | |
1526 EXPECT_CALL(favicon_service_, | |
1527 UpdateFaviconMappingsAndFetch(_, kManifestURL, FAVICON, | |
1528 /*desired_size_in_dip=*/16, _, _)); | |
1529 EXPECT_CALL(delegate_, | |
1530 OnFaviconUpdated(_, FaviconDriverObserver::NON_TOUCH_16_DIP, | |
1531 kManifestURL, _, _)); | |
pkotwicz
2017/05/16 06:36:36
This should be Times(2) with https://codereview.ch
mastiz
2017/05/16 11:05:23
I had already rebased on top of that CL.
| |
1532 | |
1533 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
pkotwicz
2017/05/16 06:36:36
You need to store the returned FaviconHandler. Oth
mastiz
2017/05/16 11:05:23
Done.
| |
1534 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | |
1535 | |
1536 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1537 ElementsAre(kPageURL, kManifestURL)); | |
1538 EXPECT_THAT(delegate_.downloads(), IsEmpty()); | |
pkotwicz
2017/05/16 06:36:36
Nit: It is probably worth moving this two expectat
mastiz
2017/05/16 11:05:23
Done.
| |
1539 | |
1540 // Complete the lookup. | |
1541 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | |
1542 base::RunLoop().RunUntilIdle(); | |
1543 } | |
1544 | |
1545 // Test that a favicon corresponding to a web manifest is reported when there is | |
1546 // data in the database for neither the page URL nor the manifest URL. | |
1547 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromUnknownManifest) { | |
1548 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1549 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | |
1550 }; | |
1551 | |
pkotwicz
2017/05/16 06:36:37
Nit: Get rid of the new line
mastiz
2017/05/16 11:05:22
All (or most) tests prior to this CL use a new lin
| |
1552 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1553 | |
1554 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(_)).Times(0); | |
1555 | |
1556 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, FAVICON, _)); | |
1557 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); | |
1558 | |
1559 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1560 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1561 ElementsAre(kPageURL, kManifestURL)); | |
1562 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16)); | |
1563 } | |
1564 | |
1565 // Test that the manifest and icon are redownloaded if the icon cached for the | |
1566 // page URL expired. | |
1567 TEST_F(FaviconHandlerManifestsEnabledTest, GetFaviconFromExpiredManifest) { | |
1568 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1569 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1570 }; | |
1571 | |
pkotwicz
2017/05/16 06:36:37
Nit: Nuke the new line
mastiz
2017/05/16 11:05:23
Ditto.
| |
1572 favicon_service_.fake()->Store(kPageURL, kManifestURL, | |
1573 CreateRawBitmapResult(kManifestURL, FAVICON, | |
1574 /*expired=*/true)); | |
1575 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1576 | |
1577 // The third notification is unnecessary, but allows simplifying the code. | |
1578 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(3); | |
1579 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _)); | |
1580 | |
1581 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1582 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1583 ElementsAre(kPageURL, kManifestURL)); | |
1584 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1585 } | |
1586 | |
1587 // Test that the manifest and icon are redownloaded if the icon cached for the | |
1588 // manifest URL expired, which was observed during a visit to a different page | |
1589 // URL. | |
1590 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1591 GetFaviconFromExpiredManifestLinkedFromOtherPage) { | |
1592 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1593 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1594 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1595 }; | |
1596 | |
pkotwicz
2017/05/16 06:36:36
Nit: nuke the new line
mastiz
2017/05/16 11:05:23
Ditto.
| |
1597 favicon_service_.fake()->Store(kSomePreviousPageURL, kManifestURL, | |
1598 CreateRawBitmapResult(kManifestURL, FAVICON, | |
1599 /*expired=*/true)); | |
1600 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1601 | |
1602 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)).Times(2); | |
1603 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _)); | |
1604 | |
1605 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1606 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1607 ElementsAre(kPageURL, kManifestURL)); | |
1608 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1609 } | |
1610 | |
1611 // Test that a favicon corresponding to a web manifest is reported when: | |
1612 // - There is data in the database for neither the page URL nor the manifest | |
1613 // URL. | |
1614 // - There is data in the database for the icon URL listed in the manifest. | |
1615 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1616 GetFaviconFromUnknownManifestButKnownIcon) { | |
1617 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1618 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1619 FaviconURL(kIconURL16x16, FAVICON, kEmptySizes), | |
1620 }; | |
1621 | |
pkotwicz
2017/05/16 06:36:36
Nit: Nuke the new line
mastiz
2017/05/16 11:05:23
Ditto.
| |
1622 favicon_service_.fake()->Store(kSomePreviousPageURL, kIconURL16x16, | |
1623 CreateRawBitmapResult(kIconURL16x16)); | |
1624 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1625 | |
1626 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL, _, _)); | |
1627 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); | |
1628 | |
1629 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL); | |
1630 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1631 ElementsAre(kPageURL, kManifestURL)); | |
1632 // This is because, in the current implementation, FaviconHandler only checks | |
1633 // whether there is an icon cached with the manifest URL as the "icon URL" | |
1634 // when a page has a non empty Web Manifest. | |
pkotwicz
2017/05/16 06:36:36
Nit: "non empty" -> "non-empty"
mastiz
2017/05/16 11:05:23
Done and change other preceding occurrences too.
| |
1635 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL16x16)); | |
1636 } | |
1637 | |
1638 // Test that attempting to download a manifest that returns a 404 gets | |
pkotwicz
2017/05/16 06:36:36
Nit: "attempting to download a manifest that retur
mastiz
2017/05/16 11:05:23
Done.
| |
1639 // blacklisted via UnableToDownloadFavicon() AND that the regular favicon is | |
1640 // selected as fallback. | |
1641 TEST_F(FaviconHandlerManifestsEnabledTest, UnknownManifestReturning404) { | |
1642 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1643 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL12x12, _, _)); | |
1644 | |
1645 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1646 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1647 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1648 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL12x12)); | |
1649 } | |
1650 | |
1651 // Test that a manifest that was previously blacklisted via | |
1652 // UnableToDownloadFavicon() is ignored and that the regular favicon is selected | |
1653 // as fallback. | |
1654 TEST_F(FaviconHandlerManifestsEnabledTest, IgnoreManifestWithPrior404) { | |
1655 ON_CALL(favicon_service_, WasUnableToDownloadFavicon(kManifestURL)) | |
1656 .WillByDefault(Return(true)); | |
1657 | |
1658 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL12x12, _, _)); | |
1659 | |
1660 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1661 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1662 ElementsAre(kPageURL, kIconURL12x12)); | |
1663 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL12x12)); | |
1664 } | |
1665 | |
1666 // Test that the regular favicon is selected when: | |
1667 // - The page links to a Web Manifest. | |
1668 // - The Web Manifest does not contain any icon URLs (it is not a 404). | |
1669 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1670 // - The database does not know about the page URL, manifest URL or icon URL. | |
1671 TEST_F(FaviconHandlerManifestsEnabledTest, UnknownManifestWithoutIcons) { | |
1672 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1673 std::vector<favicon::FaviconURL>()); | |
1674 | |
1675 // UnableToDownloadFavicon() is expected to prevent repeated downloads of the | |
1676 // same manifest (which is not otherwise cached, since it doesn't contain | |
1677 // icons). | |
1678 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1679 EXPECT_CALL(favicon_service_, SetFavicons(_, kIconURL12x12, _, _)); | |
1680 | |
1681 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1682 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1683 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1684 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL12x12)); | |
1685 } | |
1686 | |
1687 // Test that the regular favicon is selected when: | |
1688 // - The page links to a Web Manifest. | |
1689 // - The Web Manifest does not contain any icon URLs (it is not a 404). | |
1690 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1691 // - The database does not know about the page URL. | |
1692 // - The database does not know about the manifest URL. | |
1693 // - The database knows about the icon URL. | |
1694 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1695 UnknownManifestWithoutIconsAndKnownRegularIcons) { | |
1696 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1697 | |
pkotwicz
2017/05/16 06:36:36
Nit: Nuke the new line
mastiz
2017/05/16 11:05:23
Same as earlier.
| |
1698 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1699 std::vector<favicon::FaviconURL>()); | |
1700 favicon_service_.fake()->Store(kSomePreviousPageURL, kIconURL12x12, | |
1701 CreateRawBitmapResult(kIconURL12x12)); | |
1702 | |
1703 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | |
1704 | |
1705 // UnableToDownloadFavicon() is expected to prevent repeated downloads of the | |
1706 // same manifest (which is not otherwise cached, since it doesn't contain | |
1707 // icons). | |
1708 EXPECT_CALL(favicon_service_, UnableToDownloadFavicon(kManifestURL)); | |
1709 EXPECT_CALL(favicon_service_, | |
1710 UpdateFaviconMappingsAndFetch(_, kManifestURL, _, _, _, _)); | |
1711 EXPECT_CALL(favicon_service_, | |
1712 UpdateFaviconMappingsAndFetch(_, kIconURL12x12, _, _, _, _)); | |
1713 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL12x12, _, _)); | |
1714 | |
1715 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1716 EXPECT_THAT(favicon_service_.fake()->db_requests(), | |
1717 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1718 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL)); | |
1719 } | |
1720 | |
1721 // Test that the database remains unmodified when: | |
1722 // - The page links to a Web Manifest. | |
1723 // - The Web Manifest does not contain any icon URLs (it is not a 404). | |
1724 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1725 // - The database has a mapping between the page URL to the favicon URL. | |
1726 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1727 UnknownManifestWithoutIconsAndRegularIconInHistory) { | |
1728 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1729 std::vector<favicon::FaviconURL>()); | |
1730 favicon_service_.fake()->Store(kPageURL, kIconURL16x16, | |
1731 CreateRawBitmapResult(kIconURL16x16)); | |
1732 | |
1733 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL16x16, _, _)) | |
1734 .Times(AnyNumber()); | |
1735 | |
1736 InSequence seq; | |
1737 EXPECT_CALL(favicon_service_, | |
1738 UpdateFaviconMappingsAndFetch(_, kManifestURL, _, _, _, _)); | |
1739 // TODO(mastiz): This second write might never happen if for example another | |
1740 // page is loaded. | |
1741 EXPECT_CALL(favicon_service_, | |
1742 UpdateFaviconMappingsAndFetch(_, kIconURL16x16, _, _, _, _)); | |
1743 | |
1744 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}, kManifestURL); | |
1745 | |
1746 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1747 ElementsAre(kPageURL, kManifestURL, kIconURL16x16)); | |
1748 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL)); | |
1749 } | |
1750 | |
1751 // Test that Delegate::OnFaviconUpdated() is called if a page uses Javascript to | |
1752 // modify the page's <link rel="manifest"> tag to point to a different manifest. | |
1753 TEST_F(FaviconHandlerManifestsEnabledTest, ManifestUpdateViaJavascript) { | |
1754 const GURL kManifestURL1("http://www.google.com/manifest1.json"); | |
1755 const GURL kManifestURL2("http://www.google.com/manifest2.json"); | |
1756 const std::vector<favicon::FaviconURL> kManifestIcons1 = { | |
1757 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1758 }; | |
1759 const std::vector<favicon::FaviconURL> kManifestIcons2 = { | |
1760 FaviconURL(kIconURL10x10, FAVICON, kEmptySizes), | |
1761 }; | |
1762 | |
1763 delegate_.fake_manifest_downloader().Add(kManifestURL1, kManifestIcons1); | |
1764 delegate_.fake_manifest_downloader().Add(kManifestURL2, kManifestIcons2); | |
1765 | |
pkotwicz
2017/05/16 06:36:36
For the sake of consistency with the assertions on
mastiz
2017/05/16 11:05:22
Done.
| |
1766 std::unique_ptr<FaviconHandler> handler = | |
1767 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL1); | |
1768 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1769 ElementsAre(kPageURL, kManifestURL1)); | |
1770 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL1, kIconURL64x64)); | |
1771 ASSERT_TRUE(VerifyAndClearExpectations()); | |
1772 | |
1773 // Simulate the page changing it's manifest URL via Javascript. | |
1774 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL2, _, _)); | |
1775 handler->OnUpdateCandidates(kPageURL, | |
1776 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1777 kManifestURL2); | |
1778 base::RunLoop().RunUntilIdle(); | |
1779 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1780 ElementsAre(kManifestURL2)); | |
1781 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL2, kIconURL10x10)); | |
1782 } | |
1783 | |
1784 // Test that Delegate::OnFaviconUpdated() is called if a page uses Javascript to | |
1785 // remove the page's <link rel="manifest"> tag (i.e. no web manifest) WHILE a | |
1786 // lookup to the history database is ongoing for the manifest URL. | |
1787 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1788 RemoveManifestViaJavascriptWhileDatabaseLookup) { | |
1789 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1790 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1791 }; | |
1792 | |
pkotwicz
2017/05/16 06:36:37
Nit: nuke new line
mastiz
2017/05/16 11:05:23
Same as earlier.
| |
1793 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1794 // Defer the database lookup completion to control the exact timing. | |
1795 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kManifestURL); | |
1796 | |
1797 std::unique_ptr<FaviconHandler> handler = | |
1798 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}, kManifestURL); | |
1799 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1800 ElementsAre(kPageURL, kManifestURL)); | |
1801 // Database lookup for |kManifestURL1| is ongoing. | |
pkotwicz
2017/05/16 06:36:35
Nit: kManifestURL1 -> kManifestURL
mastiz
2017/05/16 11:05:23
Done.
| |
1802 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | |
1803 | |
1804 // Simulate the page changing it's manifest URL to empty via Javascript. | |
1805 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kIconURL12x12, _, _)); | |
1806 handler->OnUpdateCandidates( | |
1807 kPageURL, {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, GURL()); | |
1808 // Complete the lookup. | |
1809 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | |
1810 base::RunLoop().RunUntilIdle(); | |
1811 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1812 ElementsAre(kPageURL, kManifestURL, kIconURL12x12)); | |
1813 EXPECT_THAT(delegate_.downloads(), ElementsAre(kIconURL12x12)); | |
1814 } | |
1815 | |
1816 // Test that Delegate::OnFaviconUpdated() is called a page without manifest uses | |
1817 // Javascript to add a <link rel="manifest"> tag (i.e. a new web manifest) WHILE | |
1818 // a lookup to the history database is ongoing for the icon URL. | |
1819 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1820 AddManifestViaJavascriptWhileDatabaseLookup) { | |
1821 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1822 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1823 }; | |
1824 | |
1825 delegate_.fake_manifest_downloader().Add(kManifestURL, kManifestIcons); | |
1826 // Defer the database lookup completion to control the exact timing. | |
1827 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL12x12); | |
1828 | |
1829 std::unique_ptr<FaviconHandler> handler = | |
1830 RunHandlerWithSimpleFaviconCandidates({kIconURL12x12}); | |
1831 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1832 ElementsAre(kPageURL, kIconURL12x12)); | |
1833 // Database lookup for |kIconURL12x12| is ongoing. | |
1834 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | |
1835 | |
1836 // Simulate the page changing it's manifest URL to |kManifestURL| via | |
1837 // Javascript. | |
1838 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); | |
1839 handler->OnUpdateCandidates(kPageURL, | |
1840 {FaviconURL(kIconURL12x12, FAVICON, kEmptySizes)}, | |
1841 kManifestURL); | |
1842 // Complete the lookup. | |
1843 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | |
1844 base::RunLoop().RunUntilIdle(); | |
1845 ASSERT_THAT(favicon_service_.fake()->db_requests(), | |
1846 ElementsAre(kPageURL, kIconURL12x12, kManifestURL)); | |
1847 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL, kIconURL64x64)); | |
1848 } | |
1849 | |
1850 // Test that SetFavicons() is not called when: | |
1851 // - The page doesn't initially link to a Web Manifest. | |
1852 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1853 // - The database does not know about the page URL or icon URL. | |
1854 // - While the icon is being downloaded, the page uses Javascript to add a | |
1855 // <link rel="manifest"> tag. | |
1856 // - The database has bitmap data for the manifest URL. | |
1857 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1858 AddKnownManifestViaJavascriptWhileImageDownload) { | |
1859 const GURL kSomePreviousPageURL("https://www.google.com/previous"); | |
1860 | |
1861 favicon_service_.fake()->Store(kSomePreviousPageURL, kManifestURL, | |
1862 CreateRawBitmapResult(kManifestURL)); | |
1863 | |
1864 // Defer the image download completion to control the exact timing. | |
1865 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL16x16); | |
1866 | |
1867 std::unique_ptr<FaviconHandler> handler = | |
1868 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | |
1869 | |
1870 ASSERT_TRUE(VerifyAndClearExpectations()); | |
1871 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); | |
1872 | |
1873 // Simulate the page changing it's manifest URL to |kManifestURL| via | |
1874 // Javascript. Should invalidate the ongoing image download. | |
1875 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | |
1876 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL, _, _)); | |
1877 | |
1878 handler->OnUpdateCandidates(kPageURL, | |
1879 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, | |
1880 kManifestURL); | |
1881 | |
1882 // Finalizes download, which should be thrown away as the manifest URLs was | |
pkotwicz
2017/05/16 06:36:36
Nit: URLs -> URL
mastiz
2017/05/16 11:05:23
Done.
| |
1883 // provided. | |
1884 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); | |
1885 base::RunLoop().RunUntilIdle(); | |
1886 } | |
1887 | |
1888 // Test that SetFavicons() is not called when: | |
1889 // - The page doesn't initially link to a Web Manifest. | |
1890 // - The page has an icon URL provided via a <link rel="icon"> tag. | |
1891 // - The database does not know about the page URL or icon URL. | |
1892 // - During the database lookup, the page uses Javascript to add a | |
1893 // <link rel="manifest"> tag. | |
1894 // - The database does not know about the manifest URL. | |
1895 // - The manifest contains no icons. | |
1896 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1897 AddManifestWithoutIconsViaJavascriptWhileDatabaseLookup) { | |
1898 delegate_.fake_manifest_downloader().Add(kManifestURL, | |
1899 std::vector<favicon::FaviconURL>()); | |
1900 | |
1901 // Defer the database lookup completion to control the exact timing. | |
1902 favicon_service_.fake()->SetRunCallbackManuallyForUrl(kIconURL16x16); | |
1903 | |
1904 std::unique_ptr<FaviconHandler> handler = | |
1905 RunHandlerWithSimpleFaviconCandidates({kIconURL16x16}); | |
1906 | |
1907 ASSERT_TRUE(VerifyAndClearExpectations()); | |
1908 ASSERT_TRUE(favicon_service_.fake()->HasPendingManualCallback()); | |
1909 | |
1910 EXPECT_CALL(favicon_service_, SetFavicons(_, _, _, _)).Times(0); | |
1911 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, _, _, _)).Times(0); | |
pkotwicz
2017/05/16 06:36:36
This test seems wrong. FaviconHandler should downl
mastiz
2017/05/16 11:05:23
Fixed, PTAL.
| |
1912 | |
1913 handler->OnUpdateCandidates(kPageURL, | |
1914 {FaviconURL(kIconURL16x16, FAVICON, kEmptySizes)}, | |
1915 kManifestURL); | |
1916 | |
1917 // Finalizes lookup, which should be thrown away as the manifest URLs was | |
1918 // provided. | |
1919 EXPECT_TRUE(favicon_service_.fake()->RunCallbackManually()); | |
1920 base::RunLoop().RunUntilIdle(); | |
1921 } | |
1922 | |
1923 // Test that SetFavicons() is called when: | |
1924 // - The page link to one Web Manifest, which contains one icon. | |
pkotwicz
2017/05/16 06:36:36
Nit: link -> links
mastiz
2017/05/16 11:05:24
Done.
| |
1925 // - The database does not know about the page URL, icon URL or manifest URL. | |
1926 // - During image download, the page updates the manifest URL to point to | |
1927 // another manifest. | |
1928 // - The second manifest contains the same icons as the first. | |
1929 TEST_F(FaviconHandlerManifestsEnabledTest, | |
1930 UpdateManifestWithSameIconURLsWhileDownloading) { | |
1931 const GURL kManifestURL1("http://www.google.com/manifest1.json"); | |
1932 const GURL kManifestURL2("http://www.google.com/manifest2.json"); | |
1933 const std::vector<favicon::FaviconURL> kManifestIcons = { | |
1934 FaviconURL(kIconURL64x64, FAVICON, kEmptySizes), | |
1935 }; | |
1936 | |
1937 delegate_.fake_manifest_downloader().Add(kManifestURL1, kManifestIcons); | |
1938 delegate_.fake_manifest_downloader().Add(kManifestURL2, kManifestIcons); | |
1939 | |
1940 // Defer the download completion to control the exact timing. | |
1941 delegate_.fake_image_downloader().SetRunCallbackManuallyForUrl(kIconURL64x64); | |
1942 | |
1943 std::unique_ptr<FaviconHandler> handler = | |
1944 RunHandlerWithSimpleFaviconCandidates(URLVector(), kManifestURL1); | |
1945 | |
1946 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL1, kIconURL64x64)); | |
1947 ASSERT_TRUE(VerifyAndClearExpectations()); | |
1948 ASSERT_TRUE(delegate_.fake_image_downloader().HasPendingManualCallback()); | |
1949 | |
1950 // Calling OnUpdateCandidates() with a different manifest URL should trigger | |
1951 // its download. | |
1952 handler->OnUpdateCandidates(kPageURL, std::vector<favicon::FaviconURL>(), | |
1953 kManifestURL2); | |
1954 base::RunLoop().RunUntilIdle(); | |
1955 EXPECT_THAT(delegate_.downloads(), ElementsAre(kManifestURL2, kIconURL64x64)); | |
1956 | |
1957 // Complete the download. | |
1958 EXPECT_CALL(favicon_service_, SetFavicons(_, kManifestURL2, _, _)); | |
1959 EXPECT_CALL(delegate_, OnFaviconUpdated(_, _, kManifestURL2, _, _)); | |
1960 EXPECT_TRUE(delegate_.fake_image_downloader().RunCallbackManually()); | |
1961 base::RunLoop().RunUntilIdle(); | |
1962 } | |
1963 | |
1373 } // namespace | 1964 } // namespace |
1374 } // namespace favicon | 1965 } // namespace favicon |
OLD | NEW |