chromium/chrome/browser/web_applications/web_app_sync_bridge_unittest.cc

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

#include "chrome/browser/web_applications/web_app_sync_bridge.h"

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

#include "base/barrier_closure.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/test_future.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom-shared.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/proto/web_app_os_integration_state.pb.h"
#include "chrome/browser/web_applications/test/fake_web_app_database_factory.h"
#include "chrome/browser/web_applications/test/fake_web_app_provider.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_sync_test_utils.h"
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/browser/web_applications/test/web_app_test_observers.h"
#include "chrome/browser/web_applications/test/web_app_test_utils.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_install_manager.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "components/sync/model/data_batch.h"
#include "components/sync/model/entity_change.h"
#include "components/sync/protocol/entity_data.h"
#include "components/sync/protocol/web_app_specifics.pb.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "components/webapps/browser/install_result_code.h"
#include "components/webapps/browser/installable/installable_metrics.h"
#include "components/webapps/browser/uninstall_result_code.h"
#include "components/webapps/common/web_app_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkColor.h"

namespace web_app {

namespace {

_;

AppsList;

UserDisplayMode;
WebAppSpecifics_UserDisplayMode;
WebAppSpecifics_UserDisplayMode_BROWSER;
WebAppSpecifics_UserDisplayMode_STANDALONE;
WebAppSpecifics_UserDisplayMode_TABBED;
WebAppSpecifics_UserDisplayMode_UNSPECIFIED;

void RemoveWebAppFromAppsList(AppsList* apps_list,
                              const webapps::AppId& app_id) {}

bool IsSyncDataEqualIfApplied(const WebApp& expected_app,
                              std::unique_ptr<WebApp> app_to_apply_sync_data,
                              const syncer::EntityData& entity_data) {}

bool IsSyncDataEqual(const WebApp& expected_app,
                     const syncer::EntityData& entity_data) {}

bool RegistryContainsSyncDataBatchChanges(
    const Registry& registry,
    std::unique_ptr<syncer::DataBatch> data_batch) {}

std::unique_ptr<WebApp> CreateWebAppWithSyncOnlyFields(
    const std::string& url,
    std::optional<std::string> relative_manifest_id = std::nullopt) {}

AppsList CreateAppsList(const std::string& base_url, int num_apps) {}

void InsertAppIntoRegistry(Registry* registry, std::unique_ptr<WebApp> app) {}

void InsertAppsListIntoRegistry(Registry* registry, const AppsList& apps_list) {}

void ConvertAppToEntityChange(const WebApp& app,
                              syncer::EntityChange::ChangeType change_type,
                              syncer::EntityChangeList* sync_data_list) {}

void ConvertAppsListToEntityChangeList(
    const AppsList& apps_list,
    syncer::EntityChangeList* sync_data_list) {}

// Returns true if the app converted from entity_data exists in the apps_list.
bool RemoveEntityDataAppFromAppsList(const std::string& storage_key,
                                     const syncer::EntityData& entity_data,
                                     AppsList* apps_list) {}

void RunCallbacksOnInstall(
    const std::vector<WebApp*>& apps,
    const WebAppSyncBridge::RepeatingInstallCallback& callback,
    webapps::InstallResultCode code) {}

syncer::EntityChangeList ToEntityChageList(
    const webapps::AppId& app_id,
    const sync_pb::WebAppSpecifics& sync_proto,
    WebAppSyncBridge& sync_bridge) {}

}  // namespace

// TODO(dmurph): Replace these tests with tests in SingleClientWebAppsSyncTest,
// which can fake out the sync server and allow the WebAppProvider system to run
// in full w/o mocks.
class WebAppSyncBridgeTest : public WebAppTest {};

// Tests that the WebAppSyncBridge correctly reports data from the
// WebAppDatabase.
TEST_F(WebAppSyncBridgeTest, GetData) {}

// Tests that the client & storage tags are correct for entity data.
TEST_F(WebAppSyncBridgeTest, Identities) {}

// Test that a empty local data results in no changes sent to the sync system.
TEST_F(WebAppSyncBridgeTest, MergeFullSyncData_LocalSetAndServerSetAreEmpty) {}

TEST_F(WebAppSyncBridgeTest, MergeFullSyncData_LocalSetEqualsServerSet) {}

TEST_F(WebAppSyncBridgeTest, MergeFullSyncData_LocalSetGreaterThanServerSet) {}

TEST_F(WebAppSyncBridgeTest, MergeFullSyncData_LocalSetLessThanServerSet) {}

TEST_F(WebAppSyncBridgeTest, ApplyIncrementalSyncChanges_EmptyEntityChanges) {}

TEST_F(WebAppSyncBridgeTest, ApplyIncrementalSyncChanges_AddUpdateDelete) {}

TEST_F(WebAppSyncBridgeTest,
       ApplyIncrementalSyncChanges_DeleteHappensExternally) {}

TEST_F(WebAppSyncBridgeTest, ApplyIncrementalSyncChanges_UpdateOnly) {}

TEST_F(WebAppSyncBridgeTest,
       ApplyIncrementalSyncChanges_AddSyncAppsWithOverlappingPolicyApps) {}

TEST_F(WebAppSyncBridgeTest,
       ApplyIncrementalSyncChanges_UpdateSyncAppsWithOverlappingPolicyApps) {}

// Tests that if a policy app is installed, and that app is also in 'sync' and
// is uninstalled through sync, then it should remain on the system as a policy
// app.
TEST_F(WebAppSyncBridgeTest,
       ApplyIncrementalSyncChanges_DeleteSyncAppsWithOverlappingPolicyApps) {}

// Commits local data (e.g. installed web apps) before sync is hooked up. This
// tests that the web apps are correctly sent to USS after MergeFullSyncData is
// called.
TEST_F(WebAppSyncBridgeTest, CommitUpdate_CommitWhileNotTrackingMetadata) {}

TEST_F(WebAppSyncBridgeTest, CommitUpdate_CreateSyncApp) {}

TEST_F(WebAppSyncBridgeTest, CommitUpdate_UpdateSyncApp) {}

TEST_F(WebAppSyncBridgeTest, CommitUpdate_DeleteSyncApp) {}

TEST_F(WebAppSyncBridgeTest,
       CommitUpdate_CreateSyncAppWithOverlappingPolicyApp) {}

TEST_F(WebAppSyncBridgeTest,
       CommitUpdate_DeleteSyncAppWithOverlappingPolicyApp) {}

// Test that any apps that are still pending install from sync (or,
// |is_from_sync_and_pending_installation|) are continued to be installed when
// the bridge initializes.
TEST_F(WebAppSyncBridgeTest, InstallAppsFromSyncAndPendingInstallation) {}

// Tests that non user installable apps can also be removed by the
// WebAppSyncBridge during system startup, if `is_uninstalling` is set to true.
// Test for crbug.com/335253048, by using kSystem to mock that behavior. Since
// System Web Apps are only on Ash chrome, kPolicy is used instead on Lacro
TEST_F(WebAppSyncBridgeTest, CanDeleteNonUserInstallableApps) {}

// Tests that OnWebAppsWillBeUpdatedFromSync observer notification is called
// properly.
TEST_F(WebAppSyncBridgeTest,
       ApplyIncrementalSyncChanges_OnWebAppsWillBeUpdatedFromSync) {}

TEST_F(WebAppSyncBridgeTest, RetryIncompleteUninstalls) {}

syncer::EntityData CreateSyncEntityData(
    const std::string& name,
    const sync_pb::EntitySpecifics& specifics) {}

TEST_F(WebAppSyncBridgeTest, InvalidSyncData) {}

// Test that a serialized proto with an unrecognized new field can successfully
// sync install in the current version and preserves the field value.
TEST_F(WebAppSyncBridgeTest, SpecificsProtoWithNewFieldPreserved) {}

TEST_F(WebAppSyncBridgeTest, MigratePartiallyInstalledToCorrectStatus) {}

namespace {
UserDisplayModeSplitParam;

constexpr std::optional<WebAppSpecifics_UserDisplayMode>
    kSyncUserDisplayModes[]{};

constexpr std::optional<UserDisplayMode> kInstalledUserDisplayModes[]{};

std::string ToString(std::optional<WebAppSpecifics_UserDisplayMode> udm) {}

std::string ToString(std::optional<UserDisplayMode> udm) {}
}  // namespace

class WebAppSyncBridgeTest_UserDisplayModeSplit
    : public WebAppTest,
      public testing::WithParamInterface<UserDisplayModeSplitParam> {};

TEST_P(WebAppSyncBridgeTest_UserDisplayModeSplit, SyncUpdateToUserDisplayMode) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace web_app