chromium/components/feed/core/v2/api_test/feed_api_stream_unittest.cc

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

#include "base/feature_list.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "build/buildflag.h"
#include "components/feed/core/common/pref_names.h"
#include "components/feed/core/proto/v2/wire/feed_entry_point_source.pb.h"
#include "components/feed/core/proto/v2/wire/feed_query.pb.h"
#include "components/feed/core/proto/v2/wire/info_card.pb.h"
#include "components/feed/core/shared_prefs/pref_names.h"
#include "components/feed/core/v2/api_test/feed_api_test.h"
#include "components/feed/core/v2/config.h"
#include "components/feed/core/v2/enums.h"
#include "components/feed/core/v2/feed_network.h"
#include "components/feed/core/v2/feed_stream.h"
#include "components/feed/core/v2/feedstore_util.h"
#include "components/feed/core/v2/prefs.h"
#include "components/feed/core/v2/public/feed_api.h"
#include "components/feed/core/v2/public/feed_service.h"
#include "components/feed/core/v2/public/stream_type.h"
#include "components/feed/core/v2/public/types.h"
#include "components/feed/core/v2/scheduling.h"
#include "components/feed/core/v2/test/callback_receiver.h"
#include "components/feed/core/v2/test/stream_builder.h"
#include "components/feed/feed_feature_list.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

// This file is primarily for testing access to the Feed content, though it
// contains some other miscellaneous tests.

namespace feed {
namespace test {
namespace {

WebFeedChangeReason;

const int kTestInfoCardType1 =;
const int kTestInfoCardType2 =;
const int kMinimumViewIntervalSeconds =;

TEST_F(FeedApiTest, IsArticlesListVisibleByDefault) {}

TEST_F(FeedApiTest, DoNotRefreshIfArticlesListIsHidden) {}

TEST_F(FeedApiTest,
       DoNotRefreshIfSnippetsByDseDisabled_ignoredWithoutFlagEnabled) {}

TEST_F(FeedApiTest, DoNotRefreshIfSnippetsByDseDisabled) {}

TEST_F(FeedApiTest, BackgroundRefreshForYouSuccess) {}

TEST_F(FeedApiTest, WebFeedDoesNotBackgroundRefresh) {}

TEST_F(FeedApiTest, BackgroundRefreshPrefetchesImages) {}

TEST_F(FeedApiTest, BackgroundRefreshNotAttemptedWhenModelIsLoading) {}

TEST_F(FeedApiTest, BackgroundRefreshNotAttemptedAfterModelIsLoaded) {}

TEST_F(FeedApiTest, SurfaceReceivesInitialContent) {}

TEST_F(FeedApiTest, SurfaceReceivesInitialContentLoadedAfterAttach) {}

TEST_F(FeedApiTest, SurfaceReceivesUpdatedContent) {}

TEST_F(FeedApiTest, SurfaceReceivesSecondUpdatedContent) {}

TEST_F(FeedApiTest, RemoveAllContentResultsInZeroState) {}

TEST_F(FeedApiTest, DetachSurface) {}

TEST_F(FeedApiTest, DetachSurfaceBeforeReceivingContent) {}

TEST_F(FeedApiTest, FetchImage) {}

TEST_F(FeedApiTest, FetchAsyncData) {}

TEST_F(FeedStreamTestForAllStreamTypes,
       ReportContentLifetimeMetricsViaOnLoadStream) {}

TEST_F(FeedStreamTestForAllStreamTypes,
       DoNotReportContentLifetimeMetricsWhenStreamMetadataNotPopulated) {}

TEST_F(FeedStreamTestForAllStreamTypes,
       DoNotReportContentLifetimeStaleAgeWhenNotPopulated) {}

TEST_F(FeedStreamTestForAllStreamTypes,
       DoNotReportContentLifetimeInvalidAgeWhenNotPopulated) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadFromNetwork) {}

TEST_P(FeedStreamTestForAllStreamTypes, UseFeedQueryOverride) {}

TEST_F(FeedApiTest, FetchAfterStartup) {}

TEST_F(FeedApiTest, WebFeedLoadWithNoSubscriptionsWithoutOnboarding) {}

TEST_F(FeedApiTest, WebFeedLoadWithNoSubscriptions) {}

TEST_F(FeedApiTest, WebFeedContentExprirationWithNoSubscriptions) {}

// Test that we use QueryInteractiveFeedDiscoverApi and QueryNextPageDiscoverApi
// when kDiscoFeedEndpoint is enabled.
TEST_F(FeedApiTest, LoadFromNetworkDiscoFeedEnabled) {}

TEST_P(FeedNetworkEndpointTest, TestAllNetworkEndpointConfigs) {}

// Perform a background refresh when DiscoFeedEndpoint is enabled. A
// QueryBackgroundFeedDiscoverApi request should be made.
TEST_F(FeedApiTest, BackgroundRefreshDiscoFeedEnabled) {}

TEST_P(FeedStreamTestForAllStreamTypes, ForceRefreshForDebugging) {}

TEST_F(FeedApiTest, RefreshScheduleFlow) {}

TEST_F(FeedApiTest, ForceRefreshIfMissedScheduledRefresh) {}

TEST_F(FeedApiTest, LoadFromNetworkBecauseStoreIsStale_NetworkStaleAge) {}

TEST_F(FeedApiTest, LoadFromNetworkBecauseStoreIsExpired_NetworkExpiredAge) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadFromNetworkBecauseStoreIsStale) {}

// Same as LoadFromNetworkBecauseStoreIsStale, but with expired content.
TEST_F(FeedApiTest, LoadFromNetworkBecauseStoreIsExpired) {}

TEST_F(FeedApiTest, LoadStaleDataBecauseNetworkRequestFails) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadFailsStoredDataIsExpired) {}

TEST_F(FeedApiTest, LoadFromNetworkFailsDueToProtoTranslation) {}
TEST_F(FeedApiTest, DoNotLoadFromNetworkWhenOffline) {}

TEST_F(FeedApiTest, DoNotLoadStreamWhenArticleListIsHidden) {}

TEST_F(FeedApiTest, DoNotLoadStreamWhenEulaIsNotAccepted) {}

TEST_F(FeedApiTest, LoadStreamAfterEulaIsAccepted) {}

TEST_F(FeedApiTest, WebFeedUsesSignedInRequestAfterHistoryIsDeleted) {}

TEST_F(FeedApiTest, ShouldMakeFeedQueryRequestConsumesQuota) {}

TEST_F(FeedApiTest, LoadStreamFromStore) {}

TEST_F(FeedApiTest, LoadStreamFromStoreValidatesUser) {}

TEST_F(FeedApiTest, LoadingSpinnerIsSentInitially) {}

TEST_F(FeedApiTest, DetachSurfaceWhileLoadingModel) {}

TEST_F(FeedApiTest, AttachMultipleSurfacesLoadsModelOnce) {}

TEST_P(FeedStreamTestForAllStreamTypes, ModelChangesAreSavedToStorage) {}

TEST_F(FeedApiTest, ReportActionAfterSurfaceDestroyed) {}

TEST_F(FeedApiTest, ReportActionAfterSurfaceDestroyedAndCleanedUp) {}

TEST_F(FeedApiTest, ReportSliceViewedIdentifiesCorrectIndex) {}

TEST_F(FeedApiTest, ReportSliceViewed_AddViewedContentHashes) {}

TEST_F(FeedApiTest, ReportOpenInNewTabAction) {}

TEST_F(FeedApiTest, ReportOpenInNewTabInGroupAction) {}

TEST_F(FeedApiTest, HasUnreadContentAfterLoadFromNetwork) {}

TEST_F(FeedApiTest, HasUnreadContentInitially) {}

TEST_F(FeedApiTest, NetworkFetchWithNoNewContentDoesNotProvideUnreadContent) {}

TEST_F(FeedApiTest, RemovedUnreadContentObserverDoesNotReceiveCalls) {}

TEST_F(FeedApiTest, DeletedUnreadContentObserverDoesNotCrash) {}

TEST_F(FeedApiTest, HasUnreadContentAfterLoadFromStore) {}

TEST_F(FeedApiTest, FollowForcesRefreshWhileSurfaceAttached_NotWorking) {}

// Verify that following a web feed triggers a refresh.
// Also verify the unread content observer events.
TEST_F(FeedApiTest, FollowForcesRefresh) {}

TEST_F(FeedApiTest, ReportFeedViewedUpdatesObservers) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadMoreIndicatorSliceId) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadMoreAppendsContent) {}

TEST_P(FeedStreamTestForAllStreamTypes, LoadMorePersistsData) {}

TEST_F(FeedApiTest, LoadMorePersistAndLoadMore) {}

TEST_F(FeedApiTest, LoadMoreSendsTokens) {}

TEST_F(FeedApiTest, LoadMoreAbortsIfNoNextPageToken) {}

TEST_F(FeedApiTest, LoadMoreFail) {}

TEST_F(FeedApiTest, LoadMoreWithClearAllInResponse) {}

TEST_F(FeedApiTest, LoadMoreBeforeLoad) {}

TEST_F(FeedApiTest, ReadNetworkResponse) {}

TEST_F(FeedApiTest, ReadNetworkResponseWithNoContent) {}

TEST_F(FeedApiTest, ClearAllAfterLoadResultsInRefresh) {}

TEST_F(FeedApiTest, ClearAllWithNoSurfacesAttachedDoesNotReload) {}

TEST_F(FeedApiTest, ClearAllWhileLoadingMoreDoesNotLoadMore) {}

TEST_F(FeedApiTest, ClearAllWipesAllState) {}

TEST_F(FeedApiTest, StorePendingAction) {}

TEST_F(FeedApiTest, UploadActionWhileSignedOutIsNoOp) {}

TEST_F(FeedApiTest, SignOutWhileUploadActionDoesNotUpload) {}

TEST_F(FeedApiTest, ClearAllWhileUploadActionDoesNotUpload) {}

TEST_F(FeedApiTest, WrongUserUploadActionDoesNotUpload) {}

TEST_F(FeedApiTest, LoggingPropertiesWithNoAccountDoesNotUpload) {}

TEST_F(FeedApiTest, StorePendingActionAndUploadNow) {}

TEST_F(FeedApiTest, ProcessViewActionResultsInDelayedUpload) {}

TEST_F(FeedApiTest, ProcessViewActionDroppedBecauseNotEnabled) {}

TEST_F(FeedApiTest, ActionsUploadWithoutConditionsWhenFeatureDisabled) {}

TEST_F(FeedApiTest, LoadStreamFromNetworkUploadsActions) {}

TEST_F(FeedApiTest, UploadedActionsHaveSequentialNumbers) {}

TEST_F(FeedApiTest, LoadMoreUploadsActions) {}

TEST_F(FeedApiTest, LoadMoreDoesNotUpdateLoggingEnabled) {}

TEST_F(FeedApiTest, LoadStreamWithLoggingEnabled) {}

TEST_F(FeedApiTest, BackgroundingAppUploadsActions) {}

TEST_F(FeedApiTest, BackgroundingAppDoesNotUploadActions) {}

TEST_F(FeedApiTest, UploadedActionsAreNotSentAgain) {}

TEST_F(FeedApiTest, UploadActionsOneBatch) {}

TEST_F(FeedApiTest, UploadActionsMultipleBatches) {}

TEST_F(FeedApiTest, UploadActionsSkipsStaleActionsByTimestamp) {}

TEST_F(FeedApiTest, UploadActionsErasesStaleActionsByAttempts) {}

TEST_F(FeedApiTest, MetadataLoadedWhenDatabaseInitialized) {}

TEST_F(FeedApiTest, ClearAllWhenDatabaseInitializedForWrongUser) {}

TEST_F(FeedApiTest, ModelUnloadsAfterTimeout) {}

TEST_F(FeedApiTest, ModelDoesNotUnloadIfSurfaceIsAttached) {}

TEST_F(FeedApiTest, ModelUnloadsAfterSecondTimeout) {}

TEST_F(FeedApiTest, SendsClientInstanceId) {}

TEST_F(FeedApiTest, SignedOutSessionIdConsistency) {}

TEST_F(FeedApiTest, ClearAllResetsSessionId) {}

TEST_F(FeedApiTest, SignedOutSessionIdExpiry) {}

TEST_F(FeedApiTest, SessionIdPersistsAcrossStreamLoads) {}

TEST_F(FeedApiTest, PersistentKeyValueStoreIsClearedOnClearAll) {}

TEST_F(FeedApiTest, LoadMultipleStreams) {}

TEST_F(FeedApiTest, UnloadOnlyOneOfMultipleModels) {}

TEST_F(FeedApiTest, ExperimentsAreClearedOnClearAll) {}

TEST_F(FeedApiTest, CreateAndCommitEphemeralChange) {}

TEST_F(FeedApiTest, CreateAndCommitEphemeralChangeOnNoOperation) {}

TEST_F(FeedApiTest, RejectEphemeralChange) {}

// Test that we overwrite stored stream data, even if ContentId's do not change.
TEST_F(FeedApiTest, StreamDataOverwritesOldStream) {}

TEST_F(FeedApiTest, HasUnreadContentIsFalseAfterFeedViewed) {}

TEST_F(FeedApiTest, HasUnreadContentRemainsFalseIfFeedViewedBeforeRefresh) {}

TEST_F(FeedApiTest,
       LoadingForYouStreamTriggersWebFeedRefreshIfNoUnreadContent) {}

TEST_F(
    FeedApiTest,
    LoadingForYouStreamDoesNotTriggerWebFeedRefreshIfNoSubscriptionsWhithoutOnboarding) {}

TEST_F(
    FeedApiTest,
    LoadForYouStreamDoesNotTriggerWebFeedRefreshContentIfIsAlreadyAvailable) {}

TEST_F(FeedApiTest, WasUrlRecentlyNavigatedFromFeed) {}

// After 10 URLs are navigated, they are forgotten in FIFO order.
TEST_F(FeedApiTest, WasUrlRecentlyNavigatedFromFeedMaxHistory) {}

TEST_F(FeedApiTest, ClearAllOnStartupIfFeedIsDisabled) {}

#if BUILDFLAG(IS_ANDROID)
TEST_F(FeedApiTest, ClearAllOnStartupIfFeedIsDisabledByDse) {
  CallbackReceiver<> on_clear_all;
  on_clear_all_ = on_clear_all.BindRepeating();

  // Fetch a feed, so that there's stored data.
  response_translator_.InjectResponse(MakeTypicalInitialModelState());
  TestForYouSurface surface(stream_.get());
  WaitForIdleTaskQueue();

  // Turn off the feed, and re-create FeedStream. It should perform a ClearAll.
  profile_prefs_.SetBoolean(feed::prefs::kEnableSnippetsByDse, false);
  CreateStream(/*wait_for_initialization=*/true,
               /*is_new_tab_search_engine_url_android_enabled*/ true);
  EXPECT_TRUE(on_clear_all.called());

  // Re-create the feed, and verify ClearAll isn't called again.
  on_clear_all.Clear();
  base::HistogramTester histograms;
  CreateStream(/*wait_for_initialization=*/true,
               /*is_new_tab_search_engine_url_android_enabled*/ true);

  EXPECT_FALSE(on_clear_all.called());
}
#endif  // BUILDFLAG(IS_ANDROID)

TEST_F(FeedApiTest, ReportUserSettingsFromMetadataWaaOnDpOff) {}

TEST_F(FeedApiTest, ReportUserSettingsFromMetadataWaaOffDpOn) {}

TEST_F(FeedStreamTestForAllStreamTypes, ManualRefreshWithoutSurfaceIsAborted) {}

TEST_F(FeedStreamTestForAllStreamTypes, ManualRefreshInterestFeedSuccess) {}

TEST_F(FeedApiTest, ManualRefreshResetsRequestThrottlerQuota) {}

TEST_F(FeedStreamTestForAllStreamTypes, ManualRefreshWebFeedSuccess) {}

TEST_F(FeedApiTest, ManualRefreshFailsBecauseNetworkRequestFails) {}

TEST_F(FeedApiTest, ManualRefreshSuccessAfterUnload) {}

TEST_F(FeedApiTest, ManualRefreshSuccessAfterPreviousLoadFailure) {}

TEST_F(FeedApiTest, ManualRefreshFailesWhenLoadingInProgress) {}

TEST_F(FeedApiTest, ManualRefresh_MetricsOnNoCardViewed) {}

TEST_F(FeedApiTest, ManualRefresh_MetricsOnCardsViewed) {}

TEST_F(FeedApiTest, ManualRefresh_MetricsOnCardsViewedAfterRestart) {}

TEST_F(FeedApiTest, ForYouContentOrderUnset) {}

TEST_F(FeedApiTest, ContentOrderIsGroupedByDefault) {}

TEST_F(FeedApiTest, SetContentOrderReloadsContent) {}

TEST_F(FeedApiTest, SetContentOrderIsSavedeNotRefreshedIfUnchanged) {}

// This is a regression test for crbug.com/1249772.
TEST_F(FeedApiTest, SignInWhileSurfaceIsOpen) {}

TEST_F(FeedApiTest, SignOutWhileSurfaceIsOpen) {}

TEST_F(FeedApiTest, FollowedFromWebPageMenuCount) {}

TEST_F(FeedApiTest, InfoCardTrackingActions) {}

TEST_F(FeedApiTest, InvalidateFeedCache_CauseRefreshOnNextLoad) {}

TEST_F(FeedApiTest, InvalidateFeedCache_DoesNotForceRefreshFeedWhileInUse) {}

TEST_F(FeedApiTest, InvalidateFeedCache_UnknownDoesNotForceRefreshAnyFeeds) {}

TEST_F(FeedApiTest, InvalidateFeedCache_DoesNotRefreshOtherFeed) {}

class FeedCloseRefreshTest : public FeedApiTest {};

TEST_F(FeedCloseRefreshTest, Scroll) {}

TEST_F(FeedCloseRefreshTest, Open) {}

TEST_F(FeedCloseRefreshTest, OpenInNewTab) {}

TEST_F(FeedCloseRefreshTest, ManualRefreshResetsCoalesceTimestamp) {}

TEST_F(FeedCloseRefreshTest, FeedViewed) {}

TEST_F(FeedCloseRefreshTest, ExistingScheduleGetsReplaced) {}

TEST_F(FeedCloseRefreshTest, Retry) {}

TEST_F(FeedCloseRefreshTest, RequestType) {}

TEST_F(FeedApiTest, CheckDuplicatedContents) {}

TEST_F(FeedApiTest, GetRequestMetadataForSignedOutUser) {}

TEST_F(FeedApiTest, GetRequestMetadataForSignedInUser) {}

TEST_F(FeedApiTest, GetRequestMetadataForSigninDisallowedUser) {}

TEST_F(FeedApiTest, GetRequestMetadataForSigninDisallowedUserWhenSignedIn) {}

TEST_F(FeedApiTest, GetRequestMetadataWithDefaultSearchEngine) {}

TEST_F(FeedApiTest, ClearAllOnSigninAllowedPrefChange) {}

TEST_F(FeedApiTest, RefreshFeedOnStartWithFlag) {}

TEST_F(FeedApiTest, DoNotRefreshFeedOnStartWithoutFlag) {}

class SignedOutViewDemotionTest : public FeedApiTest {};

TEST_F(SignedOutViewDemotionTest, ViewsAreSent) {}

TEST_F(SignedOutViewDemotionTest, ViewsAreNotStoredWhenSignedIn) {}

TEST_F(SignedOutViewDemotionTest, ViewsAreNotStoredWhenFeatureIsOff) {}

TEST_F(SignedOutViewDemotionTest, OldViewsAreDeleted) {}

// Keep instantiations at the bottom.
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

}  // namespace
}  // namespace test
}  // namespace feed