OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/scoped_temp_dir.h" |
9 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
10 #include "base/time.h" | 11 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autofill/autofill_profile.h" | 13 #include "chrome/browser/autofill/autofill_profile.h" |
13 #include "chrome/browser/autofill/autofill_type.h" | 14 #include "chrome/browser/autofill/autofill_type.h" |
14 #include "chrome/browser/autofill/credit_card.h" | 15 #include "chrome/browser/autofill/credit_card.h" |
15 #include "chrome/browser/password_manager/encryptor.h" | 16 #include "chrome/browser/password_manager/encryptor.h" |
16 #include "chrome/browser/webdata/autofill_change.h" | 17 #include "chrome/browser/webdata/autofill_change.h" |
17 #include "chrome/browser/webdata/autofill_entry.h" | 18 #include "chrome/browser/webdata/autofill_entry.h" |
18 #include "chrome/browser/webdata/autofill_table.h" | 19 #include "chrome/browser/webdata/autofill_table.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 typedef std::vector<AutofillChange> AutofillChangeList; | 91 typedef std::vector<AutofillChange> AutofillChangeList; |
91 typedef std::set<AutofillEntry, | 92 typedef std::set<AutofillEntry, |
92 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; | 93 bool (*)(const AutofillEntry&, const AutofillEntry&)> AutofillEntrySet; |
93 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, | 94 typedef std::set<AutofillEntry, bool (*)(const AutofillEntry&, |
94 const AutofillEntry&)>::iterator AutofillEntrySetIterator; | 95 const AutofillEntry&)>::iterator AutofillEntrySetIterator; |
95 | 96 |
96 virtual void SetUp() { | 97 virtual void SetUp() { |
97 #if defined(OS_MACOSX) | 98 #if defined(OS_MACOSX) |
98 Encryptor::UseMockKeychain(true); | 99 Encryptor::UseMockKeychain(true); |
99 #endif | 100 #endif |
100 PathService::Get(chrome::DIR_TEST_DATA, &file_); | 101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
101 const std::string test_db = "TestWebDatabase" + | 102 file_ = temp_dir_.path().AppendASCII("TestWebDatabase"); |
102 base::Int64ToString(Time::Now().ToTimeT()) + | |
103 ".db"; | |
104 file_ = file_.AppendASCII(test_db); | |
105 file_util::Delete(file_, false); | |
106 } | |
107 | |
108 virtual void TearDown() { | |
109 file_util::Delete(file_, false); | |
110 } | 103 } |
111 | 104 |
112 static AutofillEntry MakeAutofillEntry(const char* name, | 105 static AutofillEntry MakeAutofillEntry(const char* name, |
113 const char* value, | 106 const char* value, |
114 time_t timestamp0, | 107 time_t timestamp0, |
115 time_t timestamp1) { | 108 time_t timestamp1) { |
116 std::vector<Time> timestamps; | 109 std::vector<Time> timestamps; |
117 if (timestamp0 >= 0) | 110 if (timestamp0 >= 0) |
118 timestamps.push_back(Time::FromTimeT(timestamp0)); | 111 timestamps.push_back(Time::FromTimeT(timestamp0)); |
119 if (timestamp1 >= 0) | 112 if (timestamp1 >= 0) |
120 timestamps.push_back(Time::FromTimeT(timestamp1)); | 113 timestamps.push_back(Time::FromTimeT(timestamp1)); |
121 return AutofillEntry( | 114 return AutofillEntry( |
122 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); | 115 AutofillKey(ASCIIToUTF16(name), ASCIIToUTF16(value)), timestamps); |
123 } | 116 } |
124 | 117 |
125 FilePath file_; | 118 FilePath file_; |
| 119 ScopedTempDir temp_dir_; |
126 | 120 |
127 private: | 121 private: |
128 DISALLOW_COPY_AND_ASSIGN(AutofillTableTest); | 122 DISALLOW_COPY_AND_ASSIGN(AutofillTableTest); |
129 }; | 123 }; |
130 | 124 |
131 TEST_F(AutofillTableTest, Autofill) { | 125 TEST_F(AutofillTableTest, Autofill) { |
132 WebDatabase db; | 126 WebDatabase db; |
133 | 127 |
134 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); | 128 ASSERT_EQ(sql::INIT_OK, db.Init(file_)); |
135 | 129 |
(...skipping 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1438 | 1432 |
1439 // make sure the lists of entries match | 1433 // make sure the lists of entries match |
1440 ASSERT_EQ(expected_entries.size(), entry_set.size()); | 1434 ASSERT_EQ(expected_entries.size(), entry_set.size()); |
1441 AutofillEntrySetIterator it; | 1435 AutofillEntrySetIterator it; |
1442 for (it = entry_set.begin(); it != entry_set.end(); it++) { | 1436 for (it = entry_set.begin(); it != entry_set.end(); it++) { |
1443 expected_entries.erase(*it); | 1437 expected_entries.erase(*it); |
1444 } | 1438 } |
1445 | 1439 |
1446 EXPECT_EQ(0U, expected_entries.size()); | 1440 EXPECT_EQ(0U, expected_entries.size()); |
1447 } | 1441 } |
OLD | NEW |