| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.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/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 20 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 21 #include "chrome/browser/infobars/infobar.h" | 21 #include "chrome/browser/infobars/infobar.h" |
| 22 #include "chrome/browser/infobars/infobar_manager.h" | |
| 23 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 26 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 28 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 29 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 30 #include "chrome/test/base/test_switches.h" | 29 #include "chrome/test/base/test_switches.h" |
| 31 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 32 #include "components/autofill/content/browser/content_autofill_driver.h" | 31 #include "components/autofill/content/browser/content_autofill_driver.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 has_run_message_loop_(false), | 63 has_run_message_loop_(false), |
| 65 browser_(browser), | 64 browser_(browser), |
| 66 infobar_service_(NULL) { | 65 infobar_service_(NULL) { |
| 67 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | 66 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> |
| 68 AddObserver(this); | 67 AddObserver(this); |
| 69 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, | 68 registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| 70 content::NotificationService::AllSources()); | 69 content::NotificationService::AllSources()); |
| 71 } | 70 } |
| 72 | 71 |
| 73 virtual ~WindowedPersonalDataManagerObserver() { | 72 virtual ~WindowedPersonalDataManagerObserver() { |
| 74 if (infobar_service_ && | 73 if (infobar_service_ && (infobar_service_->infobar_count() > 0)) { |
| 75 (infobar_service_->infobar_manager()->infobar_count() > 0)) { | 74 infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0)); |
| 76 InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); | |
| 77 infobar_manager->RemoveInfoBar(infobar_manager->infobar_at(0)); | |
| 78 } | 75 } |
| 79 } | 76 } |
| 80 | 77 |
| 81 void Wait() { | 78 void Wait() { |
| 82 if (!alerted_) { | 79 if (!alerted_) { |
| 83 has_run_message_loop_ = true; | 80 has_run_message_loop_ = true; |
| 84 content::RunMessageLoop(); | 81 content::RunMessageLoop(); |
| 85 } | 82 } |
| 86 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> | 83 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> |
| 87 RemoveObserver(this); | 84 RemoveObserver(this); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 OnPersonalDataChanged(); | 97 OnPersonalDataChanged(); |
| 101 } | 98 } |
| 102 | 99 |
| 103 // content::NotificationObserver: | 100 // content::NotificationObserver: |
| 104 virtual void Observe(int type, | 101 virtual void Observe(int type, |
| 105 const content::NotificationSource& source, | 102 const content::NotificationSource& source, |
| 106 const content::NotificationDetails& details) OVERRIDE { | 103 const content::NotificationDetails& details) OVERRIDE { |
| 107 EXPECT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); | 104 EXPECT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); |
| 108 infobar_service_ = InfoBarService::FromWebContents( | 105 infobar_service_ = InfoBarService::FromWebContents( |
| 109 browser_->tab_strip_model()->GetActiveWebContents()); | 106 browser_->tab_strip_model()->GetActiveWebContents()); |
| 110 InfoBarManager* infobar_manager = infobar_service_->infobar_manager(); | |
| 111 ConfirmInfoBarDelegate* infobar_delegate = | 107 ConfirmInfoBarDelegate* infobar_delegate = |
| 112 infobar_manager->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | 108 infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); |
| 113 ASSERT_TRUE(infobar_delegate); | 109 ASSERT_TRUE(infobar_delegate); |
| 114 infobar_delegate->Accept(); | 110 infobar_delegate->Accept(); |
| 115 } | 111 } |
| 116 | 112 |
| 117 private: | 113 private: |
| 118 bool alerted_; | 114 bool alerted_; |
| 119 bool has_run_message_loop_; | 115 bool has_run_message_loop_; |
| 120 Browser* browser_; | 116 Browser* browser_; |
| 121 content::NotificationRegistrar registrar_; | 117 content::NotificationRegistrar registrar_; |
| 122 InfoBarService* infobar_service_; | 118 InfoBarService* infobar_service_; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 484 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| 489 return; | 485 return; |
| 490 #endif | 486 #endif |
| 491 | 487 |
| 492 ASSERT_TRUE(test_server()->Start()); | 488 ASSERT_TRUE(test_server()->Start()); |
| 493 std::string card("4408 0412 3456 7890"); | 489 std::string card("4408 0412 3456 7890"); |
| 494 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); | 490 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); |
| 495 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); | 491 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); |
| 496 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 492 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 497 browser()->tab_strip_model()->GetActiveWebContents()); | 493 browser()->tab_strip_model()->GetActiveWebContents()); |
| 498 ASSERT_EQ(0u, infobar_service->infobar_manager()->infobar_count()); | 494 ASSERT_EQ(0u, infobar_service->infobar_count()); |
| 499 } | 495 } |
| 500 | 496 |
| 501 // Test whitespaces and separator chars are stripped for valid CC numbers. | 497 // Test whitespaces and separator chars are stripped for valid CC numbers. |
| 502 // The credit card numbers used in this test pass the Luhn test. For reference: | 498 // The credit card numbers used in this test pass the Luhn test. For reference: |
| 503 // http://www.merriampark.com/anatomycc.htm | 499 // http://www.merriampark.com/anatomycc.htm |
| 504 IN_PROC_BROWSER_TEST_F(AutofillTest, | 500 IN_PROC_BROWSER_TEST_F(AutofillTest, |
| 505 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { | 501 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { |
| 506 #if defined(OS_WIN) && defined(USE_ASH) | 502 #if defined(OS_WIN) && defined(USE_ASH) |
| 507 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | 503 // Disable this test in Metro+Ash for now (http://crbug.com/262796). |
| 508 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | 504 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 ASSERT_TRUE(test_server()->Start()); | 670 ASSERT_TRUE(test_server()->Start()); |
| 675 FormMap data; | 671 FormMap data; |
| 676 data["CREDIT_CARD_NAME"] = "Bob Smith"; | 672 data["CREDIT_CARD_NAME"] = "Bob Smith"; |
| 677 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; | 673 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; |
| 678 data["CREDIT_CARD_EXP_MONTH"] = "12"; | 674 data["CREDIT_CARD_EXP_MONTH"] = "12"; |
| 679 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; | 675 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; |
| 680 FillFormAndSubmit("cc_autocomplete_off_test.html", data); | 676 FillFormAndSubmit("cc_autocomplete_off_test.html", data); |
| 681 | 677 |
| 682 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 678 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| 683 browser()->tab_strip_model()->GetActiveWebContents()); | 679 browser()->tab_strip_model()->GetActiveWebContents()); |
| 684 ASSERT_EQ(0u, infobar_service->infobar_manager()->infobar_count()); | 680 ASSERT_EQ(0u, infobar_service->infobar_count()); |
| 685 } | 681 } |
| 686 | 682 |
| 687 // Test profile not aggregated if email found in non-email field. | 683 // Test profile not aggregated if email found in non-email field. |
| 688 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) { | 684 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) { |
| 689 ASSERT_TRUE(test_server()->Start()); | 685 ASSERT_TRUE(test_server()->Start()); |
| 690 | 686 |
| 691 FormMap data; | 687 FormMap data; |
| 692 data["NAME_FIRST"] = "Bob"; | 688 data["NAME_FIRST"] = "Bob"; |
| 693 data["NAME_LAST"] = "Smith"; | 689 data["NAME_LAST"] = "Smith"; |
| 694 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com"; | 690 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com"; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 IN_PROC_BROWSER_TEST_F(AutofillTest, | 729 IN_PROC_BROWSER_TEST_F(AutofillTest, |
| 734 DISABLED_MergeAggregatedDuplicatedProfiles) { | 730 DISABLED_MergeAggregatedDuplicatedProfiles) { |
| 735 int num_of_profiles = | 731 int num_of_profiles = |
| 736 AggregateProfilesIntoAutofillPrefs("dataset_duplicated_profiles.txt"); | 732 AggregateProfilesIntoAutofillPrefs("dataset_duplicated_profiles.txt"); |
| 737 | 733 |
| 738 ASSERT_GT(num_of_profiles, | 734 ASSERT_GT(num_of_profiles, |
| 739 static_cast<int>(personal_data_manager()->GetProfiles().size())); | 735 static_cast<int>(personal_data_manager()->GetProfiles().size())); |
| 740 } | 736 } |
| 741 | 737 |
| 742 } // namespace autofill | 738 } // namespace autofill |
| OLD | NEW |