OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/sync/test/integration/passwords_helper.h" | 7 #include "chrome/browser/sync/test/integration/passwords_helper.h" |
8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | |
9 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | |
8 #include "chrome/browser/sync/test/integration/sync_test.h" | 10 #include "chrome/browser/sync/test/integration/sync_test.h" |
9 #include "components/password_manager/core/browser/password_form_data.h" | 11 #include "components/password_manager/core/browser/password_form_data.h" |
10 | 12 |
11 using passwords_helper::AddLogin; | 13 using passwords_helper::AddLogin; |
14 using passwords_helper::AllProfilesContainSamePasswordFormsAsVerifier; | |
12 using passwords_helper::AwaitAllProfilesContainSamePasswordForms; | 15 using passwords_helper::AwaitAllProfilesContainSamePasswordForms; |
16 using passwords_helper::AwaitProfileContainsSamePasswordFormsAsVerifier; | |
13 using passwords_helper::CreateTestPasswordForm; | 17 using passwords_helper::CreateTestPasswordForm; |
14 using passwords_helper::GetPasswordCount; | 18 using passwords_helper::GetPasswordCount; |
15 using passwords_helper::GetPasswordStore; | 19 using passwords_helper::GetPasswordStore; |
20 using passwords_helper::GetVerifierPasswordCount; | |
21 using passwords_helper::GetVerifierPasswordStore; | |
22 using passwords_helper::ProfileContainsSamePasswordFormsAsVerifier; | |
23 using passwords_helper::SetDecryptionPassphrase; | |
24 using passwords_helper::SetEncryptionPassphrase; | |
25 using sync_integration_test_util::AwaitPassphraseAccepted; | |
26 using sync_integration_test_util::AwaitPassphraseRequired; | |
16 | 27 |
17 using autofill::PasswordForm; | 28 using autofill::PasswordForm; |
18 | 29 |
30 static const char* kValidPassphrase = "passphrase!"; | |
31 static const char* kAnotherValidPassphrase = "Mot de passe!"; | |
32 | |
19 class MultipleClientPasswordsSyncTest : public SyncTest { | 33 class MultipleClientPasswordsSyncTest : public SyncTest { |
20 public: | 34 public: |
21 MultipleClientPasswordsSyncTest() : SyncTest(MULTIPLE_CLIENT) {} | 35 MultipleClientPasswordsSyncTest() : SyncTest(MULTIPLE_CLIENT) {} |
22 virtual ~MultipleClientPasswordsSyncTest() {} | 36 virtual ~MultipleClientPasswordsSyncTest() {} |
23 | 37 |
24 virtual bool TestUsesSelfNotifications() OVERRIDE { | 38 virtual bool TestUsesSelfNotifications() OVERRIDE { |
25 return false; | 39 return false; |
26 } | 40 } |
27 | 41 |
28 private: | 42 private: |
29 DISALLOW_COPY_AND_ASSIGN(MultipleClientPasswordsSyncTest); | 43 DISALLOW_COPY_AND_ASSIGN(MultipleClientPasswordsSyncTest); |
30 }; | 44 }; |
31 | 45 |
32 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, Sanity) { | 46 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, Sanity) { |
33 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 47 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
34 | 48 |
35 for (int i = 0; i < num_clients(); ++i) { | 49 for (int i = 0; i < num_clients(); ++i) { |
36 PasswordForm form = CreateTestPasswordForm(i); | 50 PasswordForm form = CreateTestPasswordForm(i); |
37 AddLogin(GetPasswordStore(i), form); | 51 AddLogin(GetPasswordStore(i), form); |
38 } | 52 } |
39 | 53 |
40 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); | 54 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); |
41 ASSERT_EQ(num_clients(), GetPasswordCount(0)); | 55 ASSERT_EQ(num_clients(), GetPasswordCount(0)); |
42 } | 56 } |
57 | |
58 // TCM ID - 4577932. | |
59 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, DisablePasswords) { | |
60 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
61 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
62 | |
63 ASSERT_TRUE(GetClient(2)->DisableSyncForDatatype(syncer::PASSWORDS)); | |
64 PasswordForm form = CreateTestPasswordForm(0); | |
65 AddLogin(GetVerifierPasswordStore(), form); | |
66 ASSERT_EQ(1, GetVerifierPasswordCount()); | |
67 AddLogin(GetPasswordStore(0), form); | |
68 ASSERT_EQ(1, GetPasswordCount(0)); | |
69 | |
70 // Wait for the change to be picked up by client 1. | |
71 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); | |
72 | |
73 // Client 0 was always in sync, but client 2 is disabled and out of sync. | |
74 ASSERT_TRUE(ProfileContainsSamePasswordFormsAsVerifier(0)); | |
75 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); | |
76 | |
77 // Enable client 2 and wait for it to match. | |
78 ASSERT_TRUE(GetClient(2)->EnableSyncForDatatype(syncer::PASSWORDS)); | |
79 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); | |
Nicolas Zea
2014/05/06 00:16:37
Hmm, given that we're calling this, why do we care
rlarocque
2014/05/06 00:33:36
The expression ASSERT_EQ(1, GetPasswordCount(1)) i
Nicolas Zea
2014/05/06 18:42:15
I'd rather just rely on the verifier to be correct
rlarocque
2014/05/06 23:40:47
Done.
| |
80 ASSERT_EQ(1, GetPasswordCount(1)); | |
81 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
82 } | |
83 | |
84 // TCM ID - 4649281. | |
85 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, DisableSync) { | |
86 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
87 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
88 | |
89 ASSERT_TRUE(GetClient(2)->DisableSyncForAllDatatypes()); | |
90 PasswordForm form = CreateTestPasswordForm(0); | |
91 AddLogin(GetVerifierPasswordStore(), form); | |
92 ASSERT_EQ(1, GetVerifierPasswordCount()); | |
93 AddLogin(GetPasswordStore(0), form); | |
94 ASSERT_EQ(1, GetPasswordCount(0)); | |
95 | |
96 // Wait for the change to be picked up by client 1. | |
97 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); | |
98 | |
99 // Client 0 was always in sync, but client 2 is disabled and out of sync. | |
100 ASSERT_TRUE(ProfileContainsSamePasswordFormsAsVerifier(0)); | |
101 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); | |
102 | |
103 // Enable client 2 and wait for it to match. | |
104 ASSERT_TRUE(GetClient(2)->EnableSyncForAllDatatypes()); | |
105 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); | |
Nicolas Zea
2014/05/06 00:16:37
Same with this test
rlarocque
2014/05/06 23:40:47
Done.
| |
106 ASSERT_EQ(1, GetPasswordCount(1)); | |
107 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
108 } | |
109 | |
110 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, | |
111 SetPassphraseAndThenSetupSync) { | |
112 ASSERT_TRUE(SetupClients()); | |
113 | |
114 ASSERT_TRUE(GetClient(0)->SetupSync()); | |
115 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); | |
116 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(0))); | |
117 | |
118 // When client 1 hits a passphrase required state, we can infer that | |
119 // client 0's passphrase has been committed. to the server. | |
120 GetClient(1)->SetupSync(); | |
121 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); | |
122 | |
123 // Setup client 2 *after* the passphrase has been committed. | |
124 ASSERT_FALSE(GetClient(2)->SetupSync()); | |
125 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); | |
126 | |
127 // Get clients 1 and 2 out of the passphrase required state. | |
128 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase)); | |
129 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(1))); | |
130 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); | |
131 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); | |
132 | |
133 // For some reason, the tests won't pass unless these flags are set. | |
134 GetSyncService(1)->SetSyncSetupCompleted(); | |
Nicolas Zea
2014/05/06 00:16:37
SetupSync should be setting these bits appropriate
rlarocque
2014/05/06 00:33:36
These lines are a left-over from the old integrati
| |
135 GetSyncService(1)->SetSetupInProgress(false); | |
136 GetSyncService(2)->SetSyncSetupCompleted(); | |
137 GetSyncService(2)->SetSetupInProgress(false); | |
138 | |
139 // Move around some passwords to make sure it's all working. | |
140 PasswordForm form0 = CreateTestPasswordForm(0); | |
141 AddLogin(GetPasswordStore(0), form0); | |
142 | |
143 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); | |
144 } | |
145 | |
146 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, | |
147 SetDifferentPassphraseAndThenSetupSync) { | |
148 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
149 | |
150 ASSERT_TRUE(GetClient(0)->SetupSync()); | |
151 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); | |
152 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0)))); | |
153 | |
154 // When client 1 hits a passphrase required state, we can infer that | |
155 // client 0's passphrase has been committed. to the server. | |
156 GetClient(1)->SetupSync(); | |
157 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); | |
158 | |
159 // Give client 1 the correct passphrase. | |
160 SetDecryptionPassphrase(1, kValidPassphrase); | |
161 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1)))); | |
162 | |
163 // For some reason, the tests won't pass unless these flags are set. | |
164 GetSyncService(1)->SetSetupInProgress(false); | |
165 GetSyncService(1)->SetSyncSetupCompleted(); | |
166 | |
167 // Give client 2 a different passphrase so it fails to sync. | |
168 ASSERT_FALSE(GetClient(2)->SetupSync()); | |
169 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); | |
170 SetDecryptionPassphrase(2, kAnotherValidPassphrase); | |
171 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); | |
172 | |
173 // Add a password on 0 while client 2 has different passphrases. | |
174 PasswordForm form0 = CreateTestPasswordForm(0); | |
175 AddLogin(GetVerifierPasswordStore(), form0); | |
176 AddLogin(GetPasswordStore(0), form0); | |
177 | |
178 // It should sync to client 1. | |
179 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); | |
180 | |
181 // But it won't get synced to 2. | |
182 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); | |
183 | |
184 // Update 2 with the correct passphrase, the password should now sync over. | |
185 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); | |
186 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); | |
187 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); | |
188 | |
189 // For some reason, the tests won't pass unless these flags are set. | |
190 GetSyncService(2)->SetSetupInProgress(false); | |
191 GetSyncService(2)->SetSyncSetupCompleted(); | |
192 | |
193 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); | |
194 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
195 } | |
OLD | NEW |