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 "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/favicon/chrome_favicon_client.h" | 8 #include "chrome/browser/favicon/chrome_favicon_client.h" |
9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" | 9 #include "chrome/browser/favicon/chrome_favicon_client_factory.h" |
10 #include "chrome/browser/favicon/favicon_service.h" | 10 #include "chrome/browser/favicon/favicon_service.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 private: | 172 private: |
173 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); | 173 DISALLOW_COPY_AND_ASSIGN(HistoryRequestHandler); |
174 }; | 174 }; |
175 | 175 |
176 } // namespace | 176 } // namespace |
177 | 177 |
178 class TestFaviconClient : public FaviconClient { | 178 class TestFaviconClient : public FaviconClient { |
179 public: | 179 public: |
180 virtual ~TestFaviconClient() {}; | 180 virtual ~TestFaviconClient() {}; |
181 | 181 |
182 virtual FaviconService* GetFaviconService() OVERRIDE { | 182 virtual FaviconService* GetFaviconService() override { |
183 // Just give none NULL value, so overridden methods can be hit. | 183 // Just give none NULL value, so overridden methods can be hit. |
184 return (FaviconService*)(1); | 184 return (FaviconService*)(1); |
185 } | 185 } |
186 | 186 |
187 virtual bool IsBookmarked(const GURL& url) OVERRIDE { return false; } | 187 virtual bool IsBookmarked(const GURL& url) override { return false; } |
188 }; | 188 }; |
189 | 189 |
190 class TestFaviconDriver : public FaviconDriver { | 190 class TestFaviconDriver : public FaviconDriver { |
191 public: | 191 public: |
192 TestFaviconDriver() : favicon_validity_(false) {} | 192 TestFaviconDriver() : favicon_validity_(false) {} |
193 | 193 |
194 virtual ~TestFaviconDriver() { | 194 virtual ~TestFaviconDriver() { |
195 } | 195 } |
196 | 196 |
197 virtual bool IsOffTheRecord() OVERRIDE { return false; } | 197 virtual bool IsOffTheRecord() override { return false; } |
198 | 198 |
199 virtual const gfx::Image GetActiveFaviconImage() OVERRIDE { return image_; } | 199 virtual const gfx::Image GetActiveFaviconImage() override { return image_; } |
200 | 200 |
201 virtual const GURL GetActiveFaviconURL() OVERRIDE { return favicon_url_; } | 201 virtual const GURL GetActiveFaviconURL() override { return favicon_url_; } |
202 | 202 |
203 virtual bool GetActiveFaviconValidity() OVERRIDE { return favicon_validity_; } | 203 virtual bool GetActiveFaviconValidity() override { return favicon_validity_; } |
204 | 204 |
205 virtual const GURL GetActiveURL() OVERRIDE { return url_; } | 205 virtual const GURL GetActiveURL() override { return url_; } |
206 | 206 |
207 virtual void SetActiveFaviconImage(gfx::Image image) OVERRIDE { | 207 virtual void SetActiveFaviconImage(gfx::Image image) override { |
208 image_ = image; | 208 image_ = image; |
209 } | 209 } |
210 | 210 |
211 virtual void SetActiveFaviconURL(GURL favicon_url) OVERRIDE { | 211 virtual void SetActiveFaviconURL(GURL favicon_url) override { |
212 favicon_url_ = favicon_url; | 212 favicon_url_ = favicon_url; |
213 } | 213 } |
214 | 214 |
215 virtual void SetActiveFaviconValidity(bool favicon_validity) OVERRIDE { | 215 virtual void SetActiveFaviconValidity(bool favicon_validity) override { |
216 favicon_validity_ = favicon_validity; | 216 favicon_validity_ = favicon_validity; |
217 } | 217 } |
218 | 218 |
219 virtual int StartDownload(const GURL& url, | 219 virtual int StartDownload(const GURL& url, |
220 int max_bitmap_size) OVERRIDE { | 220 int max_bitmap_size) override { |
221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " | 221 ADD_FAILURE() << "TestFaviconDriver::StartDownload() " |
222 << "should never be called in tests."; | 222 << "should never be called in tests."; |
223 return -1; | 223 return -1; |
224 } | 224 } |
225 | 225 |
226 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { | 226 virtual void NotifyFaviconUpdated(bool icon_url_changed) override { |
227 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " | 227 ADD_FAILURE() << "TestFaviconDriver::NotifyFaviconUpdated() " |
228 << "should never be called in tests."; | 228 << "should never be called in tests."; |
229 } | 229 } |
230 | 230 |
231 void SetActiveURL(GURL url) { url_ = url; } | 231 void SetActiveURL(GURL url) { url_ = url; } |
232 | 232 |
233 private: | 233 private: |
234 GURL favicon_url_; | 234 GURL favicon_url_; |
235 GURL url_; | 235 GURL url_; |
236 gfx::Image image_; | 236 gfx::Image image_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 const FaviconCandidate& best_favicon_candidate() { | 291 const FaviconCandidate& best_favicon_candidate() { |
292 return best_favicon_candidate_; | 292 return best_favicon_candidate_; |
293 } | 293 } |
294 | 294 |
295 protected: | 295 protected: |
296 virtual void UpdateFaviconMappingAndFetch( | 296 virtual void UpdateFaviconMappingAndFetch( |
297 const GURL& page_url, | 297 const GURL& page_url, |
298 const GURL& icon_url, | 298 const GURL& icon_url, |
299 favicon_base::IconType icon_type, | 299 favicon_base::IconType icon_type, |
300 const favicon_base::FaviconResultsCallback& callback, | 300 const favicon_base::FaviconResultsCallback& callback, |
301 base::CancelableTaskTracker* tracker) OVERRIDE { | 301 base::CancelableTaskTracker* tracker) override { |
302 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, | 302 history_handler_.reset(new HistoryRequestHandler(page_url, icon_url, |
303 icon_type, callback)); | 303 icon_type, callback)); |
304 } | 304 } |
305 | 305 |
306 virtual void GetFaviconFromFaviconService( | 306 virtual void GetFaviconFromFaviconService( |
307 const GURL& icon_url, | 307 const GURL& icon_url, |
308 favicon_base::IconType icon_type, | 308 favicon_base::IconType icon_type, |
309 const favicon_base::FaviconResultsCallback& callback, | 309 const favicon_base::FaviconResultsCallback& callback, |
310 base::CancelableTaskTracker* tracker) OVERRIDE { | 310 base::CancelableTaskTracker* tracker) override { |
311 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, | 311 history_handler_.reset(new HistoryRequestHandler(GURL(), icon_url, |
312 icon_type, callback)); | 312 icon_type, callback)); |
313 } | 313 } |
314 | 314 |
315 virtual void GetFaviconForURLFromFaviconService( | 315 virtual void GetFaviconForURLFromFaviconService( |
316 const GURL& page_url, | 316 const GURL& page_url, |
317 int icon_types, | 317 int icon_types, |
318 const favicon_base::FaviconResultsCallback& callback, | 318 const favicon_base::FaviconResultsCallback& callback, |
319 base::CancelableTaskTracker* tracker) OVERRIDE { | 319 base::CancelableTaskTracker* tracker) override { |
320 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), | 320 history_handler_.reset(new HistoryRequestHandler(page_url, GURL(), |
321 icon_types, callback)); | 321 icon_types, callback)); |
322 } | 322 } |
323 | 323 |
324 virtual int DownloadFavicon(const GURL& image_url, | 324 virtual int DownloadFavicon(const GURL& image_url, |
325 int max_bitmap_size) OVERRIDE { | 325 int max_bitmap_size) override { |
326 download_id_++; | 326 download_id_++; |
327 std::vector<int> sizes; | 327 std::vector<int> sizes; |
328 sizes.push_back(0); | 328 sizes.push_back(0); |
329 download_handler_->AddDownload( | 329 download_handler_->AddDownload( |
330 download_id_, image_url, sizes, max_bitmap_size); | 330 download_id_, image_url, sizes, max_bitmap_size); |
331 return download_id_; | 331 return download_id_; |
332 } | 332 } |
333 | 333 |
334 virtual void SetHistoryFavicons(const GURL& page_url, | 334 virtual void SetHistoryFavicons(const GURL& page_url, |
335 const GURL& icon_url, | 335 const GURL& icon_url, |
336 favicon_base::IconType icon_type, | 336 favicon_base::IconType icon_type, |
337 const gfx::Image& image) OVERRIDE { | 337 const gfx::Image& image) override { |
338 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); | 338 scoped_refptr<base::RefCountedMemory> bytes = image.As1xPNGBytes(); |
339 std::vector<unsigned char> bitmap_data(bytes->front(), | 339 std::vector<unsigned char> bitmap_data(bytes->front(), |
340 bytes->front() + bytes->size()); | 340 bytes->front() + bytes->size()); |
341 history_handler_.reset(new HistoryRequestHandler( | 341 history_handler_.reset(new HistoryRequestHandler( |
342 page_url, icon_url, icon_type, bitmap_data, image.Size())); | 342 page_url, icon_url, icon_type, bitmap_data, image.Size())); |
343 } | 343 } |
344 | 344 |
345 virtual bool ShouldSaveFavicon(const GURL& url) OVERRIDE { | 345 virtual bool ShouldSaveFavicon(const GURL& url) override { |
346 return true; | 346 return true; |
347 } | 347 } |
348 | 348 |
349 virtual void NotifyFaviconUpdated(bool icon_url_changed) OVERRIDE { | 349 virtual void NotifyFaviconUpdated(bool icon_url_changed) override { |
350 ++num_favicon_updates_; | 350 ++num_favicon_updates_; |
351 } | 351 } |
352 | 352 |
353 GURL page_url_; | 353 GURL page_url_; |
354 | 354 |
355 private: | 355 private: |
356 | 356 |
357 // The unique id of a download request. It will be returned to a | 357 // The unique id of a download request. It will be returned to a |
358 // FaviconHandler. | 358 // FaviconHandler. |
359 int download_id_; | 359 int download_id_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 // Force the values of the scale factors so that the tests produce the same | 457 // Force the values of the scale factors so that the tests produce the same |
458 // results on all platforms. | 458 // results on all platforms. |
459 std::vector<ui::ScaleFactor> scale_factors; | 459 std::vector<ui::ScaleFactor> scale_factors; |
460 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 460 scale_factors.push_back(ui::SCALE_FACTOR_100P); |
461 scoped_set_supported_scale_factors_.reset( | 461 scoped_set_supported_scale_factors_.reset( |
462 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 462 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); |
463 | 463 |
464 ChromeRenderViewHostTestHarness::SetUp(); | 464 ChromeRenderViewHostTestHarness::SetUp(); |
465 } | 465 } |
466 | 466 |
467 virtual void TearDown() OVERRIDE { | 467 virtual void TearDown() override { |
468 Profile* profile = Profile::FromBrowserContext( | 468 Profile* profile = Profile::FromBrowserContext( |
469 web_contents()->GetBrowserContext()); | 469 web_contents()->GetBrowserContext()); |
470 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 470 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
471 profile, NULL); | 471 profile, NULL); |
472 ChromeRenderViewHostTestHarness::TearDown(); | 472 ChromeRenderViewHostTestHarness::TearDown(); |
473 } | 473 } |
474 | 474 |
475 private: | 475 private: |
476 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 476 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
477 ScopedSetSupportedScaleFactors; | 477 ScopedSetSupportedScaleFactors; |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1486 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1486 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
1487 EXPECT_NE(0, download_id); | 1487 EXPECT_NE(0, download_id); |
1488 // Report download success with HTTP 200 status. | 1488 // Report download success with HTTP 200 status. |
1489 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1489 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
1490 empty_icons, empty_icon_sizes); | 1490 empty_icons, empty_icon_sizes); |
1491 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1491 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
1492 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1492 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
1493 } | 1493 } |
1494 | 1494 |
1495 } // namespace. | 1495 } // namespace. |
OLD | NEW |