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

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

Issue 6989001: Misc. infobar stuff: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 7 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) 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
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(),
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(),
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 CreditCard* credit_card = new CreditCard();
sky 2011/05/09 22:56:39 How about a comment about ownership of CreditCard?
Peter Kasting 2011/05/09 23:23:33 Sure.
224 if (created_card)
225 *created_card = credit_card;
226 return new AutofillCCInfoBarDelegate(contents(), credit_card,
227 test_personal_data_.get(), metric_logger);
228 }
229
208 // Test that we log quality metrics appropriately. 230 // Test that we log quality metrics appropriately.
209 TEST_F(AutofillMetricsTest, QualityMetrics) { 231 TEST_F(AutofillMetricsTest, QualityMetrics) {
210 // Set up our form data. 232 // Set up our form data.
211 FormData form; 233 FormData form;
212 form.name = ASCIIToUTF16("TestForm"); 234 form.name = ASCIIToUTF16("TestForm");
213 form.method = ASCIIToUTF16("POST"); 235 form.method = ASCIIToUTF16("POST");
214 form.origin = GURL("http://example.com/form.html"); 236 form.origin = GURL("http://example.com/form.html");
215 form.action = GURL("http://example.com/submit.html"); 237 form.action = GURL("http://example.com/submit.html");
216 form.user_submitted = true; 238 form.user_submitted = true;
217 239
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 EXPECT_CALL(*autofill_manager_->metric_logger(), 908 EXPECT_CALL(*autofill_manager_->metric_logger(),
887 LogIsAutofillEnabledAtPageLoad(false)).Times(1); 909 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
888 910
889 autofill_manager_->set_autofill_enabled(false); 911 autofill_manager_->set_autofill_enabled(false);
890 autofill_manager_->OnFormsSeen(std::vector<FormData>()); 912 autofill_manager_->OnFormsSeen(std::vector<FormData>());
891 } 913 }
892 914
893 // Test that credit card infobar metrics are logged correctly. 915 // Test that credit card infobar metrics are logged correctly.
894 TEST_F(AutofillMetricsTest, CreditCardInfoBar) { 916 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
895 MockAutofillMetrics metric_logger; 917 MockAutofillMetrics metric_logger;
896 CreditCard* credit_card;
897 AutofillCCInfoBarDelegate* infobar;
898 ::testing::InSequence dummy; 918 ::testing::InSequence dummy;
899 919
900 // Accept the infobar. 920 // Accept the infobar.
901 EXPECT_CALL(metric_logger, 921 {
902 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 922 CreditCard* credit_card;
903 credit_card = new CreditCard(); 923 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger,
904 infobar = new AutofillCCInfoBarDelegate(contents(), 924 &credit_card));
905 credit_card, 925 EXPECT_CALL(*test_personal_data_.get(),
906 test_personal_data_.get(), 926 SaveImportedCreditCard(*credit_card));
907 &metric_logger); 927 EXPECT_CALL(metric_logger,
908 928 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
909 EXPECT_CALL(*test_personal_data_.get(), SaveImportedCreditCard(*credit_card)); 929 EXPECT_CALL(metric_logger,
910 EXPECT_CALL(metric_logger, 930 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
911 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)) 931 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Accept());
912 .Times(1); 932 }
913 EXPECT_CALL(metric_logger,
914 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED))
915 .Times(0);
916 EXPECT_TRUE(infobar->Accept());
917 infobar->InfoBarClosed();
918 933
919 // Cancel the infobar. 934 // Cancel the infobar.
920 EXPECT_CALL(metric_logger, 935 {
921 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 936 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
922 credit_card = new CreditCard(); 937 EXPECT_CALL(metric_logger,
923 infobar = new AutofillCCInfoBarDelegate(contents(), 938 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
924 credit_card, 939 EXPECT_CALL(metric_logger,
925 test_personal_data_.get(), 940 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
926 &metric_logger); 941 EXPECT_TRUE(static_cast<ConfirmInfoBarDelegate*>(infobar.get())->Cancel());
927 942 }
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 943
937 // Dismiss the infobar. 944 // Dismiss the infobar.
938 EXPECT_CALL(metric_logger, 945 {
939 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 946 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
940 credit_card = new CreditCard(); 947 EXPECT_CALL(metric_logger,
941 infobar = new AutofillCCInfoBarDelegate(contents(), 948 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
942 credit_card, 949 EXPECT_CALL(metric_logger,
943 test_personal_data_.get(), 950 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
944 &metric_logger); 951 infobar->InfoBarDismissed();
945 952 }
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 953
955 // Ignore the infobar. 954 // Ignore the infobar.
956 EXPECT_CALL(metric_logger, 955 {
957 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN)); 956 scoped_ptr<InfoBarDelegate> infobar(CreateDelegate(&metric_logger, NULL));
958 credit_card = new CreditCard(); 957 EXPECT_CALL(metric_logger,
959 infobar = new AutofillCCInfoBarDelegate(contents(), 958 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
960 credit_card, 959 }
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 } 960 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698