OLD | NEW |
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.h" | 5 #include "components/ntp_tiles/popular_sites.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "components/pref_registry/pref_registry_syncable.h" | 21 #include "components/pref_registry/pref_registry_syncable.h" |
22 #include "components/pref_registry/testing_pref_service_syncable.h" | 22 #include "components/pref_registry/testing_pref_service_syncable.h" |
23 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
24 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
25 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
26 #include "net/url_request/url_request_test_util.h" | 26 #include "net/url_request/url_request_test_util.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
29 | 29 |
30 using testing::Eq; | 30 using testing::Eq; |
31 using testing::StrEq; | 31 using testing::IsEmpty; |
32 | 32 |
33 namespace ntp_tiles { | 33 namespace ntp_tiles { |
34 namespace { | 34 namespace { |
35 | 35 |
36 const char kTitle[] = "title"; | 36 const char kTitle[] = "title"; |
37 const char kUrl[] = "url"; | 37 const char kUrl[] = "url"; |
38 const char kLargeIconUrl[] = "large_icon_url"; | 38 const char kLargeIconUrl[] = "large_icon_url"; |
39 const char kFaviconUrl[] = "favicon_url"; | 39 const char kFaviconUrl[] = "favicon_url"; |
40 | 40 |
41 using TestPopularSite = std::vector<std::pair<std::string, std::string>>; | 41 using TestPopularSite = std::map<std::string, std::string>; |
42 using TestPopularSiteVector = std::vector<TestPopularSite>; | 42 using TestPopularSiteVector = std::vector<TestPopularSite>; |
43 | 43 |
44 ::testing::Matcher<const base::string16&> Str16Eq(const std::string& s) { | 44 ::testing::Matcher<const base::string16&> Str16Eq(const std::string& s) { |
45 return ::testing::Eq(base::UTF8ToUTF16(s)); | 45 return ::testing::Eq(base::UTF8ToUTF16(s)); |
46 } | 46 } |
47 | 47 |
48 ::testing::Matcher<const GURL&> URLEq(const std::string& s) { | 48 ::testing::Matcher<const GURL&> URLEq(const std::string& s) { |
49 return ::testing::Eq(GURL(s)); | 49 return ::testing::Eq(GURL(s)); |
50 } | 50 } |
51 | 51 |
(...skipping 29 matching lines...) Expand all Loading... |
81 }, | 81 }, |
82 unsafe_json, success_callback, error_callback)); | 82 unsafe_json, success_callback, error_callback)); |
83 } | 83 } |
84 | 84 |
85 JsonUnsafeParser() = delete; | 85 JsonUnsafeParser() = delete; |
86 }; | 86 }; |
87 | 87 |
88 class PopularSitesTest : public ::testing::Test { | 88 class PopularSitesTest : public ::testing::Test { |
89 protected: | 89 protected: |
90 PopularSitesTest() | 90 PopularSitesTest() |
91 : worker_pool_owner_(2, "PopularSitesTest."), | 91 : kWikipedia{ |
| 92 {kTitle, "Wikipedia, fhta Ph'nglui mglw'nafh"}, |
| 93 {kUrl, "https://zz.m.wikipedia.org/"}, |
| 94 {kLargeIconUrl, "https://zz.m.wikipedia.org/wikipedia.png"}, |
| 95 }, |
| 96 kYouTube{ |
| 97 {kTitle, "YouTube"}, |
| 98 {kUrl, "https://m.youtube.com/"}, |
| 99 {kLargeIconUrl, "https://s.ytimg.com/apple-touch-icon.png"}, |
| 100 }, |
| 101 kChromium{ |
| 102 {kTitle, "The Chromium Project"}, |
| 103 {kUrl, "https://www.chromium.org/"}, |
| 104 {kFaviconUrl, "https://www.chromium.org/favicon.ico"}, |
| 105 }, |
| 106 worker_pool_owner_(2, "PopularSitesTest."), |
92 url_fetcher_factory_(nullptr) { | 107 url_fetcher_factory_(nullptr) { |
93 PopularSites::RegisterProfilePrefs(prefs_.registry()); | 108 PopularSites::RegisterProfilePrefs(prefs_.registry()); |
94 CHECK(cache_dir_.CreateUniqueTempDir()); | 109 CHECK(scoped_cache_dir_.CreateUniqueTempDir()); |
| 110 cache_dir_ = scoped_cache_dir_.GetPath(); |
95 } | 111 } |
96 | 112 |
97 void SetCountryAndVersion(const std::string& country, | 113 void SetCountryAndVersion(const std::string& country, |
98 const std::string& version) { | 114 const std::string& version) { |
99 prefs_.SetString(prefs::kPopularSitesOverrideCountry, country); | 115 prefs_.SetString(prefs::kPopularSitesOverrideCountry, country); |
100 prefs_.SetString(prefs::kPopularSitesOverrideVersion, version); | 116 prefs_.SetString(prefs::kPopularSitesOverrideVersion, version); |
101 } | 117 } |
102 | 118 |
103 void RespondWithJSON(const std::string& url, | 119 void RespondWithJSON(const std::string& url, |
104 const TestPopularSiteVector& sites) { | 120 const TestPopularSiteVector& sites) { |
105 base::ListValue sites_value; | 121 base::ListValue sites_value; |
106 for (const TestPopularSite& site : sites) { | 122 for (const TestPopularSite& site : sites) { |
107 auto site_value = base::MakeUnique<base::DictionaryValue>(); | 123 auto site_value = base::MakeUnique<base::DictionaryValue>(); |
108 for (const std::pair<std::string, std::string>& kv : site) { | 124 for (const std::pair<std::string, std::string>& kv : site) { |
109 site_value->SetString(kv.first, kv.second); | 125 site_value->SetString(kv.first, kv.second); |
110 } | 126 } |
111 sites_value.Append(std::move(site_value)); | 127 sites_value.Append(std::move(site_value)); |
112 } | 128 } |
113 std::string sites_string; | 129 std::string sites_string; |
114 base::JSONWriter::Write(sites_value, &sites_string); | 130 base::JSONWriter::Write(sites_value, &sites_string); |
115 url_fetcher_factory_.SetFakeResponse(GURL(url), sites_string, net::HTTP_OK, | 131 url_fetcher_factory_.SetFakeResponse(GURL(url), sites_string, net::HTTP_OK, |
116 net::URLRequestStatus::SUCCESS); | 132 net::URLRequestStatus::SUCCESS); |
117 } | 133 } |
118 | 134 |
| 135 void RespondWithData(const std::string& url, const std::string& data) { |
| 136 url_fetcher_factory_.SetFakeResponse(GURL(url), data, net::HTTP_OK, |
| 137 net::URLRequestStatus::SUCCESS); |
| 138 } |
| 139 |
119 void RespondWith404(const std::string& url) { | 140 void RespondWith404(const std::string& url) { |
120 url_fetcher_factory_.SetFakeResponse(GURL(url), "404", net::HTTP_NOT_FOUND, | 141 url_fetcher_factory_.SetFakeResponse(GURL(url), "404", net::HTTP_NOT_FOUND, |
121 net::URLRequestStatus::SUCCESS); | 142 net::URLRequestStatus::SUCCESS); |
122 } | 143 } |
123 | 144 |
124 bool FetchPopularSites(bool force_download, | 145 bool FetchPopularSites(bool force_download, |
125 std::vector<PopularSites::Site>* sites) { | 146 std::vector<PopularSites::Site>* sites) { |
126 scoped_refptr<net::TestURLRequestContextGetter> url_request_context( | 147 scoped_refptr<net::TestURLRequestContextGetter> url_request_context( |
127 new net::TestURLRequestContextGetter( | 148 new net::TestURLRequestContextGetter( |
128 base::ThreadTaskRunnerHandle::Get())); | 149 base::ThreadTaskRunnerHandle::Get())); |
129 PopularSites popular_sites(worker_pool_owner_.pool().get(), &prefs_, | 150 PopularSites popular_sites(worker_pool_owner_.pool().get(), &prefs_, |
130 /*template_url_service=*/nullptr, | 151 /*template_url_service=*/nullptr, |
131 /*variations_service=*/nullptr, | 152 /*variations_service=*/nullptr, |
132 url_request_context.get(), cache_dir_.GetPath(), | 153 url_request_context.get(), cache_dir_, |
133 base::Bind(JsonUnsafeParser::Parse)); | 154 base::Bind(JsonUnsafeParser::Parse)); |
134 | 155 |
135 base::RunLoop loop; | 156 base::RunLoop loop; |
136 bool save_success = false; | 157 bool save_success = false; |
137 popular_sites.StartFetch( | 158 popular_sites.StartFetch( |
138 force_download, | 159 force_download, |
139 base::Bind( | 160 base::Bind( |
140 [](bool* save_success, base::RunLoop* loop, bool success) { | 161 [](bool* save_success, base::RunLoop* loop, bool success) { |
141 *save_success = success; | 162 *save_success = success; |
142 loop->Quit(); | 163 loop->Quit(); |
143 }, | 164 }, |
144 &save_success, &loop)); | 165 &save_success, &loop)); |
145 loop.Run(); | 166 loop.Run(); |
146 *sites = popular_sites.sites(); | 167 *sites = popular_sites.sites(); |
147 return save_success; | 168 return save_success; |
148 } | 169 } |
149 | 170 |
| 171 const TestPopularSite kWikipedia; |
| 172 const TestPopularSite kYouTube; |
| 173 const TestPopularSite kChromium; |
| 174 |
150 base::MessageLoopForUI ui_loop_; | 175 base::MessageLoopForUI ui_loop_; |
151 base::SequencedWorkerPoolOwner worker_pool_owner_; | 176 base::SequencedWorkerPoolOwner worker_pool_owner_; |
152 base::ScopedTempDir cache_dir_; | 177 base::ScopedTempDir scoped_cache_dir_; |
| 178 base::FilePath cache_dir_; |
153 user_prefs::TestingPrefServiceSyncable prefs_; | 179 user_prefs::TestingPrefServiceSyncable prefs_; |
154 net::FakeURLFetcherFactory url_fetcher_factory_; | 180 net::FakeURLFetcherFactory url_fetcher_factory_; |
155 }; | 181 }; |
156 | 182 |
157 TEST_F(PopularSitesTest, Basic) { | 183 TEST_F(PopularSitesTest, Basic) { |
158 SetCountryAndVersion("ZZ", "9"); | 184 SetCountryAndVersion("ZZ", "9"); |
159 RespondWithJSON( | 185 RespondWithJSON( |
160 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", | 186 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
161 {{ | 187 {kWikipedia}); |
162 {kTitle, "Wikipedia, fhta Ph'nglui mglw'nafh"}, | |
163 {kUrl, "https://zz.m.wikipedia.org/"}, | |
164 {kLargeIconUrl, "https://zz.m.wikipedia.org/wikipedia.png"}, | |
165 }}); | |
166 | 188 |
167 std::vector<PopularSites::Site> sites; | 189 std::vector<PopularSites::Site> sites; |
168 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); | 190 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
169 | 191 |
170 ASSERT_THAT(sites.size(), Eq(1u)); | 192 ASSERT_THAT(sites.size(), Eq(1u)); |
171 EXPECT_THAT(sites[0].title, Str16Eq("Wikipedia, fhta Ph'nglui mglw'nafh")); | 193 EXPECT_THAT(sites[0].title, Str16Eq("Wikipedia, fhta Ph'nglui mglw'nafh")); |
172 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); | 194 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); |
173 EXPECT_THAT(sites[0].large_icon_url, | 195 EXPECT_THAT(sites[0].large_icon_url, |
174 URLEq("https://zz.m.wikipedia.org/wikipedia.png")); | 196 URLEq("https://zz.m.wikipedia.org/wikipedia.png")); |
175 EXPECT_THAT(sites[0].favicon_url, URLEq("")); | 197 EXPECT_THAT(sites[0].favicon_url, URLEq("")); |
176 } | 198 } |
177 | 199 |
178 TEST_F(PopularSitesTest, Fallback) { | 200 TEST_F(PopularSitesTest, Fallback) { |
179 SetCountryAndVersion("ZZ", "9"); | 201 SetCountryAndVersion("ZZ", "9"); |
180 RespondWith404( | 202 RespondWith404( |
181 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); | 203 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); |
182 RespondWithJSON( | 204 RespondWithJSON( |
183 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json", | 205 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json", |
184 {{ | 206 {kYouTube, kChromium}); |
185 {kTitle, "YouTube"}, | |
186 {kUrl, "https://m.youtube.com/"}, | |
187 {kLargeIconUrl, "https://s.ytimg.com/apple-touch-icon.png"}, | |
188 }, | |
189 { | |
190 {kTitle, "The Chromium Project"}, | |
191 {kUrl, "https://www.chromium.org/"}, | |
192 {kFaviconUrl, "https://www.chromium.org/favicon.ico"}, | |
193 }}); | |
194 | 207 |
195 std::vector<PopularSites::Site> sites; | 208 std::vector<PopularSites::Site> sites; |
196 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); | 209 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
197 | 210 |
198 ASSERT_THAT(sites.size(), Eq(2u)); | 211 ASSERT_THAT(sites.size(), Eq(2u)); |
199 EXPECT_THAT(sites[0].title, Str16Eq("YouTube")); | 212 EXPECT_THAT(sites[0].title, Str16Eq("YouTube")); |
200 EXPECT_THAT(sites[0].url, URLEq("https://m.youtube.com/")); | 213 EXPECT_THAT(sites[0].url, URLEq("https://m.youtube.com/")); |
201 EXPECT_THAT(sites[0].large_icon_url, | 214 EXPECT_THAT(sites[0].large_icon_url, |
202 URLEq("https://s.ytimg.com/apple-touch-icon.png")); | 215 URLEq("https://s.ytimg.com/apple-touch-icon.png")); |
203 EXPECT_THAT(sites[0].favicon_url, URLEq("")); | 216 EXPECT_THAT(sites[0].favicon_url, URLEq("")); |
204 EXPECT_THAT(sites[1].title, Str16Eq("The Chromium Project")); | 217 EXPECT_THAT(sites[1].title, Str16Eq("The Chromium Project")); |
205 EXPECT_THAT(sites[1].url, URLEq("https://www.chromium.org/")); | 218 EXPECT_THAT(sites[1].url, URLEq("https://www.chromium.org/")); |
206 EXPECT_THAT(sites[1].large_icon_url, URLEq("")); | 219 EXPECT_THAT(sites[1].large_icon_url, URLEq("")); |
207 EXPECT_THAT(sites[1].favicon_url, | 220 EXPECT_THAT(sites[1].favicon_url, |
208 URLEq("https://www.chromium.org/favicon.ico")); | 221 URLEq("https://www.chromium.org/favicon.ico")); |
209 } | 222 } |
210 | 223 |
211 TEST_F(PopularSitesTest, Failure) { | 224 TEST_F(PopularSitesTest, Failure) { |
212 SetCountryAndVersion("ZZ", "9"); | 225 SetCountryAndVersion("ZZ", "9"); |
213 RespondWith404( | 226 RespondWith404( |
214 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); | 227 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); |
215 RespondWith404( | 228 RespondWith404( |
216 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json"); | 229 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json"); |
217 | 230 |
218 std::vector<PopularSites::Site> sites; | 231 std::vector<PopularSites::Site> sites; |
219 EXPECT_FALSE(FetchPopularSites(/*force_download=*/false, &sites)); | 232 EXPECT_FALSE(FetchPopularSites(/*force_download=*/false, &sites)); |
220 ASSERT_THAT(sites.size(), Eq(0u)); | 233 ASSERT_THAT(sites, IsEmpty()); |
| 234 } |
| 235 |
| 236 TEST_F(PopularSitesTest, FailsWithoutFetchIfNoCacheDir) { |
| 237 SetCountryAndVersion("ZZ", "9"); |
| 238 std::vector<PopularSites::Site> sites; |
| 239 cache_dir_ = base::FilePath(); // Override with invalid file path. |
| 240 EXPECT_FALSE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 241 } |
| 242 |
| 243 TEST_F(PopularSitesTest, UsesCachedFile) { |
| 244 SetCountryAndVersion("ZZ", "9"); |
| 245 RespondWithJSON( |
| 246 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 247 {kWikipedia}); |
| 248 |
| 249 // First request succeeds and gets cached. |
| 250 std::vector<PopularSites::Site> sites; |
| 251 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 252 |
| 253 // File disappears from server, but we don't need it because it's cached. |
| 254 RespondWith404( |
| 255 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); |
| 256 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 257 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); |
| 258 } |
| 259 |
| 260 TEST_F(PopularSitesTest, CachesEmptyFile) { |
| 261 SetCountryAndVersion("ZZ", "9"); |
| 262 RespondWithData( |
| 263 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", "[]"); |
| 264 RespondWithJSON( |
| 265 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json", |
| 266 {kWikipedia}); |
| 267 |
| 268 // First request succeeds and caches empty suggestions list (no fallback). |
| 269 std::vector<PopularSites::Site> sites; |
| 270 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 271 EXPECT_THAT(sites, IsEmpty()); |
| 272 |
| 273 // File appears on server, but we continue to use our cached empty file. |
| 274 RespondWithJSON( |
| 275 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 276 {kWikipedia}); |
| 277 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 278 EXPECT_THAT(sites, IsEmpty()); |
| 279 } |
| 280 |
| 281 TEST_F(PopularSitesTest, DoesntUseCachedFileIfDownloadForced) { |
| 282 SetCountryAndVersion("ZZ", "9"); |
| 283 RespondWithJSON( |
| 284 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 285 {kWikipedia}); |
| 286 |
| 287 // First request succeeds and gets cached. |
| 288 std::vector<PopularSites::Site> sites; |
| 289 EXPECT_TRUE(FetchPopularSites(/*force_download=*/true, &sites)); |
| 290 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); |
| 291 |
| 292 // File disappears from server. Download is forced, so we get the new file. |
| 293 RespondWithJSON( |
| 294 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 295 {kChromium}); |
| 296 EXPECT_TRUE(FetchPopularSites(/*force_download=*/true, &sites)); |
| 297 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/")); |
| 298 } |
| 299 |
| 300 TEST_F(PopularSitesTest, RefetchesAfterCountryMoved) { |
| 301 RespondWithJSON( |
| 302 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 303 {kWikipedia}); |
| 304 RespondWithJSON( |
| 305 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZX_9.json", |
| 306 {kChromium}); |
| 307 |
| 308 std::vector<PopularSites::Site> sites; |
| 309 |
| 310 // First request (in ZZ) saves Wikipedia. |
| 311 SetCountryAndVersion("ZZ", "9"); |
| 312 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 313 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); |
| 314 |
| 315 // Second request (now in ZX) saves Chromium. |
| 316 SetCountryAndVersion("ZX", "9"); |
| 317 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 318 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/")); |
| 319 } |
| 320 |
| 321 TEST_F(PopularSitesTest, DoesntCacheInvalidFile) { |
| 322 SetCountryAndVersion("ZZ", "9"); |
| 323 RespondWithData( |
| 324 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 325 "ceci n'est pas un json"); |
| 326 RespondWith404( |
| 327 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json"); |
| 328 |
| 329 // First request falls back and gets nothing there either. |
| 330 std::vector<PopularSites::Site> sites; |
| 331 EXPECT_FALSE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 332 |
| 333 // Second request refetches ZZ_9, which now has data. |
| 334 RespondWithJSON( |
| 335 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 336 {kChromium}); |
| 337 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 338 ASSERT_THAT(sites.size(), Eq(1u)); |
| 339 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/")); |
| 340 } |
| 341 |
| 342 TEST_F(PopularSitesTest, RefetchesAfterFallback) { |
| 343 SetCountryAndVersion("ZZ", "9"); |
| 344 RespondWith404( |
| 345 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json"); |
| 346 RespondWithJSON( |
| 347 "https://www.gstatic.com/chrome/ntp/suggested_sites_DEFAULT_5.json", |
| 348 {kWikipedia}); |
| 349 |
| 350 // First request falls back. |
| 351 std::vector<PopularSites::Site> sites; |
| 352 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 353 ASSERT_THAT(sites.size(), Eq(1u)); |
| 354 EXPECT_THAT(sites[0].url, URLEq("https://zz.m.wikipedia.org/")); |
| 355 |
| 356 // Second request refetches ZZ_9, which now has data. |
| 357 RespondWithJSON( |
| 358 "https://www.gstatic.com/chrome/ntp/suggested_sites_ZZ_9.json", |
| 359 {kChromium}); |
| 360 EXPECT_TRUE(FetchPopularSites(/*force_download=*/false, &sites)); |
| 361 ASSERT_THAT(sites.size(), Eq(1u)); |
| 362 EXPECT_THAT(sites[0].url, URLEq("https://www.chromium.org/")); |
221 } | 363 } |
222 | 364 |
223 } // namespace | 365 } // namespace |
224 } // namespace ntp_tiles | 366 } // namespace ntp_tiles |
OLD | NEW |