| 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 <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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/memory/scoped_temp_dir.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/history/history.h" | 12 #include "chrome/browser/history/history.h" |
| 12 #include "chrome/browser/history/starred_url_database.h" | 13 #include "chrome/browser/history/starred_url_database.h" |
| 13 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace history { | 17 namespace history { |
| 17 | 18 |
| 18 class StarredURLDatabaseTest : public testing::Test, | 19 class StarredURLDatabaseTest : public testing::Test, |
| 19 public StarredURLDatabase { | 20 public StarredURLDatabase { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 return StarredURLDatabase::GetStarredEntry(star_id, entry); | 59 return StarredURLDatabase::GetStarredEntry(star_id, entry); |
| 59 } | 60 } |
| 60 | 61 |
| 61 bool EnsureStarredIntegrity() { | 62 bool EnsureStarredIntegrity() { |
| 62 return StarredURLDatabase::EnsureStarredIntegrity(); | 63 return StarredURLDatabase::EnsureStarredIntegrity(); |
| 63 } | 64 } |
| 64 | 65 |
| 65 private: | 66 private: |
| 66 // Test setup. | 67 // Test setup. |
| 67 void SetUp() { | 68 void SetUp() { |
| 68 PathService::Get(base::DIR_TEMP, &db_file_); | 69 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 69 db_file_ = db_file_.AppendASCII("VisitTest.db"); | 70 db_file_ = temp_dir_.path().AppendASCII("VisitTest.db"); |
| 70 file_util::Delete(db_file_, false); | 71 file_util::Delete(db_file_, false); |
| 71 | 72 |
| 72 // Copy db file over that contains starred table. | 73 // Copy db file over that contains starred table. |
| 73 FilePath old_history_path; | 74 FilePath old_history_path; |
| 74 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); | 75 PathService::Get(chrome::DIR_TEST_DATA, &old_history_path); |
| 75 old_history_path = old_history_path.AppendASCII("bookmarks"); | 76 old_history_path = old_history_path.AppendASCII("bookmarks"); |
| 76 old_history_path = old_history_path.Append( | 77 old_history_path = old_history_path.Append( |
| 77 FILE_PATH_LITERAL("History_with_empty_starred")); | 78 FILE_PATH_LITERAL("History_with_empty_starred")); |
| 78 file_util::CopyFile(old_history_path, db_file_); | 79 file_util::CopyFile(old_history_path, db_file_); |
| 79 | 80 |
| 80 EXPECT_TRUE(db_.Open(db_file_)); | 81 EXPECT_TRUE(db_.Open(db_file_)); |
| 81 | 82 |
| 82 // Initialize the tables for this test. | 83 // Initialize the tables for this test. |
| 83 CreateURLTable(false); | 84 CreateURLTable(false); |
| 84 CreateMainURLIndex(); | 85 CreateMainURLIndex(); |
| 85 EnsureStarredIntegrity(); | 86 EnsureStarredIntegrity(); |
| 86 } | 87 } |
| 87 void TearDown() { | 88 void TearDown() { |
| 88 db_.Close(); | 89 db_.Close(); |
| 89 file_util::Delete(db_file_, false); | |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Provided for URL/StarredURLDatabase. | 92 // Provided for URL/StarredURLDatabase. |
| 93 virtual sql::Connection& GetDB() { | 93 virtual sql::Connection& GetDB() { |
| 94 return db_; | 94 return db_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 ScopedTempDir temp_dir_; |
| 97 FilePath db_file_; | 98 FilePath db_file_; |
| 98 sql::Connection db_; | 99 sql::Connection db_; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 //----------------------------------------------------------------------------- | 102 //----------------------------------------------------------------------------- |
| 102 | 103 |
| 103 TEST_F(StarredURLDatabaseTest, FixOrphanedFolder) { | 104 TEST_F(StarredURLDatabaseTest, FixOrphanedFolder) { |
| 104 const int initial_count = GetStarredEntryCount(); | 105 const int initial_count = GetStarredEntryCount(); |
| 105 | 106 |
| 106 // Create a folder that isn't parented to the other/bookmark folders. | 107 // Create a folder that isn't parented to the other/bookmark folders. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 DeleteURLRow(entry.url_id); | 277 DeleteURLRow(entry.url_id); |
| 277 | 278 |
| 278 // Fix up the table. | 279 // Fix up the table. |
| 279 ASSERT_TRUE(EnsureStarredIntegrity()); | 280 ASSERT_TRUE(EnsureStarredIntegrity()); |
| 280 | 281 |
| 281 // The entry we just created should have been nuked. | 282 // The entry we just created should have been nuked. |
| 282 ASSERT_EQ(initial_count, GetStarredEntryCount()); | 283 ASSERT_EQ(initial_count, GetStarredEntryCount()); |
| 283 } | 284 } |
| 284 | 285 |
| 285 } // namespace history | 286 } // namespace history |
| OLD | NEW |