Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / two_client_passwords_sync_test.cc
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:
37   TwoClientPasswordsSyncTest() : SyncTest(TWO_CLIENT) {}
38   ~TwoClientPasswordsSyncTest() override {}
39
40   bool TestUsesSelfNotifications() override { return false; }
41
42  private:
43   DISALLOW_COPY_AND_ASSIGN(TwoClientPasswordsSyncTest);
44 };
45
46 // TCM ID - 3732277
47 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Add) {
48   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
49   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
50
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));
56
57   ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
58 }
59
60 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Race) {
61   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
62   ASSERT_TRUE(AllProfilesContainSamePasswordForms());
63
64   PasswordForm form0 = CreateTestPasswordForm(0);
65   AddLogin(GetPasswordStore(0), form0);
66
67   PasswordForm form1 = form0;
68   form1.password_value = base::ASCIIToUTF16("new_password");
69   AddLogin(GetPasswordStore(1), form1);
70
71   ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
72 }
73
74 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest,
75                        SetPassphraseAndAddPassword) {
76   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
77
78   SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
79   ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0))));
80
81   ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((1))));
82   ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
83   ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1))));
84
85   PasswordForm form = CreateTestPasswordForm(0);
86   AddLogin(GetPasswordStore(0), form);
87   ASSERT_EQ(1, GetPasswordCount(0));
88
89   ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
90 }
91
92 // TCM ID - 4603879
93 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Update) {
94   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
95   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
96
97   PasswordForm form = CreateTestPasswordForm(0);
98   AddLogin(GetVerifierPasswordStore(), form);
99   AddLogin(GetPasswordStore(0), form);
100
101   // Wait for client 0 to commit and client 1 to receive the update.
102   ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
103
104   form.password_value = base::ASCIIToUTF16("new_password");
105   UpdateLogin(GetVerifierPasswordStore(), form);
106   UpdateLogin(GetPasswordStore(1), form);
107   ASSERT_EQ(1, GetVerifierPasswordCount());
108
109   // Wait for client 1 to commit and client 0 to receive the update.
110   ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
111   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
112 }
113
114 // TCM ID - 3719309
115 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Delete) {
116   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
117   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
118
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);
125
126   // Wait for client 0 to commit and client 1 to receive the update.
127   ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
128
129   RemoveLogin(GetPasswordStore(1), form0);
130   RemoveLogin(GetVerifierPasswordStore(), form0);
131   ASSERT_EQ(1, GetVerifierPasswordCount());
132
133   // Wait for deletion from client 1 to propagate.
134   ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
135   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
136 }
137
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());
148
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());
157
158   RemoveLogins(GetPasswordStore(1));
159   RemoveLogins(GetVerifierPasswordStore());
160   ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(0));
161   ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());
162   ASSERT_EQ(0, GetVerifierPasswordCount());
163 }
164
165 // TCM ID - 3694311
166 IN_PROC_BROWSER_TEST_F(TwoClientPasswordsSyncTest, Merge) {
167   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
168   ASSERT_TRUE(AllProfilesContainSamePasswordForms());
169
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);
176
177   ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
178   ASSERT_EQ(3, GetPasswordCount(0));
179 }