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/autofill_helper.h" | 5 #include "chrome/browser/sync/test/integration/autofill_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <map> |
| 10 |
9 #include "base/guid.h" | 11 #include "base/guid.h" |
10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
11 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_test_util.h" | 16 #include "chrome/browser/sync/profile_sync_test_util.h" |
15 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" | 17 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
16 #include "chrome/browser/sync/test/integration/sync_test.h" | 18 #include "chrome/browser/sync/test/integration/sync_test.h" |
17 #include "chrome/browser/web_data_service_factory.h" | 19 #include "chrome/browser/web_data_service_factory.h" |
18 #include "components/autofill/core/browser/autofill_profile.h" | 20 #include "components/autofill/core/browser/autofill_profile.h" |
19 #include "components/autofill/core/browser/autofill_test_utils.h" | 21 #include "components/autofill/core/browser/autofill_test_utils.h" |
20 #include "components/autofill/core/browser/autofill_type.h" | 22 #include "components/autofill/core/browser/autofill_type.h" |
21 #include "components/autofill/core/browser/personal_data_manager.h" | 23 #include "components/autofill/core/browser/personal_data_manager.h" |
22 #include "components/autofill/core/browser/personal_data_manager_observer.h" | |
23 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 24 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
24 #include "components/autofill/core/browser/webdata/autofill_table.h" | 25 #include "components/autofill/core/browser/webdata/autofill_table.h" |
25 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 26 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
26 #include "components/autofill/core/common/form_field_data.h" | 27 #include "components/autofill/core/common/form_field_data.h" |
27 #include "components/browser_sync/profile_sync_service.h" | 28 #include "components/browser_sync/profile_sync_service.h" |
28 #include "components/webdata/common/web_database.h" | 29 #include "components/webdata/common/web_database.h" |
29 | 30 |
30 using autofill::AutofillChangeList; | 31 using autofill::AutofillChangeList; |
31 using autofill::AutofillEntry; | 32 using autofill::AutofillEntry; |
32 using autofill::AutofillKey; | 33 using autofill::AutofillKey; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 it != all_entries.end(); ++it) { | 248 it != all_entries.end(); ++it) { |
248 all_keys.insert(*it); | 249 all_keys.insert(*it); |
249 } | 250 } |
250 return all_keys; | 251 return all_keys; |
251 } | 252 } |
252 | 253 |
253 bool KeysMatch(int profile_a, int profile_b) { | 254 bool KeysMatch(int profile_a, int profile_b) { |
254 return GetAllKeys(profile_a) == GetAllKeys(profile_b); | 255 return GetAllKeys(profile_a) == GetAllKeys(profile_b); |
255 } | 256 } |
256 | 257 |
257 namespace { | |
258 | |
259 class KeysMatchStatusChecker : public MultiClientStatusChangeChecker { | |
260 public: | |
261 KeysMatchStatusChecker(int profile_a, int profile_b); | |
262 ~KeysMatchStatusChecker() override; | |
263 | |
264 bool IsExitConditionSatisfied() override; | |
265 std::string GetDebugMessage() const override; | |
266 | |
267 private: | |
268 const int profile_a_; | |
269 const int profile_b_; | |
270 }; | |
271 | |
272 KeysMatchStatusChecker::KeysMatchStatusChecker(int profile_a, int profile_b) | |
273 : MultiClientStatusChangeChecker( | |
274 sync_datatype_helper::test()->GetSyncServices()), | |
275 profile_a_(profile_a), | |
276 profile_b_(profile_b) { | |
277 } | |
278 | |
279 KeysMatchStatusChecker::~KeysMatchStatusChecker() { | |
280 } | |
281 | |
282 bool KeysMatchStatusChecker::IsExitConditionSatisfied() { | |
283 return KeysMatch(profile_a_, profile_b_); | |
284 } | |
285 | |
286 std::string KeysMatchStatusChecker::GetDebugMessage() const { | |
287 return "Waiting for matching autofill keys"; | |
288 } | |
289 | |
290 } // namespace | |
291 | |
292 bool AwaitKeysMatch(int a, int b) { | |
293 KeysMatchStatusChecker checker(a, b); | |
294 checker.Wait(); | |
295 return !checker.TimedOut(); | |
296 } | |
297 | |
298 void SetProfiles(int profile, std::vector<AutofillProfile>* autofill_profiles) { | 258 void SetProfiles(int profile, std::vector<AutofillProfile>* autofill_profiles) { |
299 MockPersonalDataManagerObserver observer; | 259 MockPersonalDataManagerObserver observer; |
300 EXPECT_CALL(observer, OnPersonalDataChanged()). | 260 EXPECT_CALL(observer, OnPersonalDataChanged()). |
301 WillOnce(QuitUIMessageLoop()); | 261 WillOnce(QuitUIMessageLoop()); |
302 PersonalDataManager* pdm = GetPersonalDataManager(profile); | 262 PersonalDataManager* pdm = GetPersonalDataManager(profile); |
303 pdm->AddObserver(&observer); | 263 pdm->AddObserver(&observer); |
304 pdm->SetProfiles(autofill_profiles); | 264 pdm->SetProfiles(autofill_profiles); |
305 base::RunLoop().Run(); | 265 base::RunLoop().Run(); |
306 pdm->RemoveObserver(&observer); | 266 pdm->RemoveObserver(&observer); |
307 } | 267 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 for (int i = 1; i < test()->num_clients(); ++i) { | 386 for (int i = 1; i < test()->num_clients(); ++i) { |
427 if (!ProfilesMatch(0, i)) { | 387 if (!ProfilesMatch(0, i)) { |
428 DVLOG(1) << "Profile " << i << "does not contain the same autofill " | 388 DVLOG(1) << "Profile " << i << "does not contain the same autofill " |
429 "profiles as profile 0."; | 389 "profiles as profile 0."; |
430 return false; | 390 return false; |
431 } | 391 } |
432 } | 392 } |
433 return true; | 393 return true; |
434 } | 394 } |
435 | 395 |
436 namespace { | 396 } // namespace autofill_helper |
437 | 397 |
438 class ProfilesMatchStatusChecker : public StatusChangeChecker, | 398 AutofillKeysChecker::AutofillKeysChecker(int profile_a, int profile_b) |
439 public PersonalDataManagerObserver { | 399 : MultiClientStatusChangeChecker( |
440 public: | 400 sync_datatype_helper::test()->GetSyncServices()), |
441 ProfilesMatchStatusChecker(int profile_a, int profile_b); | 401 profile_a_(profile_a), |
442 ~ProfilesMatchStatusChecker() override; | 402 profile_b_(profile_b) {} |
443 | 403 |
444 // StatusChangeChecker implementation. | 404 bool AutofillKeysChecker::IsExitConditionSatisfied() { |
445 bool IsExitConditionSatisfied() override; | 405 return autofill_helper::KeysMatch(profile_a_, profile_b_); |
446 std::string GetDebugMessage() const override; | |
447 | |
448 // PersonalDataManager implementation. | |
449 void OnPersonalDataChanged() override; | |
450 | |
451 // Wait for conidtion to beome true. | |
452 void Wait(); | |
453 | |
454 private: | |
455 const int profile_a_; | |
456 const int profile_b_; | |
457 bool registered_; | |
458 }; | |
459 | |
460 ProfilesMatchStatusChecker::ProfilesMatchStatusChecker(int profile_a, | |
461 int profile_b) | |
462 : profile_a_(profile_a), profile_b_(profile_b), registered_(false) { | |
463 } | 406 } |
464 | 407 |
465 ProfilesMatchStatusChecker::~ProfilesMatchStatusChecker() { | 408 std::string AutofillKeysChecker::GetDebugMessage() const { |
466 PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); | 409 return "Waiting for matching autofill keys"; |
467 PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); | |
468 if (registered_) { | |
469 pdm_a->RemoveObserver(this); | |
470 pdm_b->RemoveObserver(this); | |
471 } | |
472 } | 410 } |
473 | 411 |
474 bool ProfilesMatchStatusChecker::IsExitConditionSatisfied() { | 412 AutofillProfileChecker::AutofillProfileChecker(int profile_a, int profile_b) |
475 PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); | 413 : profile_a_(profile_a), profile_b_(profile_b) { |
476 PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); | 414 autofill_helper::GetPersonalDataManager(profile_a_)->AddObserver(this); |
477 | 415 autofill_helper::GetPersonalDataManager(profile_b_)->AddObserver(this); |
478 const std::vector<AutofillProfile*>& autofill_profiles_a = | |
479 pdm_a->web_profiles(); | |
480 const std::vector<AutofillProfile*>& autofill_profiles_b = | |
481 pdm_b->web_profiles(); | |
482 | |
483 return ProfilesMatchImpl( | |
484 profile_a_, autofill_profiles_a, profile_b_, autofill_profiles_b); | |
485 } | 416 } |
486 | 417 |
487 void ProfilesMatchStatusChecker::Wait() { | 418 AutofillProfileChecker::~AutofillProfileChecker() { |
488 PersonalDataManager* pdm_a = GetPersonalDataManager(profile_a_); | 419 autofill_helper::GetPersonalDataManager(profile_a_)->RemoveObserver(this); |
489 PersonalDataManager* pdm_b = GetPersonalDataManager(profile_b_); | 420 autofill_helper::GetPersonalDataManager(profile_b_)->RemoveObserver(this); |
490 | |
491 pdm_a->AddObserver(this); | |
492 pdm_b->AddObserver(this); | |
493 | |
494 pdm_a->Refresh(); | |
495 pdm_b->Refresh(); | |
496 | |
497 registered_ = true; | |
498 | |
499 StartBlockingWait(); | |
500 } | 421 } |
501 | 422 |
502 std::string ProfilesMatchStatusChecker::GetDebugMessage() const { | 423 bool AutofillProfileChecker::Wait() { |
| 424 autofill_helper::GetPersonalDataManager(profile_a_)->Refresh(); |
| 425 autofill_helper::GetPersonalDataManager(profile_b_)->Refresh(); |
| 426 return StatusChangeChecker::Wait(); |
| 427 } |
| 428 |
| 429 bool AutofillProfileChecker::IsExitConditionSatisfied() { |
| 430 const std::vector<AutofillProfile*>& autofill_profiles_a = |
| 431 autofill_helper::GetPersonalDataManager(profile_a_)->web_profiles(); |
| 432 const std::vector<AutofillProfile*>& autofill_profiles_b = |
| 433 autofill_helper::GetPersonalDataManager(profile_b_)->web_profiles(); |
| 434 return autofill_helper::ProfilesMatchImpl(profile_a_, autofill_profiles_a, |
| 435 profile_b_, autofill_profiles_b); |
| 436 } |
| 437 |
| 438 std::string AutofillProfileChecker::GetDebugMessage() const { |
503 return "Waiting for matching autofill profiles"; | 439 return "Waiting for matching autofill profiles"; |
504 } | 440 } |
505 | 441 |
506 void ProfilesMatchStatusChecker::OnPersonalDataChanged() { | 442 void AutofillProfileChecker::OnPersonalDataChanged() { |
507 CheckExitCondition(); | 443 CheckExitCondition(); |
508 } | 444 } |
509 | |
510 } // namespace | |
511 | |
512 bool AwaitProfilesMatch(int a, int b) { | |
513 ProfilesMatchStatusChecker checker(a, b); | |
514 checker.Wait(); | |
515 return !checker.TimedOut(); | |
516 } | |
517 | |
518 } // namespace autofill_helper | |
OLD | NEW |