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

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

Issue 2757643002: components/image_fetcher: Expose RequestMetadata from ImageFetcher (Closed)
Patch Set: logo_bridge 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 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_impl.h" 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/json/json_reader.h" 14 #include "base/json/json_reader.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/run_loop.h" 18 #include "base/run_loop.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
22 #include "base/test/histogram_tester.h" 22 #include "base/test/histogram_tester.h"
23 #include "base/test/simple_test_clock.h" 23 #include "base/test/simple_test_clock.h"
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "components/image_fetcher/image_decoder.h" 26 #include "components/image_fetcher/image_decoder.h"
27 #include "components/image_fetcher/image_fetcher.h" 27 #include "components/image_fetcher/image_fetcher.h"
28 #include "components/image_fetcher/image_fetcher_delegate.h" 28 #include "components/image_fetcher/image_fetcher_delegate.h"
29 #include "components/image_fetcher/request_metadata.h"
29 #include "components/ntp_snippets/category.h" 30 #include "components/ntp_snippets/category.h"
30 #include "components/ntp_snippets/category_info.h" 31 #include "components/ntp_snippets/category_info.h"
31 #include "components/ntp_snippets/category_rankers/category_ranker.h" 32 #include "components/ntp_snippets/category_rankers/category_ranker.h"
32 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h" 33 #include "components/ntp_snippets/category_rankers/constant_category_ranker.h"
33 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h" 34 #include "components/ntp_snippets/category_rankers/mock_category_ranker.h"
34 #include "components/ntp_snippets/fake_content_suggestions_provider_observer.h" 35 #include "components/ntp_snippets/fake_content_suggestions_provider_observer.h"
35 #include "components/ntp_snippets/features.h" 36 #include "components/ntp_snippets/features.h"
36 #include "components/ntp_snippets/ntp_snippets_constants.h" 37 #include "components/ntp_snippets/ntp_snippets_constants.h"
37 #include "components/ntp_snippets/pref_names.h" 38 #include "components/ntp_snippets/pref_names.h"
38 #include "components/ntp_snippets/remote/persistent_scheduler.h" 39 #include "components/ntp_snippets/remote/persistent_scheduler.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (pos == std::string::npos) { 281 if (pos == std::string::npos) {
281 NOTREACHED(); 282 NOTREACHED();
282 return std::string(); 283 return std::string();
283 } 284 }
284 json_str[pos + 1] = 'x'; 285 json_str[pos + 1] = 'x';
285 return json_str; 286 return json_str;
286 } 287 }
287 288
288 using ServeImageCallback = base::Callback<void( 289 using ServeImageCallback = base::Callback<void(
289 const std::string&, 290 const std::string&,
290 base::Callback<void(const std::string&, const gfx::Image&)>)>; 291 base::Callback<void(const std::string&,
292 const gfx::Image&,
293 const image_fetcher::RequestMetadata&)>)>;
291 294
292 void ServeOneByOneImage( 295 void ServeOneByOneImage(
293 image_fetcher::ImageFetcherDelegate* notify, 296 image_fetcher::ImageFetcherDelegate* notify,
294 const std::string& id, 297 const std::string& id,
295 base::Callback<void(const std::string&, const gfx::Image&)> callback) { 298 base::Callback<void(const std::string&,
299 const gfx::Image&,
300 const image_fetcher::RequestMetadata&)> callback) {
296 base::ThreadTaskRunnerHandle::Get()->PostTask( 301 base::ThreadTaskRunnerHandle::Get()->PostTask(
297 FROM_HERE, base::Bind(callback, id, gfx::test::CreateImage(1, 1))); 302 FROM_HERE, base::Bind(callback, id, gfx::test::CreateImage(1, 1),
303 image_fetcher::RequestMetadata()));
298 notify->OnImageDataFetched(id, "1-by-1-image-data"); 304 notify->OnImageDataFetched(id, "1-by-1-image-data");
299 } 305 }
300 306
301 gfx::Image FetchImage(RemoteSuggestionsProviderImpl* service, 307 gfx::Image FetchImage(RemoteSuggestionsProviderImpl* service,
302 const ContentSuggestion::ID& suggestion_id) { 308 const ContentSuggestion::ID& suggestion_id) {
303 gfx::Image result; 309 gfx::Image result;
304 base::RunLoop run_loop; 310 base::RunLoop run_loop;
305 service->FetchSuggestionImage(suggestion_id, 311 service->FetchSuggestionImage(suggestion_id,
306 base::Bind( 312 base::Bind(
307 [](base::Closure signal, gfx::Image* output, 313 [](base::Closure signal, gfx::Image* output,
(...skipping 30 matching lines...) Expand all
338 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND, 344 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND,
339 net::URLRequestStatus::FAILED); 345 net::URLRequestStatus::FAILED);
340 } 346 }
341 }; 347 };
342 348
343 class MockImageFetcher : public ImageFetcher { 349 class MockImageFetcher : public ImageFetcher {
344 public: 350 public:
345 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); 351 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*));
346 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); 352 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName));
347 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); 353 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&));
348 MOCK_METHOD3( 354 MOCK_METHOD3(StartOrQueueNetworkRequest,
349 StartOrQueueNetworkRequest, 355 void(const std::string&,
350 void(const std::string&, 356 const GURL&,
351 const GURL&, 357 const ImageFetcherCallback&));
352 base::Callback<void(const std::string&, const gfx::Image&)>));
353 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); 358 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*());
354 }; 359 };
355 360
356 class FakeImageDecoder : public image_fetcher::ImageDecoder { 361 class FakeImageDecoder : public image_fetcher::ImageDecoder {
357 public: 362 public:
358 FakeImageDecoder() {} 363 FakeImageDecoder() {}
359 ~FakeImageDecoder() override = default; 364 ~FakeImageDecoder() override = default;
360 void DecodeImage( 365 void DecodeImage(
361 const std::string& image_data, 366 const std::string& image_data,
362 const gfx::Size& desired_image_frame_size, 367 const gfx::Size& desired_image_frame_size,
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1806 EXPECT_CALL(scheduler, OnProviderActivated()); 1811 EXPECT_CALL(scheduler, OnProviderActivated());
1807 // The scheduler should be notified of clearing the history. 1812 // The scheduler should be notified of clearing the history.
1808 EXPECT_CALL(scheduler, OnSuggestionsCleared()); 1813 EXPECT_CALL(scheduler, OnSuggestionsCleared());
1809 1814
1810 service->SetRemoteSuggestionsScheduler(&scheduler); 1815 service->SetRemoteSuggestionsScheduler(&scheduler);
1811 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, 1816 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT,
1812 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); 1817 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN);
1813 } 1818 }
1814 1819
1815 } // namespace ntp_snippets 1820 } // namespace ntp_snippets
OLDNEW
« no previous file with comments | « components/ntp_snippets/remote/remote_suggestions_provider_impl.cc ('k') | components/ntp_tiles/icon_cacher_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698