1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
|
// Copyright 2014 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/sync/model/processor_entity.h"
#include <utility>
#include "base/hash/hash.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/protobuf_matchers.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "components/sync/base/client_tag_hash.h"
#include "components/sync/base/collaboration_id.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/deletion_origin.h"
#include "components/sync/base/features.h"
#include "components/sync/base/time.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/engine/commit_and_get_updates_types.h"
#include "components/sync/protocol/collaboration_metadata.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "components/sync/protocol/unique_position.pb.h"
#include "components/version_info/version_info.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
using base::test::EqualsProto;
using testing::Not;
const char kKey[] = "key";
const ClientTagHash kHash = ClientTagHash::FromHashed("hash");
const char kId[] = "id";
const char kName[] = "name";
const char kValue1[] = "value1";
const char kValue2[] = "value2";
const char kValue3[] = "value3";
sync_pb::EntitySpecifics GenerateSpecifics(const std::string& name,
const std::string& value) {
sync_pb::EntitySpecifics specifics;
specifics.mutable_preference()->set_name(name);
specifics.mutable_preference()->set_value(value);
return specifics;
}
std::unique_ptr<EntityData> GenerateEntityData(const ClientTagHash& hash,
const std::string& name,
const std::string& value) {
std::unique_ptr<EntityData> entity_data(new EntityData());
entity_data->client_tag_hash = hash;
entity_data->specifics = GenerateSpecifics(name, value);
entity_data->name = name;
return entity_data;
}
sync_pb::EntitySpecifics GenerateSharedTabGroupDataSpecifics(
const std::string& guid) {
sync_pb::EntitySpecifics specifics;
specifics.mutable_shared_tab_group_data()->set_guid(guid);
return specifics;
}
std::unique_ptr<EntityData> GenerateSharedTabGroupDataEntityData(
const ClientTagHash& hash,
const std::string& guid,
CollaborationMetadata collaboration_metadata) {
std::unique_ptr<EntityData> entity_data(new EntityData());
entity_data->client_tag_hash = hash;
entity_data->specifics = GenerateSharedTabGroupDataSpecifics(guid);
entity_data->collaboration_metadata = std::move(collaboration_metadata);
return entity_data;
}
UpdateResponseData GenerateSharedTabGroupDataUpdate(
const ProcessorEntity& entity,
const ClientTagHash& hash,
const std::string& server_id,
const std::string& guid,
const base::Time& mtime,
int64_t version,
CollaborationMetadata collaboration_metadata) {
std::unique_ptr<EntityData> data = GenerateSharedTabGroupDataEntityData(
hash, guid, std::move(collaboration_metadata));
data->id = server_id;
data->modification_time = mtime;
UpdateResponseData update;
update.entity = std::move(*data);
update.response_version = version;
return update;
}
UpdateResponseData GenerateUpdate(const ProcessorEntity& entity,
const ClientTagHash& hash,
const std::string& id,
const std::string& name,
const std::string& value,
const base::Time& mtime,
int64_t version) {
std::unique_ptr<EntityData> data = GenerateEntityData(hash, name, value);
data->id = id;
data->modification_time = mtime;
UpdateResponseData update;
update.entity = std::move(*data);
update.response_version = version;
return update;
}
UpdateResponseData GenerateTombstone(const ProcessorEntity& entity,
const ClientTagHash& hash,
const std::string& id,
const std::string& name,
const base::Time& mtime,
int64_t version) {
std::unique_ptr<EntityData> data = std::make_unique<EntityData>();
data->client_tag_hash = hash;
data->name = name;
data->id = id;
data->modification_time = mtime;
UpdateResponseData update;
update.entity = std::move(*data);
update.response_version = version;
return update;
}
CommitResponseData GenerateAckData(const CommitRequestData& request,
const std::string id,
int64_t version) {
CommitResponseData response;
response.id = id;
response.client_tag_hash = request.entity->client_tag_hash;
response.sequence_number = request.sequence_number;
response.response_version = version;
response.specifics_hash = request.specifics_hash;
return response;
}
sync_pb::UniquePosition GenerateUniquePosition(const ClientTagHash& hash) {
return UniquePosition::InitialPosition(UniquePosition::GenerateSuffix(hash))
.ToProto();
}
} // namespace
// Some simple sanity tests for the ProcessorEntity.
//
// A lot of the more complicated sync logic is implemented in the
// ClientTagBasedDataTypeProcessor that owns the ProcessorEntity. We
// can't unit test it here.
//
// Instead, we focus on simple tests to make sure that variables are getting
// properly intialized and flags properly set. Anything more complicated would
// be a redundant and incomplete version of the ClientTagBasedDataTypeProcessor
// tests.
class ProcessorEntityTest : public ::testing::Test {
public:
ProcessorEntityTest() : ctime_(base::Time::Now() - base::Seconds(1)) {}
std::unique_ptr<ProcessorEntity> CreateNew() {
return ProcessorEntity::CreateNew(kKey, kHash, "", ctime_);
}
std::unique_ptr<ProcessorEntity> CreateNewWithEmptyStorageKey() {
return ProcessorEntity::CreateNew("", kHash, "", ctime_);
}
std::unique_ptr<ProcessorEntity> CreateSynced() {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
UpdateResponseData update =
GenerateUpdate(*entity, kHash, kId, kName, kValue1, ctime_, 1);
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
DCHECK(!entity->IsUnsynced());
return entity;
}
std::unique_ptr<ProcessorEntity> CreateSyncedWithUniquePosition() {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
UpdateResponseData update =
GenerateUpdate(*entity, kHash, kId, kName, kValue1, ctime_, 1);
entity->RecordAcceptedRemoteUpdate(
update, /*trimmed_specifics=*/{},
/*unique_position=*/GenerateUniquePosition(kHash));
CHECK(!entity->IsUnsynced());
return entity;
}
std::unique_ptr<ProcessorEntity> RestoreFromMetadata(
sync_pb::EntityMetadata entity_metadata) {
return ProcessorEntity::CreateFromMetadata(kKey,
std::move(entity_metadata));
}
const base::Time ctime_;
};
// Test the state of the default new entity.
TEST_F(ProcessorEntityTest, DefaultEntity) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
EXPECT_EQ(kKey, entity->storage_key());
EXPECT_EQ(kHash.value(), entity->metadata().client_tag_hash());
EXPECT_EQ("", entity->metadata().server_id());
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(0, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version());
EXPECT_EQ(TimeToProtoTime(ctime_), entity->metadata().creation_time());
EXPECT_EQ(0, entity->metadata().modification_time());
EXPECT_TRUE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->IsVersionAlreadyKnown(1));
EXPECT_FALSE(entity->HasCommitData());
}
// Test creating and commiting a new local item.
TEST_F(ProcessorEntityTest, NewLocalItem) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ("", entity->metadata().server_id());
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version());
EXPECT_NE(0, entity->metadata().modification_time());
EXPECT_FALSE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->metadata().has_unique_position());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_TRUE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->IsVersionAlreadyKnown(1));
EXPECT_TRUE(entity->HasCommitData());
EXPECT_EQ(kValue1,
entity->GetCommitDataForTesting().specifics.preference().value());
// Generate a commit request. The metadata should not change.
const sync_pb::EntityMetadata metadata_v1 = entity->metadata();
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(metadata_v1.SerializeAsString(),
entity->metadata().SerializeAsString());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->IsVersionAlreadyKnown(1));
const EntityData& data = *request.entity;
EXPECT_EQ("", data.id);
EXPECT_EQ(kHash, data.client_tag_hash);
EXPECT_EQ(kName, data.name);
EXPECT_EQ(kValue1, data.specifics.preference().value());
EXPECT_EQ(TimeToProtoTime(ctime_), TimeToProtoTime(data.creation_time));
EXPECT_EQ(entity->metadata().modification_time(),
TimeToProtoTime(data.modification_time));
EXPECT_FALSE(data.is_deleted());
EXPECT_EQ(1, request.sequence_number);
EXPECT_EQ(kUncommittedVersion, request.base_version);
EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash);
// Ack the commit.
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1), false);
EXPECT_EQ(kId, entity->metadata().server_id());
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(1, entity->metadata().acked_sequence_number());
EXPECT_EQ(1, entity->metadata().server_version());
EXPECT_EQ(metadata_v1.creation_time(), entity->metadata().creation_time());
EXPECT_EQ(metadata_v1.modification_time(),
entity->metadata().modification_time());
EXPECT_FALSE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->metadata().has_unique_position());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_TRUE(entity->IsVersionAlreadyKnown(1));
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldStoreUniquePositionForNewLocalItem) {
const sync_pb::UniquePosition unique_position = GenerateUniquePosition(kHash);
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{}, unique_position);
EXPECT_TRUE(entity->metadata().has_unique_position());
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(unique_position));
// Generate a commit request. The metadata should not change.
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(unique_position));
// Ack the commit.
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1), false);
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(unique_position));
}
// Test handling of invalid server version.
TEST_F(ProcessorEntityTest,
ShouldIgnoreCommitResponseWithInvalidServerVersion) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
CommitRequestData request;
// Ack the commit - set current version to 2.
entity->InitializeCommitRequestData(&request);
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2), false);
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
ASSERT_EQ(2, entity->metadata().server_version());
ASSERT_EQ(2, entity->metadata().sequence_number());
ASSERT_EQ(1, entity->metadata().acked_sequence_number());
// Ack the commit - try server version 1.
entity->InitializeCommitRequestData(&request);
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1), false);
// no update as the server responds with an older version.
EXPECT_EQ(2, entity->metadata().server_version());
}
// Test state for a newly synced server item.
TEST_F(ProcessorEntityTest, NewServerItem) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
const base::Time mtime = base::Time::Now();
UpdateResponseData update =
GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10);
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ(kId, entity->metadata().server_id());
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(0, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(10, entity->metadata().server_version());
EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
EXPECT_FALSE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_TRUE(entity->IsVersionAlreadyKnown(9));
EXPECT_TRUE(entity->IsVersionAlreadyKnown(10));
EXPECT_FALSE(entity->IsVersionAlreadyKnown(11));
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldStoreUniquePositionForNewServerItem) {
const sync_pb::UniquePosition unique_position = GenerateUniquePosition(kHash);
std::unique_ptr<ProcessorEntity> entity = CreateNew();
UpdateResponseData update = GenerateUpdate(
*entity, kHash, kId, kName, kValue1, /*mtime=*/base::Time::Now(), 10);
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
unique_position);
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(unique_position));
}
// Test creating an entity for new server item with empty storage key, applying
// update and updating storage key.
TEST_F(ProcessorEntityTest, NewServerItem_EmptyStorageKey) {
std::unique_ptr<ProcessorEntity> entity = CreateNewWithEmptyStorageKey();
EXPECT_EQ("", entity->storage_key());
const base::Time mtime = base::Time::Now();
UpdateResponseData update =
GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10);
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
entity->SetStorageKey(kKey);
EXPECT_EQ(kKey, entity->storage_key());
}
// Test state for a tombstone received for a previously unknown item.
TEST_F(ProcessorEntityTest, NewServerTombstone) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
const base::Time mtime = base::Time::Now();
UpdateResponseData tombstone =
GenerateTombstone(*entity, kHash, kId, kName, mtime, 1);
entity->RecordAcceptedRemoteUpdate(tombstone, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ(kId, entity->metadata().server_id());
EXPECT_TRUE(entity->metadata().is_deleted());
EXPECT_EQ(0, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(1, entity->metadata().server_version());
EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
EXPECT_TRUE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_TRUE(entity->CanClearMetadata());
EXPECT_TRUE(entity->IsVersionAlreadyKnown(1));
EXPECT_FALSE(entity->IsVersionAlreadyKnown(2));
EXPECT_FALSE(entity->HasCommitData());
}
// Apply a deletion update to a synced item.
TEST_F(ProcessorEntityTest, ServerTombstone) {
// Start with a non-deleted state with version 1.
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
// A deletion update one version later.
const base::Time mtime = base::Time::Now();
UpdateResponseData tombstone =
GenerateTombstone(*entity, kHash, kId, kName, mtime, 2);
entity->RecordAcceptedRemoteUpdate(tombstone, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_TRUE(entity->metadata().is_deleted());
EXPECT_EQ(0, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(2, entity->metadata().server_version());
EXPECT_EQ(TimeToProtoTime(mtime), entity->metadata().modification_time());
EXPECT_TRUE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_TRUE(entity->CanClearMetadata());
EXPECT_TRUE(entity->IsVersionAlreadyKnown(2));
EXPECT_FALSE(entity->IsVersionAlreadyKnown(3));
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldResetUniquePositionOnServerUpdate) {
std::unique_ptr<ProcessorEntity> entity = CreateSyncedWithUniquePosition();
ASSERT_TRUE(entity->metadata().has_unique_position());
UpdateResponseData update = GenerateUpdate(
*entity, kHash, kId, kName, kValue1, /*mtime=*/base::Time::Now(), 10);
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_FALSE(entity->metadata().has_unique_position());
}
// Test a local change of a synced item.
TEST_F(ProcessorEntityTest, LocalChange) {
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
const int64_t mtime_v0 = entity->metadata().modification_time();
const std::string specifics_hash_v0 = entity->metadata().specifics_hash();
// Make a local change with different specifics.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
const int64_t mtime_v1 = entity->metadata().modification_time();
const std::string specifics_hash_v1 = entity->metadata().specifics_hash();
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(1, entity->metadata().server_version());
EXPECT_LT(mtime_v0, mtime_v1);
EXPECT_NE(specifics_hash_v0, specifics_hash_v1);
EXPECT_EQ(specifics_hash_v0, entity->metadata().base_specifics_hash());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_TRUE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_TRUE(entity->HasCommitData());
// Make a commit.
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(kId, request.entity->id);
EXPECT_FALSE(entity->RequiresCommitRequest());
// Ack the commit.
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2), false);
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(1, entity->metadata().acked_sequence_number());
EXPECT_EQ(2, entity->metadata().server_version());
EXPECT_EQ(mtime_v1, entity->metadata().modification_time());
EXPECT_EQ(specifics_hash_v1, entity->metadata().specifics_hash());
EXPECT_EQ("", entity->metadata().base_specifics_hash());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldStoreNewUniquePositionOnLocalUpdate) {
const sync_pb::UniquePosition new_unique_position =
GenerateUniquePosition(ClientTagHash::FromHashed("new_hash"));
std::unique_ptr<ProcessorEntity> entity = CreateSyncedWithUniquePosition();
ASSERT_TRUE(entity->metadata().has_unique_position());
ASSERT_THAT(entity->metadata().unique_position(),
Not(EqualsProto(new_unique_position)));
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{}, new_unique_position);
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(new_unique_position));
}
TEST_F(ProcessorEntityTest, ShouldResetUniquePositionOnLocalUpdate) {
std::unique_ptr<ProcessorEntity> entity = CreateSyncedWithUniquePosition();
ASSERT_TRUE(entity->metadata().has_unique_position());
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_FALSE(entity->metadata().has_unique_position());
}
// Test a local deletion of a synced item.
TEST_F(ProcessorEntityTest, LocalDeletion) {
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
const int64_t mtime = entity->metadata().modification_time();
const std::string specifics_hash = entity->metadata().specifics_hash();
// Make a local delete.
entity->RecordLocalDeletion(DeletionOrigin::Unspecified());
EXPECT_TRUE(entity->metadata().is_deleted());
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(1, entity->metadata().server_version());
EXPECT_LT(mtime, entity->metadata().modification_time());
EXPECT_TRUE(entity->metadata().specifics_hash().empty());
EXPECT_EQ(specifics_hash, entity->metadata().base_specifics_hash());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_TRUE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
// Generate a commit request. The metadata should not change.
const sync_pb::EntityMetadata metadata_v1 = entity->metadata();
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(metadata_v1.SerializeAsString(),
entity->metadata().SerializeAsString());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
const EntityData& data = *request.entity;
EXPECT_EQ(kId, data.id);
EXPECT_EQ(kHash, data.client_tag_hash);
EXPECT_EQ("", data.name);
EXPECT_EQ(TimeToProtoTime(ctime_), TimeToProtoTime(data.creation_time));
EXPECT_EQ(entity->metadata().modification_time(),
TimeToProtoTime(data.modification_time));
EXPECT_TRUE(data.is_deleted());
EXPECT_EQ(1, request.sequence_number);
EXPECT_EQ(1, request.base_version);
EXPECT_EQ(entity->metadata().specifics_hash(), request.specifics_hash);
EXPECT_FALSE(entity->metadata().has_deletion_origin());
// Ack the deletion.
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2), false);
EXPECT_TRUE(entity->metadata().is_deleted());
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(1, entity->metadata().acked_sequence_number());
EXPECT_EQ(2, entity->metadata().server_version());
EXPECT_EQ(metadata_v1.modification_time(),
entity->metadata().modification_time());
EXPECT_TRUE(entity->metadata().specifics_hash().empty());
EXPECT_TRUE(entity->metadata().base_specifics_hash().empty());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_TRUE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldResetUniquePositionOnLocalDeletion) {
std::unique_ptr<ProcessorEntity> entity = CreateSyncedWithUniquePosition();
ASSERT_TRUE(entity->metadata().has_unique_position());
entity->RecordLocalDeletion(DeletionOrigin::Unspecified());
EXPECT_FALSE(entity->metadata().has_unique_position());
}
TEST_F(ProcessorEntityTest, LocalDeletionWithSpecifiedOrigin) {
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
const std::string specifics_hash = entity->metadata().specifics_hash();
const base::Location location = FROM_HERE;
// Make a local delete.
entity->RecordLocalDeletion(DeletionOrigin::FromLocation(location));
ASSERT_TRUE(entity->metadata().is_deleted());
ASSERT_TRUE(entity->IsUnsynced());
ASSERT_TRUE(entity->RequiresCommitRequest());
// Generate a commit request. The metadata should not change.
const sync_pb::EntityMetadata metadata_v1 = entity->metadata();
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(metadata_v1.SerializeAsString(),
entity->metadata().SerializeAsString());
EXPECT_TRUE(entity->metadata().has_deletion_origin());
EXPECT_EQ(location.line_number(),
entity->metadata().deletion_origin().file_line_number());
EXPECT_EQ(base::PersistentHash(location.file_name()),
entity->metadata().deletion_origin().file_name_hash());
EXPECT_TRUE(entity->metadata().deletion_origin().has_chromium_version());
}
// Test a local deletion followed by an undeletion (creation).
TEST_F(ProcessorEntityTest, LocalUndeletion) {
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
const std::string specifics_hash = entity->metadata().specifics_hash();
entity->RecordLocalDeletion(DeletionOrigin::FromLocation(FROM_HERE));
ASSERT_TRUE(entity->metadata().is_deleted());
ASSERT_TRUE(entity->IsUnsynced());
ASSERT_EQ(1, entity->metadata().sequence_number());
// Undelete the entity with different specifics.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
const std::string specifics_hash_v1 = entity->metadata().specifics_hash();
ASSERT_NE(specifics_hash_v1, specifics_hash);
EXPECT_FALSE(entity->metadata().is_deleted());
EXPECT_EQ(2, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_EQ(1, entity->metadata().server_version());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_TRUE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_TRUE(entity->HasCommitData());
// Make a commit.
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(kId, request.entity->id);
EXPECT_FALSE(entity->RequiresCommitRequest());
// Ack the commit.
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 2), false);
EXPECT_EQ(2, entity->metadata().sequence_number());
EXPECT_EQ(2, entity->metadata().acked_sequence_number());
EXPECT_EQ(2, entity->metadata().server_version());
EXPECT_EQ(specifics_hash_v1, entity->metadata().specifics_hash());
EXPECT_EQ("", entity->metadata().base_specifics_hash());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
}
TEST_F(ProcessorEntityTest, ShouldStoreUniquePositionForLocalUndeletion) {
std::unique_ptr<ProcessorEntity> entity = CreateSyncedWithUniquePosition();
entity->RecordLocalDeletion(DeletionOrigin::Unspecified());
ASSERT_FALSE(entity->metadata().has_unique_position());
// Undelete the entity with unique position.
const sync_pb::UniquePosition unique_position =
GenerateUniquePosition(ClientTagHash::FromHashed("new_hash"));
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{}, unique_position);
EXPECT_THAT(entity->metadata().unique_position(),
EqualsProto(unique_position));
}
// Test that hashes and sequence numbers are handled correctly for the "commit
// commit, ack ack" case.
TEST_F(ProcessorEntityTest, LocalChangesInterleaved) {
std::unique_ptr<ProcessorEntity> entity = CreateSynced();
const std::string specifics_hash_v0 = entity->metadata().specifics_hash();
// Make the first change.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
const std::string specifics_hash_v1 = entity->metadata().specifics_hash();
EXPECT_EQ(1, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_NE(specifics_hash_v0, specifics_hash_v1);
EXPECT_EQ(specifics_hash_v0, entity->metadata().base_specifics_hash());
// Request the first commit.
CommitRequestData request_v1;
entity->InitializeCommitRequestData(&request_v1);
// Make the second change.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue3),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
const std::string specifics_hash_v2 = entity->metadata().specifics_hash();
EXPECT_EQ(2, entity->metadata().sequence_number());
EXPECT_EQ(0, entity->metadata().acked_sequence_number());
EXPECT_NE(specifics_hash_v1, specifics_hash_v2);
EXPECT_EQ(specifics_hash_v0, entity->metadata().base_specifics_hash());
// Request the second commit.
CommitRequestData request_v2;
entity->InitializeCommitRequestData(&request_v2);
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
// Ack the first commit.
entity->ReceiveCommitResponse(GenerateAckData(request_v1, kId, 2), false);
EXPECT_EQ(2, entity->metadata().sequence_number());
EXPECT_EQ(1, entity->metadata().acked_sequence_number());
EXPECT_EQ(2, entity->metadata().server_version());
EXPECT_EQ(specifics_hash_v2, entity->metadata().specifics_hash());
EXPECT_EQ(specifics_hash_v1, entity->metadata().base_specifics_hash());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
// Commit data has been moved already to the request.
EXPECT_FALSE(entity->HasCommitData());
// Ack the second commit.
entity->ReceiveCommitResponse(GenerateAckData(request_v2, kId, 3), false);
EXPECT_EQ(2, entity->metadata().sequence_number());
EXPECT_EQ(2, entity->metadata().acked_sequence_number());
EXPECT_EQ(3, entity->metadata().server_version());
EXPECT_EQ(specifics_hash_v2, entity->metadata().specifics_hash());
EXPECT_EQ("", entity->metadata().base_specifics_hash());
EXPECT_FALSE(entity->IsUnsynced());
EXPECT_FALSE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_FALSE(entity->CanClearMetadata());
EXPECT_FALSE(entity->HasCommitData());
}
// Tests that updating entity id with commit response while next local change is
// pending correctly updates that change's id and version.
TEST_F(ProcessorEntityTest, NewLocalChangeUpdatedId) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
// Create new local change. Make sure initial id is empty.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_TRUE(request.entity->id.empty());
// Before receiving commit response make local modification to the entity.
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue2),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
entity->ReceiveCommitResponse(GenerateAckData(request, kId, 1), false);
// Receiving commit response with valid id should update
// ProcessorEntity. Consecutive commit requests should include updated
// id.
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(kId, request.entity->id);
EXPECT_EQ(1, request.base_version);
}
// Tests that entity restored after restart accepts specifics that don't match
// the ones passed originally to RecordLocalUpdate.
TEST_F(ProcessorEntityTest, RestoredLocalChangeWithUpdatedSpecifics) {
// Create new entity and preserver its metadata.
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
sync_pb::EntityMetadata entity_metadata = entity->metadata();
// Restore entity from metadata and emulate bridge passing different specifics
// to SetCommitData.
entity = RestoreFromMetadata(std::move(entity_metadata));
std::unique_ptr<EntityData> entity_data =
GenerateEntityData(kHash, kName, kValue2);
entity->SetCommitData(std::move(entity_data));
// No verification is necessary. SetCommitData shouldn't DCHECK.
}
// Tests the scenario where a local creation conflicts with a remote deletion,
// where usually (and in this test) local wins. In this case, the remote update
// should be ignored but the server IDs should be updated.
TEST_F(ProcessorEntityTest, LocalCreationConflictsWithServerTombstone) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
ASSERT_TRUE(entity->IsUnsynced());
ASSERT_TRUE(entity->RequiresCommitRequest());
ASSERT_FALSE(entity->RequiresCommitData());
ASSERT_TRUE(entity->HasCommitData());
ASSERT_FALSE(entity->metadata().is_deleted());
ASSERT_TRUE(entity->metadata().server_id().empty());
// Before anything gets committed, we receive a remote tombstone, but local
// would usually win so the remote update is ignored.
UpdateResponseData tombstone =
GenerateTombstone(*entity, kHash, kId, kName, base::Time::Now(), 2);
entity->RecordIgnoredRemoteUpdate(tombstone);
EXPECT_EQ(kId, entity->metadata().server_id());
EXPECT_TRUE(entity->IsUnsynced());
EXPECT_TRUE(entity->RequiresCommitRequest());
EXPECT_FALSE(entity->RequiresCommitData());
EXPECT_TRUE(entity->HasCommitData());
EXPECT_FALSE(entity->metadata().is_deleted());
// Generate a commit request. The server ID should have been reused from the
// otherwise ignored update.
const sync_pb::EntityMetadata metadata_v1 = entity->metadata();
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
EXPECT_EQ(kId, request.entity->id);
}
TEST_F(ProcessorEntityTest, UpdatesSpecificsCacheOnRemoteUpdates) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
const base::Time mtime = base::Time::Now();
UpdateResponseData update =
GenerateUpdate(*entity, kHash, kId, kName, kValue1, mtime, 10);
sync_pb::EntitySpecifics specifics_for_caching =
GenerateSpecifics(kName, kValue2);
entity->RecordAcceptedRemoteUpdate(update, specifics_for_caching,
/*unique_position=*/std::nullopt);
EXPECT_EQ(
specifics_for_caching.SerializeAsString(),
entity->metadata().possibly_trimmed_base_specifics().SerializeAsString());
}
TEST_F(ProcessorEntityTest, UpdatesSpecificsCacheOnLocalUpdates) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
sync_pb::EntitySpecifics specifics_for_caching =
GenerateSpecifics(kName, kValue2);
entity->RecordLocalUpdate(GenerateEntityData(kHash, kName, kValue1),
specifics_for_caching,
/*unique_position=*/std::nullopt);
EXPECT_EQ(
specifics_for_caching.SerializeAsString(),
entity->metadata().possibly_trimmed_base_specifics().SerializeAsString());
}
TEST_F(ProcessorEntityTest, LocalDeletionRecordsVersionInfo) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalDeletion(DeletionOrigin::FromLocation(FROM_HERE));
std::string expected_version = std::string(version_info::GetVersionNumber());
EXPECT_EQ(expected_version, entity->metadata().deleted_by_version());
}
TEST_F(ProcessorEntityTest, ShouldCreateAndCommitNewLocalSharedItem) {
const GaiaId kCreatorUserId("creator_user_id");
const GaiaId kUpdaterUserId("updater_user_id");
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(
GenerateSharedTabGroupDataEntityData(
kHash, "guid",
CollaborationMetadata::ForLocalChange(
/*changed_by=*/kCreatorUserId, CollaborationId("collaboration"))),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ("", entity->metadata().server_id());
EXPECT_EQ(kUncommittedVersion, entity->metadata().server_version());
EXPECT_EQ("collaboration",
entity->metadata().collaboration().collaboration_id());
EXPECT_EQ(kCreatorUserId.ToString(), entity->metadata()
.collaboration()
.last_update_attribution()
.obfuscated_gaia_id());
// The same user ID is used as a creator for the first time.
EXPECT_EQ(kCreatorUserId.ToString(), entity->metadata()
.collaboration()
.creation_attribution()
.obfuscated_gaia_id());
EXPECT_TRUE(entity->IsUnsynced());
// Generate a commit request.
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
const EntityData& data = *request.entity;
ASSERT_TRUE(data.collaboration_metadata.has_value());
EXPECT_EQ(CollaborationId("collaboration"),
data.collaboration_metadata->collaboration_id());
// Verify that creator is not updated on the next local update.
entity->RecordLocalUpdate(
GenerateSharedTabGroupDataEntityData(
kHash, "guid",
CollaborationMetadata::ForLocalChange(
/*changed_by=*/kUpdaterUserId, CollaborationId("collaboration"))),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ(kUpdaterUserId.ToString(), entity->metadata()
.collaboration()
.last_update_attribution()
.obfuscated_gaia_id());
EXPECT_EQ(kCreatorUserId.ToString(), entity->metadata()
.collaboration()
.creation_attribution()
.obfuscated_gaia_id());
EXPECT_NE(entity->metadata()
.collaboration()
.last_update_attribution()
.obfuscated_gaia_id(),
entity->metadata()
.collaboration()
.creation_attribution()
.obfuscated_gaia_id());
}
TEST_F(ProcessorEntityTest, ShouldCreateNewRemoteSharedItem) {
const std::string kCreatorUserId = "creator_user_id";
const std::string kUpdaterUserId = "updater_user_id";
std::unique_ptr<ProcessorEntity> entity = CreateNew();
const base::Time mtime = base::Time::Now();
sync_pb::SyncEntity::CollaborationMetadata collaboration_remote_proto;
collaboration_remote_proto.set_collaboration_id("collaboration");
collaboration_remote_proto.mutable_creation_attribution()
->set_obfuscated_gaia_id(kCreatorUserId);
collaboration_remote_proto.mutable_last_update_attribution()
->set_obfuscated_gaia_id(kUpdaterUserId);
UpdateResponseData update = GenerateSharedTabGroupDataUpdate(
*entity, kHash, kId, "guid", mtime, /*version=*/10,
CollaborationMetadata::FromRemoteProto(collaboration_remote_proto));
entity->RecordAcceptedRemoteUpdate(update, /*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
EXPECT_EQ(kId, entity->metadata().server_id());
EXPECT_EQ("collaboration",
entity->metadata().collaboration().collaboration_id());
EXPECT_EQ(entity->metadata()
.collaboration()
.creation_attribution()
.obfuscated_gaia_id(),
kCreatorUserId);
EXPECT_EQ(entity->metadata()
.collaboration()
.last_update_attribution()
.obfuscated_gaia_id(),
kUpdaterUserId);
}
TEST_F(ProcessorEntityTest, ShouldPopulateCollaborationForTombstones) {
std::unique_ptr<ProcessorEntity> entity = CreateNew();
entity->RecordLocalUpdate(
GenerateSharedTabGroupDataEntityData(
kHash, "guid",
CollaborationMetadata::ForLocalChange(
/*changed_by=*/GaiaId(), CollaborationId("collaboration"))),
/*trimmed_specifics=*/{},
/*unique_position=*/std::nullopt);
entity->RecordLocalDeletion(DeletionOrigin::Unspecified());
CommitRequestData request;
entity->InitializeCommitRequestData(&request);
ASSERT_TRUE(request.entity->collaboration_metadata.has_value());
EXPECT_EQ(request.entity->collaboration_metadata->collaboration_id(),
CollaborationId("collaboration"));
}
} // namespace syncer
|