OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/scoped_temp_dir.h" |
10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
11 #include "base/time.h" | 12 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/password_manager/login_database.h" | 14 #include "chrome/browser/password_manager/login_database.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "webkit/forms/password_form.h" | 16 #include "webkit/forms/password_form.h" |
16 | 17 |
17 using webkit::forms::PasswordForm; | 18 using webkit::forms::PasswordForm; |
18 | 19 |
19 class LoginDatabaseTest : public testing::Test { | 20 class LoginDatabaseTest : public testing::Test { |
20 protected: | 21 protected: |
21 virtual void SetUp() { | 22 virtual void SetUp() { |
22 PathService::Get(chrome::DIR_TEST_DATA, &file_); | 23 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
23 const std::string test_db = | 24 file_ = temp_dir_.path().AppendASCII("TestMetadataStoreMacDatabase"); |
24 "TestMetadataStoreMacDatabase" + | |
25 base::Int64ToString(base::Time::Now().ToInternalValue()) + ".db"; | |
26 file_ = file_.AppendASCII(test_db); | |
27 file_util::Delete(file_, false); | |
28 } | |
29 | |
30 virtual void TearDown() { | |
31 file_util::Delete(file_, false); | |
32 } | 25 } |
33 | 26 |
34 FilePath file_; | 27 FilePath file_; |
| 28 ScopedTempDir temp_dir_; |
35 }; | 29 }; |
36 | 30 |
37 TEST_F(LoginDatabaseTest, Logins) { | 31 TEST_F(LoginDatabaseTest, Logins) { |
38 scoped_ptr<LoginDatabase> db(new LoginDatabase()); | 32 scoped_ptr<LoginDatabase> db(new LoginDatabase()); |
39 | 33 |
40 ASSERT_TRUE(db->Init(file_)); | 34 ASSERT_TRUE(db->Init(file_)); |
41 | 35 |
42 std::vector<PasswordForm*> result; | 36 std::vector<PasswordForm*> result; |
43 | 37 |
44 // Verify the database is empty. | 38 // Verify the database is empty. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // GetLogins should give the blacklisted result. | 268 // GetLogins should give the blacklisted result. |
275 EXPECT_TRUE(db->GetLogins(form, &result)); | 269 EXPECT_TRUE(db->GetLogins(form, &result)); |
276 EXPECT_EQ(1U, result.size()); | 270 EXPECT_EQ(1U, result.size()); |
277 ClearResults(&result); | 271 ClearResults(&result); |
278 | 272 |
279 // So should GetAllBlacklistedLogins. | 273 // So should GetAllBlacklistedLogins. |
280 EXPECT_TRUE(db->GetBlacklistLogins(&result)); | 274 EXPECT_TRUE(db->GetBlacklistLogins(&result)); |
281 EXPECT_EQ(1U, result.size()); | 275 EXPECT_EQ(1U, result.size()); |
282 ClearResults(&result); | 276 ClearResults(&result); |
283 } | 277 } |
OLD | NEW |