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

Side by Side Diff: components/autofill/core/browser/autofill_metrics_unittest.cc

Issue 177923004: Moved CCInfobarDelegate tests out of AutofillMetricsTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Response to review Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/autofill/core/browser/autofill_metrics.h" 5 #include "components/autofill/core/browser/autofill_metrics.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h"
15 #include "chrome/browser/autofill/personal_data_manager_factory.h" 14 #include "chrome/browser/autofill/personal_data_manager_factory.h"
16 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h" 15 #include "chrome/browser/ui/autofill/tab_autofill_manager_delegate.h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "chrome/test/base/testing_profile.h" 17 #include "chrome/test/base/testing_profile.h"
19 #include "components/autofill/core/browser/autofill_external_delegate.h" 18 #include "components/autofill/core/browser/autofill_external_delegate.h"
20 #include "components/autofill/core/browser/autofill_manager.h" 19 #include "components/autofill/core/browser/autofill_manager.h"
21 #include "components/autofill/core/browser/autofill_manager_delegate.h" 20 #include "components/autofill/core/browser/autofill_manager_delegate.h"
22 #include "components/autofill/core/browser/autofill_test_utils.h" 21 #include "components/autofill/core/browser/autofill_test_utils.h"
23 #include "components/autofill/core/browser/personal_data_manager.h" 22 #include "components/autofill/core/browser/personal_data_manager.h"
24 #include "components/autofill/core/browser/test_autofill_driver.h" 23 #include "components/autofill/core/browser/test_autofill_driver.h"
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } // namespace 234 } // namespace
236 235
237 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness { 236 class AutofillMetricsTest : public ChromeRenderViewHostTestHarness {
238 public: 237 public:
239 virtual ~AutofillMetricsTest(); 238 virtual ~AutofillMetricsTest();
240 239
241 virtual void SetUp() OVERRIDE; 240 virtual void SetUp() OVERRIDE;
242 virtual void TearDown() OVERRIDE; 241 virtual void TearDown() OVERRIDE;
243 242
244 protected: 243 protected:
245 scoped_ptr<ConfirmInfoBarDelegate> CreateDelegate(
246 MockAutofillMetrics* metric_logger);
247
248 scoped_ptr<TestAutofillDriver> autofill_driver_; 244 scoped_ptr<TestAutofillDriver> autofill_driver_;
249 scoped_ptr<TestAutofillManager> autofill_manager_; 245 scoped_ptr<TestAutofillManager> autofill_manager_;
250 scoped_ptr<TestPersonalDataManager> personal_data_; 246 scoped_ptr<TestPersonalDataManager> personal_data_;
251 scoped_ptr<AutofillExternalDelegate> external_delegate_; 247 scoped_ptr<AutofillExternalDelegate> external_delegate_;
252 }; 248 };
253 249
254 AutofillMetricsTest::~AutofillMetricsTest() { 250 AutofillMetricsTest::~AutofillMetricsTest() {
255 // Order of destruction is important as AutofillManager relies on 251 // Order of destruction is important as AutofillManager relies on
256 // PersonalDataManager to be around when it gets destroyed. 252 // PersonalDataManager to be around when it gets destroyed.
257 autofill_manager_.reset(); 253 autofill_manager_.reset();
(...skipping 26 matching lines...) Expand all
284 280
285 void AutofillMetricsTest::TearDown() { 281 void AutofillMetricsTest::TearDown() {
286 // Order of destruction is important as AutofillManager relies on 282 // Order of destruction is important as AutofillManager relies on
287 // PersonalDataManager to be around when it gets destroyed. 283 // PersonalDataManager to be around when it gets destroyed.
288 autofill_manager_.reset(); 284 autofill_manager_.reset();
289 autofill_driver_.reset(); 285 autofill_driver_.reset();
290 personal_data_.reset(); 286 personal_data_.reset();
291 ChromeRenderViewHostTestHarness::TearDown(); 287 ChromeRenderViewHostTestHarness::TearDown();
292 } 288 }
293 289
294 scoped_ptr<ConfirmInfoBarDelegate> AutofillMetricsTest::CreateDelegate(
295 MockAutofillMetrics* metric_logger) {
296 EXPECT_CALL(*metric_logger,
297 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_SHOWN));
298
299 CreditCard credit_card;
300 return AutofillCCInfoBarDelegate::Create(
301 metric_logger,
302 base::Bind(
303 base::IgnoreResult(&TestPersonalDataManager::SaveImportedCreditCard),
304 base::Unretained(personal_data_.get()), credit_card));
305 }
306
307 // Test that we log quality metrics appropriately. 290 // Test that we log quality metrics appropriately.
308 TEST_F(AutofillMetricsTest, QualityMetrics) { 291 TEST_F(AutofillMetricsTest, QualityMetrics) {
309 // Set up our form data. 292 // Set up our form data.
310 FormData form; 293 FormData form;
311 form.name = ASCIIToUTF16("TestForm"); 294 form.name = ASCIIToUTF16("TestForm");
312 form.method = ASCIIToUTF16("POST"); 295 form.method = ASCIIToUTF16("POST");
313 form.origin = GURL("http://example.com/form.html"); 296 form.origin = GURL("http://example.com/form.html");
314 form.action = GURL("http://example.com/submit.html"); 297 form.action = GURL("http://example.com/submit.html");
315 form.user_submitted = true; 298 form.user_submitted = true;
316 299
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 698
716 // Establish our expectations. 699 // Establish our expectations.
717 EXPECT_CALL(*autofill_manager_->metric_logger(), 700 EXPECT_CALL(*autofill_manager_->metric_logger(),
718 LogIsAutofillEnabledAtPageLoad(false)).Times(1); 701 LogIsAutofillEnabledAtPageLoad(false)).Times(1);
719 702
720 autofill_manager_->set_autofill_enabled(false); 703 autofill_manager_->set_autofill_enabled(false);
721 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks(), 704 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks(),
722 autofill::NO_SPECIAL_FORMS_SEEN); 705 autofill::NO_SPECIAL_FORMS_SEEN);
723 } 706 }
724 707
725 // Test that credit card infobar metrics are logged correctly.
726 TEST_F(AutofillMetricsTest, CreditCardInfoBar) {
727 testing::NiceMock<MockAutofillMetrics> metric_logger;
728 ::testing::InSequence dummy;
729
730 // Accept the infobar.
731 {
732 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
733 ASSERT_TRUE(infobar);
734 EXPECT_CALL(*personal_data_, SaveImportedCreditCard(_));
735 EXPECT_CALL(metric_logger,
736 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_ACCEPTED)).Times(1);
737 EXPECT_CALL(metric_logger,
738 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
739 EXPECT_TRUE(infobar->Accept());
740 }
741
742 // Cancel the infobar.
743 {
744 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
745 ASSERT_TRUE(infobar);
746 EXPECT_CALL(metric_logger,
747 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
748 EXPECT_CALL(metric_logger,
749 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
750 EXPECT_TRUE(infobar->Cancel());
751 }
752
753 // Dismiss the infobar.
754 {
755 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
756 ASSERT_TRUE(infobar);
757 EXPECT_CALL(metric_logger,
758 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_DENIED)).Times(1);
759 EXPECT_CALL(metric_logger,
760 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(0);
761 infobar->InfoBarDismissed();
762 }
763
764 // Ignore the infobar.
765 {
766 scoped_ptr<ConfirmInfoBarDelegate> infobar(CreateDelegate(&metric_logger));
767 ASSERT_TRUE(infobar);
768 EXPECT_CALL(metric_logger,
769 LogCreditCardInfoBarMetric(AutofillMetrics::INFOBAR_IGNORED)).Times(1);
770 }
771 }
772
773 // Verify that we correctly log user happiness metrics dealing with form loading 708 // Verify that we correctly log user happiness metrics dealing with form loading
774 // and form submission. 709 // and form submission.
775 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) { 710 TEST_F(AutofillMetricsTest, UserHappinessFormLoadAndSubmission) {
776 // Start with a form with insufficiently many fields. 711 // Start with a form with insufficiently many fields.
777 FormData form; 712 FormData form;
778 form.name = ASCIIToUTF16("TestForm"); 713 form.name = ASCIIToUTF16("TestForm");
779 form.method = ASCIIToUTF16("POST"); 714 form.method = ASCIIToUTF16("POST");
780 form.origin = GURL("http://example.com/form.html"); 715 form.origin = GURL("http://example.com/form.html");
781 form.action = GURL("http://example.com/submit.html"); 716 form.action = GURL("http://example.com/submit.html");
782 form.user_submitted = true; 717 form.user_submitted = true;
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 TimeTicks::FromInternalValue(5)); 1061 TimeTicks::FromInternalValue(5));
1127 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(), 1062 autofill_manager_->OnTextFieldDidChange(form, form.fields.front(),
1128 TimeTicks::FromInternalValue(3)); 1063 TimeTicks::FromInternalValue(3));
1129 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17)); 1064 autofill_manager_->FormSubmitted(form, TimeTicks::FromInternalValue(17));
1130 autofill_manager_->Reset(); 1065 autofill_manager_->Reset();
1131 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger()); 1066 Mock::VerifyAndClearExpectations(autofill_manager_->metric_logger());
1132 } 1067 }
1133 } 1068 }
1134 1069
1135 } // namespace autofill 1070 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698