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

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

Issue 12091086: [Autofill] Add UMA timing metrics for requestAutocomplete dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/memory/ref_counted.h" 5 #include "base/memory/ref_counted.h"
6 #include "base/tuple.h" 6 #include "base/tuple.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/autofill/autocheckout_manager.h" 8 #include "chrome/browser/autofill/autocheckout_manager.h"
9 #include "chrome/browser/autofill/autofill_common_test.h" 9 #include "chrome/browser/autofill/autofill_common_test.h"
10 #include "chrome/browser/autofill/autofill_manager.h" 10 #include "chrome/browser/autofill/autofill_manager.h"
11 #include "chrome/browser/autofill/autofill_manager_delegate.h" 11 #include "chrome/browser/autofill/autofill_manager_delegate.h"
12 #include "chrome/browser/autofill/form_structure.h" 12 #include "chrome/browser/autofill/form_structure.h"
13 #include "chrome/common/autofill_messages.h" 13 #include "chrome/common/autofill_messages.h"
14 #include "chrome/common/form_data.h" 14 #include "chrome/common/form_data.h"
15 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 15 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/mock_render_process_host.h" 17 #include "content/public/test/mock_render_process_host.h"
18 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 #include "ipc/ipc_test_sink.h" 19 #include "ipc/ipc_test_sink.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 22
23 23
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace autofill {
27
26 namespace { 28 namespace {
27 29
28 typedef Tuple2<std::vector<FormData>, 30 typedef Tuple2<std::vector<FormData>, WebElementDescriptor> AutofillParam;
29 autofill::WebElementDescriptor> AutofillParam;
30 31
31 FormFieldData BuildFieldWithValue( 32 FormFieldData BuildFieldWithValue(
32 const std::string& autocomplete_attribute, 33 const std::string& autocomplete_attribute,
33 const std::string& value) { 34 const std::string& value) {
34 FormFieldData field; 35 FormFieldData field;
35 field.name = ASCIIToUTF16(autocomplete_attribute); 36 field.name = ASCIIToUTF16(autocomplete_attribute);
36 field.value = ASCIIToUTF16(value); 37 field.value = ASCIIToUTF16(value);
37 field.autocomplete_attribute = autocomplete_attribute; 38 field.autocomplete_attribute = autocomplete_attribute;
38 field.form_control_type = "text"; 39 field.form_control_type = "text";
39 return field; 40 return field;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 kTestFields[i].field_value)); 152 kTestFields[i].field_value));
152 } 153 }
153 scoped_ptr<FormStructure> form_structure; 154 scoped_ptr<FormStructure> form_structure;
154 form_structure.reset(new FormStructure(formdata, std::string())); 155 form_structure.reset(new FormStructure(formdata, std::string()));
155 for (size_t i = 0; i < arraysize(kTestFields); ++i) 156 for (size_t i = 0; i < arraysize(kTestFields); ++i)
156 form_structure->field(i)->set_server_type(kTestFields[i].autofill_type); 157 form_structure->field(i)->set_server_type(kTestFields[i].autofill_type);
157 158
158 return form_structure.Pass(); 159 return form_structure.Pass();
159 } 160 }
160 161
161 class TestAutofillManagerDelegate : public autofill::AutofillManagerDelegate { 162 class TestAutofillManagerDelegate : public AutofillManagerDelegate {
162 public: 163 public:
163 explicit TestAutofillManagerDelegate( 164 explicit TestAutofillManagerDelegate(
164 content::BrowserContext* browser_context) 165 content::BrowserContext* browser_context)
165 : browser_context_(browser_context) { 166 : browser_context_(browser_context) {
166 } 167 }
167 168
168 virtual ~TestAutofillManagerDelegate() { 169 virtual ~TestAutofillManagerDelegate() {
169 } 170 }
170 171
171 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { 172 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE {
(...skipping 23 matching lines...) Expand all
195 virtual bool IsSavingPasswordsEnabled() const OVERRIDE { 196 virtual bool IsSavingPasswordsEnabled() const OVERRIDE {
196 return false; 197 return false;
197 } 198 }
198 199
199 virtual void ShowAutofillSettings() OVERRIDE { 200 virtual void ShowAutofillSettings() OVERRIDE {
200 } 201 }
201 202
202 virtual void ShowPasswordGenerationBubble( 203 virtual void ShowPasswordGenerationBubble(
203 const gfx::Rect& bounds, 204 const gfx::Rect& bounds,
204 const content::PasswordForm& form, 205 const content::PasswordForm& form,
205 autofill::PasswordGenerator* generator) OVERRIDE { 206 PasswordGenerator* generator) OVERRIDE {
206 } 207 }
207 208
208 virtual void ShowAutocheckoutBubble( 209 virtual void ShowAutocheckoutBubble(
209 const gfx::RectF& bounds, 210 const gfx::RectF& bounds,
210 const gfx::NativeView& native_view, 211 const gfx::NativeView& native_view,
211 const base::Closure& callback) OVERRIDE { 212 const base::Closure& callback) OVERRIDE {
212 callback.Run(); 213 callback.Run();
213 } 214 }
214 215
215 virtual void ShowRequestAutocompleteDialog( 216 virtual void ShowRequestAutocompleteDialog(
216 const FormData& form, 217 const FormData& form,
217 const GURL& source_url, 218 const GURL& source_url,
218 const content::SSLStatus& ssl_status, 219 const content::SSLStatus& ssl_status,
220 const AutofillMetrics& metric_logger,
221 DialogType dialog_type,
219 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE { 222 const base::Callback<void(const FormStructure*)>& callback) OVERRIDE {
220 callback.Run(user_supplied_data_.get()); 223 callback.Run(user_supplied_data_.get());
221 } 224 }
222 225
223 virtual void RequestAutocompleteDialogClosed() OVERRIDE { 226 virtual void RequestAutocompleteDialogClosed() OVERRIDE {
224 } 227 }
225 228
226 virtual void UpdateProgressBar(double value) OVERRIDE { 229 virtual void UpdateProgressBar(double value) OVERRIDE {
227 } 230 }
228 231
229 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) { 232 void SetUserSuppliedData(scoped_ptr<FormStructure> user_supplied_data) {
230 user_supplied_data_.reset(user_supplied_data.release()); 233 user_supplied_data_.reset(user_supplied_data.release());
231 } 234 }
232 235
233 private: 236 private:
234 content::BrowserContext* browser_context_; 237 content::BrowserContext* browser_context_;
235 scoped_ptr<FormStructure> user_supplied_data_; 238 scoped_ptr<FormStructure> user_supplied_data_;
236 }; 239 };
237 240
238 class TestAutofillManager : public AutofillManager { 241 class TestAutofillManager : public AutofillManager {
239 public: 242 public:
240 explicit TestAutofillManager(content::WebContents* contents, 243 explicit TestAutofillManager(content::WebContents* contents,
241 autofill::AutofillManagerDelegate* delegate) 244 AutofillManagerDelegate* delegate)
242 : AutofillManager(contents, delegate, NULL) { 245 : AutofillManager(contents, delegate, NULL) {
243 } 246 }
244 247
245 void SetFormStructure(scoped_ptr<FormStructure> form_structure) { 248 void SetFormStructure(scoped_ptr<FormStructure> form_structure) {
246 form_structures()->clear(); 249 form_structures()->clear();
247 form_structures()->push_back(form_structure.release()); 250 form_structures()->push_back(form_structure.release());
248 } 251 }
249 252
250 private: 253 private:
251 virtual ~TestAutofillManager() {} 254 virtual ~TestAutofillManager() {}
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 302
300 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest); 303 DISALLOW_COPY_AND_ASSIGN(AutocheckoutManagerTest);
301 }; 304 };
302 305
303 TEST_F(AutocheckoutManagerTest, TestFillForms) { 306 TEST_F(AutocheckoutManagerTest, TestFillForms) {
304 // Simulate the user submitting some data via the requestAutocomplete UI. 307 // Simulate the user submitting some data via the requestAutocomplete UI.
305 autofill_manager_delegate_->SetUserSuppliedData( 308 autofill_manager_delegate_->SetUserSuppliedData(
306 FakeUserSubmittedFormStructure()); 309 FakeUserSubmittedFormStructure());
307 310
308 // Set up page meta data. 311 // Set up page meta data.
309 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( 312 scoped_ptr<AutocheckoutPageMetaData> page_meta_data(
310 new autofill::AutocheckoutPageMetaData()); 313 new AutocheckoutPageMetaData());
311 page_meta_data->proceed_element_descriptor.reset( 314 page_meta_data->proceed_element_descriptor.reset(new WebElementDescriptor());
312 new autofill::WebElementDescriptor());
313 autocheckout_manager_->OnLoadedPageMetaData(page_meta_data.Pass()); 315 autocheckout_manager_->OnLoadedPageMetaData(page_meta_data.Pass());
314 316
315 GURL frame_url; 317 GURL frame_url;
316 content::SSLStatus ssl_status; 318 content::SSLStatus ssl_status;
317 autocheckout_manager_->ShowAutocheckoutDialog(frame_url, ssl_status); 319 autocheckout_manager_->ShowAutocheckoutDialog(frame_url, ssl_status);
318 320
319 ClearIpcSink(); 321 ClearIpcSink();
320 322
321 // Test if autocheckout manager can fill the first page. 323 // Test if autocheckout manager can fill the first page.
322 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure()); 324 autofill_manager_->SetFormStructure(CreateTestAddressFormStructure());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 autocheckout_manager_->FillForms(); 364 autocheckout_manager_->FillForms();
363 365
364 filled_forms = ReadFilledForms(); 366 filled_forms = ReadFilledForms();
365 ASSERT_EQ(1U, filled_forms.size()); 367 ASSERT_EQ(1U, filled_forms.size());
366 ASSERT_EQ(2U, filled_forms[0].fields.size()); 368 ASSERT_EQ(2U, filled_forms[0].fields.size());
367 EXPECT_FALSE(filled_forms[0].fields[0].is_checked); 369 EXPECT_FALSE(filled_forms[0].fields[0].is_checked);
368 EXPECT_EQ(ASCIIToUTF16("male"), filled_forms[0].fields[0].value); 370 EXPECT_EQ(ASCIIToUTF16("male"), filled_forms[0].fields[0].value);
369 EXPECT_TRUE(filled_forms[0].fields[1].is_checked); 371 EXPECT_TRUE(filled_forms[0].fields[1].is_checked);
370 EXPECT_EQ(ASCIIToUTF16("female"), filled_forms[0].fields[1].value); 372 EXPECT_EQ(ASCIIToUTF16("female"), filled_forms[0].fields[1].value);
371 } 373 }
374
375 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autocheckout_manager.cc ('k') | chrome/browser/autofill/autofill_external_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698