| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/sync/test/integration/passwords_helper.h" | 5 #include "chrome/browser/sync/test/integration/passwords_helper.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 // Quit the message loop to wake up passwords_helper::GetLogins. | 57 // Quit the message loop to wake up passwords_helper::GetLogins. |
| 58 base::MessageLoopForUI::current()->Quit(); | 58 base::MessageLoopForUI::current()->Quit(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 std::vector<PasswordForm>* result_; | 62 std::vector<PasswordForm>* result_; |
| 63 | 63 |
| 64 DISALLOW_COPY_AND_ASSIGN(PasswordStoreConsumerHelper); | 64 DISALLOW_COPY_AND_ASSIGN(PasswordStoreConsumerHelper); |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 // PasswordForm::date_synced is a local field. Therefore it may be different |
| 68 // across clients. |
| 69 void ClearSyncDateField(std::vector<PasswordForm>* forms) { |
| 70 for (std::vector<PasswordForm>::iterator it = forms->begin(); |
| 71 it != forms->end(); ++it) { |
| 72 it->date_synced = base::Time(); |
| 73 } |
| 74 } |
| 75 |
| 67 } // namespace | 76 } // namespace |
| 68 | 77 |
| 69 namespace passwords_helper { | 78 namespace passwords_helper { |
| 70 | 79 |
| 71 void AddLogin(PasswordStore* store, const PasswordForm& form) { | 80 void AddLogin(PasswordStore* store, const PasswordForm& form) { |
| 72 ASSERT_TRUE(store); | 81 ASSERT_TRUE(store); |
| 73 base::WaitableEvent wait_event(true, false); | 82 base::WaitableEvent wait_event(true, false); |
| 74 store->AddLogin(form); | 83 store->AddLogin(form); |
| 75 store->ScheduleTask(base::Bind(&PasswordStoreCallback, &wait_event)); | 84 store->ScheduleTask(base::Bind(&PasswordStoreCallback, &wait_event)); |
| 76 wait_event.Wait(); | 85 wait_event.Wait(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 PasswordStore* GetVerifierPasswordStore() { | 139 PasswordStore* GetVerifierPasswordStore() { |
| 131 return PasswordStoreFactory::GetForProfile(test()->verifier(), | 140 return PasswordStoreFactory::GetForProfile(test()->verifier(), |
| 132 Profile::IMPLICIT_ACCESS).get(); | 141 Profile::IMPLICIT_ACCESS).get(); |
| 133 } | 142 } |
| 134 | 143 |
| 135 bool ProfileContainsSamePasswordFormsAsVerifier(int index) { | 144 bool ProfileContainsSamePasswordFormsAsVerifier(int index) { |
| 136 std::vector<PasswordForm> verifier_forms; | 145 std::vector<PasswordForm> verifier_forms; |
| 137 std::vector<PasswordForm> forms; | 146 std::vector<PasswordForm> forms; |
| 138 GetLogins(GetVerifierPasswordStore(), verifier_forms); | 147 GetLogins(GetVerifierPasswordStore(), verifier_forms); |
| 139 GetLogins(GetPasswordStore(index), forms); | 148 GetLogins(GetPasswordStore(index), forms); |
| 149 ClearSyncDateField(&forms); |
| 140 bool result = | 150 bool result = |
| 141 password_manager::ContainsSamePasswordForms(verifier_forms, forms); | 151 password_manager::ContainsSamePasswordForms(verifier_forms, forms); |
| 142 if (!result) { | 152 if (!result) { |
| 143 LOG(ERROR) << "Password forms in Verifier Profile:"; | 153 LOG(ERROR) << "Password forms in Verifier Profile:"; |
| 144 for (std::vector<PasswordForm>::iterator it = verifier_forms.begin(); | 154 for (std::vector<PasswordForm>::iterator it = verifier_forms.begin(); |
| 145 it != verifier_forms.end(); ++it) { | 155 it != verifier_forms.end(); ++it) { |
| 146 LOG(ERROR) << *it << std::endl; | 156 LOG(ERROR) << *it << std::endl; |
| 147 } | 157 } |
| 148 LOG(ERROR) << "Password forms in Profile" << index << ":"; | 158 LOG(ERROR) << "Password forms in Profile" << index << ":"; |
| 149 for (std::vector<PasswordForm>::iterator it = forms.begin(); | 159 for (std::vector<PasswordForm>::iterator it = forms.begin(); |
| 150 it != forms.end(); ++it) { | 160 it != forms.end(); ++it) { |
| 151 LOG(ERROR) << *it << std::endl; | 161 LOG(ERROR) << *it << std::endl; |
| 152 } | 162 } |
| 153 } | 163 } |
| 154 return result; | 164 return result; |
| 155 } | 165 } |
| 156 | 166 |
| 157 bool ProfilesContainSamePasswordForms(int index_a, int index_b) { | 167 bool ProfilesContainSamePasswordForms(int index_a, int index_b) { |
| 158 std::vector<PasswordForm> forms_a; | 168 std::vector<PasswordForm> forms_a; |
| 159 std::vector<PasswordForm> forms_b; | 169 std::vector<PasswordForm> forms_b; |
| 160 GetLogins(GetPasswordStore(index_a), forms_a); | 170 GetLogins(GetPasswordStore(index_a), forms_a); |
| 161 GetLogins(GetPasswordStore(index_b), forms_b); | 171 GetLogins(GetPasswordStore(index_b), forms_b); |
| 172 ClearSyncDateField(&forms_a); |
| 173 ClearSyncDateField(&forms_b); |
| 162 bool result = password_manager::ContainsSamePasswordForms(forms_a, forms_b); | 174 bool result = password_manager::ContainsSamePasswordForms(forms_a, forms_b); |
| 163 if (!result) { | 175 if (!result) { |
| 164 LOG(ERROR) << "Password forms in Profile" << index_a << ":"; | 176 LOG(ERROR) << "Password forms in Profile" << index_a << ":"; |
| 165 for (std::vector<PasswordForm>::iterator it = forms_a.begin(); | 177 for (std::vector<PasswordForm>::iterator it = forms_a.begin(); |
| 166 it != forms_a.end(); ++it) { | 178 it != forms_a.end(); ++it) { |
| 167 LOG(ERROR) << *it << std::endl; | 179 LOG(ERROR) << *it << std::endl; |
| 168 } | 180 } |
| 169 LOG(ERROR) << "Password forms in Profile" << index_b << ":"; | 181 LOG(ERROR) << "Password forms in Profile" << index_b << ":"; |
| 170 for (std::vector<PasswordForm>::iterator it = forms_b.begin(); | 182 for (std::vector<PasswordForm>::iterator it = forms_b.begin(); |
| 171 it != forms_b.end(); ++it) { | 183 it != forms_b.end(); ++it) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 form.origin = GURL(base::StringPrintf(kIndexedFakeOrigin, index)); | 359 form.origin = GURL(base::StringPrintf(kIndexedFakeOrigin, index)); |
| 348 form.username_value = | 360 form.username_value = |
| 349 base::ASCIIToUTF16(base::StringPrintf("username%d", index)); | 361 base::ASCIIToUTF16(base::StringPrintf("username%d", index)); |
| 350 form.password_value = | 362 form.password_value = |
| 351 base::ASCIIToUTF16(base::StringPrintf("password%d", index)); | 363 base::ASCIIToUTF16(base::StringPrintf("password%d", index)); |
| 352 form.date_created = base::Time::Now(); | 364 form.date_created = base::Time::Now(); |
| 353 return form; | 365 return form; |
| 354 } | 366 } |
| 355 | 367 |
| 356 } // namespace passwords_helper | 368 } // namespace passwords_helper |
| OLD | NEW |