Commit 3b5c790b authored by Rushan Suleymanov's avatar Rushan Suleymanov Committed by Commit Bot

[Sync] Fix bookmarks reupload integration tests

Some tests related to bookmarks reupload are flaky because there is used
UpdatedProgressMarkerChecker. It doesn't guarantee that all current
changes are committed.

The better option is to wait for the actual expected data on the server
rather than for the next commit message.

For bookmarks reupload there are two possible titles in specifics:
legacy canonicalized title and full title. This CL extends the
ServerBookmarksEqualityChecker to wait until both of them are equal to
the expected title.

Bug: 1135271
Change-Id: I0a80949e30b085d94e00a82ddd8d79db39309891
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462268Reviewed-by: default avatarJan Krcal <jkrcal@chromium.org>
Commit-Queue: Rushan Suleymanov <rushans@google.com>
Cr-Commit-Position: refs/heads/master@{#816154}
parent 82a56949
...@@ -1248,12 +1248,12 @@ bool BookmarkFaviconLoadedChecker::IsExitConditionSatisfied(std::ostream* os) { ...@@ -1248,12 +1248,12 @@ bool BookmarkFaviconLoadedChecker::IsExitConditionSatisfied(std::ostream* os) {
ServerBookmarksEqualityChecker::ServerBookmarksEqualityChecker( ServerBookmarksEqualityChecker::ServerBookmarksEqualityChecker(
syncer::ProfileSyncService* service, syncer::ProfileSyncService* service,
fake_server::FakeServer* fake_server, fake_server::FakeServer* fake_server,
const std::vector<ExpectedBookmark>& expected_bookmarks, std::vector<ExpectedBookmark> expected_bookmarks,
syncer::Cryptographer* cryptographer) syncer::Cryptographer* cryptographer)
: SingleClientStatusChangeChecker(service), : SingleClientStatusChangeChecker(service),
fake_server_(fake_server), fake_server_(fake_server),
cryptographer_(cryptographer), cryptographer_(cryptographer),
expected_bookmarks_(expected_bookmarks) {} expected_bookmarks_(std::move(expected_bookmarks)) {}
bool ServerBookmarksEqualityChecker::IsExitConditionSatisfied( bool ServerBookmarksEqualityChecker::IsExitConditionSatisfied(
std::ostream* os) { std::ostream* os) {
...@@ -1293,6 +1293,7 @@ bool ServerBookmarksEqualityChecker::IsExitConditionSatisfied( ...@@ -1293,6 +1293,7 @@ bool ServerBookmarksEqualityChecker::IsExitConditionSatisfied(
[actual_specifics](const ExpectedBookmark& bookmark) { [actual_specifics](const ExpectedBookmark& bookmark) {
return actual_specifics.legacy_canonicalized_title() == return actual_specifics.legacy_canonicalized_title() ==
bookmark.title && bookmark.title &&
actual_specifics.full_title() == bookmark.title &&
actual_specifics.url() == bookmark.url; actual_specifics.url() == bookmark.url;
}); });
if (it != expected.end()) { if (it != expected.end()) {
......
...@@ -443,10 +443,11 @@ class BookmarkFaviconLoadedChecker ...@@ -443,10 +443,11 @@ class BookmarkFaviconLoadedChecker
}; };
// Checker used to block until the bookmarks on the server match a given set of // Checker used to block until the bookmarks on the server match a given set of
// expected bookmarks. // expected bookmarks. The |title| is comapred to both legacy and full titles.
class ServerBookmarksEqualityChecker : public SingleClientStatusChangeChecker { class ServerBookmarksEqualityChecker : public SingleClientStatusChangeChecker {
public: public:
struct ExpectedBookmark { struct ExpectedBookmark {
// Used to check both legacy and full titles in specifics.
std::string title; std::string title;
GURL url; GURL url;
}; };
...@@ -454,10 +455,11 @@ class ServerBookmarksEqualityChecker : public SingleClientStatusChangeChecker { ...@@ -454,10 +455,11 @@ class ServerBookmarksEqualityChecker : public SingleClientStatusChangeChecker {
// If a |cryptographer| is provided (i.e. is not nullptr), it is assumed that // If a |cryptographer| is provided (i.e. is not nullptr), it is assumed that
// the server-side data should be encrypted, and the provided cryptographer // the server-side data should be encrypted, and the provided cryptographer
// will be used to decrypt the data prior to checking for equality. // will be used to decrypt the data prior to checking for equality.
// |fake_server| must not be nullptr and must outlive this object.
ServerBookmarksEqualityChecker( ServerBookmarksEqualityChecker(
syncer::ProfileSyncService* service, syncer::ProfileSyncService* service,
fake_server::FakeServer* fake_server, fake_server::FakeServer* fake_server,
const std::vector<ExpectedBookmark>& expected_bookmarks, std::vector<ExpectedBookmark> expected_bookmarks,
syncer::Cryptographer* cryptographer); syncer::Cryptographer* cryptographer);
bool IsExitConditionSatisfied(std::ostream* os) override; bool IsExitConditionSatisfied(std::ostream* os) override;
......
...@@ -201,18 +201,20 @@ class SingleClientCustomPassphraseUseScryptSyncTest ...@@ -201,18 +201,20 @@ class SingleClientCustomPassphraseUseScryptSyncTest
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseSyncTest,
CommitsEncryptedData) { CommitsEncryptedData) {
const std::string title1 = "Hello world";
const std::string title2 = "Bookmark #2";
const GURL page_url1("https://google.com/");
const GURL page_url2("https://example.com/");
SetEncryptionPassphraseForClient(/*index=*/0, "hunter2"); SetEncryptionPassphraseForClient(/*index=*/0, "hunter2");
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
ASSERT_TRUE( ASSERT_TRUE(AddURL(/*profile=*/0, title1, page_url1));
AddURL(/*profile=*/0, "Hello world", GURL("https://google.com/"))); ASSERT_TRUE(AddURL(/*profile=*/0, title2, page_url2));
ASSERT_TRUE(
AddURL(/*profile=*/0, "Bookmark #2", GURL("https://example.com/")));
ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase)); ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase));
EXPECT_TRUE(WaitForEncryptedServerBookmarks( EXPECT_TRUE(WaitForEncryptedServerBookmarks(
{{"Hello world", GURL("https://google.com/")}, {{title1, page_url1}, {title2, page_url2}},
{"Bookmark #2", GURL("https://example.com/")}},
/*passphrase=*/"hunter2")); /*passphrase=*/"hunter2"));
} }
...@@ -261,37 +263,39 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseSyncTest, ...@@ -261,37 +263,39 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseSyncTest,
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
CommitsEncryptedDataUsingPbkdf2WhenScryptDisabled) { CommitsEncryptedDataUsingPbkdf2WhenScryptDisabled) {
const std::string title = "PBKDF2 encrypted";
const GURL page_url("https://google.com/pbkdf2-encrypted");
SetEncryptionPassphraseForClient(/*index=*/0, "hunter2"); SetEncryptionPassphraseForClient(/*index=*/0, "hunter2");
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AddURL(/*profile=*/0, "PBKDF2 encrypted", ASSERT_TRUE(AddURL(/*profile=*/0, title, page_url));
GURL("https://google.com/pbkdf2-encrypted")));
ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase)); ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase));
NigoriSpecifics nigori; NigoriSpecifics nigori;
EXPECT_TRUE(GetServerNigori(GetFakeServer(), &nigori)); EXPECT_TRUE(GetServerNigori(GetFakeServer(), &nigori));
EXPECT_EQ(nigori.custom_passphrase_key_derivation_method(), EXPECT_EQ(nigori.custom_passphrase_key_derivation_method(),
sync_pb::NigoriSpecifics::PBKDF2_HMAC_SHA1_1003); sync_pb::NigoriSpecifics::PBKDF2_HMAC_SHA1_1003);
EXPECT_TRUE(WaitForEncryptedServerBookmarks( EXPECT_TRUE(WaitForEncryptedServerBookmarks({{title, page_url}},
{{"PBKDF2 encrypted", GURL("https://google.com/pbkdf2-encrypted")}}, /*passphrase=*/"hunter2"));
/*passphrase=*/"hunter2"));
} }
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseUseScryptSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseUseScryptSyncTest,
CommitsEncryptedDataUsingScryptWhenScryptEnabled) { CommitsEncryptedDataUsingScryptWhenScryptEnabled) {
const std::string title = "scrypt encrypted";
const GURL page_url("https://google.com/scrypt-encrypted");
SetEncryptionPassphraseForClient(/*index=*/0, "hunter2"); SetEncryptionPassphraseForClient(/*index=*/0, "hunter2");
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
ASSERT_TRUE(AddURL(/*profile=*/0, "scrypt encrypted", ASSERT_TRUE(AddURL(/*profile=*/0, title, page_url));
GURL("https://google.com/scrypt-encrypted")));
ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase)); ASSERT_TRUE(WaitForNigori(PassphraseType::kCustomPassphrase));
NigoriSpecifics nigori; NigoriSpecifics nigori;
EXPECT_TRUE(GetServerNigori(GetFakeServer(), &nigori)); EXPECT_TRUE(GetServerNigori(GetFakeServer(), &nigori));
EXPECT_EQ(nigori.custom_passphrase_key_derivation_method(), EXPECT_EQ(nigori.custom_passphrase_key_derivation_method(),
sync_pb::NigoriSpecifics::SCRYPT_8192_8_11); sync_pb::NigoriSpecifics::SCRYPT_8192_8_11);
EXPECT_TRUE(WaitForEncryptedServerBookmarks( EXPECT_TRUE(WaitForEncryptedServerBookmarks({{title, page_url}},
{{"scrypt encrypted", GURL("https://google.com/scrypt-encrypted")}}, /*passphrase=*/"hunter2"));
/*passphrase=*/"hunter2"));
} }
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
...@@ -313,12 +317,13 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, ...@@ -313,12 +317,13 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
DoesNotLeakUnencryptedData) { DoesNotLeakUnencryptedData) {
const std::string title = "Should be encrypted";
const GURL page_url("https://google.com/encrypted");
SetEncryptionPassphraseForClient(/*index=*/0, "hunter2"); SetEncryptionPassphraseForClient(/*index=*/0, "hunter2");
ASSERT_TRUE(SetupClients()); ASSERT_TRUE(SetupClients());
// Create local bookmarks before sync is enabled. // Create local bookmarks before sync is enabled.
ASSERT_TRUE(AddURL(/*profile=*/0, "Should be encrypted", ASSERT_TRUE(AddURL(/*profile=*/0, title, page_url));
GURL("https://google.com/encrypted")));
CommittedBookmarkEntityNameObserver observer(GetFakeServer()); CommittedBookmarkEntityNameObserver observer(GetFakeServer());
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
...@@ -332,19 +337,20 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, ...@@ -332,19 +337,20 @@ IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
// once, we are certain that no bookmarks other than those we've verified to // once, we are certain that no bookmarks other than those we've verified to
// be encrypted have been committed. // be encrypted have been committed.
EXPECT_TRUE(WaitForEncryptedServerBookmarks( EXPECT_TRUE(WaitForEncryptedServerBookmarks(
{{"Should be encrypted", GURL("https://google.com/encrypted")}}, {{title, page_url}},
{KeyDerivationParams::CreateForPbkdf2(), "hunter2"})); {KeyDerivationParams::CreateForPbkdf2(), "hunter2"}));
EXPECT_THAT(observer.GetCommittedEntityNames(), ElementsAre("encrypted")); EXPECT_THAT(observer.GetCommittedEntityNames(), ElementsAre("encrypted"));
} }
IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest, IN_PROC_BROWSER_TEST_F(SingleClientCustomPassphraseDoNotUseScryptSyncTest,
ReencryptsDataWhenPassphraseIsSet) { ReencryptsDataWhenPassphraseIsSet) {
const std::string title = "Re-encryption is great";
const GURL page_url("https://google.com/re-encrypted");
ASSERT_TRUE(SetupSync()); ASSERT_TRUE(SetupSync());
ASSERT_TRUE(WaitForNigori(PassphraseType::kKeystorePassphrase)); ASSERT_TRUE(WaitForNigori(PassphraseType::kKeystorePassphrase));
ASSERT_TRUE(AddURL(/*profile=*/0, "Re-encryption is great", ASSERT_TRUE(AddURL(/*profile=*/0, title, page_url));
GURL("https://google.com/re-encrypted"))); const std::vector<ServerBookmarksEqualityChecker::ExpectedBookmark> expected =
std::vector<ServerBookmarksEqualityChecker::ExpectedBookmark> expected = { {{title, page_url}};
{"Re-encryption is great", GURL("https://google.com/re-encrypted")}};
ASSERT_TRUE(WaitForUnencryptedServerBookmarks(expected)); ASSERT_TRUE(WaitForUnencryptedServerBookmarks(expected));
GetSyncService()->GetUserSettings()->SetEncryptionPassphrase("hunter2"); GetSyncService()->GetUserSettings()->SetEncryptionPassphrase("hunter2");
......
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