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

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

Issue 1396923003: Autofill: Replace "save credit card" infobar with a bubble (Views only). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: defined(TOOLKIT_VIEWS) -> defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX). Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/autofill/autofill_uitest_util.h" 5 #include "chrome/browser/autofill/autofill_uitest_util.h"
6 #include "chrome/browser/autofill/personal_data_manager_factory.h" 6 #include "chrome/browser/autofill/personal_data_manager_factory.h"
7 #include "chrome/browser/infobars/infobar_service.h"
8 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "components/autofill/core/browser/personal_data_manager.h" 9 #include "components/autofill/core/browser/personal_data_manager.h"
11 #include "components/autofill/core/browser/personal_data_manager_observer.h" 10 #include "components/autofill/core/browser/personal_data_manager_observer.h"
12 #include "components/infobars/core/confirm_infobar_delegate.h"
13 #include "components/infobars/core/infobar.h"
14 #include "components/infobars/core/infobar_manager.h"
15 #include "content/public/test/test_utils.h" 11 #include "content/public/test/test_utils.h"
16 12
17 namespace autofill { 13 namespace autofill {
18 14
19 // This class is used to wait for asynchronous updates to PersonalDataManager 15 // This class is used to wait for asynchronous updates to PersonalDataManager
20 // to complete. 16 // to complete.
21 class PdmChangeWaiter 17 class PdmChangeWaiter : public PersonalDataManagerObserver {
22 : public PersonalDataManagerObserver,
23 public infobars::InfoBarManager::Observer {
24 public: 18 public:
25 explicit PdmChangeWaiter(Browser* browser) 19 explicit PdmChangeWaiter(Browser* browser)
26 : alerted_(false), 20 : alerted_(false), has_run_message_loop_(false), browser_(browser) {
27 has_run_message_loop_(false),
28 browser_(browser),
29 infobar_service_(InfoBarService::FromWebContents(
30 browser_->tab_strip_model()->GetActiveWebContents())) {
31 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> 21 PersonalDataManagerFactory::GetForProfile(browser_->profile())->
32 AddObserver(this); 22 AddObserver(this);
33 infobar_service_->AddObserver(this);
34 } 23 }
35 24
36 ~PdmChangeWaiter() override { 25 ~PdmChangeWaiter() override {}
37 while (infobar_service_->infobar_count() > 0) {
38 infobar_service_->RemoveInfoBar(infobar_service_->infobar_at(0));
39 }
40 infobar_service_->RemoveObserver(this);
41 }
42 26
43 // PersonalDataManagerObserver: 27 // PersonalDataManagerObserver:
44 void OnPersonalDataChanged() override { 28 void OnPersonalDataChanged() override {
45 if (has_run_message_loop_) { 29 if (has_run_message_loop_) {
46 base::MessageLoopForUI::current()->QuitWhenIdle(); 30 base::MessageLoopForUI::current()->QuitWhenIdle();
47 has_run_message_loop_ = false; 31 has_run_message_loop_ = false;
48 } 32 }
49 alerted_ = true; 33 alerted_ = true;
50 } 34 }
51 35
52 void OnInsufficientFormData() override { OnPersonalDataChanged(); } 36 void OnInsufficientFormData() override { OnPersonalDataChanged(); }
53 37
54
55 void Wait() { 38 void Wait() {
56 if (!alerted_) { 39 if (!alerted_) {
57 has_run_message_loop_ = true; 40 has_run_message_loop_ = true;
58 content::RunMessageLoop(); 41 content::RunMessageLoop();
59 } 42 }
60 PersonalDataManagerFactory::GetForProfile(browser_->profile())-> 43 PersonalDataManagerFactory::GetForProfile(browser_->profile())->
61 RemoveObserver(this); 44 RemoveObserver(this);
62 } 45 }
63 46
64 private: 47 private:
65 // infobars::InfoBarManager::Observer:
66 void OnInfoBarAdded(infobars::InfoBar* infobar) override {
67 infobar_service_->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate()->
68 Accept();
69 }
70
71 bool alerted_; 48 bool alerted_;
72 bool has_run_message_loop_; 49 bool has_run_message_loop_;
73 Browser* browser_; 50 Browser* browser_;
74 InfoBarService* infobar_service_;
75 51
76 DISALLOW_COPY_AND_ASSIGN(PdmChangeWaiter); 52 DISALLOW_COPY_AND_ASSIGN(PdmChangeWaiter);
77 }; 53 };
78 54
79 static PersonalDataManager* GetPersonalDataManager(Profile* profile) { 55 static PersonalDataManager* GetPersonalDataManager(Profile* profile) {
80 return PersonalDataManagerFactory::GetForProfile(profile); 56 return PersonalDataManagerFactory::GetForProfile(profile);
81 } 57 }
82 58
83 void AddTestProfile(Browser* browser, const AutofillProfile& profile) { 59 void AddTestProfile(Browser* browser, const AutofillProfile& profile) {
84 PdmChangeWaiter observer(browser); 60 PdmChangeWaiter observer(browser);
(...skipping 10 matching lines...) Expand all
95 SetTestProfiles(browser, &profiles); 71 SetTestProfiles(browser, &profiles);
96 } 72 }
97 73
98 void SetTestProfiles(Browser* browser, std::vector<AutofillProfile>* profiles) { 74 void SetTestProfiles(Browser* browser, std::vector<AutofillProfile>* profiles) {
99 PdmChangeWaiter observer(browser); 75 PdmChangeWaiter observer(browser);
100 GetPersonalDataManager(browser->profile())->SetProfiles(profiles); 76 GetPersonalDataManager(browser->profile())->SetProfiles(profiles);
101 observer.Wait(); 77 observer.Wait();
102 } 78 }
103 79
104 } // namespace autofill 80 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_interactive_uitest.cc ('k') | chrome/browser/ui/autofill/chrome_autofill_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698