Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: chrome/browser/autofill/autofill_browsertest.cc

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 return;
76
77 InfoBarManager& infobar_manager = infobar_service_->infobar_manager();
78 if (infobar_manager.infobar_count() > 0)
79 infobar_manager.RemoveInfoBar(infobar_manager.infobar_at(0));
75 } 80 }
76 81
77 void Wait() { 82 void Wait() {
78 if (!alerted_) { 83 if (!alerted_) {
79 has_run_message_loop_ = true; 84 has_run_message_loop_ = true;
80 content::RunMessageLoop(); 85 content::RunMessageLoop();
81 } 86 }
82 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> 87 PersonalDataManagerFactory::GetForProfile(browser_->profile())->
83 RemoveObserver(this); 88 RemoveObserver(this);
84 } 89 }
(...skipping 12 matching lines...) Expand all
97 } 102 }
98 103
99 // content::NotificationObserver: 104 // content::NotificationObserver:
100 virtual void Observe(int type, 105 virtual void Observe(int type,
101 const content::NotificationSource& source, 106 const content::NotificationSource& source,
102 const content::NotificationDetails& details) OVERRIDE { 107 const content::NotificationDetails& details) OVERRIDE {
103 EXPECT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type); 108 EXPECT_EQ(chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, type);
104 infobar_service_ = InfoBarService::FromWebContents( 109 infobar_service_ = InfoBarService::FromWebContents(
105 browser_->tab_strip_model()->GetActiveWebContents()); 110 browser_->tab_strip_model()->GetActiveWebContents());
106 ConfirmInfoBarDelegate* infobar_delegate = 111 ConfirmInfoBarDelegate* infobar_delegate =
107 infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); 112 infobar_service_->infobar_manager()
113 .infobar_at(0)
114 ->delegate()
115 ->AsConfirmInfoBarDelegate();
108 ASSERT_TRUE(infobar_delegate); 116 ASSERT_TRUE(infobar_delegate);
109 infobar_delegate->Accept(); 117 infobar_delegate->Accept();
110 } 118 }
111 119
112 private: 120 private:
113 bool alerted_; 121 bool alerted_;
114 bool has_run_message_loop_; 122 bool has_run_message_loop_;
115 Browser* browser_; 123 Browser* browser_;
116 content::NotificationRegistrar registrar_; 124 content::NotificationRegistrar registrar_;
117 InfoBarService* infobar_service_; 125 InfoBarService* infobar_service_;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 491 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
484 return; 492 return;
485 #endif 493 #endif
486 494
487 ASSERT_TRUE(test_server()->Start()); 495 ASSERT_TRUE(test_server()->Start());
488 std::string card("4408 0412 3456 7890"); 496 std::string card("4408 0412 3456 7890");
489 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card))); 497 ASSERT_FALSE(autofill::IsValidCreditCardNumber(ASCIIToUTF16(card)));
490 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014"); 498 SubmitCreditCard("Bob Smith", card.c_str(), "12", "2014");
491 ASSERT_EQ(0u, 499 ASSERT_EQ(0u,
492 InfoBarService::FromWebContents( 500 InfoBarService::FromWebContents(
493 browser()->tab_strip_model()->GetActiveWebContents())-> 501 browser()->tab_strip_model()->GetActiveWebContents())
494 infobar_count()); 502 ->infobar_manager()
503 .infobar_count());
495 } 504 }
496 505
497 // Test whitespaces and separator chars are stripped for valid CC numbers. 506 // 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: 507 // The credit card numbers used in this test pass the Luhn test. For reference:
499 // http://www.merriampark.com/anatomycc.htm 508 // http://www.merriampark.com/anatomycc.htm
500 IN_PROC_BROWSER_TEST_F(AutofillTest, 509 IN_PROC_BROWSER_TEST_F(AutofillTest,
501 WhitespacesAndSeparatorCharsStrippedForValidCCNums) { 510 WhitespacesAndSeparatorCharsStrippedForValidCCNums) {
502 #if defined(OS_WIN) && defined(USE_ASH) 511 #if defined(OS_WIN) && defined(USE_ASH)
503 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 512 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
504 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 513 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 ASSERT_TRUE(test_server()->Start()); 679 ASSERT_TRUE(test_server()->Start());
671 FormMap data; 680 FormMap data;
672 data["CREDIT_CARD_NAME"] = "Bob Smith"; 681 data["CREDIT_CARD_NAME"] = "Bob Smith";
673 data["CREDIT_CARD_NUMBER"] = "4408041234567893"; 682 data["CREDIT_CARD_NUMBER"] = "4408041234567893";
674 data["CREDIT_CARD_EXP_MONTH"] = "12"; 683 data["CREDIT_CARD_EXP_MONTH"] = "12";
675 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014"; 684 data["CREDIT_CARD_EXP_4_DIGIT_YEAR"] = "2014";
676 FillFormAndSubmit("cc_autocomplete_off_test.html", data); 685 FillFormAndSubmit("cc_autocomplete_off_test.html", data);
677 686
678 ASSERT_EQ(0u, 687 ASSERT_EQ(0u,
679 InfoBarService::FromWebContents( 688 InfoBarService::FromWebContents(
680 browser()->tab_strip_model()->GetActiveWebContents())-> 689 browser()->tab_strip_model()->GetActiveWebContents())
681 infobar_count()); 690 ->infobar_manager()
691 .infobar_count());
682 } 692 }
683 693
684 // Test profile not aggregated if email found in non-email field. 694 // Test profile not aggregated if email found in non-email field.
685 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) { 695 IN_PROC_BROWSER_TEST_F(AutofillTest, ProfileWithEmailInOtherFieldNotSaved) {
686 ASSERT_TRUE(test_server()->Start()); 696 ASSERT_TRUE(test_server()->Start());
687 697
688 FormMap data; 698 FormMap data;
689 data["NAME_FIRST"] = "Bob"; 699 data["NAME_FIRST"] = "Bob";
690 data["NAME_LAST"] = "Smith"; 700 data["NAME_LAST"] = "Smith";
691 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com"; 701 data["ADDRESS_HOME_LINE1"] = "bsmith@gmail.com";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 IN_PROC_BROWSER_TEST_F(AutofillTest, 740 IN_PROC_BROWSER_TEST_F(AutofillTest,
731 DISABLED_MergeAggregatedDuplicatedProfiles) { 741 DISABLED_MergeAggregatedDuplicatedProfiles) {
732 int num_of_profiles = 742 int num_of_profiles =
733 AggregateProfilesIntoAutofillPrefs("dataset_duplicated_profiles.txt"); 743 AggregateProfilesIntoAutofillPrefs("dataset_duplicated_profiles.txt");
734 744
735 ASSERT_GT(num_of_profiles, 745 ASSERT_GT(num_of_profiles,
736 static_cast<int>(personal_data_manager()->GetProfiles().size())); 746 static_cast<int>(personal_data_manager()->GetProfiles().size()));
737 } 747 }
738 748
739 } // namespace autofill 749 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698