Chromium Code Reviews| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "chrome/browser/password_manager/password_store_factory.h" | 12 #include "chrome/browser/password_manager/password_store_factory.h" |
| 13 #include "chrome/browser/sync/profile_sync_service.h" | 13 #include "chrome/browser/sync/profile_sync_service.h" |
| 14 #include "chrome/browser/sync/profile_sync_service_factory.h" | 14 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 15 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h" | 15 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke r.h" |
| 16 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 16 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 17 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h" | |
| 17 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 18 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "components/password_manager/core/browser/password_form_data.h" | 20 #include "components/password_manager/core/browser/password_form_data.h" |
| 20 #include "components/password_manager/core/browser/password_store.h" | 21 #include "components/password_manager/core/browser/password_store.h" |
| 21 #include "components/password_manager/core/browser/password_store_consumer.h" | 22 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 22 | 23 |
| 23 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
| 24 using password_manager::PasswordStore; | 25 using password_manager::PasswordStore; |
| 25 using sync_datatype_helper::test; | 26 using sync_datatype_helper::test; |
| 26 | 27 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 it != forms_b.end(); ++it) { | 171 it != forms_b.end(); ++it) { |
| 171 LOG(ERROR) << *it << std::endl; | 172 LOG(ERROR) << *it << std::endl; |
| 172 } | 173 } |
| 173 } | 174 } |
| 174 return result; | 175 return result; |
| 175 } | 176 } |
| 176 | 177 |
| 177 bool AllProfilesContainSamePasswordFormsAsVerifier() { | 178 bool AllProfilesContainSamePasswordFormsAsVerifier() { |
| 178 for (int i = 0; i < test()->num_clients(); ++i) { | 179 for (int i = 0; i < test()->num_clients(); ++i) { |
| 179 if (!ProfileContainsSamePasswordFormsAsVerifier(i)) { | 180 if (!ProfileContainsSamePasswordFormsAsVerifier(i)) { |
| 180 LOG(ERROR) << "Profile " << i << " does not contain the same password" | 181 LOG(INFO) << "Profile " << i << " does not contain the same password" |
|
Nicolas Zea
2014/05/06 00:16:37
any reason this was changed?
rlarocque
2014/05/06 00:33:36
ERROR isn't quite right anymore. In some ways it
Nicolas Zea
2014/05/06 18:42:15
If it's expected for this to be called, I think it
rlarocque
2014/05/06 23:40:47
Done.
| |
| 181 " forms as the verifier."; | 182 " forms as the verifier."; |
| 182 return false; | 183 return false; |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 return true; | 186 return true; |
| 186 } | 187 } |
| 187 | 188 |
| 188 bool AllProfilesContainSamePasswordForms() { | 189 bool AllProfilesContainSamePasswordForms() { |
| 189 for (int i = 1; i < test()->num_clients(); ++i) { | 190 for (int i = 1; i < test()->num_clients(); ++i) { |
| 190 if (!ProfilesContainSamePasswordForms(0, i)) { | 191 if (!ProfilesContainSamePasswordForms(0, i)) { |
| 191 LOG(ERROR) << "Profile " << i << " does not contain the same password" | 192 LOG(INFO) << "Profile " << i << " does not contain the same password" |
| 192 " forms as Profile 0."; | 193 " forms as Profile 0."; |
| 193 return false; | 194 return false; |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 return true; | 197 return true; |
| 197 } | 198 } |
| 198 | 199 |
| 199 namespace { | 200 namespace { |
| 200 | 201 |
| 201 // Helper class used in the implementation of | 202 // Helper class used in the implementation of |
| 202 // AwaitAllProfilesContainSamePasswordForms. | 203 // AwaitAllProfilesContainSamePasswordForms. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace | 261 } // namespace |
| 261 | 262 |
| 262 bool AwaitAllProfilesContainSamePasswordForms() { | 263 bool AwaitAllProfilesContainSamePasswordForms() { |
| 263 SamePasswordFormsChecker checker; | 264 SamePasswordFormsChecker checker; |
| 264 checker.Wait(); | 265 checker.Wait(); |
| 265 return !checker.TimedOut(); | 266 return !checker.TimedOut(); |
| 266 } | 267 } |
| 267 | 268 |
| 269 namespace { | |
| 270 | |
| 271 // Helper class used in the implementation of | |
| 272 // AwaitProfileContainSamePasswordFormsAsVerifier. | |
| 273 class SamePasswordFormsAsVerifierChecker | |
| 274 : public SingleClientStatusChangeChecker { | |
| 275 public: | |
| 276 explicit SamePasswordFormsAsVerifierChecker(int index); | |
| 277 virtual ~SamePasswordFormsAsVerifierChecker(); | |
| 278 | |
| 279 virtual bool IsExitConditionSatisfied() OVERRIDE; | |
| 280 virtual std::string GetDebugMessage() const OVERRIDE; | |
| 281 | |
| 282 private: | |
| 283 int index_; | |
| 284 | |
| 285 bool in_progress_; | |
| 286 bool needs_recheck_; | |
| 287 }; | |
| 288 | |
| 289 SamePasswordFormsAsVerifierChecker::SamePasswordFormsAsVerifierChecker(int i) | |
| 290 : SingleClientStatusChangeChecker( | |
| 291 sync_datatype_helper::test()->GetSyncService(i)), | |
| 292 index_(i), | |
| 293 in_progress_(false), | |
| 294 needs_recheck_(false) { | |
| 295 } | |
| 296 | |
| 297 SamePasswordFormsAsVerifierChecker::~SamePasswordFormsAsVerifierChecker() { | |
| 298 } | |
| 299 | |
| 300 // This method uses the same re-entrancy prevention trick as | |
| 301 // the SamePasswordFormsChecker. | |
| 302 bool SamePasswordFormsAsVerifierChecker::IsExitConditionSatisfied() { | |
| 303 if (in_progress_) { | |
| 304 LOG(WARNING) << "Setting flag and returning early to prevent nesting."; | |
| 305 needs_recheck_ = true; | |
| 306 return false; | |
| 307 } | |
| 308 | |
| 309 // Keep retrying until we get a good reading. | |
| 310 bool result = false; | |
| 311 in_progress_ = true; | |
| 312 do { | |
| 313 needs_recheck_ = false; | |
| 314 result = ProfileContainsSamePasswordFormsAsVerifier(index_); | |
| 315 } while (needs_recheck_); | |
| 316 in_progress_ = false; | |
| 317 return result; | |
| 318 } | |
| 319 | |
| 320 std::string SamePasswordFormsAsVerifierChecker::GetDebugMessage() const { | |
| 321 return "Waiting for passwords to match verifier"; | |
| 322 } | |
| 323 | |
| 324 } // namespace | |
| 325 | |
| 326 bool AwaitProfileContainsSamePasswordFormsAsVerifier(int index) { | |
| 327 SamePasswordFormsAsVerifierChecker checker(index); | |
| 328 checker.Wait(); | |
| 329 return !checker.TimedOut(); | |
| 330 } | |
| 331 | |
| 268 int GetPasswordCount(int index) { | 332 int GetPasswordCount(int index) { |
| 269 std::vector<PasswordForm> forms; | 333 std::vector<PasswordForm> forms; |
| 270 GetLogins(GetPasswordStore(index), forms); | 334 GetLogins(GetPasswordStore(index), forms); |
| 271 return forms.size(); | 335 return forms.size(); |
| 272 } | 336 } |
| 273 | 337 |
| 274 int GetVerifierPasswordCount() { | 338 int GetVerifierPasswordCount() { |
| 275 std::vector<PasswordForm> verifier_forms; | 339 std::vector<PasswordForm> verifier_forms; |
| 276 GetLogins(GetVerifierPasswordStore(), verifier_forms); | 340 GetLogins(GetVerifierPasswordStore(), verifier_forms); |
| 277 return verifier_forms.size(); | 341 return verifier_forms.size(); |
| 278 } | 342 } |
| 279 | 343 |
| 280 PasswordForm CreateTestPasswordForm(int index) { | 344 PasswordForm CreateTestPasswordForm(int index) { |
| 281 PasswordForm form; | 345 PasswordForm form; |
| 282 form.signon_realm = kFakeSignonRealm; | 346 form.signon_realm = kFakeSignonRealm; |
| 283 form.origin = GURL(base::StringPrintf(kIndexedFakeOrigin, index)); | 347 form.origin = GURL(base::StringPrintf(kIndexedFakeOrigin, index)); |
| 284 form.username_value = | 348 form.username_value = |
| 285 base::ASCIIToUTF16(base::StringPrintf("username%d", index)); | 349 base::ASCIIToUTF16(base::StringPrintf("username%d", index)); |
| 286 form.password_value = | 350 form.password_value = |
| 287 base::ASCIIToUTF16(base::StringPrintf("password%d", index)); | 351 base::ASCIIToUTF16(base::StringPrintf("password%d", index)); |
| 288 form.date_created = base::Time::Now(); | 352 form.date_created = base::Time::Now(); |
| 289 return form; | 353 return form; |
| 290 } | 354 } |
| 291 | 355 |
| 292 } // namespace passwords_helper | 356 } // namespace passwords_helper |
| OLD | NEW |