Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_passwords_sync_test.cc
blob695b98b851e39fd299de067ad854fd874e154486
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.
5 // TODO(shadi): create a common macro for end-to-end tests that need to be
6 // disabled in regular bots.
7 #define E2E_ONLY(x) DISABLED_E2ETest##x
9 #include "base/guid.h"
10 #include "base/hash.h"
11 #include "base/rand_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/sync/test/integration/passwords_helper.h"
14 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
15 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h"
16 #include "chrome/browser/sync/test/integration/sync_test.h"
17 #include "sync/internal_api/public/engine/model_safe_worker.h"
18 #include "sync/internal_api/public/sessions/sync_session_snapshot.h"
20 using passwords_helper::AddLogin;
21 using passwords_helper::AllProfilesContainSamePasswordForms;
22 using passwords_helper::AllProfilesContainSamePasswordFormsAsVerifier;
23 using passwords_helper::AwaitAllProfilesContainSamePasswordForms;
24 using passwords_helper::AwaitProfileContainsSamePasswordFormsAsVerifier;
25 using passwords_helper::CreateTestPasswordForm;
26 using passwords_helper::GetPasswordCount;
27 using passwords_helper::GetPasswordStore;
28 using passwords_helper::GetVerifierPasswordCount;
29 using passwords_helper::GetVerifierPasswordStore;
30 using passwords_helper::RemoveLogin;
31 using passwords_helper::RemoveLogins;
32 using passwords_helper::SetDecryptionPassphrase;
33 using passwords_helper::SetEncryptionPassphrase;
34 using passwords_helper::UpdateLogin;
35 using sync_integration_test_util::AwaitPassphraseAccepted;
36 using sync_integration_test_util::AwaitPassphraseRequired;
38 using autofill::PasswordForm;
40 static const char* kValidPassphrase = "passphrase!";
42 class TwoClientPasswordsSyncTest : public SyncTest {
43 public:
44 TwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT) {}
45 ~TwoClientPasswordsSyncTest() override {}
47 bool TestUsesSelfNotifications() override { return false; }
49 private:
50 DISALLOW_COPY_AND_ASSIGN(TwoClientPasswordsSyncTest);
53 // TCM ID - 3732277
54 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Add) {
55 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
56 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
58 PasswordForm form = CreateTestPasswordForm(0);
59 AddLogin(GetVerifierPasswordStore(), form);
60 ASSERT_EQ(1, GetVerifierPasswordCount());
61 AddLogin(GetPasswordStore(0), form);
62 ASSERT_EQ(1, GetPasswordCount(0));
64 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
67 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Race) {
68 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
69 ASSERT_TRUE(AllProfilesContainSamePasswordForms());
71 PasswordForm form0 = CreateTestPasswordForm(0);
72 AddLogin(GetPasswordStore(0), form0);
74 PasswordForm form1 = form0;
75 form1.password_value = base::ASCIIToUTF16("new_password");
76 AddLogin(GetPasswordStore(1), form1);
78 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
81 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,
82 SetPassphraseAndAddPassword) {
83 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
85 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
86 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0))));
88 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((1))));
89 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
90 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1))));
92 PasswordForm form = CreateTestPasswordForm(0);
93 AddLogin(GetPasswordStore(0), form);
94 ASSERT_EQ(1, GetPasswordCount(0));
96 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
99 // TCM ID - 4603879
100 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Update) {
101 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
102 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
104 PasswordForm form = CreateTestPasswordForm(0);
105 AddLogin(GetVerifierPasswordStore(), form);
106 AddLogin(GetPasswordStore(0), form);
108 // Wait for client 0 to commit and client 1 to receive the update.
109 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
111 form.password_value = base::ASCIIToUTF16("new_password");
112 UpdateLogin(GetVerifierPasswordStore(), form);
113 UpdateLogin(GetPasswordStore(1), form);
114 ASSERT_EQ(1, GetVerifierPasswordCount());
116 // Wait for client 1 to commit and client 0 to receive the update.
117 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
118 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
121 // TCM ID - 3719309
122 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Delete) {
123 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
124 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
126 PasswordForm form0 = CreateTestPasswordForm(0);
127 AddLogin(GetVerifierPasswordStore(), form0);
128 AddLogin(GetPasswordStore(0), form0);
129 PasswordForm form1 = CreateTestPasswordForm(1);
130 AddLogin(GetVerifierPasswordStore(), form1);
131 AddLogin(GetPasswordStore(0), form1);
133 // Wait for client 0 to commit and client 1 to receive the update.
134 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
136 RemoveLogin(GetPasswordStore(1), form0);
137 RemoveLogin(GetVerifierPasswordStore(), form0);
138 ASSERT_EQ(1, GetVerifierPasswordCount());
140 // Wait for deletion from client 1 to propagate.
141 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
142 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
145 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, E2E_ONLY(Delete)) {
146 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
147 ASSERT_TRUE(AllProfilesContainSamePasswordForms());
149 PasswordForm form0 = CreateTestPasswordForm(base::Hash(base::GenerateGUID()));
150 PasswordForm form1 = CreateTestPasswordForm(base::Hash(base::GenerateGUID()));
151 AddLogin(GetPasswordStore(0), form0);
152 AddLogin(GetPasswordStore(0), form1);
154 const int init_password_count = GetPasswordCount(0);
156 // Wait for client 0 to commit and client 1 to receive the update.
157 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
158 ASSERT_EQ(init_password_count, GetPasswordCount(1));
160 RemoveLogin(GetPasswordStore(1), form0);
162 // Wait for deletion from client 1 to propagate.
163 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
164 ASSERT_EQ(init_password_count - 1, GetPasswordCount(0));
166 RemoveLogin(GetPasswordStore(1), form1);
168 // Wait for deletion from client 1 to propagate.
169 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
170 ASSERT_EQ(init_password_count - 2, GetPasswordCount(0));
173 // TCM ID - 7573511
174 // Flaky on Mac and Windows: http://crbug.com/111399
175 #if defined(OS_WIN) || defined(OS_MACOSX)
176 #define MAYBE_DeleteAll DISABLED_DeleteAll
177 #else
178 #define MAYBE_DeleteAll DeleteAll
179 #endif
180 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, MAYBE_DeleteAll) {
181 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
182 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
184 PasswordForm form0 = CreateTestPasswordForm(0);
185 AddLogin(GetVerifierPasswordStore(), form0);
186 AddLogin(GetPasswordStore(0), form0);
187 PasswordForm form1 = CreateTestPasswordForm(1);
188 AddLogin(GetVerifierPasswordStore(), form1);
189 AddLogin(GetPasswordStore(0), form1);
190 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
191 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
193 RemoveLogins(GetPasswordStore(1));
194 RemoveLogins(GetVerifierPasswordStore());
195 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
196 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
197 ASSERT_EQ(0, GetVerifierPasswordCount());
200 // TCM ID - 3694311
201 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Merge) {
202 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
203 ASSERT_TRUE(AllProfilesContainSamePasswordForms());
205 PasswordForm form0 = CreateTestPasswordForm(0);
206 AddLogin(GetPasswordStore(0), form0);
207 PasswordForm form1 = CreateTestPasswordForm(1);
208 AddLogin(GetPasswordStore(1), form1);
209 PasswordForm form2 = CreateTestPasswordForm(2);
210 AddLogin(GetPasswordStore(1), form2);
212 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
213 ASSERT_EQ(3, GetPasswordCount(0));
216 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, E2E_ONLY(TwoClientAddPass)) {
217 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
218 // All profiles should sync same passwords.
219 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()) <<
220 "Initial password forms did not match for all profiles";
221 const int init_password_count = GetPasswordCount(0);
223 // Add one new password per profile. A unique form is created for each to
224 // prevent them from overwriting each other.
225 for (int i = 0; i < num_clients(); ++i) {
226 AddLogin(GetPasswordStore(i),
227 CreateTestPasswordForm(base::RandInt(0, kint32max)));
230 // Blocks and waits for password forms in all profiles to match.
231 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
233 // Check that total number of passwords is as expected.
234 for (int i = 0; i < num_clients(); ++i) {
235 ASSERT_EQ(GetPasswordCount(i), init_password_count + num_clients()) <<
236 "Total password count is wrong.";