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

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: fix CrOS 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (pos == std::string::npos) { 279 if (pos == std::string::npos) {
279 NOTREACHED(); 280 NOTREACHED();
280 return std::string(); 281 return std::string();
281 } 282 }
282 json_str[pos + 1] = 'x'; 283 json_str[pos + 1] = 'x';
283 return json_str; 284 return json_str;
284 } 285 }
285 286
286 using ServeImageCallback = base::Callback<void( 287 using ServeImageCallback = base::Callback<void(
287 const std::string&, 288 const std::string&,
288 base::Callback<void(const std::string&, const gfx::Image&)>)>; 289 base::Callback<void(const std::string&,
290 const gfx::Image&,
291 const image_fetcher::RequestMetadata&)>)>;
289 292
290 void ServeOneByOneImage( 293 void ServeOneByOneImage(
291 image_fetcher::ImageFetcherDelegate* notify, 294 image_fetcher::ImageFetcherDelegate* notify,
292 const std::string& id, 295 const std::string& id,
293 base::Callback<void(const std::string&, const gfx::Image&)> callback) { 296 base::Callback<void(const std::string&,
297 const gfx::Image&,
298 const image_fetcher::RequestMetadata&)> callback) {
294 base::ThreadTaskRunnerHandle::Get()->PostTask( 299 base::ThreadTaskRunnerHandle::Get()->PostTask(
295 FROM_HERE, base::Bind(callback, id, gfx::test::CreateImage(1, 1))); 300 FROM_HERE, base::Bind(callback, id, gfx::test::CreateImage(1, 1),
301 image_fetcher::RequestMetadata()));
296 notify->OnImageDataFetched(id, "1-by-1-image-data"); 302 notify->OnImageDataFetched(id, "1-by-1-image-data");
297 } 303 }
298 304
299 gfx::Image FetchImage(RemoteSuggestionsProviderImpl* service, 305 gfx::Image FetchImage(RemoteSuggestionsProviderImpl* service,
300 const ContentSuggestion::ID& suggestion_id) { 306 const ContentSuggestion::ID& suggestion_id) {
301 gfx::Image result; 307 gfx::Image result;
302 base::RunLoop run_loop; 308 base::RunLoop run_loop;
303 service->FetchSuggestionImage(suggestion_id, 309 service->FetchSuggestionImage(suggestion_id,
304 base::Bind( 310 base::Bind(
305 [](base::Closure signal, gfx::Image* output, 311 [](base::Closure signal, gfx::Image* output,
(...skipping 30 matching lines...) Expand all
336 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND, 342 url, d, /*response_data=*/std::string(), net::HTTP_NOT_FOUND,
337 net::URLRequestStatus::FAILED); 343 net::URLRequestStatus::FAILED);
338 } 344 }
339 }; 345 };
340 346
341 class MockImageFetcher : public ImageFetcher { 347 class MockImageFetcher : public ImageFetcher {
342 public: 348 public:
343 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*)); 349 MOCK_METHOD1(SetImageFetcherDelegate, void(ImageFetcherDelegate*));
344 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName)); 350 MOCK_METHOD1(SetDataUseServiceName, void(DataUseServiceName));
345 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&)); 351 MOCK_METHOD1(SetDesiredImageFrameSize, void(const gfx::Size&));
346 MOCK_METHOD3( 352 MOCK_METHOD3(StartOrQueueNetworkRequest,
347 StartOrQueueNetworkRequest, 353 void(const std::string&,
348 void(const std::string&, 354 const GURL&,
349 const GURL&, 355 const ImageFetcherCallback&));
350 base::Callback<void(const std::string&, const gfx::Image&)>));
351 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*()); 356 MOCK_METHOD0(GetImageDecoder, image_fetcher::ImageDecoder*());
352 }; 357 };
353 358
354 class FakeImageDecoder : public image_fetcher::ImageDecoder { 359 class FakeImageDecoder : public image_fetcher::ImageDecoder {
355 public: 360 public:
356 FakeImageDecoder() {} 361 FakeImageDecoder() {}
357 ~FakeImageDecoder() override = default; 362 ~FakeImageDecoder() override = default;
358 void DecodeImage( 363 void DecodeImage(
359 const std::string& image_data, 364 const std::string& image_data,
360 const gfx::Size& desired_image_frame_size, 365 const gfx::Size& desired_image_frame_size,
(...skipping 1443 matching lines...) Expand 10 before | Expand all | Expand 10 after
1804 EXPECT_CALL(scheduler, OnProviderActivated()); 1809 EXPECT_CALL(scheduler, OnProviderActivated());
1805 // The scheduler should be notified of clearing the history. 1810 // The scheduler should be notified of clearing the history.
1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); 1811 EXPECT_CALL(scheduler, OnSuggestionsCleared());
1807 1812
1808 service->SetRemoteSuggestionsScheduler(&scheduler); 1813 service->SetRemoteSuggestionsScheduler(&scheduler);
1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, 1814 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT,
1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); 1815 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN);
1811 } 1816 }
1812 1817
1813 } // namespace ntp_snippets 1818 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698