Commit 34683f17 authored by Pavel Yatsuk's avatar Pavel Yatsuk Committed by Commit Bot

[Sync] Verify that correct value of CookieJarMismatch is passed to SyncCycleContext

SingleClientSessionsSyncTest.CookieJarMismatch test is flaky. It fails on the
step when signed in account gets included in the list of accounts in cookie jar.
In this case value of cookie_jar_mismatch should turn to false.

I wasn't able to reproduce this bug, nor I was able to find scenario how this
test could fail.

I'm adding a check that ensures correct value of cookie_jar_mismatch is passed
to sync engine. The next time this test fails it will be clear if failure caused
by incorrect value or the value wasn't delivered to the server.

R=pnoland@chromium.org
BUG=789129

Change-Id: I508e5d37083e98b2c02e1bf3a35917dad3a9645f
Reviewed-on: https://chromium-review.googlesource.com/804556
Commit-Queue: Pavel Yatsuk <pavely@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@google.com>
Cr-Commit-Position: refs/heads/master@{#521583}
parent 29d3678b
...@@ -108,18 +108,19 @@ class SingleClientSessionsSyncTest : public SyncTest { ...@@ -108,18 +108,19 @@ class SingleClientSessionsSyncTest : public SyncTest {
// Simulates receiving list of accounts in the cookie jar from ListAccounts // Simulates receiving list of accounts in the cookie jar from ListAccounts
// endpoint. Adds |account_ids| into signed in accounts, notifies // endpoint. Adds |account_ids| into signed in accounts, notifies
// ProfileSyncService and waits for change to propagate to sync engine. // ProfileSyncService and waits for change to propagate to sync engine.
void UpdateCookieJarAccountsAndWait(std::vector<std::string> account_ids) { void UpdateCookieJarAccountsAndWait(std::vector<std::string> account_ids,
GoogleServiceAuthError error(GoogleServiceAuthError::NONE); bool expected_cookie_jar_mismatch) {
std::vector<gaia::ListedAccount> accounts; std::vector<gaia::ListedAccount> accounts;
std::vector<gaia::ListedAccount> signed_out_accounts;
for (const auto& account_id : account_ids) { for (const auto& account_id : account_ids) {
gaia::ListedAccount signed_in_account; gaia::ListedAccount signed_in_account;
signed_in_account.id = account_id; signed_in_account.id = account_id;
accounts.push_back(signed_in_account); accounts.push_back(signed_in_account);
} }
base::RunLoop run_loop; base::RunLoop run_loop;
EXPECT_EQ(expected_cookie_jar_mismatch,
GetClient(0)->service()->HasCookieJarMismatch(accounts));
GetClient(0)->service()->OnGaiaAccountsInCookieUpdatedWithCallback( GetClient(0)->service()->OnGaiaAccountsInCookieUpdatedWithCallback(
accounts, signed_out_accounts, error, run_loop.QuitClosure()); accounts, run_loop.QuitClosure());
run_loop.Run(); run_loop.Run();
} }
...@@ -376,9 +377,9 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, SourceTabIDSet) { ...@@ -376,9 +377,9 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, SourceTabIDSet) {
EXPECT_EQ(new_tab_helper->source_tab_id(), source_tab_id); EXPECT_EQ(new_tab_helper->source_tab_id(), source_tab_id);
} }
// Test is flaky. https://crbug.com/789129 // TODO(pavely): This test is flaky. Report failures in
IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, // https://crbug.com/789129.
DISABLED_CookieJarMismatch) { IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, CookieJarMismatch) {
ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
ASSERT_TRUE(CheckInitialState(0)); ASSERT_TRUE(CheckInitialState(0));
...@@ -387,7 +388,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ...@@ -387,7 +388,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
// Simulate empty list of accounts in the cookie jar. This will record cookie // Simulate empty list of accounts in the cookie jar. This will record cookie
// jar mismatch. // jar mismatch.
UpdateCookieJarAccountsAndWait({}); UpdateCookieJarAccountsAndWait({}, true);
// The HistogramTester objects are scoped to allow more precise verification. // The HistogramTester objects are scoped to allow more precise verification.
{ {
HistogramTester histogram_tester; HistogramTester histogram_tester;
...@@ -414,7 +415,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest, ...@@ -414,7 +415,7 @@ IN_PROC_BROWSER_TEST_F(SingleClientSessionsSyncTest,
// want to block here and not create the HistogramTester below until we know // want to block here and not create the HistogramTester below until we know
// the cookie jar stats have been updated. // the cookie jar stats have been updated.
UpdateCookieJarAccountsAndWait( UpdateCookieJarAccountsAndWait(
{GetClient(0)->service()->signin()->GetAuthenticatedAccountId()}); {GetClient(0)->service()->signin()->GetAuthenticatedAccountId()}, false);
{ {
HistogramTester histogram_tester; HistogramTester histogram_tester;
......
...@@ -1907,36 +1907,35 @@ void ProfileSyncService::OnGaiaAccountsInCookieUpdated( ...@@ -1907,36 +1907,35 @@ void ProfileSyncService::OnGaiaAccountsInCookieUpdated(
const std::vector<gaia::ListedAccount>& accounts, const std::vector<gaia::ListedAccount>& accounts,
const std::vector<gaia::ListedAccount>& signed_out_accounts, const std::vector<gaia::ListedAccount>& signed_out_accounts,
const GoogleServiceAuthError& error) { const GoogleServiceAuthError& error) {
OnGaiaAccountsInCookieUpdatedWithCallback(accounts, signed_out_accounts, OnGaiaAccountsInCookieUpdatedWithCallback(accounts, base::Closure());
error, base::Closure());
} }
void ProfileSyncService::OnGaiaAccountsInCookieUpdatedWithCallback( void ProfileSyncService::OnGaiaAccountsInCookieUpdatedWithCallback(
const std::vector<gaia::ListedAccount>& accounts, const std::vector<gaia::ListedAccount>& accounts,
const std::vector<gaia::ListedAccount>& signed_out_accounts,
const GoogleServiceAuthError& error,
const base::Closure& callback) { const base::Closure& callback) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
if (!IsEngineInitialized()) if (!IsEngineInitialized())
return; return;
bool cookie_jar_mismatch = true; bool cookie_jar_mismatch = HasCookieJarMismatch(accounts);
bool cookie_jar_empty = accounts.size() == 0; bool cookie_jar_empty = accounts.size() == 0;
std::string account_id = signin_->GetAccountIdToUse();
// Iterate through list of accounts, looking for current sync account.
for (const auto& account : accounts) {
if (account.id == account_id) {
cookie_jar_mismatch = false;
break;
}
}
DVLOG(1) << "Cookie jar mismatch: " << cookie_jar_mismatch; DVLOG(1) << "Cookie jar mismatch: " << cookie_jar_mismatch;
DVLOG(1) << "Cookie jar empty: " << cookie_jar_empty; DVLOG(1) << "Cookie jar empty: " << cookie_jar_empty;
engine_->OnCookieJarChanged(cookie_jar_mismatch, cookie_jar_empty, callback); engine_->OnCookieJarChanged(cookie_jar_mismatch, cookie_jar_empty, callback);
} }
bool ProfileSyncService::HasCookieJarMismatch(
const std::vector<gaia::ListedAccount>& cookie_jar_accounts) {
std::string account_id = signin_->GetAccountIdToUse();
// Iterate through list of accounts, looking for current sync account.
for (const auto& account : cookie_jar_accounts) {
if (account.id == account_id)
return false;
}
return true;
}
void ProfileSyncService::AddProtocolEventObserver( void ProfileSyncService::AddProtocolEventObserver(
ProtocolEventObserver* observer) { ProtocolEventObserver* observer) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
......
...@@ -393,10 +393,13 @@ class ProfileSyncService : public syncer::SyncServiceBase, ...@@ -393,10 +393,13 @@ class ProfileSyncService : public syncer::SyncServiceBase,
// Similar to above but with a callback that will be invoked on completion. // Similar to above but with a callback that will be invoked on completion.
void OnGaiaAccountsInCookieUpdatedWithCallback( void OnGaiaAccountsInCookieUpdatedWithCallback(
const std::vector<gaia::ListedAccount>& accounts, const std::vector<gaia::ListedAccount>& accounts,
const std::vector<gaia::ListedAccount>& signed_out_accounts,
const GoogleServiceAuthError& error,
const base::Closure& callback); const base::Closure& callback);
// Returns true if currently signed in account is not present in the list of
// accounts from cookie jar.
bool HasCookieJarMismatch(
const std::vector<gaia::ListedAccount>& cookie_jar_accounts);
// Get the sync status code. // Get the sync status code.
SyncStatusSummary QuerySyncStatusSummary(); SyncStatusSummary QuerySyncStatusSummary();
......
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