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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
groby-ooo-7-16
2013/04/16 00:00:29
Sorry, missed that the first time round - needs ba
Ilya Sherman
2013/04/16 00:57:53
Done.
| |
10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/time.h" | 15 #include "base/time.h" |
16 #include "base/tuple.h" | 16 #include "base/tuple.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
19 #include "chrome/browser/password_manager/password_manager.h" | 19 #include "chrome/browser/password_manager/password_manager.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
34 #include "components/autofill/browser/credit_card.h" | 34 #include "components/autofill/browser/credit_card.h" |
35 #include "components/autofill/browser/personal_data_manager.h" | 35 #include "components/autofill/browser/personal_data_manager.h" |
36 #include "components/autofill/browser/test_autofill_external_delegate.h" | 36 #include "components/autofill/browser/test_autofill_external_delegate.h" |
37 #include "components/autofill/common/autofill_messages.h" | 37 #include "components/autofill/common/autofill_messages.h" |
38 #include "components/autofill/common/form_data.h" | 38 #include "components/autofill/common/form_data.h" |
39 #include "components/autofill/common/form_field_data.h" | 39 #include "components/autofill/common/form_field_data.h" |
40 #include "components/user_prefs/user_prefs.h" | 40 #include "components/user_prefs/user_prefs.h" |
41 #include "content/public/browser/web_contents.h" | 41 #include "content/public/browser/web_contents.h" |
42 #include "content/public/test/mock_render_process_host.h" | 42 #include "content/public/test/mock_render_process_host.h" |
43 #include "content/public/test/test_browser_thread.h" | 43 #include "content/public/test/test_browser_thread.h" |
44 #include "content/public/test/test_utils.h" | |
44 #include "googleurl/src/gurl.h" | 45 #include "googleurl/src/gurl.h" |
45 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
46 #include "ipc/ipc_test_sink.h" | 47 #include "ipc/ipc_test_sink.h" |
47 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
48 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
51 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
52 #include "ui/gfx/rect.h" | 53 #include "ui/gfx/rect.h" |
53 | 54 |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
477 has_address_fields, true, true); | 478 has_address_fields, true, true); |
478 } | 479 } |
479 | 480 |
480 class TestAutofillManager : public AutofillManager { | 481 class TestAutofillManager : public AutofillManager { |
481 public: | 482 public: |
482 TestAutofillManager(content::WebContents* web_contents, | 483 TestAutofillManager(content::WebContents* web_contents, |
483 autofill::AutofillManagerDelegate* delegate, | 484 autofill::AutofillManagerDelegate* delegate, |
484 TestPersonalDataManager* personal_data) | 485 TestPersonalDataManager* personal_data) |
485 : AutofillManager(web_contents, delegate, personal_data), | 486 : AutofillManager(web_contents, delegate, personal_data), |
486 personal_data_(personal_data), | 487 personal_data_(personal_data), |
487 autofill_enabled_(true), | 488 autofill_enabled_(true) {} |
488 did_finish_async_form_submit_(false), | |
489 message_loop_is_running_(false) { | |
490 } | |
491 virtual ~TestAutofillManager() {} | 489 virtual ~TestAutofillManager() {} |
492 | 490 |
493 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 491 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
494 | 492 |
495 void set_autofill_enabled(bool autofill_enabled) { | 493 void set_autofill_enabled(bool autofill_enabled) { |
496 autofill_enabled_ = autofill_enabled; | 494 autofill_enabled_ = autofill_enabled; |
497 } | 495 } |
498 | 496 |
499 void set_autocheckout_url_prefix(const std::string& autocheckout_url_prefix) { | 497 void set_autocheckout_url_prefix(const std::string& autocheckout_url_prefix) { |
500 autocheckout_url_prefix_ = autocheckout_url_prefix; | 498 autocheckout_url_prefix_ = autocheckout_url_prefix; |
(...skipping 12 matching lines...) Expand all Loading... | |
513 void set_expected_submitted_field_types( | 511 void set_expected_submitted_field_types( |
514 const std::vector<FieldTypeSet>& expected_types) { | 512 const std::vector<FieldTypeSet>& expected_types) { |
515 expected_submitted_field_types_ = expected_types; | 513 expected_submitted_field_types_ = expected_types; |
516 } | 514 } |
517 | 515 |
518 virtual void UploadFormDataAsyncCallback( | 516 virtual void UploadFormDataAsyncCallback( |
519 const FormStructure* submitted_form, | 517 const FormStructure* submitted_form, |
520 const base::TimeTicks& load_time, | 518 const base::TimeTicks& load_time, |
521 const base::TimeTicks& interaction_time, | 519 const base::TimeTicks& interaction_time, |
522 const base::TimeTicks& submission_time) OVERRIDE { | 520 const base::TimeTicks& submission_time) OVERRIDE { |
523 if (message_loop_is_running_) { | 521 message_loop_runner_->Quit(); |
524 MessageLoop::current()->Quit(); | |
525 message_loop_is_running_ = false; | |
526 } else { | |
527 did_finish_async_form_submit_ = true; | |
528 } | |
529 | 522 |
530 // If we have expected field types set, make sure they match. | 523 // If we have expected field types set, make sure they match. |
531 if (!expected_submitted_field_types_.empty()) { | 524 if (!expected_submitted_field_types_.empty()) { |
532 ASSERT_EQ(expected_submitted_field_types_.size(), | 525 ASSERT_EQ(expected_submitted_field_types_.size(), |
533 submitted_form->field_count()); | 526 submitted_form->field_count()); |
534 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) { | 527 for (size_t i = 0; i < expected_submitted_field_types_.size(); ++i) { |
535 SCOPED_TRACE( | 528 SCOPED_TRACE( |
536 base::StringPrintf( | 529 base::StringPrintf( |
537 "Field %d with value %s", static_cast<int>(i), | 530 "Field %d with value %s", static_cast<int>(i), |
538 UTF16ToUTF8(submitted_form->field(i)->value).c_str())); | 531 UTF16ToUTF8(submitted_form->field(i)->value).c_str())); |
539 const FieldTypeSet& possible_types = | 532 const FieldTypeSet& possible_types = |
540 submitted_form->field(i)->possible_types(); | 533 submitted_form->field(i)->possible_types(); |
541 EXPECT_EQ(expected_submitted_field_types_[i].size(), | 534 EXPECT_EQ(expected_submitted_field_types_[i].size(), |
542 possible_types.size()); | 535 possible_types.size()); |
543 for (FieldTypeSet::const_iterator it = | 536 for (FieldTypeSet::const_iterator it = |
544 expected_submitted_field_types_[i].begin(); | 537 expected_submitted_field_types_[i].begin(); |
545 it != expected_submitted_field_types_[i].end(); ++it) { | 538 it != expected_submitted_field_types_[i].end(); ++it) { |
546 EXPECT_TRUE(possible_types.count(*it)) | 539 EXPECT_TRUE(possible_types.count(*it)) |
547 << "Expected type: " << AutofillType::FieldTypeToString(*it); | 540 << "Expected type: " << AutofillType::FieldTypeToString(*it); |
548 } | 541 } |
549 } | 542 } |
550 } | 543 } |
551 | 544 |
552 AutofillManager::UploadFormDataAsyncCallback(submitted_form, | 545 AutofillManager::UploadFormDataAsyncCallback(submitted_form, |
553 load_time, | 546 load_time, |
554 interaction_time, | 547 interaction_time, |
555 submission_time); | 548 submission_time); |
556 } | 549 } |
557 | 550 |
551 // Resets the MessageLoopRunner so that it can way for an asynchronous form | |
groby-ooo-7-16
2013/04/15 22:19:20
nit: "wait for"
Ilya Sherman
2013/04/16 00:57:53
Done.
| |
552 // submission to complete. | |
553 void ResetMessageLoopRunner() { | |
554 message_loop_runner_ = new content::MessageLoopRunner(); | |
555 } | |
556 | |
558 // Wait for the asynchronous OnFormSubmitted() call to complete. | 557 // Wait for the asynchronous OnFormSubmitted() call to complete. |
559 void WaitForAsyncFormSubmit() { | 558 void WaitForAsyncFormSubmit() { |
560 if (!did_finish_async_form_submit_) { | 559 message_loop_runner_->Run(); |
561 // TODO(isherman): It seems silly to need this variable. Is there some | |
562 // way I can just query the message loop's state? | |
563 message_loop_is_running_ = true; | |
564 MessageLoop::current()->Run(); | |
565 } else { | |
566 did_finish_async_form_submit_ = false; | |
567 } | |
568 } | 560 } |
569 | 561 |
570 virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { | 562 virtual void UploadFormData(const FormStructure& submitted_form) OVERRIDE { |
571 submitted_form_signature_ = submitted_form.FormSignature(); | 563 submitted_form_signature_ = submitted_form.FormSignature(); |
572 } | 564 } |
573 | 565 |
574 virtual void SendPasswordGenerationStateToRenderer( | 566 virtual void SendPasswordGenerationStateToRenderer( |
575 content::RenderViewHost* host, bool enabled) OVERRIDE { | 567 content::RenderViewHost* host, bool enabled) OVERRIDE { |
576 sent_states_.push_back(enabled); | 568 sent_states_.push_back(enabled); |
577 } | 569 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
626 } | 618 } |
627 | 619 |
628 private: | 620 private: |
629 // Weak reference. | 621 // Weak reference. |
630 TestPersonalDataManager* personal_data_; | 622 TestPersonalDataManager* personal_data_; |
631 | 623 |
632 bool autofill_enabled_; | 624 bool autofill_enabled_; |
633 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > | 625 std::vector<std::pair<WebFormElement::AutocompleteResult, FormData> > |
634 request_autocomplete_results_; | 626 request_autocomplete_results_; |
635 | 627 |
636 bool did_finish_async_form_submit_; | 628 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
637 bool message_loop_is_running_; | |
638 | 629 |
639 std::string autocheckout_url_prefix_; | 630 std::string autocheckout_url_prefix_; |
640 std::string submitted_form_signature_; | 631 std::string submitted_form_signature_; |
641 std::vector<FieldTypeSet> expected_submitted_field_types_; | 632 std::vector<FieldTypeSet> expected_submitted_field_types_; |
642 std::vector<bool> sent_states_; | 633 std::vector<bool> sent_states_; |
643 | 634 |
644 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); | 635 DISALLOW_COPY_AND_ASSIGN(TestAutofillManager); |
645 }; | 636 }; |
646 | 637 |
647 } // namespace | 638 } // namespace |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 | 715 |
725 void FormsSeen(const std::vector<FormData>& forms) { | 716 void FormsSeen(const std::vector<FormData>& forms) { |
726 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); | 717 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), false); |
727 } | 718 } |
728 | 719 |
729 void PartialFormsSeen(const std::vector<FormData>& forms) { | 720 void PartialFormsSeen(const std::vector<FormData>& forms) { |
730 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); | 721 autofill_manager_->OnFormsSeen(forms, base::TimeTicks(), true); |
731 } | 722 } |
732 | 723 |
733 void FormSubmitted(const FormData& form) { | 724 void FormSubmitted(const FormData& form) { |
725 autofill_manager_->ResetMessageLoopRunner(); | |
734 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) | 726 if (autofill_manager_->OnFormSubmitted(form, base::TimeTicks::Now())) |
735 autofill_manager_->WaitForAsyncFormSubmit(); | 727 autofill_manager_->WaitForAsyncFormSubmit(); |
736 } | 728 } |
737 | 729 |
738 void FillAutofillFormData(int query_id, | 730 void FillAutofillFormData(int query_id, |
739 const FormData& form, | 731 const FormData& form, |
740 const FormFieldData& field, | 732 const FormFieldData& field, |
741 int unique_id) { | 733 int unique_id) { |
742 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); | 734 autofill_manager_->OnFillAutofillFormData(query_id, form, field, unique_id); |
743 } | 735 } |
(...skipping 2589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3333 CreateTestAddressFormData(&form); | 3325 CreateTestAddressFormData(&form); |
3334 std::vector<FormData> forms(1, form); | 3326 std::vector<FormData> forms(1, form); |
3335 FormsSeen(forms); | 3327 FormsSeen(forms); |
3336 const FormFieldData& field = form.fields[0]; | 3328 const FormFieldData& field = form.fields[0]; |
3337 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3329 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3338 | 3330 |
3339 autofill_manager_->SetExternalDelegate(NULL); | 3331 autofill_manager_->SetExternalDelegate(NULL); |
3340 } | 3332 } |
3341 | 3333 |
3342 } // namespace autofill | 3334 } // namespace autofill |
OLD | NEW |