• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
13 using passwords_helper::AddLogin;
14 using passwords_helper::AllProfilesContainSamePasswordForms;
15 using passwords_helper::AllProfilesContainSamePasswordFormsAsVerifier;
16 using passwords_helper::AwaitAllProfilesContainSamePasswordForms;
17 using passwords_helper::AwaitProfileContainsSamePasswordFormsAsVerifier;
18 using passwords_helper::CreateTestPasswordForm;
19 using passwords_helper::GetPasswordCount;
20 using passwords_helper::GetPasswordStore;
21 using passwords_helper::GetVerifierPasswordCount;
22 using passwords_helper::GetVerifierPasswordStore;
23 using passwords_helper::RemoveLogin;
24 using passwords_helper::RemoveLogins;
25 using passwords_helper::SetDecryptionPassphrase;
26 using passwords_helper::SetEncryptionPassphrase;
27 using passwords_helper::UpdateLogin;
28 using sync_integration_test_util::AwaitPassphraseAccepted;
29 using sync_integration_test_util::AwaitPassphraseRequired;
30 
31 using autofill::PasswordForm;
32 
33 static const char* kValidPassphrase = "passphrase!";
34 
35 class TwoClientPasswordsSyncTest : public SyncTest {
36  public:
TwoClientPasswordsSyncTest()37   TwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT) {}
~TwoClientPasswordsSyncTest()38   virtual ~TwoClientPasswordsSyncTest() {}
39 
TestUsesSelfNotifications()40   virtual bool TestUsesSelfNotifications() OVERRIDE { return false; }
41 
42  private:
43   DISALLOW_COPY_AND_ASSIGN(TwoClientPasswordsSyncTest);
44 };
45 
46 class LegacyTwoClientPasswordsSyncTest : public SyncTest {
47  public:
LegacyTwoClientPasswordsSyncTest()48   LegacyTwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT_LEGACY) {}
~LegacyTwoClientPasswordsSyncTest()49   virtual ~LegacyTwoClientPasswordsSyncTest() {}
50 
51  private:
52   DISALLOW_COPY_AND_ASSIGN(LegacyTwoClientPasswordsSyncTest);
53 };
54 
55 // TCM ID - 3732277
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,Add)56 IN_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 
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,Race)69 IN_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 
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,SetPassphraseAndAddPassword)83 IN_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
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,Update)102 IN_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
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,Delete)124 IN_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
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,MAYBE_DeleteAll)154 IN_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
IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,Merge)175 IN_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