chromium/chrome/browser/search_engines/template_url_service_sync_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>

#include <memory>
#include <utility>

#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/search_engines/template_url_service_test_util.h"
#include "chrome/test/base/testing_profile.h"
#include "components/prefs/testing_pref_service.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_engines_test_util.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_client.h"
#include "components/search_engines/template_url_starter_pack_data.h"
#include "components/search_engines/util.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/search_engine_specifics.pb.h"
#include "components/sync/test/sync_change_processor_wrapper_for_test.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/url_formatter/url_formatter.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

Time;
IsNull;
NotNull;

namespace {

const char kOmniboxScheme[] =;

// Extract the GUID from a search engine syncer::SyncData.
std::string GetGUID(const syncer::SyncData& sync_data) {}

// Extract the URL from a search engine syncer::SyncData.
std::string GetURL(const syncer::SyncData& sync_data) {}

// Extract the keyword from a search engine syncer::SyncData.
std::string GetKeyword(const syncer::SyncData& sync_data) {}

// Much like TemplateURLService::CreateSyncDataFromTemplateURL(), but allows the
// caller to override the keyword, URL, or GUID fields with empty strings, in
// order to create custom data that should be handled specially when synced to a
// client.
syncer::SyncData CreateCustomSyncData(const TemplateURL& turl,
                                      bool autogenerate_keyword,
                                      const std::string& url,
                                      const std::string& sync_guid,
                                      int prepopulate_id = -1) {}


// TestChangeProcessor --------------------------------------------------------

// Dummy SyncChangeProcessor used to help review what SyncChanges are pushed
// back up to Sync.
class TestChangeProcessor : public syncer::SyncChangeProcessor {};

TestChangeProcessor::TestChangeProcessor() :{}

TestChangeProcessor::~TestChangeProcessor() {}

std::optional<syncer::ModelError> TestChangeProcessor::ProcessSyncChanges(
    const base::Location& from_here,
    const syncer::SyncChangeList& change_list) {}

class TestTemplateURLServiceClient : public TemplateURLServiceClient {};

}  // namespace

// TemplateURLServiceSyncTest -------------------------------------------------
// TODO(crbug.com/40276119): Remove this test when the default search provider
// preference stops being synced.
class TemplateURLServiceSyncTest : public testing::Test {};

TemplateURLServiceSyncTest::TemplateURLServiceSyncTest()
    :{}

void TemplateURLServiceSyncTest::SetUp() {}

void TemplateURLServiceSyncTest::TearDown() {}

std::unique_ptr<syncer::SyncChangeProcessor>
TemplateURLServiceSyncTest::PassProcessor() {}

void TemplateURLServiceSyncTest::AssertEquals(const TemplateURL& expected,
                                              const TemplateURL& actual) const {}

void TemplateURLServiceSyncTest::AssertEquals(
    const syncer::SyncDataList& data1,
    const syncer::SyncDataList& data2) const {}

syncer::SyncChange TemplateURLServiceSyncTest::CreateTestSyncChange(
    syncer::SyncChange::SyncChangeType type,
    std::unique_ptr<TemplateURL> turl) const {}

syncer::SyncDataList TemplateURLServiceSyncTest::CreateInitialSyncData() const {}

std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::Deserialize(
    const syncer::SyncData& sync_data) {}

std::unique_ptr<TemplateURL> TemplateURLServiceSyncTest::CopyTemplateURL(
    const TemplateURLData* turl,
    const std::string& url,
    const std::string& guid) {}

std::optional<syncer::ModelError>
TemplateURLServiceSyncTest::MergeAndExpectNotify(
    syncer::SyncDataList initial_sync_data,
    int expected_notify_count) {}

std::optional<syncer::ModelError>
TemplateURLServiceSyncTest::MergeAndExpectNotifyAtLeast(
    syncer::SyncDataList initial_sync_data) {}

std::optional<syncer::ModelError>
TemplateURLServiceSyncTest::ProcessAndExpectNotify(
    syncer::SyncChangeList changes,
    int expected_notify_count) {}

std::optional<syncer::ModelError>
TemplateURLServiceSyncTest::ProcessAndExpectNotifyAtLeast(
    syncer::SyncChangeList changes) {}

// Actual tests ---------------------------------------------------------------

TEST_F(TemplateURLServiceSyncTest, SerializeDeserialize) {}

TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataBasic) {}

TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithOmniboxExtension) {}

TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataWithSearchOverrideExtension) {}

TEST_F(TemplateURLServiceSyncTest, GetAllSyncDataNoManagedEngines) {}

TEST_F(TemplateURLServiceSyncTest, StartSyncEmpty) {}

TEST_F(TemplateURLServiceSyncTest, MergeIntoEmpty) {}

TEST_F(TemplateURLServiceSyncTest, MergeInAllNewData) {}

TEST_F(TemplateURLServiceSyncTest, MergeSyncIsTheSame) {}

TEST_F(TemplateURLServiceSyncTest, MergeUpdateFromSync) {}

TEST_F(TemplateURLServiceSyncTest, MergeAddFromOlderSyncData) {}

TEST_F(TemplateURLServiceSyncTest, MergeAddFromNewerSyncData) {}

TEST_F(TemplateURLServiceSyncTest, MergeIgnoresPolicyAndPlayAPIEngines) {}

TEST_F(TemplateURLServiceSyncTest, ProcessChangesEmptyModel) {}

TEST_F(TemplateURLServiceSyncTest, ProcessChangesNoConflicts) {}

TEST_F(TemplateURLServiceSyncTest,
       ProcessChangesWithDuplicateKeywordsSyncWins) {}

TEST_F(TemplateURLServiceSyncTest,
       ProcessChangesWithDuplicateKeywordsLocalWins) {}

TEST_F(TemplateURLServiceSyncTest, ProcessTemplateURLChange) {}

TEST_F(TemplateURLServiceSyncTest, ProcessChangesWithLocalExtensions) {}

TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordMigrated) {}

TEST_F(TemplateURLServiceSyncTest, AutogeneratedKeywordConflicts) {}

TEST_F(TemplateURLServiceSyncTest, DuplicateEncodingsRemoved) {}

TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsBasic) {}

TEST_F(TemplateURLServiceSyncTest, MergeTwoClientsDupesAndConflicts) {}

TEST_F(TemplateURLServiceSyncTest, StopSyncing) {}

TEST_F(TemplateURLServiceSyncTest, SyncErrorOnInitialSync) {}

TEST_F(TemplateURLServiceSyncTest, SyncErrorOnLaterSync) {}

TEST_F(TemplateURLServiceSyncTest, MergeTwiceWithSameSyncData) {}

TEST_F(TemplateURLServiceSyncTest, SyncedDefaultGUIDArrivesFirst) {}

TEST_F(TemplateURLServiceSyncTest, DefaultGuidDeletedBeforeNewDSPArrives) {}

TEST_F(TemplateURLServiceSyncTest,
       DefaultGuidDeletedAndUpdatedBeforeNewDSPArrives) {}

TEST_F(TemplateURLServiceSyncTest, SyncedDefaultArrivesAfterStartup) {}

TEST_F(TemplateURLServiceSyncTest, SyncedDefaultAlreadySetOnStartup) {}

TEST_F(TemplateURLServiceSyncTest, SyncWithManagedDefaultSearch) {}

TEST_F(TemplateURLServiceSyncTest, SyncWithExtensionDefaultSearch) {}

TEST_F(TemplateURLServiceSyncTest, OverrideSyncPrefWithExtensionDefaultSearch) {}

// Check that keyword conflict between synced engine and extension engine is
// resolved correctly.
TEST_F(TemplateURLServiceSyncTest, ExtensionAndNormalEngineConflict) {}

TEST_F(TemplateURLServiceSyncTest, SyncMergeDeletesDefault) {}

TEST_F(TemplateURLServiceSyncTest, LocalDefaultWinsConflict) {}

TEST_F(TemplateURLServiceSyncTest, DeleteBogusData) {}

TEST_F(TemplateURLServiceSyncTest, PreSyncDeletes) {}

TEST_F(TemplateURLServiceSyncTest, PreSyncUpdates) {}

TEST_F(TemplateURLServiceSyncTest, SyncBaseURLs) {}

TEST_F(TemplateURLServiceSyncTest, MergeInSyncTemplateURL) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, AddPrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, UpdatePrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, MergeEditedPrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, MergeConflictingPrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngineWithChangedKeyword) {}

// The following tests check the case where, when turning on Sync, we get the
// following incoming changes: a) The default prepopulated engine (usually
// google.com) was modified (new keyword), and b) a new custom engine is chosen
// as the default. This maps to three events: adding an engine, changing the
// prepopulated engine, and changing the pref that defines the default engine.
// These can happen in any order, so there are multiple tests to verify that all
// orders work correctly.

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine_Pref_Change_Add) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine_Pref_Add_Change) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine_Change_Add_Pref) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngine_Add_Change_Pref) {}

TEST_F(TemplateURLServiceSyncTest, MergeNonEditedPrepopulatedEngine) {}

TEST_F(TemplateURLServiceSyncTest, MergePrepopulatedEngineIgnoresId0) {}

TEST_F(TemplateURLServiceSyncTest, MergeStarterPackEngine) {}

TEST_F(TemplateURLServiceSyncTest, GUIDUpdatedOnDefaultSearchChange) {}

TEST_F(TemplateURLServiceSyncTest, NonAsciiKeywordDoesNotCrash) {}