chromium/components/autofill/core/browser/webdata/autocomplete/autocomplete_sync_bridge_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/autofill/core/browser/webdata/autocomplete/autocomplete_sync_bridge.h"

#include <algorithm>
#include <map>
#include <memory>
#include <utility>
#include <vector>

#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/autofill/core/browser/webdata/autocomplete/autocomplete_entry.h"
#include "components/autofill/core/browser/webdata/autocomplete/autocomplete_table.h"
#include "components/autofill/core/browser/webdata/autofill_sync_metadata_table.h"
#include "components/autofill/core/browser/webdata/mock_autofill_webdata_backend.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/data_type.h"
#include "components/sync/engine/data_type_activation_response.h"
#include "components/sync/model/client_tag_based_data_type_processor.h"
#include "components/sync/model/data_batch.h"
#include "components/sync/model/data_type_activation_request.h"
#include "components/sync/model/metadata_batch.h"
#include "components/sync/model/model_error.h"
#include "components/sync/protocol/autofill_specifics.pb.h"
#include "components/sync/protocol/data_type_state.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/test/mock_commit_queue.h"
#include "components/sync/test/mock_data_type_local_change_processor.h"
#include "components/sync/test/test_matchers.h"
#include "components/webdata/common/web_database.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

ScopedTempDir;
Time;
UTF8ToUTF16;
AutofillSpecifics;
DataTypeState;
EntityMetadata;
DataBatch;
DataType;
DataTypeLocalChangeProcessor;
DataTypeSyncBridge;
EntityChange;
EntityChangeList;
EntityData;
HasInitialSyncDone;
IsEmptyMetadataBatch;
KeyAndData;
MockDataTypeLocalChangeProcessor;
ModelError;
_;
IsEmpty;
Not;
Return;
SizeIs;

namespace autofill {

namespace {

const char kNameFormat[] =;
const char kValueFormat[] =;

MATCHER_P(HasSpecifics, expected, "") {}

void VerifyDataBatch(std::map<std::string, AutofillSpecifics> expected,
                     std::unique_ptr<DataBatch> batch) {}

AutocompleteEntry CreateAutocompleteEntry(
    const AutofillSpecifics& autofill_specifics) {}

}  // namespace

class AutocompleteSyncBridgeTest : public testing::Test {};

TEST_F(AutocompleteSyncBridgeTest, GetClientTag) {}

TEST_F(AutocompleteSyncBridgeTest, GetClientTagNotAffectedByTimestamp) {}

TEST_F(AutocompleteSyncBridgeTest, GetClientTagRespectsNullCharacter) {}

// The client tags should never change as long as we want to maintain backwards
// compatibility with the previous iteration of autocomplete-sync integration,
// AutocompleteSyncableService and Sync's Directory. This is because old clients
// will re-generate client tags and then hashes on local changes, and this
// process must create identical values to what this client has created. If this
// test case starts failing, you should not alter the fixed values here unless
// you know what you're doing.
TEST_F(AutocompleteSyncBridgeTest, GetClientTagFixed) {}

TEST_F(AutocompleteSyncBridgeTest, GetStorageKey) {}

TEST_F(AutocompleteSyncBridgeTest, GetStorageKeyNotAffectedByTimestamp) {}

TEST_F(AutocompleteSyncBridgeTest, GetStorageKeyRespectsNullCharacter) {}

// The storage key should never accidentally change for existing data. This
// would cause lookups to fail and either lose or duplicate user data. It should
// be possible for the data type to migrate storage key formats, but doing so
// would need to be done very carefully.
TEST_F(AutocompleteSyncBridgeTest, GetStorageKeyFixed) {}

TEST_F(AutocompleteSyncBridgeTest, GetDataForCommit) {}

TEST_F(AutocompleteSyncBridgeTest, GetDataForCommitNotExist) {}

TEST_F(AutocompleteSyncBridgeTest, GetAllData) {}

TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesEmpty) {}

TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesSimple) {}

// Should be resilient to deleting and updating non-existent things, and adding
// existing ones.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesWrongChangeType) {}

// The format in the table has a fixed 2 timestamp format. Round tripping is
// lossy and the middle value should be thrown out.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesThreeTimestamps) {}

// The correct format of timestamps is that the first should be smaller and the
// second should be larger. Bad foreign data should be repaired.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesWrongOrder) {}

// In a minor attempt to save bandwidth, we only send one of the two timestamps
// when they share a value.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesRepeatedTime) {}

// Again, the format in the table is lossy, and cannot distinguish between no
// time, and valid time zero.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesNoTime) {}

// If has_value() returns false, then the specifics are determined to be old
// style and ignored.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesNoValue) {}

// Should be treated the same as an empty string name. This inconsistency is
// being perpetuated from the previous sync integration.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesNoName) {}

// UTF-8 characters should not be dropped when round tripping, including middle
// of string \0 characters.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesUTF) {}

// Timestamps should always use the oldest creation time, and the most recent
// usage time.
TEST_F(AutocompleteSyncBridgeTest,
       ApplyIncrementalSyncChangesMinMaxTimestamps) {}

// An error should be generated when parsing the storage key happens. This
// should never happen in practice because storage keys should be generated at
// runtime by the bridge and not loaded from disk.
TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesBadStorageKey) {}

TEST_F(AutocompleteSyncBridgeTest, ApplyIncrementalSyncChangesDatabaseFailure) {}

TEST_F(AutocompleteSyncBridgeTest, LocalEntriesAdded) {}

TEST_F(AutocompleteSyncBridgeTest, LocalEntryAddedThenUpdated) {}

TEST_F(AutocompleteSyncBridgeTest, LocalEntryDeleted) {}

// Tests that AutocompleteEntry marked with AutocompleteChange::EXPIRE are
// unlinked from sync, and their sync metadata is deleted in this client.
TEST_F(AutocompleteSyncBridgeTest, LocalEntryExpired) {}

TEST_F(AutocompleteSyncBridgeTest, LoadMetadataCalled) {}

TEST_F(AutocompleteSyncBridgeTest, LoadMetadataReportsErrorForMissingDB) {}

TEST_F(AutocompleteSyncBridgeTest, MergeFullSyncDataEmpty) {}

TEST_F(AutocompleteSyncBridgeTest, MergeFullSyncDataRemoteOnly) {}

TEST_F(AutocompleteSyncBridgeTest, MergeFullSyncDataLocalOnly) {}

TEST_F(AutocompleteSyncBridgeTest, MergeFullSyncDataAllMerged) {}

TEST_F(AutocompleteSyncBridgeTest, MergeFullSyncDataMixed) {}

}  // namespace autofill