| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/favicon/favicon_handler.h" | 6 #include "chrome/browser/favicon/favicon_handler.h" |
| 7 #include "chrome/browser/favicon/favicon_service.h" | 7 #include "chrome/browser/favicon/favicon_service.h" |
| 8 #include "chrome/browser/favicon/favicon_service_factory.h" | 8 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 9 #include "chrome/browser/history/history_service_factory.h" | 9 #include "chrome/browser/history/history_service_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 | 446 |
| 447 favicon_handler->OnUpdateFaviconURL(candidate_icons); | 447 favicon_handler->OnUpdateFaviconURL(candidate_icons); |
| 448 } | 448 } |
| 449 | 449 |
| 450 virtual void SetUp() { | 450 virtual void SetUp() { |
| 451 // The score computed by SelectFaviconFrames() is dependent on the supported | 451 // The score computed by SelectFaviconFrames() is dependent on the supported |
| 452 // scale factors of the platform. It is used for determining the goodness of | 452 // scale factors of the platform. It is used for determining the goodness of |
| 453 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). | 453 // a downloaded bitmap in FaviconHandler::OnDidDownloadFavicon(). |
| 454 // Force the values of the scale factors so that the tests produce the same | 454 // Force the values of the scale factors so that the tests produce the same |
| 455 // results on all platforms. | 455 // results on all platforms. |
| 456 std::vector<ui::ScaleFactor> scale_factors; | 456 std::vector<ui::ScaleFactor> favicon_scales; |
| 457 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 457 favicon_scales.push_back(ui::SCALE_FACTOR_100P); |
| 458 scoped_set_supported_scale_factors_.reset( | 458 scoped_set_supported_favicon_scales_.reset( |
| 459 new ui::test::ScopedSetSupportedScaleFactors(scale_factors)); | 459 new ui::test::ScopedSetSupportedScaleFactors(favicon_scales)); |
| 460 | 460 |
| 461 ChromeRenderViewHostTestHarness::SetUp(); | 461 ChromeRenderViewHostTestHarness::SetUp(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 virtual void TearDown() OVERRIDE { | 464 virtual void TearDown() OVERRIDE { |
| 465 Profile* profile = Profile::FromBrowserContext( | 465 Profile* profile = Profile::FromBrowserContext( |
| 466 web_contents()->GetBrowserContext()); | 466 web_contents()->GetBrowserContext()); |
| 467 FaviconServiceFactory::GetInstance()->SetTestingFactory( | 467 FaviconServiceFactory::GetInstance()->SetTestingFactory( |
| 468 profile, NULL); | 468 profile, NULL); |
| 469 ChromeRenderViewHostTestHarness::TearDown(); | 469 ChromeRenderViewHostTestHarness::TearDown(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 private: | 472 private: |
| 473 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> | 473 typedef scoped_ptr<ui::test::ScopedSetSupportedScaleFactors> |
| 474 ScopedSetSupportedScaleFactors; | 474 ScopedSetSupportedScaleFactors; |
| 475 ScopedSetSupportedScaleFactors scoped_set_supported_scale_factors_; | 475 ScopedSetSupportedScaleFactors scoped_set_supported_favicon_scales_; |
| 476 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); | 476 DISALLOW_COPY_AND_ASSIGN(FaviconHandlerTest); |
| 477 }; | 477 }; |
| 478 | 478 |
| 479 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { | 479 TEST_F(FaviconHandlerTest, GetFaviconFromHistory) { |
| 480 const GURL page_url("http://www.google.com"); | 480 const GURL page_url("http://www.google.com"); |
| 481 const GURL icon_url("http://www.google.com/favicon"); | 481 const GURL icon_url("http://www.google.com/favicon"); |
| 482 | 482 |
| 483 TestFaviconDriver driver; | 483 TestFaviconDriver driver; |
| 484 TestFaviconClient client; | 484 TestFaviconClient client; |
| 485 TestFaviconHandler helper( | 485 TestFaviconHandler helper( |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 std::vector<gfx::Size>()), | 1049 std::vector<gfx::Size>()), |
| 1050 FaviconURL(GURL("http://www.google.com/d"), | 1050 FaviconURL(GURL("http://www.google.com/d"), |
| 1051 favicon_base::FAVICON, | 1051 favicon_base::FAVICON, |
| 1052 std::vector<gfx::Size>()), | 1052 std::vector<gfx::Size>()), |
| 1053 FaviconURL(GURL("http://www.google.com/e"), | 1053 FaviconURL(GURL("http://www.google.com/e"), |
| 1054 favicon_base::FAVICON, | 1054 favicon_base::FAVICON, |
| 1055 std::vector<gfx::Size>())}; | 1055 std::vector<gfx::Size>())}; |
| 1056 | 1056 |
| 1057 // Set the supported scale factors to 1x and 2x. This affects the behavior of | 1057 // Set the supported scale factors to 1x and 2x. This affects the behavior of |
| 1058 // SelectFaviconFrames(). | 1058 // SelectFaviconFrames(). |
| 1059 std::vector<ui::ScaleFactor> scale_factors; | 1059 std::vector<ui::ScaleFactor> favicon_scales; |
| 1060 scale_factors.push_back(ui::SCALE_FACTOR_100P); | 1060 favicon_scales.push_back(ui::SCALE_FACTOR_100P); |
| 1061 scale_factors.push_back(ui::SCALE_FACTOR_200P); | 1061 favicon_scales.push_back(ui::SCALE_FACTOR_200P); |
| 1062 ui::test::ScopedSetSupportedScaleFactors scoped_supported(scale_factors); | 1062 ui::test::ScopedSetSupportedScaleFactors scoped_supported(favicon_scales); |
| 1063 | 1063 |
| 1064 // 1) Test that if there are several single resolution favicons to choose from | 1064 // 1) Test that if there are several single resolution favicons to choose from |
| 1065 // that the largest exact match is chosen. | 1065 // that the largest exact match is chosen. |
| 1066 TestFaviconDriver driver1; | 1066 TestFaviconDriver driver1; |
| 1067 TestFaviconClient client; | 1067 TestFaviconClient client; |
| 1068 TestFaviconHandler handler1( | 1068 TestFaviconHandler handler1( |
| 1069 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); | 1069 kPageURL, &client, &driver1, FaviconHandler::FAVICON, false); |
| 1070 | 1070 |
| 1071 const int kSizes1[] = { 16, 24, 32, 48, 256 }; | 1071 const int kSizes1[] = { 16, 24, 32, 48, 256 }; |
| 1072 std::vector<FaviconURL> urls1(kSourceIconURLs, | 1072 std::vector<FaviconURL> urls1(kSourceIconURLs, |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); | 1481 download_id = favicon_tab_helper->StartDownload(missing_icon_url, 0); |
| 1482 EXPECT_NE(0, download_id); | 1482 EXPECT_NE(0, download_id); |
| 1483 // Report download success with HTTP 200 status. | 1483 // Report download success with HTTP 200 status. |
| 1484 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, | 1484 favicon_tab_helper->DidDownloadFavicon(download_id, 200, missing_icon_url, |
| 1485 empty_icons, empty_icon_sizes); | 1485 empty_icons, empty_icon_sizes); |
| 1486 // Icon is not marked as UnableToDownload as HTTP status is not 404. | 1486 // Icon is not marked as UnableToDownload as HTTP status is not 404. |
| 1487 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); | 1487 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url)); |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 } // namespace. | 1490 } // namespace. |
| OLD | NEW |