chromium/components/offline_pages/core/background/request_coordinator_unittest.cc

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

#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 {
// put test constants here
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 {};

}  // namespace

// This class is a friend of RequestCoordinator, and can't be in the anonymous
// namespace.
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) {}

// If one item completes, and there are no more user requeted items left,
// we should make a scheduler entry for a non-user requested item.
TEST_F(RequestCoordinatorTest, RequestNotPickedDisabledItemsRemain) {}

// If one item completes, and there are no more user requeted items left,
// we should make a scheduler entry for a non-user requested item.
TEST_F(RequestCoordinatorTest, RequestNotPickedNonUserRequestedItemsRemain) {}

TEST_F(RequestCoordinatorTest, SchedulerGetsLeastRestrictiveConditions) {}

TEST_F(RequestCoordinatorTest, StartScheduledProcessingWithLoadingDisabled) {}

// TODO(dougarnett): Add StartScheduledProcessing test for QUEUE_UPDATE_FAILED.

// This tests a StopProcessing call before we have actually started the
// offliner.
TEST_F(RequestCoordinatorTest,
       StartScheduledProcessingThenStopProcessingImmediately) {}

// This tests a StopProcessing call after the background loading has been
// started.
TEST_F(RequestCoordinatorTest,
       StartScheduledProcessingThenStopProcessingLater) {}

// Test handling of StartScheduledProcessing before a previous attempt has been
// fully stopped.
TEST_F(RequestCoordinatorTest, StartAttemptBeforeFullyStopped) {}

// Verify the request coordinator can stop while in the picking state.
TEST_F(RequestCoordinatorTest, StopProcessingWhilePicking) {}

// This tests that canceling a request will result in TryNextRequest() getting
// called.
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) {}

}  // namespace offline_pages