two_client_passwords_sync_test.cc revision 010d83a9304c5a91596085d917d248abff47903a
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "base/strings/utf_string_conversions.h" 6#include "chrome/browser/sync/test/integration/passwords_helper.h" 7#include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 8#include "chrome/browser/sync/test/integration/sync_integration_test_util.h" 9#include "chrome/browser/sync/test/integration/sync_test.h" 10#include "sync/internal_api/public/engine/model_safe_worker.h" 11#include "sync/internal_api/public/sessions/sync_session_snapshot.h" 12 13using passwords_helper::AddLogin; 14using passwords_helper::AllProfilesContainSamePasswordForms; 15using passwords_helper::AllProfilesContainSamePasswordFormsAsVerifier; 16using passwords_helper::AwaitAllProfilesContainSamePasswordForms; 17using passwords_helper::AwaitProfileContainsSamePasswordFormsAsVerifier; 18using passwords_helper::CreateTestPasswordForm; 19using passwords_helper::GetPasswordCount; 20using passwords_helper::GetPasswordStore; 21using passwords_helper::GetVerifierPasswordCount; 22using passwords_helper::GetVerifierPasswordStore; 23using passwords_helper::RemoveLogin; 24using passwords_helper::RemoveLogins; 25using passwords_helper::SetDecryptionPassphrase; 26using passwords_helper::SetEncryptionPassphrase; 27using passwords_helper::UpdateLogin; 28using sync_integration_test_util::AwaitPassphraseAccepted; 29using sync_integration_test_util::AwaitPassphraseRequired; 30 31using autofill::PasswordForm; 32 33static const char* kValidPassphrase = "passphrase!"; 34 35class TwoClientPasswordsSyncTest : public SyncTest { 36 public: 37 TwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT) {} 38 virtual ~TwoClientPasswordsSyncTest() {} 39 40 virtual bool TestUsesSelfNotifications() OVERRIDE { return false; } 41 42 private: 43 DISALLOW_COPY_AND_ASSIGN(TwoClientPasswordsSyncTest); 44}; 45 46class LegacyTwoClientPasswordsSyncTest : public SyncTest { 47 public: 48 LegacyTwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {} 49 virtual ~LegacyTwoClientPasswordsSyncTest() {} 50 51 private: 52 DISALLOW_COPY_AND_ASSIGN(LegacyTwoClientPasswordsSyncTest); 53}; 54 55// TCM ID - 3732277 56IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Add) { 57 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 58 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 59 60 PasswordForm form = CreateTestPasswordForm(0); 61 AddLogin(GetVerifierPasswordStore(), form); 62 ASSERT_EQ(1, GetVerifierPasswordCount()); 63 AddLogin(GetPasswordStore(0), form); 64 ASSERT_EQ(1, GetPasswordCount(0)); 65 66 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); 67} 68 69IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Race) { 70 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 71 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); 72 73 PasswordForm form0 = CreateTestPasswordForm(0); 74 AddLogin(GetPasswordStore(0), form0); 75 76 PasswordForm form1 = form0; 77 form1.password_value = base::ASCIIToUTF16("new_password"); 78 AddLogin(GetPasswordStore(1), form1); 79 80 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); 81} 82 83IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, 84 SetPassphraseAndAddPassword) { 85 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 86 87 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); 88 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0)))); 89 90 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((1)))); 91 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase)); 92 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1)))); 93 94 PasswordForm form = CreateTestPasswordForm(0); 95 AddLogin(GetPasswordStore(0), form); 96 ASSERT_EQ(1, GetPasswordCount(0)); 97 98 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); 99} 100 101// TCM ID - 4603879 102IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Update) { 103 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 104 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 105 106 PasswordForm form = CreateTestPasswordForm(0); 107 AddLogin(GetVerifierPasswordStore(), form); 108 AddLogin(GetPasswordStore(0), form); 109 110 // Wait for client 0 to commit and client 1 to receive the update. 111 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); 112 113 form.password_value = base::ASCIIToUTF16("new_password"); 114 UpdateLogin(GetVerifierPasswordStore(), form); 115 UpdateLogin(GetPasswordStore(1), form); 116 ASSERT_EQ(1, GetVerifierPasswordCount()); 117 118 // Wait for client 1 to commit and client 0 to receive the update. 119 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0)); 120 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 121} 122 123// TCM ID - 3719309 124IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Delete) { 125 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 126 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 127 128 PasswordForm form0 = CreateTestPasswordForm(0); 129 AddLogin(GetVerifierPasswordStore(), form0); 130 AddLogin(GetPasswordStore(0), form0); 131 PasswordForm form1 = CreateTestPasswordForm(1); 132 AddLogin(GetVerifierPasswordStore(), form1); 133 AddLogin(GetPasswordStore(0), form1); 134 135 // Wait for client 0 to commit and client 1 to receive the update. 136 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); 137 138 RemoveLogin(GetPasswordStore(1), form0); 139 RemoveLogin(GetVerifierPasswordStore(), form0); 140 ASSERT_EQ(1, GetVerifierPasswordCount()); 141 142 // Wait for deletion from client 1 to propagate. 143 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0)); 144 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 145} 146 147// TCM ID - 7573511 148// Flaky on Mac and Windows: http://crbug.com/111399 149#if defined(OS_WIN) || defined(OS_MACOSX) 150#define MAYBE_DeleteAll DISABLED_DeleteAll 151#else 152#define MAYBE_DeleteAll DeleteAll 153#endif 154IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, MAYBE_DeleteAll) { 155 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 156 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 157 158 PasswordForm form0 = CreateTestPasswordForm(0); 159 AddLogin(GetVerifierPasswordStore(), form0); 160 AddLogin(GetPasswordStore(0), form0); 161 PasswordForm form1 = CreateTestPasswordForm(1); 162 AddLogin(GetVerifierPasswordStore(), form1); 163 AddLogin(GetPasswordStore(0), form1); 164 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); 165 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 166 167 RemoveLogins(GetPasswordStore(1)); 168 RemoveLogins(GetVerifierPasswordStore()); 169 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0)); 170 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); 171 ASSERT_EQ(0, GetVerifierPasswordCount()); 172} 173 174// TCM ID - 3694311 175IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Merge) { 176 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 177 ASSERT_TRUE(AllProfilesContainSamePasswordForms()); 178 179 PasswordForm form0 = CreateTestPasswordForm(0); 180 AddLogin(GetPasswordStore(0), form0); 181 PasswordForm form1 = CreateTestPasswordForm(1); 182 AddLogin(GetPasswordStore(1), form1); 183 PasswordForm form2 = CreateTestPasswordForm(2); 184 AddLogin(GetPasswordStore(1), form2); 185 186 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); 187 ASSERT_EQ(3, GetPasswordCount(0)); 188} 189