Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: components/favicon/content/content_favicon_driver_unittest.cc

Issue 2710953002: Add metrics for quantity and type of Favicon candidates (Closed)
Patch Set: Adress comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/favicon/content/BUILD.gn ('k') | components/favicon/core/favicon_driver_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/content/content_favicon_driver.h" 5 #include "components/favicon/content/content_favicon_driver.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "base/test/histogram_tester.h"
12 #include "components/favicon/core/favicon_client.h" 13 #include "components/favicon/core/favicon_client.h"
13 #include "components/favicon/core/favicon_handler.h" 14 #include "components/favicon/core/favicon_handler.h"
14 #include "components/favicon/core/test/mock_favicon_service.h" 15 #include "components/favicon/core/test/mock_favicon_service.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/common/favicon_url.h" 17 #include "content/public/common/favicon_url.h"
17 #include "content/public/test/test_renderer_host.h" 18 #include "content/public/test/test_renderer_host.h"
18 #include "content/public/test/web_contents_tester.h" 19 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/gfx/favicon_size.h" 23 #include "ui/gfx/favicon_size.h"
23 24
24 namespace favicon { 25 namespace favicon {
25 namespace { 26 namespace {
26 27
28 using testing::ElementsAre;
27 using testing::Return; 29 using testing::Return;
28 using testing::_; 30 using testing::_;
29 31
30 class ContentFaviconDriverTest : public content::RenderViewHostTestHarness { 32 class ContentFaviconDriverTest : public content::RenderViewHostTestHarness {
31 protected: 33 protected:
32 const std::vector<gfx::Size> kEmptyIconSizes; 34 const std::vector<gfx::Size> kEmptyIconSizes;
33 const std::vector<SkBitmap> kEmptyIcons; 35 const std::vector<SkBitmap> kEmptyIcons;
34 const std::vector<favicon_base::FaviconRawBitmapResult> kEmptyRawBitmapResult; 36 const std::vector<favicon_base::FaviconRawBitmapResult> kEmptyRawBitmapResult;
35 const GURL kPageURL = GURL("http://www.google.com/"); 37 const GURL kPageURL = GURL("http://www.google.com/");
36 const GURL kIconURL = GURL("http://www.google.com/favicon.ico"); 38 const GURL kIconURL = GURL("http://www.google.com/favicon.ico");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL)); 130 EXPECT_FALSE(web_contents_tester()->HasPendingDownloadImage(kIconURL));
129 } 131 }
130 132
131 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no 133 // Test that ContentFaviconDriver ignores updated favicon URLs if there is no
132 // last committed entry. This occurs when script is injected in about:blank. 134 // last committed entry. This occurs when script is injected in about:blank.
133 // See crbug.com/520759 for more details 135 // See crbug.com/520759 for more details
134 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) { 136 TEST_F(ContentFaviconDriverTest, FaviconUpdateNoLastCommittedEntry) {
135 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry()); 137 ASSERT_EQ(nullptr, web_contents()->GetController().GetLastCommittedEntry());
136 138
137 std::vector<content::FaviconURL> favicon_urls; 139 std::vector<content::FaviconURL> favicon_urls;
138 favicon_urls.push_back(content::FaviconURL( 140 favicon_urls.push_back(
139 GURL("http://www.google.ca/favicon.ico"), content::FaviconURL::FAVICON, 141 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"),
140 std::vector<gfx::Size>())); 142 content::FaviconURL::FAVICON, kEmptyIconSizes));
141 favicon::ContentFaviconDriver* driver = 143 favicon::ContentFaviconDriver* driver =
142 favicon::ContentFaviconDriver::FromWebContents(web_contents()); 144 favicon::ContentFaviconDriver::FromWebContents(web_contents());
143 static_cast<content::WebContentsObserver*>(driver) 145 static_cast<content::WebContentsObserver*>(driver)
144 ->DidUpdateFaviconURL(favicon_urls); 146 ->DidUpdateFaviconURL(favicon_urls);
145 147
146 // Test that ContentFaviconDriver ignored the favicon url update. 148 // Test that ContentFaviconDriver ignored the favicon url update.
147 EXPECT_TRUE(driver->favicon_urls().empty()); 149 EXPECT_TRUE(driver->favicon_urls().empty());
148 } 150 }
149 151
152 TEST_F(ContentFaviconDriverTest, RecordsHistorgramsForCandidates) {
153 const std::vector<gfx::Size> kSizes16x16and32x32({{16, 16}, {32, 32}});
154 base::HistogramTester tester;
155 content::WebContentsObserver* driver_as_observer =
156 ContentFaviconDriver::FromWebContents(web_contents());
157
158 // Navigation to a page updating one icon.
159 NavigateAndCommit(GURL("http://www.youtube.com"));
160 driver_as_observer->DidUpdateFaviconURL(
161 {content::FaviconURL(GURL("http://www.youtube.com/favicon.ico"),
162 content::FaviconURL::FAVICON, kSizes16x16and32x32)});
163
164 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"),
165 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
166 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"),
167 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
168 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"),
169 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
170
171 std::vector<content::FaviconURL> favicon_urls = {
172 content::FaviconURL(GURL("http://www.google.ca/favicon.ico"),
173 content::FaviconURL::FAVICON, kSizes16x16and32x32),
174 content::FaviconURL(GURL("http://www.google.ca/precomposed_icon.png"),
175 content::FaviconURL::TOUCH_PRECOMPOSED_ICON,
176 kEmptyIconSizes),
177 content::FaviconURL(GURL("http://www.google.ca/touch_icon.png"),
178 content::FaviconURL::TOUCH_ICON, kEmptyIconSizes)};
179
180 // Double navigation to a page with 3 different icons.
181 NavigateAndCommit(GURL("http://www.google.ca"));
182 driver_as_observer->DidUpdateFaviconURL(favicon_urls);
183 NavigateAndCommit(GURL("http://www.google.ca"));
184 driver_as_observer->DidUpdateFaviconURL(favicon_urls);
185
186 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesCount"),
187 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1),
188 base::Bucket(/*min=*/3, /*count=*/2)));
189 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithDefinedSizesCount"),
190 ElementsAre(base::Bucket(/*min=*/1, /*count=*/3)));
191 EXPECT_THAT(tester.GetAllSamples("Favicons.CandidatesWithTouchIconsCount"),
192 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
193 base::Bucket(/*min=*/2, /*count=*/2)));
194 }
195
150 } // namespace 196 } // namespace
151 } // namespace favicon 197 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/content/BUILD.gn ('k') | components/favicon/core/favicon_driver_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698