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

Side by Side Diff: components/ntp_tiles/popular_sites_impl_unittest.cc

Issue 2695713004: Add baked-in favicons for default popular sites on NTP (Closed)
Patch Set: Rebase. 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/ntp_tiles/popular_sites_impl.h" 5 #include "components/ntp_tiles/popular_sites_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 16 matching lines...) Expand all
27 #include "components/pref_registry/pref_registry_syncable.h" 27 #include "components/pref_registry/pref_registry_syncable.h"
28 #include "components/sync_preferences/testing_pref_service_syncable.h" 28 #include "components/sync_preferences/testing_pref_service_syncable.h"
29 #include "net/http/http_status_code.h" 29 #include "net/http/http_status_code.h"
30 #include "net/url_request/test_url_fetcher_factory.h" 30 #include "net/url_request/test_url_fetcher_factory.h"
31 #include "net/url_request/url_request_status.h" 31 #include "net/url_request/url_request_status.h"
32 #include "net/url_request/url_request_test_util.h" 32 #include "net/url_request/url_request_test_util.h"
33 #include "testing/gmock/include/gmock/gmock.h" 33 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
35 35
36 using testing::Eq; 36 using testing::Eq;
37 using testing::Gt;
37 using testing::IsEmpty; 38 using testing::IsEmpty;
38 39
39 namespace ntp_tiles { 40 namespace ntp_tiles {
40 namespace { 41 namespace {
41 42
42 const char kTitle[] = "title"; 43 const char kTitle[] = "title";
43 const char kUrl[] = "url"; 44 const char kUrl[] = "url";
44 const char kLargeIconUrl[] = "large_icon_url"; 45 const char kLargeIconUrl[] = "large_icon_url";
45 const char kFaviconUrl[] = "favicon_url"; 46 const char kFaviconUrl[] = "favicon_url";
46 47
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 const TestPopularSite kChromium; 163 const TestPopularSite kChromium;
163 164
164 base::MessageLoopForUI ui_loop_; 165 base::MessageLoopForUI ui_loop_;
165 base::SequencedWorkerPoolOwner worker_pool_owner_; 166 base::SequencedWorkerPoolOwner worker_pool_owner_;
166 base::ScopedTempDir scoped_cache_dir_; 167 base::ScopedTempDir scoped_cache_dir_;
167 base::FilePath cache_dir_; 168 base::FilePath cache_dir_;
168 sync_preferences::TestingPrefServiceSyncable prefs_; 169 sync_preferences::TestingPrefServiceSyncable prefs_;
169 net::FakeURLFetcherFactory url_fetcher_factory_; 170 net::FakeURLFetcherFactory url_fetcher_factory_;
170 }; 171 };
171 172
172 TEST_F(PopularSitesTest, Basic) { 173 TEST_F(PopularSitesTest, ContainsDefaultTilesRightAfterConstruction) {
174 scoped_refptr<net::TestURLRequestContextGetter> url_request_context(
175 new net::TestURLRequestContextGetter(
176 base::ThreadTaskRunnerHandle::Get()));
177
178 auto popular_sites = CreatePopularSites(url_request_context.get());
179 EXPECT_THAT(popular_sites->sites().size(),
180 Eq(GetNumberOfDefaultPopularSitesForPlatform()));
181 }
182
183 TEST_F(PopularSitesTest, Zasic) {
173 SetCountryAndVersion("ZZ", "9"); 184 SetCountryAndVersion("ZZ", "9");
174 RespondWithJSON( 185 RespondWithJSON(
175 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", 186 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json",
176 {kWikipedia}); 187 {kWikipedia});
177 188
178 PopularSites::SitesVector sites; 189 PopularSites::SitesVector sites;
179 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites), 190 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites),
180 Eq(base::Optional<bool>(true))); 191 Eq(base::Optional<bool>(true)));
181 192
182 ASSERT_THAT(sites.size(), Eq(1u)); 193 ASSERT_THAT(sites.size(), Eq(1u));
183 EXPECT_THAT(sites[0].title, Str16Eq("Wikipedia, fhta Ph'nglui mglw'nafh")); 194 EXPECT_THAT(sites[0].title, Str16Eq("Wikipedia, fhta Ph'nglui mglw'nafh"));
184 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); 195 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/"));
185 EXPECT_THAT(sites[0].large_icon_url, 196 EXPECT_THAT(sites[0].large_icon_url,
186 URLEq("https://zz.m.wikipedia.org/wikipedia.png")); 197 URLEq("https://zz.m.wikipedia.org/wikipedia.png"));
187 EXPECT_THAT(sites[0].favicon_url, URLEq("")); 198 EXPECT_THAT(sites[0].favicon_url, URLEq(""));
188 } 199 }
189 200
190 TEST_F(PopularSitesTest, ContainsDefaultTilesRightAfterConstruction) {
191 scoped_refptr<net::TestURLRequestContextGetter> url_request_context(
192 new net::TestURLRequestContextGetter(
193 base::ThreadTaskRunnerHandle::Get()));
194
195 EXPECT_THAT(CreatePopularSites(url_request_context.get())->sites().size(),
196 Eq(GetNumberOfDefaultPopularSitesForPlatform()));
197 }
198
199 TEST_F(PopularSitesTest, Fallback) { 201 TEST_F(PopularSitesTest, Fallback) {
200 SetCountryAndVersion("ZZ", "9"); 202 SetCountryAndVersion("ZZ", "9");
201 RespondWith404( 203 RespondWith404(
202 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); 204 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json");
203 RespondWithJSON( 205 RespondWithJSON(
204 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json", 206 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json",
205 {kYouTube, kChromium}); 207 {kYouTube, kChromium});
206 208
207 PopularSites::SitesVector sites; 209 PopularSites::SitesVector sites;
208 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites), 210 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites),
(...skipping 18 matching lines...) Expand all
227 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); 229 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json");
228 RespondWith404( 230 RespondWith404(
229 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json"); 231 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json");
230 232
231 PopularSites::SitesVector sites; 233 PopularSites::SitesVector sites;
232 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites), 234 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites),
233 Eq(base::Optional<bool>(false))); 235 Eq(base::Optional<bool>(false)));
234 EXPECT_THAT(sites.size(), Eq(GetNumberOfDefaultPopularSitesForPlatform())); 236 EXPECT_THAT(sites.size(), Eq(GetNumberOfDefaultPopularSitesForPlatform()));
235 } 237 }
236 238
239 TEST_F(PopularSitesTest, AddsIconResourcesToDefaultPages) {
240 scoped_refptr<net::TestURLRequestContextGetter> url_request_context(
241 new net::TestURLRequestContextGetter(
242 base::ThreadTaskRunnerHandle::Get()));
243 std::unique_ptr<PopularSites> popular_sites =
244 CreatePopularSites(url_request_context.get());
245
246 #if defined(GOOGLE_CHROME_BUILD)
247 ASSERT_FALSE(popular_sites->sites().empty());
248 for (const auto& site : popular_sites->sites()) {
249 EXPECT_THAT(site.default_icon_resource, Gt(0));
250 }
251 #endif
252 }
253
237 TEST_F(PopularSitesTest, ProvidesDefaultSitesUntilCallbackReturns) { 254 TEST_F(PopularSitesTest, ProvidesDefaultSitesUntilCallbackReturns) {
238 SetCountryAndVersion("ZZ", "9"); 255 SetCountryAndVersion("ZZ", "9");
239 RespondWithJSON( 256 RespondWithJSON(
240 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", 257 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json",
241 {kWikipedia}); 258 {kWikipedia});
242 scoped_refptr<net::TestURLRequestContextGetter> url_request_context( 259 scoped_refptr<net::TestURLRequestContextGetter> url_request_context(
243 new net::TestURLRequestContextGetter( 260 new net::TestURLRequestContextGetter(
244 base::ThreadTaskRunnerHandle::Get())); 261 base::ThreadTaskRunnerHandle::Get()));
245 std::unique_ptr<PopularSites> popular_sites = 262 std::unique_ptr<PopularSites> popular_sites =
246 CreatePopularSites(url_request_context.get()); 263 CreatePopularSites(url_request_context.get());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", 432 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json",
416 {kChromium}); 433 {kChromium});
417 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites), 434 EXPECT_THAT(FetchPopularSites(/*force_download=*/false, &sites),
418 Eq(base::Optional<bool>(true))); 435 Eq(base::Optional<bool>(true)));
419 ASSERT_THAT(sites.size(), Eq(1u)); 436 ASSERT_THAT(sites.size(), Eq(1u));
420 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/")); 437 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/"));
421 } 438 }
422 439
423 } // namespace 440 } // namespace
424 } // namespace ntp_tiles 441 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/popular_sites_impl.cc ('k') | components/ntp_tiles/resources/default_popular_sites.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698