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

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

Issue 6259017: Fix crash in autofill metrics logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace Created 9 years, 11 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
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <vector> 5 #include <vector>
6 6
7 #include "base/ref_counted.h" 7 #include "base/ref_counted.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 autofill_test::CreateTestFormField( 196 autofill_test::CreateTestFormField(
197 "Empty", "empty", "", "text", &field); 197 "Empty", "empty", "", "text", &field);
198 form.fields.push_back(field); 198 form.fields.push_back(field);
199 autofill_test::CreateTestFormField( 199 autofill_test::CreateTestFormField(
200 "Unknown", "unknown", "garbage", "text", &field); 200 "Unknown", "unknown", "garbage", "text", &field);
201 form.fields.push_back(field); 201 form.fields.push_back(field);
202 autofill_test::CreateTestFormField( 202 autofill_test::CreateTestFormField(
203 "Select", "select", "USA", "select-one", &field); 203 "Select", "select", "USA", "select-one", &field);
204 form.fields.push_back(field); 204 form.fields.push_back(field);
205 205
206 // Simulate having seen this form on page load.
207 // |form_structure| will be owned by |autofill_manager_|.
208 TestFormStructure* form_structure = new TestFormStructure(form);
209 autofill_manager_->AddSeenForm(form_structure);
210
206 // Establish our expectations. 211 // Establish our expectations.
207 ::testing::InSequence dummy; 212 ::testing::InSequence dummy;
208 EXPECT_CALL(*autofill_manager_->metric_logger(), 213 EXPECT_CALL(*autofill_manager_->metric_logger(),
209 Log(AutoFillMetrics::FIELD_SUBMITTED)); 214 Log(AutoFillMetrics::FIELD_SUBMITTED));
210 EXPECT_CALL(*autofill_manager_->metric_logger(), 215 EXPECT_CALL(*autofill_manager_->metric_logger(),
211 Log(AutoFillMetrics::FIELD_AUTOFILLED)); 216 Log(AutoFillMetrics::FIELD_AUTOFILLED));
212 EXPECT_CALL(*autofill_manager_->metric_logger(), 217 EXPECT_CALL(*autofill_manager_->metric_logger(),
213 Log(AutoFillMetrics::FIELD_SUBMITTED)); 218 Log(AutoFillMetrics::FIELD_SUBMITTED));
214 EXPECT_CALL(*autofill_manager_->metric_logger(), 219 EXPECT_CALL(*autofill_manager_->metric_logger(),
215 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED)); 220 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 server_types.push_back(failure_cases[i].server_type); 317 server_types.push_back(failure_cases[i].server_type);
313 318
314 } 319 }
315 320
316 // Simulate having seen this form with the desired heuristic and server types. 321 // Simulate having seen this form with the desired heuristic and server types.
317 // |form_structure| will be owned by |autofill_manager_|. 322 // |form_structure| will be owned by |autofill_manager_|.
318 TestFormStructure* form_structure = new TestFormStructure(form); 323 TestFormStructure* form_structure = new TestFormStructure(form);
319 form_structure->SetFieldTypes(heuristic_types, server_types); 324 form_structure->SetFieldTypes(heuristic_types, server_types);
320 autofill_manager_->AddSeenForm(form_structure); 325 autofill_manager_->AddSeenForm(form_structure);
321 326
322 // Establish our expectations. Only print gmock errors, as the warnings are 327 // Establish our expectations.
323 // too verbose.
324 ::testing::InSequence dummy; 328 ::testing::InSequence dummy;
325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) { 329 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(failure_cases); ++i) {
326 EXPECT_CALL(*autofill_manager_->metric_logger(), 330 EXPECT_CALL(*autofill_manager_->metric_logger(),
327 Log(AutoFillMetrics::FIELD_SUBMITTED)); 331 Log(AutoFillMetrics::FIELD_SUBMITTED));
328 EXPECT_CALL(*autofill_manager_->metric_logger(), 332 EXPECT_CALL(*autofill_manager_->metric_logger(),
329 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED)); 333 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED));
330 EXPECT_CALL(*autofill_manager_->metric_logger(), 334 EXPECT_CALL(*autofill_manager_->metric_logger(),
331 Log(failure_cases[i].heuristic_metric)); 335 Log(failure_cases[i].heuristic_metric));
332 EXPECT_CALL(*autofill_manager_->metric_logger(), 336 EXPECT_CALL(*autofill_manager_->metric_logger(),
333 Log(failure_cases[i].server_metric)); 337 Log(failure_cases[i].server_metric));
334 } 338 }
335 339
336 // Simulate form submission. 340 // Simulate form submission.
337 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 341 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
338 } 342 }
339 343
344 // Test that we behave sanely when the cached form differs from the submitted
345 // one.
346 TEST_F(AutoFillMetricsTest, SaneMetricsWithCacheMismatch) {
347 // Set up our form data.
348 FormData form;
349 form.name = ASCIIToUTF16("TestForm");
350 form.method = ASCIIToUTF16("POST");
351 form.origin = GURL("http://example.com/form.html");
352 form.action = GURL("http://example.com/submit.html");
353 form.user_submitted = true;
354
355 std::vector<AutoFillFieldType> heuristic_types, server_types;
356
357 FormField field;
358 autofill_test::CreateTestFormField(
359 "Both match", "match", "Elvis Presley", "text", &field);
360 field.set_autofilled(true);
361 form.fields.push_back(field);
362 heuristic_types.push_back(NAME_FULL);
363 server_types.push_back(NAME_FULL);
364 autofill_test::CreateTestFormField(
365 "Both mismatch", "mismatch", "buddy@gmail.com", "text", &field);
366 form.fields.push_back(field);
367 heuristic_types.push_back(PHONE_HOME_NUMBER);
368 server_types.push_back(PHONE_HOME_NUMBER);
369 autofill_test::CreateTestFormField(
370 "Only heuristics match", "mixed", "Memphis", "text", &field);
371 form.fields.push_back(field);
372 heuristic_types.push_back(ADDRESS_HOME_CITY);
373 server_types.push_back(PHONE_HOME_NUMBER);
374 autofill_test::CreateTestFormField(
375 "Unknown", "unknown", "garbage", "text", &field);
376 form.fields.push_back(field);
377 heuristic_types.push_back(UNKNOWN_TYPE);
378 server_types.push_back(UNKNOWN_TYPE);
379
380 // Simulate having seen this form with the desired heuristic and server types.
381 // |form_structure| will be owned by |autofill_manager_|.
382 TestFormStructure* form_structure = new TestFormStructure(form);
383 form_structure->SetFieldTypes(heuristic_types, server_types);
384 autofill_manager_->AddSeenForm(form_structure);
385
386 // Add a field and re-arrange the remaining form fields before submitting.
387 std::vector<FormField> cached_fields = form.fields;
388 form.fields.clear();
389 autofill_test::CreateTestFormField(
390 "New field", "new field", "Tennessee", "text", &field);
391 form.fields.push_back(field);
392 form.fields.push_back(cached_fields[2]);
393 form.fields.push_back(cached_fields[1]);
394 form.fields.push_back(cached_fields[3]);
395 form.fields.push_back(cached_fields[0]);
396
397 // Establish our expectations.
398 ::testing::InSequence dummy;
399 EXPECT_CALL(*autofill_manager_->metric_logger(),
400 Log(AutoFillMetrics::FIELD_SUBMITTED));
401 EXPECT_CALL(*autofill_manager_->metric_logger(),
402 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED));
403 EXPECT_CALL(*autofill_manager_->metric_logger(),
404 Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN));
405 EXPECT_CALL(*autofill_manager_->metric_logger(),
406 Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN));
407 EXPECT_CALL(*autofill_manager_->metric_logger(),
408 Log(AutoFillMetrics::FIELD_SUBMITTED));
409 EXPECT_CALL(*autofill_manager_->metric_logger(),
410 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED));
411 EXPECT_CALL(*autofill_manager_->metric_logger(),
412 Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH));
413 EXPECT_CALL(*autofill_manager_->metric_logger(),
414 Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH));
415 EXPECT_CALL(*autofill_manager_->metric_logger(),
416 Log(AutoFillMetrics::FIELD_SUBMITTED));
417 EXPECT_CALL(*autofill_manager_->metric_logger(),
418 Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED));
419 EXPECT_CALL(*autofill_manager_->metric_logger(),
420 Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH));
421 EXPECT_CALL(*autofill_manager_->metric_logger(),
422 Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH));
423 EXPECT_CALL(*autofill_manager_->metric_logger(),
424 Log(AutoFillMetrics::FIELD_SUBMITTED));
425 EXPECT_CALL(*autofill_manager_->metric_logger(),
426 Log(AutoFillMetrics::FIELD_SUBMITTED));
427 EXPECT_CALL(*autofill_manager_->metric_logger(),
428 Log(AutoFillMetrics::FIELD_AUTOFILLED));
429
430 // Simulate form submission.
431 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
432 }
433
340 // Test that we don't log quality metrics for non-autofillable forms. 434 // Test that we don't log quality metrics for non-autofillable forms.
341 TEST_F(AutoFillMetricsTest, NoQualityMetricsForNonAutoFillableForms) { 435 TEST_F(AutoFillMetricsTest, NoQualityMetricsForNonAutoFillableForms) {
342 // Forms must include at least three fields to be auto-fillable. 436 // Forms must include at least three fields to be auto-fillable.
343 FormData form; 437 FormData form;
344 form.name = ASCIIToUTF16("TestForm"); 438 form.name = ASCIIToUTF16("TestForm");
345 form.method = ASCIIToUTF16("POST"); 439 form.method = ASCIIToUTF16("POST");
346 form.origin = GURL("http://example.com/form.html"); 440 form.origin = GURL("http://example.com/form.html");
347 form.action = GURL("http://example.com/submit.html"); 441 form.action = GURL("http://example.com/submit.html");
348 form.user_submitted = true; 442 form.user_submitted = true;
349 443
(...skipping 15 matching lines...) Expand all
365 form.action = GURL("http://example.com/search?q=Elvis%20Presley"); 459 form.action = GURL("http://example.com/search?q=Elvis%20Presley");
366 autofill_test::CreateTestFormField( 460 autofill_test::CreateTestFormField(
367 "Empty", "empty", "", "text", &field); 461 "Empty", "empty", "", "text", &field);
368 form.fields.push_back(field); 462 form.fields.push_back(field);
369 463
370 // Simulate form submission. 464 // Simulate form submission.
371 EXPECT_CALL(*autofill_manager_->metric_logger(), 465 EXPECT_CALL(*autofill_manager_->metric_logger(),
372 Log(AutoFillMetrics::FIELD_SUBMITTED)).Times(0); 466 Log(AutoFillMetrics::FIELD_SUBMITTED)).Times(0);
373 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form)); 467 EXPECT_NO_FATAL_FAILURE(autofill_manager_->OnFormSubmitted(form));
374 } 468 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698