OLD | NEW |
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 <utility> | 5 #include <utility> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/memory/scoped_vector.h" |
11 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "components/autofill/core/browser/autofill_profile.h" | 17 #include "components/autofill/core/browser/autofill_profile.h" |
17 #include "components/autofill/core/browser/autofill_test_utils.h" | 18 #include "components/autofill/core/browser/autofill_test_utils.h" |
18 #include "components/autofill/core/browser/autofill_type.h" | 19 #include "components/autofill/core/browser/autofill_type.h" |
19 #include "components/autofill/core/browser/credit_card.h" | 20 #include "components/autofill/core/browser/credit_card.h" |
20 #include "components/autofill/core/browser/webdata/autofill_change.h" | 21 #include "components/autofill/core/browser/webdata/autofill_change.h" |
(...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1784 | 1785 |
1785 // The original one should have been replaced. | 1786 // The original one should have been replaced. |
1786 table_->GetServerProfiles(&outputs); | 1787 table_->GetServerProfiles(&outputs); |
1787 ASSERT_EQ(1u, outputs.size()); | 1788 ASSERT_EQ(1u, outputs.size()); |
1788 EXPECT_EQ(two.server_id(), outputs[0]->server_id()); | 1789 EXPECT_EQ(two.server_id(), outputs[0]->server_id()); |
1789 | 1790 |
1790 STLDeleteContainerPointers(outputs.begin(), outputs.end()); | 1791 STLDeleteContainerPointers(outputs.begin(), outputs.end()); |
1791 outputs.clear(); | 1792 outputs.clear(); |
1792 } | 1793 } |
1793 | 1794 |
| 1795 // Tests that deleting time ranges re-masks server credit cards that were |
| 1796 // unmasked in that time. |
| 1797 TEST_F(AutofillTableTest, DeleteUnmaskedCard) { |
| 1798 // This isn't the exact unmasked time, since the database will use the |
| 1799 // current time that it is called. The code below has to be approximate. |
| 1800 base::Time unmasked_time = base::Time::Now(); |
| 1801 |
| 1802 // Add a masked card. |
| 1803 base::string16 masked_number = ASCIIToUTF16("1111"); |
| 1804 CreditCard masked_card(CreditCard::MASKED_SERVER_CARD, "a123"); |
| 1805 masked_card.SetRawInfo(CREDIT_CARD_NAME, ASCIIToUTF16("Paul F. Tompkins")); |
| 1806 masked_card.SetRawInfo(CREDIT_CARD_EXP_MONTH, ASCIIToUTF16("1")); |
| 1807 masked_card.SetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, ASCIIToUTF16("2020")); |
| 1808 masked_card.SetRawInfo(CREDIT_CARD_NUMBER, masked_number); |
| 1809 masked_card.SetTypeForMaskedCard(kVisaCard); |
| 1810 |
| 1811 std::vector<CreditCard> inputs; |
| 1812 inputs.push_back(masked_card); |
| 1813 table_->SetServerCreditCards(inputs); |
| 1814 |
| 1815 // Unmask it. |
| 1816 base::string16 full_number = ASCIIToUTF16("4111111111111111"); |
| 1817 table_->UnmaskServerCreditCard(masked_card.server_id(), full_number); |
| 1818 |
| 1819 // Delete data in a range a year in the future. |
| 1820 std::vector<std::string> profile_guids; |
| 1821 std::vector<std::string> credit_card_guids; |
| 1822 ASSERT_TRUE(table_->RemoveAutofillDataModifiedBetween( |
| 1823 unmasked_time + base::TimeDelta::FromDays(365), |
| 1824 unmasked_time + base::TimeDelta::FromDays(530), |
| 1825 &profile_guids, &credit_card_guids)); |
| 1826 |
| 1827 // This should not affect the unmasked card (should be unmasked). |
| 1828 ScopedVector<CreditCard> outputs; |
| 1829 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get())); |
| 1830 ASSERT_EQ(1u, outputs.size()); |
| 1831 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, outputs[0]->record_type()); |
| 1832 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); |
| 1833 outputs.clear(); |
| 1834 |
| 1835 // Delete data in the range of the last 24 hours. |
| 1836 base::Time now = base::Time::Now(); |
| 1837 ASSERT_TRUE(table_->RemoveAutofillDataModifiedBetween( |
| 1838 now - base::TimeDelta::FromDays(1), now, |
| 1839 &profile_guids, &credit_card_guids)); |
| 1840 |
| 1841 // This should re-mask. |
| 1842 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get())); |
| 1843 ASSERT_EQ(1u, outputs.size()); |
| 1844 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type()); |
| 1845 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); |
| 1846 outputs.clear(); |
| 1847 |
| 1848 // Unmask again, the card should be back. |
| 1849 table_->UnmaskServerCreditCard(masked_card.server_id(), full_number); |
| 1850 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get())); |
| 1851 ASSERT_EQ(1u, outputs.size()); |
| 1852 EXPECT_EQ(CreditCard::FULL_SERVER_CARD, outputs[0]->record_type()); |
| 1853 EXPECT_EQ(full_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); |
| 1854 outputs.clear(); |
| 1855 |
| 1856 // Delete all data. |
| 1857 ASSERT_TRUE(table_->RemoveAutofillDataModifiedBetween( |
| 1858 base::Time(), base::Time::Max(), &profile_guids, &credit_card_guids)); |
| 1859 |
| 1860 // Should be masked again. |
| 1861 ASSERT_TRUE(table_->GetServerCreditCards(&outputs.get())); |
| 1862 ASSERT_EQ(1u, outputs.size()); |
| 1863 EXPECT_EQ(CreditCard::MASKED_SERVER_CARD, outputs[0]->record_type()); |
| 1864 EXPECT_EQ(masked_number, outputs[0]->GetRawInfo(CREDIT_CARD_NUMBER)); |
| 1865 outputs.clear(); |
| 1866 } |
| 1867 |
1794 } // namespace autofill | 1868 } // namespace autofill |
OLD | NEW |