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