Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / two_client_passwords_sync_test.cc
blob0cb80a60395e3697549036b13e70964985953444
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 #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"
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;
31 using autofill::PasswordForm;
33 static const char* kValidPassphrase = "passphrase!";
35 class TwoClientPasswordsSyncTest : public SyncTest {
36 public:
37 TwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT) {}
38 ~TwoClientPasswordsSyncTest() override {}
40 bool TestUsesSelfNotifications() override { return false; }
42 private:
43 DISALLOW_COPY_AND_ASSIGN(TwoClientPasswordsSyncTest);
46 // TCM ID - 3732277
47 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Add) {
48 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
49 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
51 PasswordForm form = CreateTestPasswordForm(0);
52 AddLogin(GetVerifierPasswordStore(), form);
53 ASSERT_EQ(1, GetVerifierPasswordCount());
54 AddLogin(GetPasswordStore(0), form);
55 ASSERT_EQ(1, GetPasswordCount(0));
57 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
60 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Race) {
61 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
62 ASSERT_TRUE(AllProfilesContainSamePasswordForms());
64 PasswordForm form0 = CreateTestPasswordForm(0);
65 AddLogin(GetPasswordStore(0), form0);
67 PasswordForm form1 = form0;
68 form1.password_value = base::ASCIIToUTF16("new_password");
69 AddLogin(GetPasswordStore(1), form1);
71 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
74 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,
75 SetPassphraseAndAddPassword) {
76 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
78 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
79 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0))));
81 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((1))));
82 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
83 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1))));
85 PasswordForm form = CreateTestPasswordForm(0);
86 AddLogin(GetPasswordStore(0), form);
87 ASSERT_EQ(1, GetPasswordCount(0));
89 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
92 // TCM ID - 4603879
93 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Update) {
94 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
95 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
97 PasswordForm form = CreateTestPasswordForm(0);
98 AddLogin(GetVerifierPasswordStore(), form);
99 AddLogin(GetPasswordStore(0), form);
101 // Wait for client 0 to commit and client 1 to receive the update.
102 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
104 form.password_value = base::ASCIIToUTF16("new_password");
105 UpdateLogin(GetVerifierPasswordStore(), form);
106 UpdateLogin(GetPasswordStore(1), form);
107 ASSERT_EQ(1, GetVerifierPasswordCount());
109 // Wait for client 1 to commit and client 0 to receive the update.
110 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
111 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
114 // TCM ID - 3719309
115 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Delete) {
116 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
119 PasswordForm form0 = CreateTestPasswordForm(0);
120 AddLogin(GetVerifierPasswordStore(), form0);
121 AddLogin(GetPasswordStore(0), form0);
122 PasswordForm form1 = CreateTestPasswordForm(1);
123 AddLogin(GetVerifierPasswordStore(), form1);
124 AddLogin(GetPasswordStore(0), form1);
126 // Wait for client 0 to commit and client 1 to receive the update.
127 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
129 RemoveLogin(GetPasswordStore(1), form0);
130 RemoveLogin(GetVerifierPasswordStore(), form0);
131 ASSERT_EQ(1, GetVerifierPasswordCount());
133 // Wait for deletion from client 1 to propagate.
134 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
135 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
138 // TCM ID - 7573511
139 // Flaky on Mac and Windows: http://crbug.com/111399
140 #if defined(OS_WIN) || defined(OS_MACOSX)
141 #define MAYBE_DeleteAll DISABLED_DeleteAll
142 #else
143 #define MAYBE_DeleteAll DeleteAll
144 #endif
145 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, MAYBE_DeleteAll) {
146 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
147 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
149 PasswordForm form0 = CreateTestPasswordForm(0);
150 AddLogin(GetVerifierPasswordStore(), form0);
151 AddLogin(GetPasswordStore(0), form0);
152 PasswordForm form1 = CreateTestPasswordForm(1);
153 AddLogin(GetVerifierPasswordStore(), form1);
154 AddLogin(GetPasswordStore(0), form1);
155 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
156 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
158 RemoveLogins(GetPasswordStore(1));
159 RemoveLogins(GetVerifierPasswordStore());
160 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
161 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
162 ASSERT_EQ(0, GetVerifierPasswordCount());
165 // TCM ID - 3694311
166 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Merge) {
167 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
168 ASSERT_TRUE(AllProfilesContainSamePasswordForms());
170 PasswordForm form0 = CreateTestPasswordForm(0);
171 AddLogin(GetPasswordStore(0), form0);
172 PasswordForm form1 = CreateTestPasswordForm(1);
173 AddLogin(GetPasswordStore(1), form1);
174 PasswordForm form2 = CreateTestPasswordForm(2);
175 AddLogin(GetPasswordStore(1), form2);
177 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
178 ASSERT_EQ(3, GetPasswordCount(0));