chromium/components/feed/core/v2/api_test/feed_api_test.h

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_FEED_CORE_V2_API_TEST_FEED_API_TEST_H_
#define COMPONENTS_FEED_CORE_V2_API_TEST_FEED_API_TEST_H_

#include <map>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <vector>

#include "base/functional/callback_forward.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/feed/core/common/pref_names.h"
#include "components/feed/core/proto/v2/keyvalue_store.pb.h"
#include "components/feed/core/proto/v2/wire/reliability_logging_enums.pb.h"
#include "components/feed/core/proto/v2/wire/there_and_back_again_data.pb.h"
#include "components/feed/core/proto/v2/wire/web_feeds.pb.h"
#include "components/feed/core/shared_prefs/pref_names.h"
#include "components/feed/core/v2/enums.h"
#include "components/feed/core/v2/feed_network.h"
#include "components/feed/core/v2/feed_store.h"
#include "components/feed/core/v2/feed_stream.h"
#include "components/feed/core/v2/feed_stream_surface.h"
#include "components/feed/core/v2/image_fetcher.h"
#include "components/feed/core/v2/metrics_reporter.h"
#include "components/feed/core/v2/prefs.h"
#include "components/feed/core/v2/public/reliability_logging_bridge.h"
#include "components/feed/core/v2/public/types.h"
#include "components/feed/core/v2/stream_model.h"
#include "components/feed/core/v2/test/proto_printer.h"
#include "components/feed/core/v2/test/stream_builder.h"
#include "components/feed/core/v2/test/test_util.h"
#include "components/feed/core/v2/types.h"
#include "components/feed/core/v2/wire_response_translator.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "components/search_engines/search_engines_test_environment.h"
#include "components/signin/public/base/signin_pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "net/http/http_status_code.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace feed {
namespace test {

std::unique_ptr<StreamModel> LoadModelFromStore(const StreamType& stream_type,
                                                FeedStore* store);
std::unique_ptr<StreamModelUpdateRequest> StoredModelData(
    const StreamType& stream_type,
    FeedStore* store);

// Returns the model state string (|StreamModel::DumpStateForTesting()|),
// given a model initialized with |update_request| and having |operations|
// applied.
std::string ModelStateFor(
    std::unique_ptr<StreamModelUpdateRequest> update_request,
    std::vector<feedstore::DataOperation> operations = {};

// Returns the model state string (|StreamModel::DumpStateForTesting()|),
// given a model initialized with |store|.
std::string ModelStateFor(const StreamType& stream_type, FeedStore* store);

feedwire::FeedAction MakeFeedAction(int64_t id, size_t pad_size = 0);

std::vector<feedstore::StoredAction> ReadStoredActions(FeedStore& store);

std::string SerializedOfflineBadgeContent();

feedwire::ThereAndBackAgainData MakeThereAndBackAgainData(int64_t id);

std::string DatastoreEntryToString(std::string_view key,
                                   std::string_view value);

class TestReliabilityLoggingBridge : public ReliabilityLoggingBridge {};

class TestSurfaceBase : public feed::SurfaceRenderer {};

class TestForYouSurface : public TestSurfaceBase {};
class TestWebFeedSurface : public TestSurfaceBase {};
class TestSingleWebFeedSurface : public TestSurfaceBase {};
class TestSupervisedFeedSurface : public TestSurfaceBase {};

class TestImageFetcher : public ImageFetcher {};

class TestUnreadContentObserver : public UnreadContentObserver {};

class TestFeedNetwork : public FeedNetwork {};

// Forwards to |FeedStream::WireResponseTranslator| unless a response is
// injected.
class TestWireResponseTranslator : public WireResponseTranslator {};

class FakeRefreshTaskScheduler : public RefreshTaskScheduler {};

class TestMetricsReporter : public MetricsReporter {};

// Base text fixture for feed API tests.
// Note: The web-feeds feature is enabled by default for these tests because
// GetCountry() is overridden to return one of the launch counties.
class FeedApiTest : public testing::Test, public FeedStream::Delegate {};

class FeedStreamTestForAllStreamTypes
    : public FeedApiTest,
      public ::testing::WithParamInterface<StreamType> {};

class FeedNetworkEndpointTest
    : public FeedApiTest,
      public ::testing::WithParamInterface<::testing::tuple<bool, bool>> {};

}  // namespace test
}  // namespace feed

#endif  // COMPONENTS_FEED_CORE_V2_API_TEST_FEED_API_TEST_H_