| 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_snippets/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 | 104 |
| 105 MOCK_METHOD1(Run, void(NTPSnippetsFetcher::OptionalSnippets* snippets)); | 105 MOCK_METHOD1(Run, void(NTPSnippetsFetcher::OptionalSnippets* snippets)); |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 // Factory for FakeURLFetcher objects that always generate errors. | 108 // Factory for FakeURLFetcher objects that always generate errors. |
| 109 class FailingFakeURLFetcherFactory : public net::URLFetcherFactory { | 109 class FailingFakeURLFetcherFactory : public net::URLFetcherFactory { |
| 110 public: | 110 public: |
| 111 std::unique_ptr<net::URLFetcher> CreateURLFetcher( | 111 std::unique_ptr<net::URLFetcher> CreateURLFetcher( |
| 112 int id, const GURL& url, net::URLFetcher::RequestType request_type, | 112 int id, const GURL& url, net::URLFetcher::RequestType request_type, |
| 113 net::URLFetcherDelegate* d) override { | 113 net::URLFetcherDelegate* d) override { |
| 114 return base::WrapUnique(new net::FakeURLFetcher( | 114 return base::MakeUnique<net::FakeURLFetcher>( |
| 115 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND, | 115 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND, |
| 116 net::URLRequestStatus::FAILED)); | 116 net::URLRequestStatus::FAILED); |
| 117 } | 117 } |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 void ParseJson( | 120 void ParseJson( |
| 121 const std::string& json, | 121 const std::string& json, |
| 122 const ntp_snippets::NTPSnippetsFetcher::SuccessCallback& success_callback, | 122 const ntp_snippets::NTPSnippetsFetcher::SuccessCallback& success_callback, |
| 123 const ntp_snippets::NTPSnippetsFetcher::ErrorCallback& error_callback) { | 123 const ntp_snippets::NTPSnippetsFetcher::ErrorCallback& error_callback) { |
| 124 base::JSONReader json_reader; | 124 base::JSONReader json_reader; |
| 125 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); | 125 std::unique_ptr<base::Value> value = json_reader.ReadToValue(json); |
| 126 if (value) | 126 if (value) |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 if (snippets) { | 805 if (snippets) { |
| 806 // Matchers above aren't any more precise than this, so this is sufficient | 806 // Matchers above aren't any more precise than this, so this is sufficient |
| 807 // for test-failure diagnostics. | 807 // for test-failure diagnostics. |
| 808 return os << "list with " << snippets->size() << " elements"; | 808 return os << "list with " << snippets->size() << " elements"; |
| 809 } else { | 809 } else { |
| 810 return os << "null"; | 810 return os << "null"; |
| 811 } | 811 } |
| 812 } | 812 } |
| 813 | 813 |
| 814 } // namespace ntp_snippets | 814 } // namespace ntp_snippets |
| OLD | NEW |