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