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

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

Issue 2578173002: NTP: Extract JSON requests from Fetcher. (Closed)
Patch Set: Use |GetVariationParamByFeatureAsBool|. Created 3 years, 12 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 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 [](base::Closure signal, gfx::Image* output, 298 [](base::Closure signal, gfx::Image* output,
299 const gfx::Image& loaded) { 299 const gfx::Image& loaded) {
300 *output = loaded; 300 *output = loaded;
301 signal.Run(); 301 signal.Run();
302 }, 302 },
303 run_loop.QuitClosure(), &result)); 303 run_loop.QuitClosure(), &result));
304 run_loop.Run(); 304 run_loop.Run();
305 return result; 305 return result;
306 } 306 }
307 307
308 void ParseJson( 308 void ParseJson(const std::string& json,
309 const std::string& json, 309 const SuccessCallback& success_callback,
310 const ntp_snippets::NTPSnippetsFetcher::SuccessCallback& success_callback, 310 const ErrorCallback& error_callback) {
311 const ntp_snippets::NTPSnippetsFetcher::ErrorCallback& error_callback) {
312 base::JSONReader json_reader; 311 base::JSONReader json_reader;
313 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); 312 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json);
314 if (value) { 313 if (value) {
315 success_callback.Run(std::move(value)); 314 success_callback.Run(std::move(value));
316 } else { 315 } else {
317 error_callback.Run(json_reader.GetErrorMessage()); 316 error_callback.Run(json_reader.GetErrorMessage());
318 } 317 }
319 } 318 }
320 319
321 // Factory for FakeURLFetcher objects that always generate errors. 320 // Factory for FakeURLFetcher objects that always generate errors.
(...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 service->FetchSnippetsInTheBackground(); 1823 service->FetchSnippetsInTheBackground();
1825 base::RunLoop().RunUntilIdle(); 1824 base::RunLoop().RunUntilIdle();
1826 EXPECT_EQ( 1825 EXPECT_EQ(
1827 simple_test_clock_ptr->Now().ToInternalValue(), 1826 simple_test_clock_ptr->Now().ToInternalValue(),
1828 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime)); 1827 pref_service()->GetInt64(prefs::kLastSuccessfulBackgroundFetchTime));
1829 // TODO(markusheintz): Add a test that simulates a browser restart once the 1828 // TODO(markusheintz): Add a test that simulates a browser restart once the
1830 // scheduler refactoring is done (crbug.com/672434). 1829 // scheduler refactoring is done (crbug.com/672434).
1831 } 1830 }
1832 1831
1833 } // namespace ntp_snippets 1832 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698