Commit 878a38d6 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Sync::USS] Unittesting the case of a corrupted password store sync

Some wrong DCHECKs have gone undiscovered for sometime due of the lack
of unit tests of the case when the password store sync fails.

This CL adds some simple unit testing that tests that during initial
merge, if the store fails to add a login or to read all logins, an
error is returned without crashing.

Bug: 936823
Change-Id: Iefd2759b3a73c702c2e9bc4e95c96a43e1ed945c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1499543
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637635}
parent 657a1ca1
...@@ -623,6 +623,34 @@ TEST_F(PasswordSyncBridgeTest, ...@@ -623,6 +623,34 @@ TEST_F(PasswordSyncBridgeTest,
EXPECT_FALSE(error); EXPECT_FALSE(error);
} }
// This tests that if reading logins from the store fails,
// ShouldMergeSync() would return an error without crashing.
TEST_F(PasswordSyncBridgeTest,
ShouldMergeSyncRemoteAndLocalPasswordsWithErrorWhenStoreReadFails) {
// Simulate a failed ReadAllLogins() by returning false.
ON_CALL(*mock_password_store_sync(), ReadAllLogins(_))
.WillByDefault(testing::Return(false));
base::Optional<syncer::ModelError> error =
bridge()->MergeSyncData(bridge()->CreateMetadataChangeList(), {});
EXPECT_TRUE(error);
}
// This tests that if adding logins to the store fails,
// ShouldMergeSync() would return an error without crashing.
TEST_F(PasswordSyncBridgeTest,
ShouldMergeSyncRemoteAndLocalPasswordsWithErrorWhenStoreAddFails) {
// Simulate a failed AddLoginSync() by returning an empty change list.
ON_CALL(*mock_password_store_sync(), AddLoginSync(_))
.WillByDefault(testing::Return(PasswordStoreChangeList()));
base::Optional<syncer::ModelError> error = bridge()->MergeSyncData(
bridge()->CreateMetadataChangeList(),
{syncer::EntityChange::CreateAdd(
/*storage_key=*/"",
SpecificsToEntity(CreateSpecificsWithSignonRealm(kSignonRealm1)))});
EXPECT_TRUE(error);
}
TEST_F(PasswordSyncBridgeTest, ShouldGetAllDataForDebuggingWithHiddenPassword) { TEST_F(PasswordSyncBridgeTest, ShouldGetAllDataForDebuggingWithHiddenPassword) {
const int kPrimaryKey1 = 1000; const int kPrimaryKey1 = 1000;
const int kPrimaryKey2 = 1001; const int kPrimaryKey2 = 1001;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment