chromium/content/browser/background_sync/background_sync_manager_unittest.cc

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

#include "content/browser/background_sync/background_sync_manager.h"

#include <stdint.h>

#include <memory>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/check_deref.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/mock_entropy_provider.h"
#include "base/test/simple_test_clock.h"
#include "build/build_config.h"
#include "content/browser/background_sync/background_sync_launcher.h"
#include "content/browser/background_sync/background_sync_network_observer.h"
#include "content/browser/background_sync/background_sync_status.h"
#include "content/browser/devtools/devtools_background_services_context_impl.h"
#include "content/browser/service_worker/embedded_worker_test_helper.h"
#include "content/browser/service_worker/service_worker_container_host.h"
#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_registration_object_host.h"
#include "content/browser/storage_partition_impl.h"
#include "content/public/browser/background_sync_parameters.h"
#include "content/public/test/background_sync_test_util.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_permission_manager.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_utils.h"
#include "content/test/mock_background_sync_controller.h"
#include "content/test/test_background_sync_context.h"
#include "content/test/test_background_sync_manager.h"
#include "content/test/test_background_sync_proxy.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/permissions/permission_status.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration_options.mojom.h"

PermissionType;

namespace content {

namespace {

_;
Return;

const char kScope1[] =;
const char kScope2[] =;
const char kScript1[] =;
const char kScript2[] =;

void RegisterServiceWorkerCallback(bool* called,
                                   int64_t* store_registration_id,
                                   blink::ServiceWorkerStatusCode status,
                                   const std::string& status_message,
                                   int64_t registration_id) {}

void FindServiceWorkerRegistrationCallback(
    scoped_refptr<ServiceWorkerRegistration>* out_registration,
    blink::ServiceWorkerStatusCode status,
    scoped_refptr<ServiceWorkerRegistration> registration) {}

void UnregisterServiceWorkerCallback(bool* called,
                                     blink::ServiceWorkerStatusCode code) {}

blink::mojom::BackgroundSyncType GetBackgroundSyncType(
    const blink::mojom::SyncRegistrationOptions& options) {}

}  // namespace

class BackgroundSyncManagerTest
    : public testing::Test,
      public DevToolsBackgroundServicesContextImpl::EventObserver {};

TEST_F(BackgroundSyncManagerTest, Register) {}

TEST_F(BackgroundSyncManagerTest, Unregister) {}

TEST_F(BackgroundSyncManagerTest, UnregistrationStopsPeriodicTasks) {}

TEST_F(BackgroundSyncManagerTest, RegisterAndWaitToFireUntilResolved) {}

TEST_F(BackgroundSyncManagerTest, ResolveInvalidRegistration) {}

TEST_F(BackgroundSyncManagerTest, RegistrationIntact) {}

TEST_F(BackgroundSyncManagerTest, RegisterWithoutLiveSWRegistration) {}

TEST_F(BackgroundSyncManagerTest, RegisterWithoutActiveSWRegistration) {}

TEST_F(BackgroundSyncManagerTest, RegisterBadBackend) {}

TEST_F(BackgroundSyncManagerTest, RegisterPermissionDenied) {}

TEST_F(BackgroundSyncManagerTest, RegisterPermissionGranted) {}

TEST_F(BackgroundSyncManagerTest, TwoRegistrations) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationNonExisting) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationExisting) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationBadBackend) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationsZero) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationsOne) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationsTwo) {}

TEST_F(BackgroundSyncManagerTest, GetRegistrationsBadBackend) {}

TEST_F(BackgroundSyncManagerTest, Reregister) {}

TEST_F(BackgroundSyncManagerTest, ReregisterSecond) {}

TEST_F(BackgroundSyncManagerTest, ReregisterPeriodicSync) {}

TEST_F(BackgroundSyncManagerTest, RegisterMaxTagLength) {}

TEST_F(BackgroundSyncManagerTest, RebootRecovery) {}

TEST_F(BackgroundSyncManagerTest, RebootRecoveryPeriodicSync) {}

TEST_F(BackgroundSyncManagerTest, RebootRecoveryTwoServiceWorkers) {}

TEST_F(BackgroundSyncManagerTest, InitWithBadBackend) {}

TEST_F(BackgroundSyncManagerTest, SequentialOperations) {}

TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorker) {}

TEST_F(BackgroundSyncManagerTest,
       UnregisterServiceWorkerDuringSyncRegistration) {}

TEST_F(BackgroundSyncManagerTest, DeleteAndStartOverServiceWorkerContext) {}

TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterBrowserRestart) {}

TEST_F(BackgroundSyncManagerTest, DisabledManagerWorksAfterDeleteAndStartOver) {}

TEST_F(BackgroundSyncManagerTest, RegistrationEqualsTag) {}

TEST_F(BackgroundSyncManagerTest, StoreAndRetrievePreservesValues) {}

TEST_F(BackgroundSyncManagerTest, EmptyTagSupported) {}

TEST_F(BackgroundSyncManagerTest, PeriodicSyncOptions) {}

TEST_F(BackgroundSyncManagerTest, BothTypesOfSyncShareATag) {}

TEST_F(BackgroundSyncManagerTest, FiresOnRegistration) {}

TEST_F(BackgroundSyncManagerTest, PeriodicSyncFiresWhenExpected) {}

TEST_F(BackgroundSyncManagerTest, TestSupensionAndRevival) {}

TEST_F(BackgroundSyncManagerTest, UnregisterForOrigin) {}

TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptFails) {}

TEST_F(BackgroundSyncManagerTest, RunCallbackAfterEventsComplete) {}

TEST_F(BackgroundSyncManagerTest, ReregisterMidSyncFirstAttemptSucceeds) {}

TEST_F(BackgroundSyncManagerTest, OverwritePendingRegistration) {}

TEST_F(BackgroundSyncManagerTest, DisableWhilePending) {}

TEST_F(BackgroundSyncManagerTest, DisableWhileFiring) {}

TEST_F(BackgroundSyncManagerTest, FiresOnNetworkChange) {}

TEST_F(BackgroundSyncManagerTest, MultipleRegistrationsFireOnNetworkChange) {}

TEST_F(BackgroundSyncManagerTest, FiresOnManagerRestart) {}

TEST_F(BackgroundSyncManagerTest, FailedRegistrationShouldBeRemoved) {}

TEST_F(BackgroundSyncManagerTest, FailedRegistrationReregisteredAndFires) {}

TEST_F(BackgroundSyncManagerTest, DelayMidSync) {}

TEST_F(BackgroundSyncManagerTest, BadBackendMidSync) {}

TEST_F(BackgroundSyncManagerTest, UnregisterServiceWorkerMidSync) {}

TEST_F(BackgroundSyncManagerTest, KillManagerMidSync) {}

TEST_F(BackgroundSyncManagerTest, RegisterWithoutMainFrame) {}

TEST_F(BackgroundSyncManagerTest, RegisterExistingWithoutMainFrame) {}

TEST_F(BackgroundSyncManagerTest, DefaultParameters) {}

TEST_F(BackgroundSyncManagerTest, OverrideParameters) {}

TEST_F(BackgroundSyncManagerTest, DisablingFromControllerKeepsRegistrations) {}

TEST_F(BackgroundSyncManagerTest, DisabledPermanently) {}

TEST_F(BackgroundSyncManagerTest, NotifyBackgroundSyncRegistered) {}

// TODO(crbug.com/40641360): Update and enable when browser wake up logic has
// been updated to not schedule a wakeup with delay of 0.
TEST_F(BackgroundSyncManagerTest, DISABLED_WakeBrowserCalledForOneShotSync) {}

TEST_F(BackgroundSyncManagerTest, WakeBrowserCalledForPeriodicSync) {}

TEST_F(BackgroundSyncManagerTest, GetSoonestWakeupDeltaConsidersSyncType) {}

TEST_F(BackgroundSyncManagerTest, SoonestWakeupDeltaDecreasesWithTime) {}

TEST_F(BackgroundSyncManagerTest, SoonestWakeupDeltaAppliesBrowserWakeupLimit) {}

TEST_F(BackgroundSyncManagerTest, StaggeredPeriodicSyncRegistrations) {}

TEST_F(BackgroundSyncManagerTest, RelyOnAndroidNetworkDetection) {}

TEST_F(BackgroundSyncManagerTest, OneAttempt) {}

TEST_F(BackgroundSyncManagerTest, TwoFailedAttemptsForPeriodicSync) {}

TEST_F(BackgroundSyncManagerTest, TwoAttempts) {}

TEST_F(BackgroundSyncManagerTest, ThreeAttempts) {}

TEST_F(BackgroundSyncManagerTest, WaitsFullDelayTime) {}

TEST_F(BackgroundSyncManagerTest, RetryOnBrowserRestart) {}

TEST_F(BackgroundSyncManagerTest, RescheduleOnBrowserRestart) {}

TEST_F(BackgroundSyncManagerTest, RetryIfClosedMidSync) {}

TEST_F(BackgroundSyncManagerTest, AllTestsEventuallyFire) {}

TEST_F(BackgroundSyncManagerTest, LastChance) {}

TEST_F(BackgroundSyncManagerTest, EmulateOfflineSingleClient) {}

TEST_F(BackgroundSyncManagerTest, EmulateOfflineMultipleClients) {}

static void EmulateDispatchSyncEventCallback(
    bool* was_called,
    blink::ServiceWorkerStatusCode* code,
    blink::ServiceWorkerStatusCode status_code) {}

TEST_F(BackgroundSyncManagerTest, EmulateDispatchSyncEvent) {}

TEST_F(BackgroundSyncManagerTest, DispatchPeriodicSyncEvent) {}

TEST_F(BackgroundSyncManagerTest, EventsLoggedForRegistration) {}

TEST_F(BackgroundSyncManagerTest, EventsLoggedForPeriodicSyncRegistration) {}

TEST_F(BackgroundSyncManagerTest, UkmRecordedAtCompletion) {}

TEST_F(BackgroundSyncManagerTest, MaxSyncAttemptsWithNotificationPermission) {}

}  // namespace content