| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 11 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
| 12 #include "chrome/browser/autofill/autofill_common_test.h" | 12 #include "chrome/browser/autofill/autofill_common_test.h" |
| 13 #include "chrome/browser/autofill/autofill_manager.h" | 13 #include "chrome/browser/autofill/autofill_manager.h" |
| 14 #include "chrome/browser/autofill/autofill_metrics.h" | 14 #include "chrome/browser/autofill/autofill_metrics.h" |
| 15 #include "chrome/browser/autofill/personal_data_manager.h" | 15 #include "chrome/browser/autofill/personal_data_manager.h" |
| 16 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 16 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 18 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" |
| 19 #include "chrome/browser/webdata/web_data_service.h" | 19 #include "chrome/browser/webdata/web_data_service.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "content/browser/tab_contents/test_tab_contents.h" | 21 #include "content/browser/tab_contents/test_tab_contents.h" |
| 22 #include "content/test/test_browser_thread.h" | 22 #include "content/test/test_browser_thread.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 25 #include "ui/gfx/rect.h" |
| 25 #include "webkit/glue/form_data.h" | 26 #include "webkit/glue/form_data.h" |
| 26 #include "webkit/glue/form_field.h" | 27 #include "webkit/glue/form_field.h" |
| 27 | 28 |
| 28 using content::BrowserThread; | 29 using content::BrowserThread; |
| 29 using ::testing::_; | 30 using ::testing::_; |
| 30 using ::testing::AnyNumber; | 31 using ::testing::AnyNumber; |
| 31 using ::testing::Mock; | 32 using ::testing::Mock; |
| 32 using base::TimeTicks; | 33 using base::TimeTicks; |
| 33 using base::TimeDelta; | 34 using base::TimeDelta; |
| 34 using webkit_glue::FormData; | 35 using webkit_glue::FormData; |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 autofill_manager_->AddSeenForm(form, field_types, field_types, | 970 autofill_manager_->AddSeenForm(form, field_types, field_types, |
| 970 std::string()); | 971 std::string()); |
| 971 | 972 |
| 972 // Establish our expectations. | 973 // Establish our expectations. |
| 973 ::testing::FLAGS_gmock_verbose = "error"; | 974 ::testing::FLAGS_gmock_verbose = "error"; |
| 974 ::testing::InSequence dummy; | 975 ::testing::InSequence dummy; |
| 975 EXPECT_CALL(*autofill_manager_->metric_logger(), | 976 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 976 LogAddressSuggestionsCount(2)).Times(1); | 977 LogAddressSuggestionsCount(2)).Times(1); |
| 977 | 978 |
| 978 // Simulate activating the autofill popup for the phone field. | 979 // Simulate activating the autofill popup for the phone field. |
| 979 autofill_manager_->OnQueryFormFieldAutofill(0, form, field); | 980 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect()); |
| 980 | 981 |
| 981 // Simulate activating the autofill popup for the email field after typing. | 982 // Simulate activating the autofill popup for the email field after typing. |
| 982 // No new metric should be logged, since we're still on the same page. | 983 // No new metric should be logged, since we're still on the same page. |
| 983 autofill_test::CreateTestFormField("Email", "email", "b", "email", &field); | 984 autofill_test::CreateTestFormField("Email", "email", "b", "email", &field); |
| 984 autofill_manager_->OnQueryFormFieldAutofill(0, form, field); | 985 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect()); |
| 985 | 986 |
| 986 // Reset the autofill manager state. | 987 // Reset the autofill manager state. |
| 987 autofill_manager_->Reset(); | 988 autofill_manager_->Reset(); |
| 988 autofill_manager_->AddSeenForm(form, field_types, field_types, | 989 autofill_manager_->AddSeenForm(form, field_types, field_types, |
| 989 std::string()); | 990 std::string()); |
| 990 | 991 |
| 991 // Establish our expectations. | 992 // Establish our expectations. |
| 992 EXPECT_CALL(*autofill_manager_->metric_logger(), | 993 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 993 LogAddressSuggestionsCount(1)).Times(1); | 994 LogAddressSuggestionsCount(1)).Times(1); |
| 994 | 995 |
| 995 // Simulate activating the autofill popup for the email field after typing. | 996 // Simulate activating the autofill popup for the email field after typing. |
| 996 autofill_manager_->OnQueryFormFieldAutofill(0, form, field); | 997 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect()); |
| 997 | 998 |
| 998 // Reset the autofill manager state again. | 999 // Reset the autofill manager state again. |
| 999 autofill_manager_->Reset(); | 1000 autofill_manager_->Reset(); |
| 1000 autofill_manager_->AddSeenForm(form, field_types, field_types, | 1001 autofill_manager_->AddSeenForm(form, field_types, field_types, |
| 1001 std::string()); | 1002 std::string()); |
| 1002 | 1003 |
| 1003 // Establish our expectations. | 1004 // Establish our expectations. |
| 1004 EXPECT_CALL(*autofill_manager_->metric_logger(), | 1005 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 1005 LogAddressSuggestionsCount(::testing::_)).Times(0); | 1006 LogAddressSuggestionsCount(::testing::_)).Times(0); |
| 1006 | 1007 |
| 1007 // Simulate activating the autofill popup for the email field after typing. | 1008 // Simulate activating the autofill popup for the email field after typing. |
| 1008 form.fields[0].is_autofilled = true; | 1009 form.fields[0].is_autofilled = true; |
| 1009 autofill_manager_->OnQueryFormFieldAutofill(0, form, field); | 1010 autofill_manager_->OnQueryFormFieldAutofill(0, form, field, gfx::Rect()); |
| 1010 } | 1011 } |
| 1011 | 1012 |
| 1012 // Test that we log whether Autofill is enabled when filling a form. | 1013 // Test that we log whether Autofill is enabled when filling a form. |
| 1013 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { | 1014 TEST_F(AutofillMetricsTest, AutofillIsEnabledAtPageLoad) { |
| 1014 // Establish our expectations. | 1015 // Establish our expectations. |
| 1015 ::testing::FLAGS_gmock_verbose = "error"; | 1016 ::testing::FLAGS_gmock_verbose = "error"; |
| 1016 ::testing::InSequence dummy; | 1017 ::testing::InSequence dummy; |
| 1017 EXPECT_CALL(*autofill_manager_->metric_logger(), | 1018 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 1018 LogIsAutofillEnabledAtPageLoad(true)).Times(1); | 1019 LogIsAutofillEnabledAtPageLoad(true)).Times(1); |
| 1019 | 1020 |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1460 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), | 1461 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), |
| 1461 TimeTicks::FromInternalValue(3)); | 1462 TimeTicks::FromInternalValue(3)); |
| 1462 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); | 1463 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); |
| 1463 autofill_manager_->Reset(); | 1464 autofill_manager_->Reset(); |
| 1464 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); | 1465 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); |
| 1465 } | 1466 } |
| 1466 | 1467 |
| 1467 // Restore the global Gmock verbosity level to its default value. | 1468 // Restore the global Gmock verbosity level to its default value. |
| 1468 ::testing::FLAGS_gmock_verbose = "warning"; | 1469 ::testing::FLAGS_gmock_verbose = "warning"; |
| 1469 } | 1470 } |
| OLD | NEW |