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 2407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3209 private: | 3213 private: |
3210 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); | 3214 DISALLOW_COPY_AND_ASSIGN(MockAutofillExternalDelegate); |
3211 }; | 3215 }; |
3212 | 3216 |
3213 } // namespace | 3217 } // namespace |
3214 | 3218 |
3215 // Test that Autocheckout bubble is offered when server specifies field types. | 3219 // Test that Autocheckout bubble is offered when server specifies field types. |
3216 TEST_F(AutofillManagerTest, TestBubbleShown) { | 3220 TEST_F(AutofillManagerTest, TestBubbleShown) { |
3217 MockAutofillManagerDelegate delegate; | 3221 MockAutofillManagerDelegate delegate; |
3218 autofill_manager_.reset(new TestAutofillManager( | 3222 autofill_manager_.reset(new TestAutofillManager( |
3219 web_contents(), &delegate, &personal_data_)); | 3223 autofill_driver_.get(), &delegate, &personal_data_)); |
3220 autofill_manager_->set_autofill_enabled(true); | 3224 autofill_manager_->set_autofill_enabled(true); |
3221 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3225 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
3222 | 3226 |
3223 EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _)); | 3227 EXPECT_CALL(delegate, ShowAutocheckoutBubble(_, _, _)); |
3224 | 3228 |
3225 FormData form; | 3229 FormData form; |
3226 CreateTestAddressFormData(&form); | 3230 CreateTestAddressFormData(&form); |
3227 | 3231 |
3228 TestFormStructure* form_structure = new TestFormStructure(form); | 3232 TestFormStructure* form_structure = new TestFormStructure(form); |
3229 AutofillMetrics metrics_logger; // ignored | 3233 AutofillMetrics metrics_logger; // ignored |
3230 form_structure->DetermineHeuristicTypes(metrics_logger); | 3234 form_structure->DetermineHeuristicTypes(metrics_logger); |
3231 | 3235 |
3232 // Build and add form structure with server data. | 3236 // Build and add form structure with server data. |
3233 std::vector<AutofillFieldType> heuristic_types, server_types; | 3237 std::vector<AutofillFieldType> heuristic_types, server_types; |
3234 for (size_t i = 0; i < form.fields.size(); ++i) { | 3238 for (size_t i = 0; i < form.fields.size(); ++i) { |
3235 heuristic_types.push_back(UNKNOWN_TYPE); | 3239 heuristic_types.push_back(UNKNOWN_TYPE); |
3236 server_types.push_back(form_structure->field(i)->type()); | 3240 server_types.push_back(form_structure->field(i)->type()); |
3237 } | 3241 } |
3238 form_structure->SetFieldTypes(heuristic_types, server_types); | 3242 form_structure->SetFieldTypes(heuristic_types, server_types); |
3239 autofill_manager_->AddSeenForm(form_structure); | 3243 autofill_manager_->AddSeenForm(form_structure); |
3240 | 3244 |
3241 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); | 3245 autofill_manager_->OnMaybeShowAutocheckoutBubble(form, gfx::RectF()); |
3242 } | 3246 } |
3243 | 3247 |
3244 // Test that Autocheckout bubble is not offered when server doesn't have data | 3248 // Test that Autocheckout bubble is not offered when server doesn't have data |
3245 // for the form. | 3249 // for the form. |
3246 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { | 3250 TEST_F(AutofillManagerTest, TestAutocheckoutBubbleNotShown) { |
3247 MockAutofillManagerDelegate delegate; | 3251 MockAutofillManagerDelegate delegate; |
3248 autofill_manager_.reset(new TestAutofillManager( | 3252 autofill_manager_.reset(new TestAutofillManager( |
3249 web_contents(), &delegate, &personal_data_)); | 3253 autofill_driver_.get(), &delegate, &personal_data_)); |
3250 autofill_manager_->set_autofill_enabled(true); | 3254 autofill_manager_->set_autofill_enabled(true); |
3251 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); | 3255 autofill_manager_->MarkAsFirstPageInAutocheckoutFlow(); |
3252 | 3256 |
3253 FormData form; | 3257 FormData form; |
3254 CreateTestAddressFormData(&form); | 3258 CreateTestAddressFormData(&form); |
3255 | 3259 |
3256 TestFormStructure* form_structure = new TestFormStructure(form); | 3260 TestFormStructure* form_structure = new TestFormStructure(form); |
3257 AutofillMetrics metrics_logger; // ignored | 3261 AutofillMetrics metrics_logger; // ignored |
3258 form_structure->DetermineHeuristicTypes(metrics_logger); | 3262 form_structure->DetermineHeuristicTypes(metrics_logger); |
3259 | 3263 |
(...skipping 20 matching lines...) Expand all Loading... |
3280 CreateTestAddressFormData(&form); | 3284 CreateTestAddressFormData(&form); |
3281 std::vector<FormData> forms(1, form); | 3285 std::vector<FormData> forms(1, form); |
3282 FormsSeen(forms); | 3286 FormsSeen(forms); |
3283 const FormFieldData& field = form.fields[0]; | 3287 const FormFieldData& field = form.fields[0]; |
3284 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() | 3288 GetAutofillSuggestions(form, field); // should call the delegate's OnQuery() |
3285 | 3289 |
3286 autofill_manager_->SetExternalDelegate(NULL); | 3290 autofill_manager_->SetExternalDelegate(NULL); |
3287 } | 3291 } |
3288 | 3292 |
3289 } // namespace autofill | 3293 } // namespace autofill |
OLD | NEW |