#include "components/offline_pages/core/background/request_coordinator.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/containers/circular_deque.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/waitable_event.h"
#include "base/system/sys_info.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_mock_time_task_runner.h"
#include "base/time/time.h"
#include "components/offline_items_collection/core/pending_state.h"
#include "components/offline_pages/core/background/device_conditions.h"
#include "components/offline_pages/core/background/offliner.h"
#include "components/offline_pages/core/background/offliner_policy.h"
#include "components/offline_pages/core/background/offliner_stub.h"
#include "components/offline_pages/core/background/request_coordinator_stub_taco.h"
#include "components/offline_pages/core/background/request_queue.h"
#include "components/offline_pages/core/background/request_queue_store.h"
#include "components/offline_pages/core/background/save_page_request.h"
#include "components/offline_pages/core/background/scheduler.h"
#include "components/offline_pages/core/background/scheduler_stub.h"
#include "components/offline_pages/core/client_namespace_constants.h"
#include "components/offline_pages/core/offline_clock.h"
#include "components/offline_pages/core/offline_page_feature.h"
#include "services/network/test/test_network_quality_tracker.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace offline_pages {
namespace {
const std::string kClientNamespace("bookmark");
const std::string kId1("42");
const std::string kId2("life*universe+everything");
const ClientId kClientId1(kClientNamespace, kId1);
const ClientId kClientId2(kClientNamespace, kId2);
const int kRequestId1(1);
const int kRequestId2(2);
const long kTestTimeBudgetSeconds = …;
const int kBatteryPercentageHigh = …;
const bool kPowerRequired = …;
const bool kUserRequested = …;
const int kAttemptCount = …;
const std::string kRequestOrigin("abc.xyz");
class BoolCallbackResult { … };
class ObserverStub : public RequestCoordinator::Observer { … };
class ActiveTabInfoStub : public RequestCoordinator::ActiveTabInfo { … };
}
class RequestCoordinatorTest : public testing::Test { … };
RequestCoordinatorTest::RequestCoordinatorTest()
: … { … }
RequestCoordinatorTest::~RequestCoordinatorTest() { … }
void RequestCoordinatorTest::SetUp() { … }
void RequestCoordinatorTest::PumpLoop() { … }
void RequestCoordinatorTest::GetRequestsDone(
GetRequestsResult result,
std::vector<std::unique_ptr<SavePageRequest>> requests) { … }
void RequestCoordinatorTest::RemoveRequestsDone(
const MultipleItemStatuses& results) { … }
void RequestCoordinatorTest::GetQueuedRequestsDone(
std::vector<std::unique_ptr<SavePageRequest>> requests) { … }
void RequestCoordinatorTest::SetupForOfflinerDoneCallbackTest(
offline_pages::SavePageRequest* request) { … }
void RequestCoordinatorTest::SendOfflinerDoneCallback(
const SavePageRequest& request,
Offliner::RequestStatus status) { … }
SavePageRequest RequestCoordinatorTest::AddRequest1() { … }
SavePageRequest RequestCoordinatorTest::AddRequest2() { … }
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithNoRequests) { … }
TEST_F(RequestCoordinatorTest, NetworkProgressCallback) { … }
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithRequestInProgress) { … }
TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithNoRequests) { … }
TEST_F(RequestCoordinatorTest, StartImmediateProcessingOnSvelte) { … }
TEST_F(RequestCoordinatorTest, StartImmediateProcessingWhenDisconnected) { … }
TEST_F(RequestCoordinatorTest, StartImmediateProcessingWithRequestInProgress) { … }
TEST_F(RequestCoordinatorTest, SavePageLater) { … }
TEST_F(RequestCoordinatorTest, SavePageLaterFailed) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceeded) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestSucceededButLostNetwork) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailed) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoRetryFailure) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneRequestFailedNoNextFailure) { … }
TEST_F(RequestCoordinatorTest, OfflinerDoneForegroundCancel) { … }
TEST_F(RequestCoordinatorTest, RequestDeferred) { … }
TEST_F(RequestCoordinatorTest, RequestNotDeferred) { … }
TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) { … }
TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) { … }
TEST_F(RequestCoordinatorTest, SchedulerGetsLeastRestrictiveConditions) { … }
TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithLoadingDisabled) { … }
TEST_F(RequestCoordinatorTest,
StartScheduledProcessingThenStopProcessingImmediately) { … }
TEST_F(RequestCoordinatorTest,
StartScheduledProcessingThenStopProcessingLater) { … }
TEST_F(RequestCoordinatorTest, StartAttemptBeforeFullyStopped) { … }
TEST_F(RequestCoordinatorTest, StopProcessingWhilePicking) { … }
TEST_F(RequestCoordinatorTest, RemoveInflightRequest) { … }
TEST_F(RequestCoordinatorTest, RemoveInflightRequestAndAddAnother) { … }
TEST_F(RequestCoordinatorTest, MarkRequestCompleted) { … }
TEST_F(RequestCoordinatorTest, EnableForOffliner) { … }
TEST_F(RequestCoordinatorTest,
WatchdogTimeoutForScheduledProcessingNoLastSnapshot) { … }
TEST_F(RequestCoordinatorTest,
WatchdogTimeoutForImmediateProcessingNoLastSnapshot) { … }
TEST_F(RequestCoordinatorTest, TimeBudgetExceeded) { … }
TEST_F(RequestCoordinatorTest, TryNextRequestWithNoNetwork) { … }
TEST_F(RequestCoordinatorTest, GetAllRequests) { … }
TEST_F(RequestCoordinatorTest, SetAutoFetchNotificationState) { … }
TEST_F(RequestCoordinatorTest, RemoveRequestsIf) { … }
TEST_F(RequestCoordinatorTest, PauseAndResumeObserver) { … }
TEST_F(RequestCoordinatorTest, RemoveRequest) { … }
TEST_F(RequestCoordinatorTest,
SavePageStartsProcessingWhenConnectedAndNotLowEndDevice) { … }
TEST_F(RequestCoordinatorTest, SavePageDoesntStartProcessingWhenDisconnected) { … }
TEST_F(RequestCoordinatorTest,
SavePageDoesStartProcessingWhenPoorlyConnected) { … }
TEST_F(RequestCoordinatorTest,
ResumeStartsProcessingWhenConnectedAndNotLowEndDevice) { … }
TEST_F(RequestCoordinatorTest, SnapshotOnLastTryForScheduledProcessing) { … }
TEST_F(RequestCoordinatorTest, SnapshotOnLastTryForImmediateProcessing) { … }
TEST_F(RequestCoordinatorTest, RequestPendingNetworkOnResumeWithNoNetwork) { … }
TEST_F(RequestCoordinatorTest,
RequestPendingDownloadOnResumeWithOffliningDownload) { … }
TEST_F(RequestCoordinatorTest, RequestPendingNetworkOnAddWithNoNetwork) { … }
TEST_F(RequestCoordinatorTest,
RequestPendingDownloadOnAddedWithOffliningDownload) { … }
TEST_F(RequestCoordinatorTest, SavePageLaterRejectedDuplicateUrl) { … }
}