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 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, |
| 59 SetPassphraseAndThenSetupSync) { |
| 60 ASSERT_TRUE(SetupClients()); |
| 61 |
| 62 ASSERT_TRUE(GetClient(0)->SetupSync()); |
| 63 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); |
| 64 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(0))); |
| 65 |
| 66 // When client 1 hits a passphrase required state, we can infer that |
| 67 // client 0's passphrase has been committed. to the server. |
| 68 GetClient(1)->SetupSync(); |
| 69 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); |
| 70 |
| 71 // Setup client 2 *after* the passphrase has been committed. |
| 72 ASSERT_FALSE(GetClient(2)->SetupSync()); |
| 73 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); |
| 74 |
| 75 // Get clients 1 and 2 out of the passphrase required state. |
| 76 ASSERT_TRUE(SetDecryptionPassphrase(1, kValidPassphrase)); |
| 77 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(1))); |
| 78 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); |
| 79 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); |
| 80 |
| 81 // For some reason, the tests won't pass unless these flags are set. |
| 82 GetSyncService(1)->SetSyncSetupCompleted(); |
| 83 GetSyncService(1)->SetSetupInProgress(false); |
| 84 GetSyncService(2)->SetSyncSetupCompleted(); |
| 85 GetSyncService(2)->SetSetupInProgress(false); |
| 86 |
| 87 // Move around some passwords to make sure it's all working. |
| 88 PasswordForm form0 = CreateTestPasswordForm(0); |
| 89 AddLogin(GetPasswordStore(0), form0); |
| 90 |
| 91 ASSERT_TRUE(AwaitAllProfilesContainSamePasswordForms()); |
| 92 } |
| 93 |
| 94 IN_PROC_BROWSER_TEST_F(MultipleClientPasswordsSyncTest, |
| 95 SetDifferentPassphraseAndThenSetupSync) { |
| 96 ASSERT_TRUE(SetupClients()) << "SetupClients() failed."; |
| 97 |
| 98 ASSERT_TRUE(GetClient(0)->SetupSync()); |
| 99 SetEncryptionPassphrase(0, kValidPassphrase, ProfileSyncService::EXPLICIT); |
| 100 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((0)))); |
| 101 |
| 102 // When client 1 hits a passphrase required state, we can infer that |
| 103 // client 0's passphrase has been committed. to the server. |
| 104 GetClient(1)->SetupSync(); |
| 105 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(1))); |
| 106 |
| 107 // Give client 1 the correct passphrase. |
| 108 SetDecryptionPassphrase(1, kValidPassphrase); |
| 109 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService((1)))); |
| 110 |
| 111 // For some reason, the tests won't pass unless these flags are set. |
| 112 GetSyncService(1)->SetSetupInProgress(false); |
| 113 GetSyncService(1)->SetSyncSetupCompleted(); |
| 114 |
| 115 // Give client 2 a different passphrase so it fails to sync. |
| 116 ASSERT_FALSE(GetClient(2)->SetupSync()); |
| 117 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); |
| 118 SetDecryptionPassphrase(2, kAnotherValidPassphrase); |
| 119 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService((2)))); |
| 120 |
| 121 // Add a password on 0 while client 2 has different passphrases. |
| 122 PasswordForm form0 = CreateTestPasswordForm(0); |
| 123 AddLogin(GetVerifierPasswordStore(), form0); |
| 124 AddLogin(GetPasswordStore(0), form0); |
| 125 |
| 126 // It should sync to client 1. |
| 127 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(1)); |
| 128 |
| 129 // But it won't get synced to 2. |
| 130 ASSERT_FALSE(ProfileContainsSamePasswordFormsAsVerifier(2)); |
| 131 |
| 132 // Update 2 with the correct passphrase, the password should now sync over. |
| 133 ASSERT_TRUE(AwaitPassphraseRequired(GetSyncService(2))); |
| 134 ASSERT_TRUE(SetDecryptionPassphrase(2, kValidPassphrase)); |
| 135 ASSERT_TRUE(AwaitPassphraseAccepted(GetSyncService(2))); |
| 136 |
| 137 // For some reason, the tests won't pass unless these flags are set. |
| 138 GetSyncService(2)->SetSetupInProgress(false); |
| 139 GetSyncService(2)->SetSyncSetupCompleted(); |
| 140 |
| 141 ASSERT_TRUE(AwaitProfileContainsSamePasswordFormsAsVerifier(2)); |
| 142 ASSERT_TRUE(AllProfilesContainSamePasswordFormsAsVerifier()); |
| 143 } |
OLD | NEW |