#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) { … }
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) { … }
}
class WebAppSyncBridgeTest : public WebAppTest { … };
TEST_F(WebAppSyncBridgeTest, GetData) { … }
TEST_F(WebAppSyncBridgeTest, Identities) { … }
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) { … }
TEST_F(WebAppSyncBridgeTest,
ApplyIncrementalSyncChanges_DeleteSyncAppsWithOverlappingPolicyApps) { … }
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_F(WebAppSyncBridgeTest, InstallAppsFromSyncAndPendingInstallation) { … }
TEST_F(WebAppSyncBridgeTest, CanDeleteNonUserInstallableApps) { … }
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_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) { … }
}
class WebAppSyncBridgeTest_UserDisplayModeSplit
: public WebAppTest,
public testing::WithParamInterface<UserDisplayModeSplitParam> { … };
TEST_P(WebAppSyncBridgeTest_UserDisplayModeSplit, SyncUpdateToUserDisplayMode) { … }
INSTANTIATE_TEST_SUITE_P(…);
}