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 "chrome/browser/history/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/history/in_memory_history_backend.h" | 29 #include "chrome/browser/history/in_memory_history_backend.h" |
30 #include "chrome/browser/history/visit_filter.h" | 30 #include "chrome/browser/history/visit_filter.h" |
31 #include "chrome/common/chrome_constants.h" | 31 #include "chrome/common/chrome_constants.h" |
32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/importer/imported_favicon_usage.h" | 33 #include "chrome/common/importer/imported_favicon_usage.h" |
34 #include "chrome/test/base/testing_profile.h" | 34 #include "chrome/test/base/testing_profile.h" |
35 #include "components/bookmarks/core/browser/bookmark_model.h" | 35 #include "components/bookmarks/core/browser/bookmark_model.h" |
36 #include "components/bookmarks/core/browser/bookmark_utils.h" | 36 #include "components/bookmarks/core/browser/bookmark_utils.h" |
37 #include "components/bookmarks/core/test/bookmark_test_helpers.h" | 37 #include "components/bookmarks/core/test/bookmark_test_helpers.h" |
38 #include "components/bookmarks/core/test/test_bookmark_client.h" | 38 #include "components/bookmarks/core/test/test_bookmark_client.h" |
| 39 #include "components/history/core/browser/test_history_client.h" |
39 #include "content/public/browser/notification_details.h" | 40 #include "content/public/browser/notification_details.h" |
40 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
41 #include "content/public/test/test_browser_thread.h" | 42 #include "content/public/test/test_browser_thread.h" |
42 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
43 #include "url/gurl.h" | 44 #include "url/gurl.h" |
44 | 45 |
45 using base::Time; | 46 using base::Time; |
46 | 47 |
47 // This file only tests functionality where it is most convenient to call the | 48 // This file only tests functionality where it is most convenient to call the |
48 // backend directly. Most of the history backend functions are tested by the | 49 // backend directly. Most of the history backend functions are tested by the |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // Send the notifications directly to the in-memory database. | 146 // Send the notifications directly to the in-memory database. |
146 content::Details<HistoryDetails> det(details.get()); | 147 content::Details<HistoryDetails> det(details.get()); |
147 mem_backend_->Observe( | 148 mem_backend_->Observe( |
148 type, content::Source<HistoryBackendTestBase>(NULL), det); | 149 type, content::Source<HistoryBackendTestBase>(NULL), det); |
149 | 150 |
150 // The backend passes ownership of the details pointer to us. | 151 // The backend passes ownership of the details pointer to us. |
151 broadcasted_notifications_.push_back( | 152 broadcasted_notifications_.push_back( |
152 std::make_pair(type, details.release())); | 153 std::make_pair(type, details.release())); |
153 } | 154 } |
154 | 155 |
| 156 TestHistoryClient history_client_; |
155 test::TestBookmarkClient bookmark_client_; | 157 test::TestBookmarkClient bookmark_client_; |
156 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. | 158 scoped_refptr<HistoryBackend> backend_; // Will be NULL on init failure. |
157 scoped_ptr<InMemoryHistoryBackend> mem_backend_; | 159 scoped_ptr<InMemoryHistoryBackend> mem_backend_; |
158 scoped_ptr<BookmarkModel> bookmark_model_; | 160 scoped_ptr<BookmarkModel> bookmark_model_; |
159 bool loaded_; | 161 bool loaded_; |
160 | 162 |
161 private: | 163 private: |
162 friend class HistoryBackendTestDelegate; | 164 friend class HistoryBackendTestDelegate; |
163 | 165 |
164 // testing::Test | 166 // testing::Test |
165 virtual void SetUp() { | 167 virtual void SetUp() { |
166 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), | 168 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), |
167 &test_dir_)) | 169 &test_dir_)) |
168 return; | 170 return; |
169 backend_ = new HistoryBackend( | 171 backend_ = new HistoryBackend( |
170 test_dir_, new HistoryBackendTestDelegate(this), bookmark_model_.get()); | 172 test_dir_, new HistoryBackendTestDelegate(this), &history_client_); |
171 backend_->Init(std::string(), false); | 173 backend_->Init(std::string(), false); |
172 } | 174 } |
173 | 175 |
174 virtual void TearDown() { | 176 virtual void TearDown() { |
175 if (backend_.get()) | 177 if (backend_.get()) |
176 backend_->Closing(); | 178 backend_->Closing(); |
177 backend_ = NULL; | 179 backend_ = NULL; |
178 mem_backend_.reset(); | 180 mem_backend_.reset(); |
179 base::DeleteFile(test_dir_, true); | 181 base::DeleteFile(test_dir_, true); |
180 base::RunLoop().RunUntilIdle(); | 182 base::RunLoop().RunUntilIdle(); |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 // in Teardown. | 1481 // in Teardown. |
1480 base::FilePath new_history_path(test_dir()); | 1482 base::FilePath new_history_path(test_dir()); |
1481 base::DeleteFile(new_history_path, true); | 1483 base::DeleteFile(new_history_path, true); |
1482 base::CreateDirectory(new_history_path); | 1484 base::CreateDirectory(new_history_path); |
1483 base::FilePath new_history_file = | 1485 base::FilePath new_history_file = |
1484 new_history_path.Append(chrome::kHistoryFilename); | 1486 new_history_path.Append(chrome::kHistoryFilename); |
1485 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); | 1487 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); |
1486 | 1488 |
1487 backend_ = new HistoryBackend(new_history_path, | 1489 backend_ = new HistoryBackend(new_history_path, |
1488 new HistoryBackendTestDelegate(this), | 1490 new HistoryBackendTestDelegate(this), |
1489 bookmark_model_.get()); | 1491 &history_client_); |
1490 backend_->Init(std::string(), false); | 1492 backend_->Init(std::string(), false); |
1491 backend_->Closing(); | 1493 backend_->Closing(); |
1492 backend_ = NULL; | 1494 backend_ = NULL; |
1493 | 1495 |
1494 // Now the database should already be migrated. | 1496 // Now the database should already be migrated. |
1495 // Check version first. | 1497 // Check version first. |
1496 int cur_version = HistoryDatabase::GetCurrentVersion(); | 1498 int cur_version = HistoryDatabase::GetCurrentVersion(); |
1497 sql::Connection db; | 1499 sql::Connection db; |
1498 ASSERT_TRUE(db.Open(new_history_file)); | 1500 ASSERT_TRUE(db.Open(new_history_file)); |
1499 sql::Statement s(db.GetUniqueStatement( | 1501 sql::Statement s(db.GetUniqueStatement( |
(...skipping 1382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2882 base::CreateDirectory(new_history_path); | 2884 base::CreateDirectory(new_history_path); |
2883 base::FilePath new_history_file = | 2885 base::FilePath new_history_file = |
2884 new_history_path.Append(chrome::kHistoryFilename); | 2886 new_history_path.Append(chrome::kHistoryFilename); |
2885 base::FilePath new_archived_file = | 2887 base::FilePath new_archived_file = |
2886 new_history_path.Append(chrome::kArchivedHistoryFilename); | 2888 new_history_path.Append(chrome::kArchivedHistoryFilename); |
2887 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); | 2889 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); |
2888 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); | 2890 ASSERT_TRUE(base::CopyFile(old_archived, new_archived_file)); |
2889 | 2891 |
2890 backend_ = new HistoryBackend(new_history_path, | 2892 backend_ = new HistoryBackend(new_history_path, |
2891 new HistoryBackendTestDelegate(this), | 2893 new HistoryBackendTestDelegate(this), |
2892 bookmark_model_.get()); | 2894 &history_client_); |
2893 backend_->Init(std::string(), false); | 2895 backend_->Init(std::string(), false); |
2894 backend_->Closing(); | 2896 backend_->Closing(); |
2895 backend_ = NULL; | 2897 backend_ = NULL; |
2896 | 2898 |
2897 // Now both history and archived_history databases should already be migrated. | 2899 // Now both history and archived_history databases should already be migrated. |
2898 | 2900 |
2899 // Check version in history database first. | 2901 // Check version in history database first. |
2900 int cur_version = HistoryDatabase::GetCurrentVersion(); | 2902 int cur_version = HistoryDatabase::GetCurrentVersion(); |
2901 sql::Connection db; | 2903 sql::Connection db; |
2902 ASSERT_TRUE(db.Open(new_history_file)); | 2904 ASSERT_TRUE(db.Open(new_history_file)); |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3384 // Verify that the second term is no longer returned as result, and also check | 3386 // Verify that the second term is no longer returned as result, and also check |
3385 // at the low level that it is gone for good. The term corresponding to the | 3387 // at the low level that it is gone for good. The term corresponding to the |
3386 // first URLRow should not be affected. | 3388 // first URLRow should not be affected. |
3387 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); | 3389 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); |
3388 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); | 3390 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); |
3389 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); | 3391 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); |
3390 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); | 3392 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); |
3391 } | 3393 } |
3392 | 3394 |
3393 } // namespace history | 3395 } // namespace history |
OLD | NEW |