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 <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/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 30 #include "components/autofill/browser/autocomplete_history_manager.h" | 30 #include "components/autofill/browser/autocomplete_history_manager.h" |
| 31 #include "components/autofill/browser/autofill_common_test.h" | 31 #include "components/autofill/browser/autofill_common_test.h" |
| 32 #include "components/autofill/browser/autofill_manager.h" | 32 #include "components/autofill/browser/autofill_manager.h" |
| 33 #include "components/autofill/browser/autofill_metrics.h" | 33 #include "components/autofill/browser/autofill_metrics.h" |
| 34 #include "components/autofill/browser/autofill_profile.h" | 34 #include "components/autofill/browser/autofill_profile.h" |
| 35 #include "components/autofill/browser/credit_card.h" | 35 #include "components/autofill/browser/credit_card.h" |
| 36 #include "components/autofill/browser/personal_data_manager.h" | 36 #include "components/autofill/browser/personal_data_manager.h" |
| 37 #include "components/autofill/browser/test_autofill_driver.h" | |
| 37 #include "components/autofill/browser/test_autofill_external_delegate.h" | 38 #include "components/autofill/browser/test_autofill_external_delegate.h" |
| 38 #include "components/autofill/browser/test_autofill_manager_delegate.h" | 39 #include "components/autofill/browser/test_autofill_manager_delegate.h" |
| 39 #include "components/autofill/common/autofill_messages.h" | 40 #include "components/autofill/common/autofill_messages.h" |
| 40 #include "components/autofill/common/form_data.h" | 41 #include "components/autofill/common/form_data.h" |
| 41 #include "components/autofill/common/form_field_data.h" | 42 #include "components/autofill/common/form_field_data.h" |
| 42 #include "components/autofill/common/forms_seen_state.h" | 43 #include "components/autofill/common/forms_seen_state.h" |
| 43 #include "components/user_prefs/user_prefs.h" | 44 #include "components/user_prefs/user_prefs.h" |
| 44 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 45 #include "content/public/test/mock_render_process_host.h" | 46 #include "content/public/test/mock_render_process_host.h" |
| 46 #include "content/public/test/test_utils.h" | 47 #include "content/public/test/test_utils.h" |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 const char* year, | 475 const char* year, |
| 475 const char* month) { | 476 const char* month) { |
| 476 ExpectFilledForm(page_id, filled_form, expected_page_id, | 477 ExpectFilledForm(page_id, filled_form, expected_page_id, |
| 477 "", "", "", "", "", "", "", "", "", "", "", | 478 "", "", "", "", "", "", "", "", "", "", "", |
| 478 "Miku Hatsune", "4234567890654321", month, year, | 479 "Miku Hatsune", "4234567890654321", month, year, |
| 479 has_address_fields, true, true); | 480 has_address_fields, true, true); |
| 480 } | 481 } |
| 481 | 482 |
| 482 class TestAutofillManager : public AutofillManager { | 483 class TestAutofillManager : public AutofillManager { |
| 483 public: | 484 public: |
| 484 TestAutofillManager(content::WebContents* web_contents, | 485 TestAutofillManager(AutofillDriver* driver, |
| 485 autofill::AutofillManagerDelegate* delegate, | 486 autofill::AutofillManagerDelegate* delegate, |
| 486 TestPersonalDataManager* personal_data) | 487 TestPersonalDataManager* personal_data) |
| 487 : AutofillManager(web_contents, delegate, personal_data), | 488 : AutofillManager(driver, delegate, personal_data), |
| 488 personal_data_(personal_data), | 489 personal_data_(personal_data), |
| 489 autofill_enabled_(true) {} | 490 autofill_enabled_(true) {} |
| 490 virtual ~TestAutofillManager() {} | 491 virtual ~TestAutofillManager() {} |
| 491 | 492 |
| 492 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } | 493 virtual bool IsAutofillEnabled() const OVERRIDE { return autofill_enabled_; } |
| 493 | 494 |
| 494 void set_autofill_enabled(bool autofill_enabled) { | 495 void set_autofill_enabled(bool autofill_enabled) { |
| 495 autofill_enabled_ = autofill_enabled; | 496 autofill_enabled_ = autofill_enabled; |
| 496 } | 497 } |
| 497 | 498 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 profile->CreateRequestContext(); | 654 profile->CreateRequestContext(); |
| 654 browser_context_.reset(profile); | 655 browser_context_.reset(profile); |
| 655 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( | 656 autofill::PersonalDataManagerFactory::GetInstance()->SetTestingFactory( |
| 656 profile, TestPersonalDataManager::Build); | 657 profile, TestPersonalDataManager::Build); |
| 657 | 658 |
| 658 ChromeRenderViewHostTestHarness::SetUp(); | 659 ChromeRenderViewHostTestHarness::SetUp(); |
| 659 | 660 |
| 660 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); | 661 autofill::TabAutofillManagerDelegate::CreateForWebContents(web_contents()); |
| 661 | 662 |
| 662 personal_data_.SetBrowserContext(profile); | 663 personal_data_.SetBrowserContext(profile); |
| 664 autofill_driver_.reset(new TestAutofillDriver(web_contents())); | |
| 663 autofill_manager_.reset(new TestAutofillManager( | 665 autofill_manager_.reset(new TestAutofillManager( |
| 664 web_contents(), | 666 autofill_driver_.get(), |
| 665 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), | 667 autofill::TabAutofillManagerDelegate::FromWebContents(web_contents()), |
| 666 &personal_data_)); | 668 &personal_data_)); |
| 667 } | 669 } |
| 668 | 670 |
| 669 virtual void TearDown() OVERRIDE { | 671 virtual void TearDown() OVERRIDE { |
| 670 // Order of destruction is important as AutofillManager relies on | 672 // Order of destruction is important as AutofillManager relies on |
| 671 // PersonalDataManager to be around when it gets destroyed. Also, a real | 673 // PersonalDataManager to be around when it gets destroyed. Also, a real |
| 672 // AutofillManager is tied to the lifetime of the WebContents, so it must | 674 // AutofillManager is tied to the lifetime of the WebContents, so it must |
| 673 // be destroyed at the destruction of the WebContents. | 675 // be destroyed at the destruction of the WebContents. |
| 674 autofill_manager_.reset(); | 676 autofill_manager_.reset(); |
| 677 autofill_driver_.reset(); | |
| 675 ChromeRenderViewHostTestHarness::TearDown(); | 678 ChromeRenderViewHostTestHarness::TearDown(); |
| 676 | 679 |
| 677 // Remove the BrowserContext so TestPersonalDataManager does not need to | 680 // Remove the BrowserContext so TestPersonalDataManager does not need to |
| 678 // care about removing self as an observer in destruction. | 681 // care about removing self as an observer in destruction. |
| 679 personal_data_.SetBrowserContext(NULL); | 682 personal_data_.SetBrowserContext(NULL); |
| 680 } | 683 } |
| 681 | 684 |
| 682 virtual TestingProfile* CreateProfile() { | 685 virtual TestingProfile* CreateProfile() { |
| 683 return new TestingProfile(); | 686 return new TestingProfile(); |
| 684 } | 687 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 782 if (page_id) | 785 if (page_id) |
| 783 *page_id = autofill_param.a; | 786 *page_id = autofill_param.a; |
| 784 if (results) | 787 if (results) |
| 785 *results = autofill_param.b; | 788 *results = autofill_param.b; |
| 786 | 789 |
| 787 process()->sink().ClearMessages(); | 790 process()->sink().ClearMessages(); |
| 788 return true; | 791 return true; |
| 789 } | 792 } |
| 790 | 793 |
| 791 protected: | 794 protected: |
| 795 scoped_ptr<TestAutofillDriver> autofill_driver_; | |
| 792 scoped_ptr<TestAutofillManager> autofill_manager_; | 796 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 793 TestPersonalDataManager personal_data_; | 797 TestPersonalDataManager personal_data_; |
| 794 | 798 |
| 795 // Used when we want an off the record profile. This will store the original | 799 // Used when we want an off the record profile. This will store the original |
| 796 // profile from which the off the record profile is derived. | 800 // profile from which the off the record profile is derived. |
| 797 scoped_ptr<Profile> other_browser_context_; | 801 scoped_ptr<Profile> other_browser_context_; |
| 798 }; | 802 }; |
| 799 | 803 |
| 800 class TestFormStructure : public FormStructure { | 804 class TestFormStructure : public FormStructure { |
| 801 public: | 805 public: |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 817 | 821 |
| 818 UpdateAutofillCount(); | 822 UpdateAutofillCount(); |
| 819 } | 823 } |
| 820 | 824 |
| 821 private: | 825 private: |
| 822 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 826 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
| 823 }; | 827 }; |
| 824 | 828 |
| 825 // Test that browser asks for all forms when Autocheckout is enabled. | 829 // Test that browser asks for all forms when Autocheckout is enabled. |
| 826 TEST_F(AutofillManagerTest, GetAllForms) { | 830 TEST_F(AutofillManagerTest, GetAllForms) { |
| 831 /* | |
| 827 FormData form; | 832 FormData form; |
| 828 CreateTestAddressFormData(&form); | 833 CreateTestAddressFormData(&form); |
| 829 std::vector<FormData> forms(1, form); | 834 std::vector<FormData> forms(1, form); |
| 830 // Enable autocheckout. | 835 // Enable autocheckout. |
| 831 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); | 836 autofill_manager_->set_autocheckout_url_prefix("test-prefix"); |
| 832 | 837 |
| 833 PartialFormsSeen(forms); | 838 PartialFormsSeen(forms); |
| 834 | 839 |
| 835 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); | 840 ASSERT_TRUE(HasSeenAutofillGetAllFormsMessage()); |
| 841 */ | |
|
Ilya Sherman
2013/06/12 00:07:46
Why is this test commented out?
blundell
2013/06/12 16:29:37
Cruft from debugging! Thanks.
On 2013/06/12 00:07
| |
| 836 } | 842 } |
| 837 | 843 |
| 838 // Test that we return all address profile suggestions when all form fields are | 844 // Test that we return all address profile suggestions when all form fields are |
| 839 // empty. | 845 // empty. |
| 840 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { | 846 TEST_F(AutofillManagerTest, GetProfileSuggestionsEmptyValue) { |
| 841 // Set up our form data. | 847 // Set up our form data. |
| 842 FormData form; | 848 FormData form; |
| 843 CreateTestAddressFormData(&form); | 849 CreateTestAddressFormData(&form); |
| 844 std::vector<FormData> forms(1, form); | 850 std::vector<FormData> forms(1, form); |
| 845 FormsSeen(forms); | 851 FormsSeen(forms); |
| (...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3209 private: | 3215 private: |
| 3210 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 3216 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
| 3211 }; | 3217 }; |
| 3212 | 3218 |
| 3213 } // namespace | 3219 } // namespace |
| 3214 | 3220 |
| 3215 // Test that Autocheckout bubble is offered when server specifies field types. | 3221 // Test that Autocheckout bubble is offered when server specifies field types. |
| 3216 TEST_F(AutofillManagerTest, TestBubbleShown) { | 3222 TEST_F(AutofillManagerTest, TestBubbleShown) { |
| 3217 MockAutofillManagerDelegate delegate; | 3223 MockAutofillManagerDelegate delegate; |
| 3218 autofill_manager_.reset(new TestAutofillManager( | 3224 autofill_manager_.reset(new TestAutofillManager( |
| 3219 web_contents(), &delegate, &personal_data_)); | 3225 autofill_driver_.get(), &delegate, &personal_data_)); |
| 3220 autofill_manager_->set_autofill_enabled(true); | 3226 autofill_manager_->set_autofill_enabled(true); |
| 3221 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3227 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
| 3222 | 3228 |
| 3223 EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _)); | 3229 EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _)); |
| 3224 | 3230 |
| 3225 FormData form; | 3231 FormData form; |
| 3226 CreateTestAddressFormData(&form); | 3232 CreateTestAddressFormData(&form); |
| 3227 | 3233 |
| 3228 TestFormStructure* form_structure = new TestFormStructure(form); | 3234 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3229 AutofillMetrics metrics_logger; // ignored | 3235 AutofillMetrics metrics_logger; // ignored |
| 3230 form_structure->DetermineHeuristicTypes(metrics_logger); | 3236 form_structure->DetermineHeuristicTypes(metrics_logger); |
| 3231 | 3237 |
| 3232 // Build and add form structure with server data. | 3238 // Build and add form structure with server data. |
| 3233 std::vector<AutofillFieldType> heuristic_types, server_types; | 3239 std::vector<AutofillFieldType> heuristic_types, server_types; |
| 3234 for (size_t i = 0; i < form.fields.size(); ++i) { | 3240 for (size_t i = 0; i < form.fields.size(); ++i) { |
| 3235 heuristic_types.push_back(UNKNOWN_TYPE); | 3241 heuristic_types.push_back(UNKNOWN_TYPE); |
| 3236 server_types.push_back(form_structure->field(i)->type()); | 3242 server_types.push_back(form_structure->field(i)->type()); |
| 3237 } | 3243 } |
| 3238 form_structure->SetFieldTypes(heuristic_types, server_types); | 3244 form_structure->SetFieldTypes(heuristic_types, server_types); |
| 3239 autofill_manager_->AddSeenForm(form_structure); | 3245 autofill_manager_->AddSeenForm(form_structure); |
| 3240 | 3246 |
| 3241 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3247 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
| 3242 } | 3248 } |
| 3243 | 3249 |
| 3244 // Test that Autocheckout bubble is not offered when server doesn't have data | 3250 // Test that Autocheckout bubble is not offered when server doesn't have data |
| 3245 // for the form. | 3251 // for the form. |
| 3246 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { | 3252 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { |
| 3247 MockAutofillManagerDelegate delegate; | 3253 MockAutofillManagerDelegate delegate; |
| 3248 autofill_manager_.reset(new TestAutofillManager( | 3254 autofill_manager_.reset(new TestAutofillManager( |
| 3249 web_contents(), &delegate, &personal_data_)); | 3255 autofill_driver_.get(), &delegate, &personal_data_)); |
| 3250 autofill_manager_->set_autofill_enabled(true); | 3256 autofill_manager_->set_autofill_enabled(true); |
| 3251 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3257 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
| 3252 | 3258 |
| 3253 FormData form; | 3259 FormData form; |
| 3254 CreateTestAddressFormData(&form); | 3260 CreateTestAddressFormData(&form); |
| 3255 | 3261 |
| 3256 TestFormStructure* form_structure = new TestFormStructure(form); | 3262 TestFormStructure* form_structure = new TestFormStructure(form); |
| 3257 AutofillMetrics metrics_logger; // ignored | 3263 AutofillMetrics metrics_logger; // ignored |
| 3258 form_structure->DetermineHeuristicTypes(metrics_logger); | 3264 form_structure->DetermineHeuristicTypes(metrics_logger); |
| 3259 | 3265 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 3280 CreateTestAddressFormData(&form); | 3286 CreateTestAddressFormData(&form); |
| 3281 std::vector<FormData> forms(1, form); | 3287 std::vector<FormData> forms(1, form); |
| 3282 FormsSeen(forms); | 3288 FormsSeen(forms); |
| 3283 const FormFieldData& field = form.fields[0]; | 3289 const FormFieldData& field = form.fields[0]; |
| 3284 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3290 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
| 3285 | 3291 |
| 3286 autofill_manager_->SetExternalDelegate(NULL); | 3292 autofill_manager_->SetExternalDelegate(NULL); |
| 3287 } | 3293 } |
| 3288 | 3294 |
| 3289 } // namespace autofill | 3295 } // namespace autofill |
| OLD | NEW |