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

Side by Side Diff: components/autofill/core/browser/webdata/autofill_table_unittest.cc

Issue 2639403002: [Autofill] Remove direct use of base::Time::Now() in Autofill (Closed)
Patch Set: Rebase Created 3 years, 10 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
17 #include "base/guid.h" 17 #include "base/guid.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/memory/scoped_vector.h" 19 #include "base/memory/scoped_vector.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
24 #include "base/time/time.h" 24 #include "base/time/time.h"
25 #include "build/build_config.h" 25 #include "build/build_config.h"
26 #include "components/autofill/core/browser/autofill_clock.h"
26 #include "components/autofill/core/browser/autofill_profile.h" 27 #include "components/autofill/core/browser/autofill_profile.h"
27 #include "components/autofill/core/browser/autofill_test_utils.h" 28 #include "components/autofill/core/browser/autofill_test_utils.h"
28 #include "components/autofill/core/browser/autofill_type.h" 29 #include "components/autofill/core/browser/autofill_type.h"
29 #include "components/autofill/core/browser/credit_card.h" 30 #include "components/autofill/core/browser/credit_card.h"
30 #include "components/autofill/core/browser/webdata/autofill_change.h" 31 #include "components/autofill/core/browser/webdata/autofill_change.h"
31 #include "components/autofill/core/browser/webdata/autofill_entry.h" 32 #include "components/autofill/core/browser/webdata/autofill_entry.h"
32 #include "components/autofill/core/browser/webdata/autofill_table.h" 33 #include "components/autofill/core/browser/webdata/autofill_table.h"
33 #include "components/autofill/core/common/autofill_constants.h" 34 #include "components/autofill/core/common/autofill_constants.h"
34 #include "components/autofill/core/common/autofill_switches.h" 35 #include "components/autofill/core/common/autofill_switches.h"
35 #include "components/autofill/core/common/autofill_util.h" 36 #include "components/autofill/core/common/autofill_util.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 152
152 TEST_F(AutofillTableTest, Autofill) { 153 TEST_F(AutofillTableTest, Autofill) {
153 Time t1 = Time::Now(); 154 Time t1 = Time::Now();
154 155
155 // Simulate the submission of a handful of entries in a field called "Name", 156 // Simulate the submission of a handful of entries in a field called "Name",
156 // some more often than others. 157 // some more often than others.
157 AutofillChangeList changes; 158 AutofillChangeList changes;
158 FormFieldData field; 159 FormFieldData field;
159 field.name = ASCIIToUTF16("Name"); 160 field.name = ASCIIToUTF16("Name");
160 field.value = ASCIIToUTF16("Superman"); 161 field.value = ASCIIToUTF16("Superman");
161 base::Time now = base::Time::Now(); 162 base::Time now = AutofillClock::Now();
162 base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2); 163 base::TimeDelta two_seconds = base::TimeDelta::FromSeconds(2);
163 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes)); 164 EXPECT_TRUE(table_->AddFormFieldValue(field, &changes));
164 std::vector<base::string16> v; 165 std::vector<base::string16> v;
165 for (int i = 0; i < 5; ++i) { 166 for (int i = 0; i < 5; ++i) {
166 field.value = ASCIIToUTF16("Clark Kent"); 167 field.value = ASCIIToUTF16("Clark Kent");
167 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes, 168 EXPECT_TRUE(table_->AddFormFieldValueTime(field, &changes,
168 now + i * two_seconds)); 169 now + i * two_seconds));
169 } 170 }
170 for (int i = 0; i < 3; ++i) { 171 for (int i = 0; i < 3; ++i) {
171 field.value = ASCIIToUTF16("Clark Sutter"); 172 field.value = ASCIIToUTF16("Clark Sutter");
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after
1850 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); 1851 EXPECT_EQ(one.server_id(), outputs[0]->server_id());
1851 EXPECT_EQ(0U, outputs[0]->use_count()); 1852 EXPECT_EQ(0U, outputs[0]->use_count());
1852 EXPECT_EQ(base::Time(), outputs[0]->use_date()); 1853 EXPECT_EQ(base::Time(), outputs[0]->use_date());
1853 // We don't track modification date for server profiles. It should always be 1854 // We don't track modification date for server profiles. It should always be
1854 // base::Time(). 1855 // base::Time().
1855 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); 1856 EXPECT_EQ(base::Time(), outputs[0]->modification_date());
1856 outputs.clear(); 1857 outputs.clear();
1857 1858
1858 // Update the usage stats; make sure they're reflected in GetServerProfiles. 1859 // Update the usage stats; make sure they're reflected in GetServerProfiles.
1859 inputs.back().set_use_count(4U); 1860 inputs.back().set_use_count(4U);
1860 inputs.back().set_use_date(base::Time::Now()); 1861 inputs.back().set_use_date(AutofillClock::Now());
1861 table_->UpdateServerAddressMetadata(inputs.back()); 1862 table_->UpdateServerAddressMetadata(inputs.back());
1862 table_->GetServerProfiles(&outputs); 1863 table_->GetServerProfiles(&outputs);
1863 ASSERT_EQ(1u, outputs.size()); 1864 ASSERT_EQ(1u, outputs.size());
1864 EXPECT_EQ(one.server_id(), outputs[0]->server_id()); 1865 EXPECT_EQ(one.server_id(), outputs[0]->server_id());
1865 EXPECT_EQ(4U, outputs[0]->use_count()); 1866 EXPECT_EQ(4U, outputs[0]->use_count());
1866 EXPECT_NE(base::Time(), outputs[0]->use_date()); 1867 EXPECT_NE(base::Time(), outputs[0]->use_date());
1867 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); 1868 EXPECT_EQ(base::Time(), outputs[0]->modification_date());
1868 outputs.clear(); 1869 outputs.clear();
1869 1870
1870 // Setting the profiles again shouldn't delete the usage stats. 1871 // Setting the profiles again shouldn't delete the usage stats.
(...skipping 17 matching lines...) Expand all
1888 EXPECT_EQ(base::Time(), outputs[0]->use_date()); 1889 EXPECT_EQ(base::Time(), outputs[0]->use_date());
1889 EXPECT_EQ(base::Time(), outputs[0]->modification_date()); 1890 EXPECT_EQ(base::Time(), outputs[0]->modification_date());
1890 outputs.clear(); 1891 outputs.clear();
1891 } 1892 }
1892 1893
1893 // Tests that deleting time ranges re-masks server credit cards that were 1894 // Tests that deleting time ranges re-masks server credit cards that were
1894 // unmasked in that time. 1895 // unmasked in that time.
1895 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { 1896 TEST_F(AutofillTableTest, DeleteUnmaskedCard) {
1896 // This isn't the exact unmasked time, since the database will use the 1897 // This isn't the exact unmasked time, since the database will use the
1897 // current time that it is called. The code below has to be approximate. 1898 // current time that it is called. The code below has to be approximate.
1898 base::Time unmasked_time = base::Time::Now(); 1899 base::Time unmasked_time = AutofillClock::Now();
1899 1900
1900 // Add a masked card. 1901 // Add a masked card.
1901 base::string16 masked_number = ASCIIToUTF16("1111"); 1902 base::string16 masked_number = ASCIIToUTF16("1111");
1902 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); 1903 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123");
1903 masked_card.SetRawInfo(CREDIT_CARD_NAME_FULL, 1904 masked_card.SetRawInfo(CREDIT_CARD_NAME_FULL,
1904 ASCIIToUTF16("Paul F. Tompkins")); 1905 ASCIIToUTF16("Paul F. Tompkins"));
1905 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); 1906 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1"));
1906 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020")); 1907 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020"));
1907 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, masked_number); 1908 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, masked_number);
1908 masked_card.SetTypeForMaskedCard(kVisaCard); 1909 masked_card.SetTypeForMaskedCard(kVisaCard);
(...skipping 18 matching lines...) Expand all
1927 std::vector<std::unique_ptr<CreditCard>> outputs; 1928 std::vector<std::unique_ptr<CreditCard>> outputs;
1928 ASSERT_TRUE(table_->GetServerCreditCards(&outputs)); 1929 ASSERT_TRUE(table_->GetServerCreditCards(&outputs));
1929 ASSERT_EQ(1u, outputs.size()); 1930 ASSERT_EQ(1u, outputs.size());
1930 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, outputs[0]->record_type()); 1931 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, outputs[0]->record_type());
1931 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); 1932 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1932 outputs.clear(); 1933 outputs.clear();
1933 1934
1934 // Delete data in the range of the last 24 hours. 1935 // Delete data in the range of the last 24 hours.
1935 // Fudge |now| to make sure it's strictly greater than the |now| that 1936 // Fudge |now| to make sure it's strictly greater than the |now| that
1936 // the database uses. 1937 // the database uses.
1937 base::Time now = base::Time::Now() + base::TimeDelta::FromSeconds(1); 1938 base::Time now = AutofillClock::Now() + base::TimeDelta::FromSeconds(1);
1938 ASSERT_TRUE(table_->RemoveAutofillDataModifiedBetween( 1939 ASSERT_TRUE(table_->RemoveAutofillDataModifiedBetween(
1939 now - base::TimeDelta::FromDays(1), now, 1940 now - base::TimeDelta::FromDays(1), now,
1940 &profile_guids, &credit_card_guids)); 1941 &profile_guids, &credit_card_guids));
1941 1942
1942 // This should re-mask. 1943 // This should re-mask.
1943 ASSERT_TRUE(table_->GetServerCreditCards(&outputs)); 1944 ASSERT_TRUE(table_->GetServerCreditCards(&outputs));
1944 ASSERT_EQ(1u, outputs.size()); 1945 ASSERT_EQ(1u, outputs.size());
1945 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type()); 1946 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type());
1946 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); 1947 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER));
1947 outputs.clear(); 1948 outputs.clear();
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 "(rowid, value) VALUES(1, ?)")); 2102 "(rowid, value) VALUES(1, ?)"));
2102 s2.BindString(0, "unparseable"); 2103 s2.BindString(0, "unparseable");
2103 2104
2104 EXPECT_TRUE(s.Run()); 2105 EXPECT_TRUE(s.Run());
2105 EXPECT_TRUE(s2.Run()); 2106 EXPECT_TRUE(s2.Run());
2106 2107
2107 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch)); 2108 EXPECT_FALSE(table_->GetAllSyncMetadata(syncer::AUTOFILL, &metadata_batch));
2108 } 2109 }
2109 2110
2110 } // namespace autofill 2111 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698