API for binary_dependencies, and import changes to call the new API.
[chromium-blink-merge.git] / components / favicon / content / content_favicon_driver_unittest.cc
blob4851945d818c72a39c66905761f8d7eea8d59da1
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/favicon/content/content_favicon_driver.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "components/favicon/core/favicon_client.h"
9 #include "components/favicon/core/favicon_handler.h"
10 #include "components/favicon/core/favicon_service.h"
11 #include "content/public/test/test_renderer_host.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/gfx/favicon_size.h"
15 namespace favicon {
16 namespace {
18 class ContentFaviconDriverTest : public content::RenderViewHostTestHarness {
19 public:
20 ContentFaviconDriverTest() {}
22 ~ContentFaviconDriverTest() override {}
24 private:
25 DISALLOW_COPY_AND_ASSIGN(ContentFaviconDriverTest);
28 // Test that Favicon is not requested repeatedly during the same session if
29 // server returns HTTP 404 status.
30 TEST_F(ContentFaviconDriverTest, UnableToDownloadFavicon) {
31 const GURL missing_icon_url("http://www.google.com/favicon.ico");
32 const GURL another_icon_url("http://www.youtube.com/favicon.ico");
34 scoped_ptr<FaviconService> favicon_service(
35 new FaviconService(nullptr, nullptr));
36 ContentFaviconDriver::CreateForWebContents(
37 web_contents(), favicon_service.get(), nullptr, nullptr);
38 ContentFaviconDriver* content_favicon_driver =
39 ContentFaviconDriver::FromWebContents(web_contents());
41 std::vector<SkBitmap> empty_icons;
42 std::vector<gfx::Size> empty_icon_sizes;
43 int download_id = 0;
45 // Try to download missing icon.
46 download_id = content_favicon_driver->StartDownload(missing_icon_url, 0);
47 EXPECT_NE(0, download_id);
48 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
50 // Report download failure with HTTP 503 status.
51 content_favicon_driver->DidDownloadFavicon(download_id, 503, missing_icon_url,
52 empty_icons, empty_icon_sizes);
53 // Icon is not marked as UnableToDownload as HTTP status is not 404.
54 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
56 // Try to download again.
57 download_id = content_favicon_driver->StartDownload(missing_icon_url, 0);
58 EXPECT_NE(0, download_id);
59 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
61 // Report download failure with HTTP 404 status.
62 content_favicon_driver->DidDownloadFavicon(download_id, 404, missing_icon_url,
63 empty_icons, empty_icon_sizes);
64 // Icon is marked as UnableToDownload.
65 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
67 // Try to download again.
68 download_id = content_favicon_driver->StartDownload(missing_icon_url, 0);
69 // Download is not started and Icon is still marked as UnableToDownload.
70 EXPECT_EQ(0, download_id);
71 EXPECT_TRUE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
73 // Try to download another icon.
74 download_id = content_favicon_driver->StartDownload(another_icon_url, 0);
75 // Download is started as another icon URL is not same as missing_icon_url.
76 EXPECT_NE(0, download_id);
77 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
79 // Clear the list of missing icons.
80 favicon_service->ClearUnableToDownloadFavicons();
81 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
82 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(another_icon_url));
84 // Try to download again.
85 download_id = content_favicon_driver->StartDownload(missing_icon_url, 0);
86 EXPECT_NE(0, download_id);
87 // Report download success with HTTP 200 status.
88 content_favicon_driver->DidDownloadFavicon(download_id, 200, missing_icon_url,
89 empty_icons, empty_icon_sizes);
90 // Icon is not marked as UnableToDownload as HTTP status is not 404.
91 EXPECT_FALSE(favicon_service->WasUnableToDownloadFavicon(missing_icon_url));
93 favicon_service->Shutdown();
96 } // namespace
97 } // namespace favicon