OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 10 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 virtual ~WindowedPersonalDataManagerObserver() {} | 38 virtual ~WindowedPersonalDataManagerObserver() {} |
39 | 39 |
40 // Waits for the PersonalDataManager's list of profiles to be updated. | 40 // Waits for the PersonalDataManager's list of profiles to be updated. |
41 void Wait() { | 41 void Wait() { |
42 message_loop_runner_->Run(); | 42 message_loop_runner_->Run(); |
43 PersonalDataManagerFactory::GetForProfile(profile_)->RemoveObserver(this); | 43 PersonalDataManagerFactory::GetForProfile(profile_)->RemoveObserver(this); |
44 } | 44 } |
45 | 45 |
46 // PersonalDataManagerObserver: | 46 // PersonalDataManagerObserver: |
47 virtual void OnPersonalDataChanged() OVERRIDE { | 47 virtual void OnPersonalDataChanged() override { |
48 message_loop_runner_->Quit(); | 48 message_loop_runner_->Quit(); |
49 } | 49 } |
50 | 50 |
51 private: | 51 private: |
52 Profile* profile_; | 52 Profile* profile_; |
53 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 53 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
54 }; | 54 }; |
55 | 55 |
56 class WindowedNetworkObserver : public net::TestURLFetcher::DelegateForTests { | 56 class WindowedNetworkObserver : public net::TestURLFetcher::DelegateForTests { |
57 public: | 57 public: |
58 explicit WindowedNetworkObserver(const std::string& expected_upload_data) | 58 explicit WindowedNetworkObserver(const std::string& expected_upload_data) |
59 : factory_(new net::TestURLFetcherFactory), | 59 : factory_(new net::TestURLFetcherFactory), |
60 expected_upload_data_(expected_upload_data), | 60 expected_upload_data_(expected_upload_data), |
61 message_loop_runner_(new content::MessageLoopRunner) { | 61 message_loop_runner_(new content::MessageLoopRunner) { |
62 factory_->SetDelegateForTests(this); | 62 factory_->SetDelegateForTests(this); |
63 } | 63 } |
64 ~WindowedNetworkObserver() {} | 64 ~WindowedNetworkObserver() {} |
65 | 65 |
66 // Waits for a network request with the |expected_upload_data_|. | 66 // Waits for a network request with the |expected_upload_data_|. |
67 void Wait() { | 67 void Wait() { |
68 message_loop_runner_->Run(); | 68 message_loop_runner_->Run(); |
69 factory_.reset(); | 69 factory_.reset(); |
70 } | 70 } |
71 | 71 |
72 // net::TestURLFetcher::DelegateForTests: | 72 // net::TestURLFetcher::DelegateForTests: |
73 virtual void OnRequestStart(int fetcher_id) OVERRIDE { | 73 virtual void OnRequestStart(int fetcher_id) override { |
74 net::TestURLFetcher* fetcher = factory_->GetFetcherByID(fetcher_id); | 74 net::TestURLFetcher* fetcher = factory_->GetFetcherByID(fetcher_id); |
75 if (fetcher->upload_data() == expected_upload_data_) | 75 if (fetcher->upload_data() == expected_upload_data_) |
76 message_loop_runner_->Quit(); | 76 message_loop_runner_->Quit(); |
77 | 77 |
78 // Not interested in any further status updates from this fetcher. | 78 // Not interested in any further status updates from this fetcher. |
79 fetcher->SetDelegateForTests(NULL); | 79 fetcher->SetDelegateForTests(NULL); |
80 } | 80 } |
81 virtual void OnChunkUpload(int fetcher_id) OVERRIDE {} | 81 virtual void OnChunkUpload(int fetcher_id) override {} |
82 virtual void OnRequestEnd(int fetcher_id) OVERRIDE {} | 82 virtual void OnRequestEnd(int fetcher_id) override {} |
83 | 83 |
84 private: | 84 private: |
85 // Mocks out network requests. | 85 // Mocks out network requests. |
86 scoped_ptr<net::TestURLFetcherFactory> factory_; | 86 scoped_ptr<net::TestURLFetcherFactory> factory_; |
87 | 87 |
88 const std::string expected_upload_data_; | 88 const std::string expected_upload_data_; |
89 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 89 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
90 | 90 |
91 DISALLOW_COPY_AND_ASSIGN(WindowedNetworkObserver); | 91 DISALLOW_COPY_AND_ASSIGN(WindowedNetworkObserver); |
92 }; | 92 }; |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 class AutofillServerTest : public InProcessBrowserTest { | 96 class AutofillServerTest : public InProcessBrowserTest { |
97 public: | 97 public: |
98 virtual void SetUpOnMainThread() OVERRIDE { | 98 virtual void SetUpOnMainThread() override { |
99 // Disable interactions with the Mac Keychain. | 99 // Disable interactions with the Mac Keychain. |
100 PrefService* pref_service = browser()->profile()->GetPrefs(); | 100 PrefService* pref_service = browser()->profile()->GetPrefs(); |
101 test::DisableSystemServices(pref_service); | 101 test::DisableSystemServices(pref_service); |
102 | 102 |
103 // Enable uploads, and load a new tab to force the AutofillDownloadManager | 103 // Enable uploads, and load a new tab to force the AutofillDownloadManager |
104 // to update its cached view of the prefs. | 104 // to update its cached view of the prefs. |
105 pref_service->SetDouble(prefs::kAutofillPositiveUploadRate, 1.0); | 105 pref_service->SetDouble(prefs::kAutofillPositiveUploadRate, 1.0); |
106 pref_service->SetDouble(prefs::kAutofillNegativeUploadRate, 1.0); | 106 pref_service->SetDouble(prefs::kAutofillNegativeUploadRate, 1.0); |
107 AddBlankTabAndShow(browser()); | 107 AddBlankTabAndShow(browser()); |
108 } | 108 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 "</autofillupload>"; | 165 "</autofillupload>"; |
166 WindowedNetworkObserver upload_network_observer(kUploadRequest); | 166 WindowedNetworkObserver upload_network_observer(kUploadRequest); |
167 content::WebContents* web_contents = | 167 content::WebContents* web_contents = |
168 browser()->tab_strip_model()->GetActiveWebContents(); | 168 browser()->tab_strip_model()->GetActiveWebContents(); |
169 content::SimulateMouseClick( | 169 content::SimulateMouseClick( |
170 web_contents, 0, blink::WebMouseEvent::ButtonLeft); | 170 web_contents, 0, blink::WebMouseEvent::ButtonLeft); |
171 upload_network_observer.Wait(); | 171 upload_network_observer.Wait(); |
172 } | 172 } |
173 | 173 |
174 } // namespace autofill | 174 } // namespace autofill |
OLD | NEW |