#include "chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_handler.h"
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "base/base64.h"
#include "base/files/file_util.h"
#include "base/functional/callback_forward.h"
#include "base/test/bind.h"
#include "base/test/gmock_move_support.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "base/timer/elapsed_timer.h"
#include "base/token.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/image_fetcher/image_decoder_impl.h"
#include "chrome/browser/optimization_guide/mock_optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service.h"
#include "chrome/browser/optimization_guide/optimization_guide_keyed_service_factory.h"
#include "chrome/browser/search/background/wallpaper_search/wallpaper_search_background_manager.h"
#include "chrome/browser/search/background/wallpaper_search/wallpaper_search_data.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/ui/hats/hats_service_factory.h"
#include "chrome/browser/ui/hats/mock_hats_service.h"
#include "chrome/browser/ui/hats/survey_config.h"
#include "chrome/browser/ui/webui/side_panel/customize_chrome/wallpaper_search/wallpaper_search_string_map.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "components/image_fetcher/core/mock_image_decoder.h"
#include "components/optimization_guide/core/model_execution/feature_keys.h"
#include "components/optimization_guide/core/model_quality/feature_type_map.h"
#include "components/optimization_guide/core/model_quality/model_quality_log_entry.h"
#include "components/optimization_guide/core/model_quality/test_model_quality_logs_uploader_service.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/proto/features/wallpaper_search.pb.h"
#include "components/optimization_guide/proto/model_execution.pb.h"
#include "components/optimization_guide/proto/model_quality_service.pb.h"
#include "components/search/ntp_features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/signin/public/identity_manager/identity_test_utils.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "skia/ext/image_operations.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
namespace {
ModelQualityLogEntry;
LogAiDataRequest;
_;
An;
DoAll;
Invoke;
Return;
SaveArg;
class MockClient
: public side_panel::customize_chrome::mojom::WallpaperSearchClient { … };
class MockWallpaperSearchBackgroundManager
: public WallpaperSearchBackgroundManager { … };
class MockWallpaperSearchStringMap : public WallpaperSearchStringMap { … };
std::unique_ptr<TestingProfile> MakeTestingProfile(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
TestingPrefServiceSimple* local_state) { … }
}
class WallpaperSearchHandlerTest : public testing::Test { … };
TEST_F(WallpaperSearchHandlerTest, GetHistory) { … }
TEST_F(WallpaperSearchHandlerTest,
GetDescriptors_Success_DescriptorsFormatCorrect) { … }
TEST_F(WallpaperSearchHandlerTest,
GetDescriptors_Success_PrioritizesLatestRequest) { … }
TEST_F(WallpaperSearchHandlerTest,
GetDescriptors_Failure_DescriptorsFormatIncorrect) { … }
TEST_F(WallpaperSearchHandlerTest, GetDescriptors_Failure_NoValidDescriptors) { … }
TEST_F(WallpaperSearchHandlerTest, GetDescriptors_Success_MissingTranslations) { … }
TEST_F(WallpaperSearchHandlerTest, GetDescriptors_Failure_DataIsUnreachable) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_Success) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_MultipleRequests) { … }
TEST_F(WallpaperSearchHandlerTest,
GetWallpaperSearchResults_TwoDescriptorsQueryFormatCorrect) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_ConvertsHueToHex) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_NoResponse) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_NoImages) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_RequestThrottled) { … }
TEST_F(WallpaperSearchHandlerTest, GetWallpaperSearchResults_SignedOut) { … }
TEST_F(WallpaperSearchHandlerTest, SetBackgroundToHistoryImage) { … }
TEST_F(WallpaperSearchHandlerTest, SetBackgroundToWallpaperSearchResult) { … }
TEST_F(WallpaperSearchHandlerTest, SetUserFeedback) { … }
TEST_F(WallpaperSearchHandlerTest, LaunchHatsSurvey) { … }
TEST_F(WallpaperSearchHandlerTest, GetInspirations_Success) { … }
TEST_F(WallpaperSearchHandlerTest, GetInspirations_Success_Descriptors) { … }
TEST_F(WallpaperSearchHandlerTest,
GetInspirations_InspirationsFormatIncorrect) { … }
TEST_F(WallpaperSearchHandlerTest, GetInspirations_Failure_DataUnreachable) { … }
TEST_F(WallpaperSearchHandlerTest, SetBackgroundToInspirationImage) { … }