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) { | |
Nicolas Zea
2014/05/06 23:46:58
My point is that these tests don't need to be mult
rlarocque
2014/05/07 00:06:42
Actually, client 1 is doing something.
The goal o
| |
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)); | |
80 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
81 } | |
82 | |
83 // TCM ID - 4649281. | |
84 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, DisableSync) { | |
85 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
86 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
87 | |
88 ASSERT_TRUE(GetClient(2)->DisableSyncForAllDatatypes()); | |
89 PasswordForm form = CreateTestPasswordForm(0); | |
90 AddLogin(GetVerifierPasswordStore(), form); | |
91 ASSERT_EQ(1, GetVerifierPasswordCount()); | |
92 AddLogin(GetPasswordStore(0), form); | |
93 ASSERT_EQ(1, GetPasswordCount(0)); | |
94 | |
95 // Wait for the change to be picked up by client 1. | |
96 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); | |
97 | |
98 // Client 0 was always in sync, but client 2 is disabled and out of sync. | |
99 ASSERT_TRUE(ProfileContainsSamePasswordFormsAsVerifier(0)); | |
100 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); | |
101 | |
102 // Enable client 2 and wait for it to match. | |
103 ASSERT_TRUE(GetClient(2)->EnableSyncForAllDatatypes()); | |
104 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); | |
105 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
106 } | |
107 | |
108 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, | |
109 SetPassphraseAndThenSetupSync) { | |
110 ASSERT_TRUE(SetupClients()); | |
111 | |
112 ASSERT_TRUE(GetClient(0)->SetupSync()); | |
113 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); | |
114 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(0))); | |
115 | |
116 // When client 1 hits a passphrase required state, we can infer that | |
117 // client 0's passphrase has been committed. to the server. | |
118 GetClient(1)->SetupSync(); | |
119 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); | |
120 | |
121 // Setup client 2 *after* the passphrase has been committed. | |
122 ASSERT_FALSE(GetClient(2)->SetupSync()); | |
123 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); | |
124 | |
125 // Get clients 1 and 2 out of the passphrase required state. | |
126 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase)); | |
127 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(1))); | |
128 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); | |
129 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); | |
130 | |
131 // For some reason, the tests won't pass unless these flags are set. | |
132 GetSyncService(1)->SetSyncSetupCompleted(); | |
133 GetSyncService(1)->SetSetupInProgress(false); | |
134 GetSyncService(2)->SetSyncSetupCompleted(); | |
135 GetSyncService(2)->SetSetupInProgress(false); | |
136 | |
137 // Move around some passwords to make sure it's all working. | |
138 PasswordForm form0 = CreateTestPasswordForm(0); | |
139 AddLogin(GetPasswordStore(0), form0); | |
140 | |
141 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); | |
142 } | |
143 | |
144 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, | |
145 SetDifferentPassphraseAndThenSetupSync) { | |
146 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; | |
147 | |
148 ASSERT_TRUE(GetClient(0)->SetupSync()); | |
149 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); | |
150 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0)))); | |
151 | |
152 // When client 1 hits a passphrase required state, we can infer that | |
153 // client 0's passphrase has been committed. to the server. | |
154 GetClient(1)->SetupSync(); | |
155 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); | |
156 | |
157 // Give client 1 the correct passphrase. | |
158 SetDecryptionPassphrase(1, kValidPassphrase); | |
159 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1)))); | |
160 | |
161 // For some reason, the tests won't pass unless these flags are set. | |
162 GetSyncService(1)->SetSetupInProgress(false); | |
163 GetSyncService(1)->SetSyncSetupCompleted(); | |
164 | |
165 // Give client 2 a different passphrase so it fails to sync. | |
166 ASSERT_FALSE(GetClient(2)->SetupSync()); | |
167 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); | |
168 SetDecryptionPassphrase(2, kAnotherValidPassphrase); | |
169 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); | |
170 | |
171 // Add a password on 0 while client 2 has different passphrases. | |
172 PasswordForm form0 = CreateTestPasswordForm(0); | |
173 AddLogin(GetVerifierPasswordStore(), form0); | |
174 AddLogin(GetPasswordStore(0), form0); | |
175 | |
176 // It should sync to client 1. | |
177 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); | |
178 | |
179 // But it won't get synced to 2. | |
180 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); | |
181 | |
182 // Update 2 with the correct passphrase, the password should now sync over. | |
183 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); | |
184 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); | |
185 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); | |
186 | |
187 // For some reason, the tests won't pass unless these flags are set. | |
188 GetSyncService(2)->SetSetupInProgress(false); | |
189 GetSyncService(2)->SetSyncSetupCompleted(); | |
190 | |
191 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); | |
192 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); | |
193 } | |
OLD | NEW |