Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / multiple_client_passwords_sync_test.cc
blob27e19d247d2317421041b6a9fb9bcab706b0ba25
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
3 // found in the LICENSE file.
5 #include "base/strings/stringprintf.h"
6 #include "base/strings/utf_string_conversions.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"
10 #include "chrome/browser/sync/test/integration/sync_test.h"
11 #include "components/password_manager/core/browser/password_manager_test_utils.h"
13 using passwords_helper::AddLogin;
14 using passwords_helper::AllProfilesContainSamePasswordFormsAsVerifier;
15 using passwords_helper::AwaitAllProfilesContainSamePasswordForms;
16 using passwords_helper::AwaitProfileContainsSamePasswordFormsAsVerifier;
17 using passwords_helper::CreateTestPasswordForm;
18 using passwords_helper::GetPasswordCount;
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;
28 using autofill::PasswordForm;
30 static const char* kValidPassphrase = "passphrase!";
31 static const char* kAnotherValidPassphrase = "Mot de passe!";
33 class MultipleClientPasswordsSyncTest : public SyncTest {
34 public:
35 MultipleClientPasswordsSyncTest() : SyncTest(MULTIPLE_CLIENT) {}
36 ~MultipleClientPasswordsSyncTest() override {}
38 bool TestUsesSelfNotifications() override { return false; }
40 private:
41 DISALLOW_COPY_AND_ASSIGN(MultipleClientPasswordsSyncTest);
44 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, Sanity) {
45 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
47 for (int i = 0; i < num_clients(); ++i) {
48 PasswordForm form = CreateTestPasswordForm(i);
49 AddLogin(GetPasswordStore(i), form);
52 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
53 ASSERT_EQ(num_clients(), GetPasswordCount(0));
56 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest,
57 SetPassphraseAndThenSetupSync) {
58 ASSERT_TRUE(SetupClients());
60 ASSERT_TRUE(GetClient(0)->SetupSync());
61 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
62 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(0)));
64 // When client 1 hits a passphrase required state, we can infer that
65 // client 0's passphrase has been committed. to the server.
66 GetClient(1)->SetupSync();
67 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1)));
69 // Setup client 2 *after* the passphrase has been committed.
70 ASSERT_FALSE(GetClient(2)->SetupSync());
71 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2)));
73 // Get clients 1 and 2 out of the passphrase required state.
74 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase));
75 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(1)));
76 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase));
77 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2)));
79 // For some reason, the tests won't pass unless these flags are set.
80 GetSyncService(1)->SetSyncSetupCompleted();
81 GetSyncService(1)->SetSetupInProgress(false);
82 GetSyncService(2)->SetSyncSetupCompleted();
83 GetSyncService(2)->SetSetupInProgress(false);
85 // Move around some passwords to make sure it's all working.
86 PasswordForm form0 = CreateTestPasswordForm(0);
87 AddLogin(GetPasswordStore(0), form0);
89 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms());
92 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest,
93 SetDifferentPassphraseAndThenSetupSync) {
94 ASSERT_TRUE(SetupClients()) << "SetupClients() failed.";
96 ASSERT_TRUE(GetClient(0)->SetupSync());
97 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT);
98 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0))));
100 // When client 1 hits a passphrase required state, we can infer that
101 // client 0's passphrase has been committed. to the server.
102 GetClient(1)->SetupSync();
103 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1)));
105 // Give client 1 the correct passphrase.
106 SetDecryptionPassphrase(1, kValidPassphrase);
107 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1))));
109 // For some reason, the tests won't pass unless these flags are set.
110 GetSyncService(1)->SetSetupInProgress(false);
111 GetSyncService(1)->SetSyncSetupCompleted();
113 // Give client 2 a different passphrase so it fails to sync.
114 ASSERT_FALSE(GetClient(2)->SetupSync());
115 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2))));
116 SetDecryptionPassphrase(2, kAnotherValidPassphrase);
117 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2))));
119 // Add a password on 0 while client 2 has different passphrases.
120 PasswordForm form0 = CreateTestPasswordForm(0);
121 AddLogin(GetVerifierPasswordStore(), form0);
122 AddLogin(GetPasswordStore(0), form0);
124 // It should sync to client 1.
125 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1));
127 // But it won't get synced to 2.
128 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2));
130 // Update 2 with the correct passphrase, the password should now sync over.
131 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2)));
132 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase));
133 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2)));
135 // For some reason, the tests won't pass unless these flags are set.
136 GetSyncService(2)->SetSetupInProgress(false);
137 GetSyncService(2)->SetSyncSetupCompleted();
139 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2));
140 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier());