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

Side by Side Diff: components/ntp_snippets/remote/remote_suggestions_provider_unittest.cc

Issue 2578173002: NTP: Extract JSON requests from Fetcher. (Closed)
Patch Set: Created 4 years 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 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/ntp_snippets/remote/remote_suggestions_provider.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 *output = loaded; 275 *output = loaded;
276 signal.Run(); 276 signal.Run();
277 }, 277 },
278 run_loop.QuitClosure(), &result)); 278 run_loop.QuitClosure(), &result));
279 run_loop.Run(); 279 run_loop.Run();
280 return result; 280 return result;
281 } 281 }
282 282
283 void ParseJson( 283 void ParseJson(
284 const std::string& json, 284 const std::string& json,
285 const ntp_snippets::NTPSnippetsFetcher::SuccessCallback& success_callback, 285 const internal::NTPSnippetsJsonRequest::SuccessCallback& success_callback,
286 const ntp_snippets::NTPSnippetsFetcher::ErrorCallback& error_callback) { 286 const internal::NTPSnippetsJsonRequest::ErrorCallback& error_callback) {
287 base::JSONReader json_reader; 287 base::JSONReader json_reader;
288 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); 288 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json);
289 if (value) { 289 if (value) {
290 success_callback.Run(std::move(value)); 290 success_callback.Run(std::move(value));
291 } else { 291 } else {
292 error_callback.Run(json_reader.GetErrorMessage()); 292 error_callback.Run(json_reader.GetErrorMessage());
293 } 293 }
294 } 294 }
295 295
296 // Factory for FakeURLFetcher objects that always generate errors. 296 // Factory for FakeURLFetcher objects that always generate errors.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 auto image_decoder = base::MakeUnique<FakeImageDecoder>(); 450 auto image_decoder = base::MakeUnique<FakeImageDecoder>();
451 image_decoder_ = image_decoder.get(); 451 image_decoder_ = image_decoder.get();
452 EXPECT_FALSE(observer_); 452 EXPECT_FALSE(observer_);
453 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>(); 453 observer_ = base::MakeUnique<FakeContentSuggestionsProviderObserver>();
454 auto database = base::MakeUnique<RemoteSuggestionsDatabase>( 454 auto database = base::MakeUnique<RemoteSuggestionsDatabase>(
455 database_dir_.GetPath(), task_runner); 455 database_dir_.GetPath(), task_runner);
456 database_ = database.get(); 456 database_ = database.get();
457 return base::MakeUnique<RemoteSuggestionsProvider>( 457 return base::MakeUnique<RemoteSuggestionsProvider>(
458 observer_.get(), &category_factory_, utils_.pref_service(), "fr", 458 observer_.get(), &category_factory_, utils_.pref_service(), "fr",
459 &user_classifier_, &scheduler_, std::move(snippets_fetcher), 459 &user_classifier_, &scheduler_, std::move(snippets_fetcher),
460 std::move(image_fetcher), std::move(image_decoder), 460 std::move(image_fetcher), std::move(image_decoder), std::move(database),
461 std::move(database),
462 base::MakeUnique<RemoteSuggestionsStatusService>( 461 base::MakeUnique<RemoteSuggestionsStatusService>(
463 utils_.fake_signin_manager(), utils_.pref_service())); 462 utils_.fake_signin_manager(), utils_.pref_service()));
464 } 463 }
465 464
466 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service, 465 void WaitForSnippetsServiceInitialization(RemoteSuggestionsProvider* service,
467 bool set_empty_response) { 466 bool set_empty_response) {
468 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_); 467 EXPECT_EQ(RemoteSuggestionsProvider::State::NOT_INITED, service->state_);
469 468
470 // Add an initial fetch response, as the service tries to fetch when there 469 // Add an initial fetch response, as the service tries to fetch when there
471 // is nothing in the DB. 470 // is nothing in the DB.
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1713 service->FetchSnippetsInTheBackground(); 1712 service->FetchSnippetsInTheBackground();
1714 base::RunLoop().RunUntilIdle(); 1713 base::RunLoop().RunUntilIdle();
1715 EXPECT_EQ( 1714 EXPECT_EQ(
1716 simple_test_clock_ptr->Now().ToInternalValue(), 1715 simple_test_clock_ptr->Now().ToInternalValue(),
1717 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); 1716 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime));
1718 // TODO(markusheintz): Add a test that simulates a browser restart once the 1717 // TODO(markusheintz): Add a test that simulates a browser restart once the
1719 // scheduler refactoring is done (crbug.com/672434). 1718 // scheduler refactoring is done (crbug.com/672434).
1720 } 1719 }
1721 1720
1722 } // namespace ntp_snippets 1721 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698