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

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

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Rebase Created 3 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
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/test/histogram_tester.h" 17 #include "base/test/histogram_tester.h"
18 #include "base/test/user_action_tester.h" 18 #include "base/test/user_action_tester.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "components/autofill/core/browser/autofill_clock.h"
20 #include "components/autofill/core/browser/autofill_external_delegate.h" 21 #include "components/autofill/core/browser/autofill_external_delegate.h"
21 #include "components/autofill/core/browser/autofill_manager.h" 22 #include "components/autofill/core/browser/autofill_manager.h"
22 #include "components/autofill/core/browser/autofill_test_utils.h" 23 #include "components/autofill/core/browser/autofill_test_utils.h"
23 #include "components/autofill/core/browser/payments/payments_client.h" 24 #include "components/autofill/core/browser/payments/payments_client.h"
24 #include "components/autofill/core/browser/personal_data_manager.h" 25 #include "components/autofill/core/browser/personal_data_manager.h"
25 #include "components/autofill/core/browser/test_autofill_client.h" 26 #include "components/autofill/core/browser/test_autofill_client.h"
26 #include "components/autofill/core/browser/test_autofill_driver.h" 27 #include "components/autofill/core/browser/test_autofill_driver.h"
27 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 28 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
28 #include "components/autofill/core/common/form_data.h" 29 #include "components/autofill/core/common/form_data.h"
29 #include "components/autofill/core/common/form_field_data.h" 30 #include "components/autofill/core/common/form_field_data.h"
(...skipping 3584 matching lines...) Expand 10 before | Expand all | Expand 10 after
3614 base::HistogramTester histogram_tester; 3615 base::HistogramTester histogram_tester;
3615 autofill_manager_->set_autofill_enabled(false); 3616 autofill_manager_->set_autofill_enabled(false);
3616 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks()); 3617 autofill_manager_->OnFormsSeen(std::vector<FormData>(), TimeTicks());
3617 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", false, 1); 3618 histogram_tester.ExpectUniqueSample("Autofill.IsEnabled.PageLoad", false, 1);
3618 } 3619 }
3619 3620
3620 // Test that we log the days since last use of a credit card when it is used. 3621 // Test that we log the days since last use of a credit card when it is used.
3621 TEST_F(AutofillMetricsTest, DaysSinceLastUse_CreditCard) { 3622 TEST_F(AutofillMetricsTest, DaysSinceLastUse_CreditCard) {
3622 base::HistogramTester histogram_tester; 3623 base::HistogramTester histogram_tester;
3623 CreditCard credit_card; 3624 CreditCard credit_card;
3624 credit_card.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(21)); 3625 credit_card.set_use_date(AutofillClock::Now() -
3626 base::TimeDelta::FromDays(21));
3625 credit_card.RecordAndLogUse(); 3627 credit_card.RecordAndLogUse();
3626 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.CreditCard", 21, 3628 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.CreditCard", 21,
3627 1); 3629 1);
3628 } 3630 }
3629 3631
3630 // Test that we log the days since last use of a profile when it is used. 3632 // Test that we log the days since last use of a profile when it is used.
3631 TEST_F(AutofillMetricsTest, DaysSinceLastUse_Profile) { 3633 TEST_F(AutofillMetricsTest, DaysSinceLastUse_Profile) {
3632 base::HistogramTester histogram_tester; 3634 base::HistogramTester histogram_tester;
3633 AutofillProfile profile; 3635 AutofillProfile profile;
3634 profile.set_use_date(base::Time::Now() - base::TimeDelta::FromDays(13)); 3636 profile.set_use_date(AutofillClock::Now() - base::TimeDelta::FromDays(13));
3635 profile.RecordAndLogUse(); 3637 profile.RecordAndLogUse();
3636 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13, 3638 histogram_tester.ExpectBucketCount("Autofill.DaysSinceLastUse.Profile", 13,
3637 1); 3639 1);
3638 } 3640 }
3639 3641
3640 // Verify that we correctly log the submitted form's state. 3642 // Verify that we correctly log the submitted form's state.
3641 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) { 3643 TEST_F(AutofillMetricsTest, AutofillFormSubmittedState) {
3642 // Start with a form with insufficiently many fields. 3644 // Start with a form with insufficiently many fields.
3643 FormData form; 3645 FormData form;
3644 form.name = ASCIIToUTF16("TestForm"); 3646 form.name = ASCIIToUTF16("TestForm");
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
4317 EXPECT_THAT( 4319 EXPECT_THAT(
4318 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"), 4320 histogram_tester.GetAllSamples("Autofill.ServerResponseHasDataForForm"),
4319 ElementsAre(Bucket(true, 2))); 4321 ElementsAre(Bucket(true, 2)));
4320 4322
4321 // No RAPPOR metrics are logged in the case there is at least some server data 4323 // No RAPPOR metrics are logged in the case there is at least some server data
4322 // available for all forms. 4324 // available for all forms.
4323 EXPECT_EQ(0, rappor_service_.GetReportsCount()); 4325 EXPECT_EQ(0, rappor_service_.GetReportsCount());
4324 } 4326 }
4325 4327
4326 } // namespace autofill 4328 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698