| 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/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 private: | 176 private: |
| 177 std::string server_experiment_id_; | 177 std::string server_experiment_id_; |
| 178 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); | 178 DISALLOW_COPY_AND_ASSIGN(TestFormStructure); |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 } // namespace | 181 } // namespace |
| 182 | 182 |
| 183 class AutofillMetricsTest : public TabContentsWrapperTestHarness { | 183 class AutofillMetricsTest : public TabContentsWrapperTestHarness { |
| 184 public: | 184 public: |
| 185 AutofillMetricsTest() {} | 185 AutofillMetricsTest(); |
| 186 virtual ~AutofillMetricsTest() { | 186 virtual ~AutofillMetricsTest(); |
| 187 // Order of destruction is important as AutofillManager relies on | |
| 188 // PersonalDataManager to be around when it gets destroyed. | |
| 189 autofill_manager_.reset(NULL); | |
| 190 test_personal_data_ = NULL; | |
| 191 } | |
| 192 | 187 |
| 193 virtual void SetUp() { | 188 virtual void SetUp(); |
| 194 TabContentsWrapperTestHarness::SetUp(); | |
| 195 test_personal_data_ = new TestPersonalDataManager(); | |
| 196 autofill_manager_.reset(new TestAutofillManager(contents_wrapper(), | |
| 197 test_personal_data_.get())); | |
| 198 } | |
| 199 | 189 |
| 200 protected: | 190 protected: |
| 191 AutofillCCInfoBarDelegate* CreateDelegate(MockAutofillMetrics* metric_logger, |
| 192 CreditCard** created_card); |
| 193 |
| 201 scoped_ptr<TestAutofillManager> autofill_manager_; | 194 scoped_ptr<TestAutofillManager> autofill_manager_; |
| 202 scoped_refptr<TestPersonalDataManager> test_personal_data_; | 195 scoped_refptr<TestPersonalDataManager> test_personal_data_; |
| 203 | 196 |
| 204 private: | 197 private: |
| 205 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); | 198 DISALLOW_COPY_AND_ASSIGN(AutofillMetricsTest); |
| 206 }; | 199 }; |
| 207 | 200 |
| 201 AutofillMetricsTest::AutofillMetricsTest() { |
| 202 } |
| 203 |
| 204 AutofillMetricsTest::~AutofillMetricsTest() { |
| 205 // Order of destruction is important as AutofillManager relies on |
| 206 // PersonalDataManager to be around when it gets destroyed. |
| 207 autofill_manager_.reset(NULL); |
| 208 test_personal_data_ = NULL; |
| 209 } |
| 210 |
| 211 void AutofillMetricsTest::SetUp() { |
| 212 TabContentsWrapperTestHarness::SetUp(); |
| 213 test_personal_data_ = new TestPersonalDataManager(); |
| 214 autofill_manager_.reset(new TestAutofillManager(contents_wrapper(), |
| 215 test_personal_data_.get())); |
| 216 } |
| 217 |
| 218 AutofillCCInfoBarDelegate* AutofillMetricsTest::CreateDelegate( |
| 219 MockAutofillMetrics* metric_logger, |
| 220 CreditCard** created_card) { |
| 221 EXPECT_CALL(*metric_logger, |
| 222 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); |
| 223 // The delegate created below will take ownership of this object. |
| 224 CreditCard* credit_card = new CreditCard(); |
| 225 if (created_card) |
| 226 *created_card = credit_card; |
| 227 return new AutofillCCInfoBarDelegate(contents(), credit_card, |
| 228 test_personal_data_.get(), metric_logger); |
| 229 } |
| 230 |
| 208 // Test that we log quality metrics appropriately. | 231 // Test that we log quality metrics appropriately. |
| 209 TEST_F(AutofillMetricsTest, QualityMetrics) { | 232 TEST_F(AutofillMetricsTest, QualityMetrics) { |
| 210 // Set up our form data. | 233 // Set up our form data. |
| 211 FormData form; | 234 FormData form; |
| 212 form.name = ASCIIToUTF16("TestForm"); | 235 form.name = ASCIIToUTF16("TestForm"); |
| 213 form.method = ASCIIToUTF16("POST"); | 236 form.method = ASCIIToUTF16("POST"); |
| 214 form.origin = GURL("http://example.com/form.html"); | 237 form.origin = GURL("http://example.com/form.html"); |
| 215 form.action = GURL("http://example.com/submit.html"); | 238 form.action = GURL("http://example.com/submit.html"); |
| 216 form.user_submitted = true; | 239 form.user_submitted = true; |
| 217 | 240 |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 EXPECT_CALL(*autofill_manager_->metric_logger(), | 909 EXPECT_CALL(*autofill_manager_->metric_logger(), |
| 887 LogIsAutofillEnabledAtPageLoad(false)).Times(1); | 910 LogIsAutofillEnabledAtPageLoad(false)).Times(1); |
| 888 | 911 |
| 889 autofill_manager_->set_autofill_enabled(false); | 912 autofill_manager_->set_autofill_enabled(false); |
| 890 autofill_manager_->OnFormsSeen(std::vector<FormData>()); | 913 autofill_manager_->OnFormsSeen(std::vector<FormData>()); |
| 891 } | 914 } |
| 892 | 915 |
| 893 // Test that credit card infobar metrics are logged correctly. | 916 // Test that credit card infobar metrics are logged correctly. |
| 894 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { | 917 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { |
| 895 MockAutofillMetrics metric_logger; | 918 MockAutofillMetrics metric_logger; |
| 896 CreditCard* credit_card; | |
| 897 AutofillCCInfoBarDelegate* infobar; | |
| 898 ::testing::InSequence dummy; | 919 ::testing::InSequence dummy; |
| 899 | 920 |
| 900 // Accept the infobar. | 921 // Accept the infobar. |
| 901 EXPECT_CALL(metric_logger, | 922 { |
| 902 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 923 CreditCard* credit_card; |
| 903 credit_card = new CreditCard(); | 924 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, |
| 904 infobar = new AutofillCCInfoBarDelegate(contents(), | 925 &credit_card)); |
| 905 credit_card, | 926 EXPECT_CALL(*test_personal_data_.get(), |
| 906 test_personal_data_.get(), | 927 SaveImportedCreditCard(*credit_card)); |
| 907 &metric_logger); | 928 EXPECT_CALL(metric_logger, |
| 908 | 929 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1); |
| 909 EXPECT_CALL(*test_personal_data_.get(), SaveImportedCreditCard(*credit_card)); | 930 EXPECT_CALL(metric_logger, |
| 910 EXPECT_CALL(metric_logger, | 931 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 911 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)) | 932 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Accept()); |
| 912 .Times(1); | 933 } |
| 913 EXPECT_CALL(metric_logger, | |
| 914 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) | |
| 915 .Times(0); | |
| 916 EXPECT_TRUE(infobar->Accept()); | |
| 917 infobar->InfoBarClosed(); | |
| 918 | 934 |
| 919 // Cancel the infobar. | 935 // Cancel the infobar. |
| 920 EXPECT_CALL(metric_logger, | 936 { |
| 921 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 937 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); |
| 922 credit_card = new CreditCard(); | 938 EXPECT_CALL(metric_logger, |
| 923 infobar = new AutofillCCInfoBarDelegate(contents(), | 939 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 924 credit_card, | 940 EXPECT_CALL(metric_logger, |
| 925 test_personal_data_.get(), | 941 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 926 &metric_logger); | 942 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Cancel()); |
| 927 | 943 } |
| 928 EXPECT_CALL(metric_logger, | |
| 929 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)) | |
| 930 .Times(1); | |
| 931 EXPECT_CALL(metric_logger, | |
| 932 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) | |
| 933 .Times(0); | |
| 934 EXPECT_TRUE(infobar->Cancel()); | |
| 935 infobar->InfoBarClosed(); | |
| 936 | 944 |
| 937 // Dismiss the infobar. | 945 // Dismiss the infobar. |
| 938 EXPECT_CALL(metric_logger, | 946 { |
| 939 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 947 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); |
| 940 credit_card = new CreditCard(); | 948 EXPECT_CALL(metric_logger, |
| 941 infobar = new AutofillCCInfoBarDelegate(contents(), | 949 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1); |
| 942 credit_card, | 950 EXPECT_CALL(metric_logger, |
| 943 test_personal_data_.get(), | 951 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0); |
| 944 &metric_logger); | 952 infobar->InfoBarDismissed(); |
| 945 | 953 } |
| 946 EXPECT_CALL(metric_logger, | |
| 947 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)) | |
| 948 .Times(1); | |
| 949 EXPECT_CALL(metric_logger, | |
| 950 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) | |
| 951 .Times(0); | |
| 952 infobar->InfoBarDismissed(); | |
| 953 infobar->InfoBarClosed(); | |
| 954 | 954 |
| 955 // Ignore the infobar. | 955 // Ignore the infobar. |
| 956 EXPECT_CALL(metric_logger, | 956 { |
| 957 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); | 957 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL)); |
| 958 credit_card = new CreditCard(); | 958 EXPECT_CALL(metric_logger, |
| 959 infobar = new AutofillCCInfoBarDelegate(contents(), | 959 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1); |
| 960 credit_card, | 960 } |
| 961 test_personal_data_.get(), | |
| 962 &metric_logger); | |
| 963 | |
| 964 EXPECT_CALL(metric_logger, | |
| 965 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)) | |
| 966 .Times(1); | |
| 967 infobar->InfoBarClosed(); | |
| 968 } | 961 } |
| OLD | NEW |