| 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 "components/history/core/browser/history_backend.h" | 5 #include "components/history/core/browser/history_backend.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 namespace { | 59 namespace { |
| 60 | 60 |
| 61 using ::testing::ElementsAre; | 61 using ::testing::ElementsAre; |
| 62 using base::HistogramBase; | 62 using base::HistogramBase; |
| 63 | 63 |
| 64 const int kTinyEdgeSize = 10; | 64 const int kTinyEdgeSize = 10; |
| 65 const int kSmallEdgeSize = 16; | 65 const int kSmallEdgeSize = 16; |
| 66 const int kLargeEdgeSize = 32; | 66 const int kLargeEdgeSize = 32; |
| 67 | 67 |
| 68 const char kAcceptLanguagesForTest[] = "en-US,en"; | |
| 69 | |
| 70 const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize); | 68 const gfx::Size kTinySize = gfx::Size(kTinyEdgeSize, kTinyEdgeSize); |
| 71 const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize); | 69 const gfx::Size kSmallSize = gfx::Size(kSmallEdgeSize, kSmallEdgeSize); |
| 72 const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize); | 70 const gfx::Size kLargeSize = gfx::Size(kLargeEdgeSize, kLargeEdgeSize); |
| 73 | 71 |
| 74 typedef base::Callback<void(const history::URLRow*, | 72 typedef base::Callback<void(const history::URLRow*, |
| 75 const history::URLRow*, | 73 const history::URLRow*, |
| 76 const history::URLRow*)> | 74 const history::URLRow*)> |
| 77 SimulateNotificationCallback; | 75 SimulateNotificationCallback; |
| 78 | 76 |
| 79 void SimulateNotificationURLVisited(history::HistoryServiceObserver* observer, | 77 void SimulateNotificationURLVisited(history::HistoryServiceObserver* observer, |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 friend class HistoryBackendTestDelegate; | 248 friend class HistoryBackendTestDelegate; |
| 251 | 249 |
| 252 // testing::Test | 250 // testing::Test |
| 253 void SetUp() override { | 251 void SetUp() override { |
| 254 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), | 252 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), |
| 255 &test_dir_)) | 253 &test_dir_)) |
| 256 return; | 254 return; |
| 257 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), | 255 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), |
| 258 history_client_.CreateBackendClient(), | 256 history_client_.CreateBackendClient(), |
| 259 base::ThreadTaskRunnerHandle::Get()); | 257 base::ThreadTaskRunnerHandle::Get()); |
| 260 backend_->Init(std::string(), false, | 258 backend_->Init(false, TestHistoryDatabaseParamsForPath(test_dir_)); |
| 261 TestHistoryDatabaseParamsForPath(test_dir_)); | |
| 262 } | 259 } |
| 263 | 260 |
| 264 void TearDown() override { | 261 void TearDown() override { |
| 265 if (backend_.get()) | 262 if (backend_.get()) |
| 266 backend_->Closing(); | 263 backend_->Closing(); |
| 267 backend_ = NULL; | 264 backend_ = NULL; |
| 268 mem_backend_.reset(); | 265 mem_backend_.reset(); |
| 269 base::DeleteFile(test_dir_, true); | 266 base::DeleteFile(test_dir_, true); |
| 270 base::RunLoop().RunUntilIdle(); | 267 base::RunLoop().RunUntilIdle(); |
| 271 history_client_.ClearAllBookmarks(); | 268 history_client_.ClearAllBookmarks(); |
| (...skipping 1428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1700 // in Teardown. | 1697 // in Teardown. |
| 1701 base::FilePath new_history_path(test_dir()); | 1698 base::FilePath new_history_path(test_dir()); |
| 1702 base::DeleteFile(new_history_path, true); | 1699 base::DeleteFile(new_history_path, true); |
| 1703 base::CreateDirectory(new_history_path); | 1700 base::CreateDirectory(new_history_path); |
| 1704 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); | 1701 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); |
| 1705 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); | 1702 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); |
| 1706 | 1703 |
| 1707 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), | 1704 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), |
| 1708 history_client_.CreateBackendClient(), | 1705 history_client_.CreateBackendClient(), |
| 1709 base::ThreadTaskRunnerHandle::Get()); | 1706 base::ThreadTaskRunnerHandle::Get()); |
| 1710 backend_->Init(std::string(), false, | 1707 backend_->Init(false, TestHistoryDatabaseParamsForPath(new_history_path)); |
| 1711 TestHistoryDatabaseParamsForPath(new_history_path)); | |
| 1712 backend_->Closing(); | 1708 backend_->Closing(); |
| 1713 backend_ = NULL; | 1709 backend_ = NULL; |
| 1714 | 1710 |
| 1715 // Now the database should already be migrated. | 1711 // Now the database should already be migrated. |
| 1716 // Check version first. | 1712 // Check version first. |
| 1717 int cur_version = HistoryDatabase::GetCurrentVersion(); | 1713 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 1718 sql::Connection db; | 1714 sql::Connection db; |
| 1719 ASSERT_TRUE(db.Open(new_history_file)); | 1715 ASSERT_TRUE(db.Open(new_history_file)); |
| 1720 sql::Statement s(db.GetUniqueStatement( | 1716 sql::Statement s(db.GetUniqueStatement( |
| 1721 "SELECT value FROM meta WHERE key = 'version'")); | 1717 "SELECT value FROM meta WHERE key = 'version'")); |
| (...skipping 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3259 // in Teardown. | 3255 // in Teardown. |
| 3260 base::FilePath new_history_path(test_dir()); | 3256 base::FilePath new_history_path(test_dir()); |
| 3261 base::DeleteFile(new_history_path, true); | 3257 base::DeleteFile(new_history_path, true); |
| 3262 base::CreateDirectory(new_history_path); | 3258 base::CreateDirectory(new_history_path); |
| 3263 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); | 3259 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); |
| 3264 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); | 3260 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
| 3265 | 3261 |
| 3266 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), | 3262 backend_ = new HistoryBackend(new HistoryBackendTestDelegate(this), |
| 3267 history_client_.CreateBackendClient(), | 3263 history_client_.CreateBackendClient(), |
| 3268 base::ThreadTaskRunnerHandle::Get()); | 3264 base::ThreadTaskRunnerHandle::Get()); |
| 3269 backend_->Init(std::string(), false, | 3265 backend_->Init(false, TestHistoryDatabaseParamsForPath(new_history_path)); |
| 3270 TestHistoryDatabaseParamsForPath(new_history_path)); | |
| 3271 backend_->Closing(); | 3266 backend_->Closing(); |
| 3272 backend_ = NULL; | 3267 backend_ = NULL; |
| 3273 | 3268 |
| 3274 // Now the history database should already be migrated. | 3269 // Now the history database should already be migrated. |
| 3275 | 3270 |
| 3276 // Check version in history database first. | 3271 // Check version in history database first. |
| 3277 int cur_version = HistoryDatabase::GetCurrentVersion(); | 3272 int cur_version = HistoryDatabase::GetCurrentVersion(); |
| 3278 sql::Connection db; | 3273 sql::Connection db; |
| 3279 ASSERT_TRUE(db.Open(new_history_file)); | 3274 ASSERT_TRUE(db.Open(new_history_file)); |
| 3280 sql::Statement s(db.GetUniqueStatement( | 3275 sql::Statement s(db.GetUniqueStatement( |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 TEST_F(HistoryBackendTest, RemoveNotification) { | 3482 TEST_F(HistoryBackendTest, RemoveNotification) { |
| 3488 base::ScopedTempDir scoped_temp_dir; | 3483 base::ScopedTempDir scoped_temp_dir; |
| 3489 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(test_dir())); | 3484 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDirUnderPath(test_dir())); |
| 3490 | 3485 |
| 3491 // Add a URL. | 3486 // Add a URL. |
| 3492 GURL url("http://www.google.com"); | 3487 GURL url("http://www.google.com"); |
| 3493 scoped_ptr<HistoryService> service( | 3488 scoped_ptr<HistoryService> service( |
| 3494 new HistoryService(make_scoped_ptr(new HistoryClientFakeBookmarks), | 3489 new HistoryService(make_scoped_ptr(new HistoryClientFakeBookmarks), |
| 3495 scoped_ptr<history::VisitDelegate>())); | 3490 scoped_ptr<history::VisitDelegate>())); |
| 3496 EXPECT_TRUE( | 3491 EXPECT_TRUE( |
| 3497 service->Init(kAcceptLanguagesForTest, | 3492 service->Init(TestHistoryDatabaseParamsForPath(scoped_temp_dir.path()))); |
| 3498 TestHistoryDatabaseParamsForPath(scoped_temp_dir.path()))); | |
| 3499 | 3493 |
| 3500 service->AddPage( | 3494 service->AddPage( |
| 3501 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), | 3495 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), |
| 3502 ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); | 3496 ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); |
| 3503 | 3497 |
| 3504 // This won't actually delete the URL, rather it'll empty out the visits. | 3498 // This won't actually delete the URL, rather it'll empty out the visits. |
| 3505 // This triggers blocking on the BookmarkModel. | 3499 // This triggers blocking on the BookmarkModel. |
| 3506 service->DeleteURL(url); | 3500 service->DeleteURL(url); |
| 3507 } | 3501 } |
| 3508 | 3502 |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3738 // Verify that the second term is no longer returned as result, and also check | 3732 // Verify that the second term is no longer returned as result, and also check |
| 3739 // at the low level that it is gone for good. The term corresponding to the | 3733 // at the low level that it is gone for good. The term corresponding to the |
| 3740 // first URLRow should not be affected. | 3734 // first URLRow should not be affected. |
| 3741 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3735 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
| 3742 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3736 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
| 3743 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3737 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
| 3744 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3738 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
| 3745 } | 3739 } |
| 3746 | 3740 |
| 3747 } // namespace history | 3741 } // namespace history |
| OLD | NEW |