Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: chrome/browser/history/history_unittest.cc

Issue 849323002: Componentize HistoryDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // History unit tests come in two flavors: 5 // History unit tests come in two flavors:
6 // 6 //
7 // 1. The more complicated style is that the unit test creates a full history 7 // 1. The more complicated style is that the unit test creates a full history
8 // service. This spawns a background thread for the history backend, and 8 // service. This spawns a background thread for the history backend, and
9 // all communication is asynchronous. This is useful for testing more 9 // all communication is asynchronous. This is useful for testing more
10 // complicated things or end-to-end behavior. 10 // complicated things or end-to-end behavior.
(...skipping 25 matching lines...) Expand all
36 #include "base/memory/scoped_vector.h" 36 #include "base/memory/scoped_vector.h"
37 #include "base/message_loop/message_loop.h" 37 #include "base/message_loop/message_loop.h"
38 #include "base/path_service.h" 38 #include "base/path_service.h"
39 #include "base/strings/string_util.h" 39 #include "base/strings/string_util.h"
40 #include "base/strings/stringprintf.h" 40 #include "base/strings/stringprintf.h"
41 #include "base/strings/utf_string_conversions.h" 41 #include "base/strings/utf_string_conversions.h"
42 #include "base/task/cancelable_task_tracker.h" 42 #include "base/task/cancelable_task_tracker.h"
43 #include "base/threading/platform_thread.h" 43 #include "base/threading/platform_thread.h"
44 #include "base/time/time.h" 44 #include "base/time/time.h"
45 #include "chrome/browser/history/history_backend.h" 45 #include "chrome/browser/history/history_backend.h"
46 #include "chrome/browser/history/history_database.h"
47 #include "chrome/browser/history/history_notifications.h" 46 #include "chrome/browser/history/history_notifications.h"
48 #include "chrome/browser/history/history_service.h" 47 #include "chrome/browser/history/history_service.h"
49 #include "chrome/browser/history/in_memory_history_backend.h" 48 #include "chrome/browser/history/in_memory_history_backend.h"
50 #include "chrome/common/chrome_constants.h" 49 #include "chrome/common/chrome_constants.h"
51 #include "chrome/common/chrome_paths.h" 50 #include "chrome/common/chrome_paths.h"
52 #include "chrome/tools/profiles/thumbnail-inl.h" 51 #include "chrome/tools/profiles/thumbnail-inl.h"
53 #include "components/history/content/browser/download_constants_utils.h" 52 #include "components/history/content/browser/download_constants_utils.h"
54 #include "components/history/core/browser/download_constants.h" 53 #include "components/history/core/browser/download_constants.h"
55 #include "components/history/core/browser/download_row.h" 54 #include "components/history/core/browser/download_row.h"
56 #include "components/history/core/browser/history_constants.h" 55 #include "components/history/core/browser/history_constants.h"
56 #include "components/history/core/browser/history_database.h"
57 #include "components/history/core/browser/history_database_params.h"
57 #include "components/history/core/browser/history_db_task.h" 58 #include "components/history/core/browser/history_db_task.h"
58 #include "components/history/core/browser/in_memory_database.h" 59 #include "components/history/core/browser/in_memory_database.h"
59 #include "components/history/core/browser/page_usage_data.h" 60 #include "components/history/core/browser/page_usage_data.h"
60 #include "components/history/core/common/thumbnail_score.h" 61 #include "components/history/core/common/thumbnail_score.h"
61 #include "components/history/core/test/history_unittest_base.h" 62 #include "components/history/core/test/history_unittest_base.h"
63 #include "components/history/core/test/test_history_database.h"
62 #include "content/public/browser/download_item.h" 64 #include "content/public/browser/download_item.h"
63 #include "content/public/browser/notification_details.h" 65 #include "content/public/browser/notification_details.h"
64 #include "content/public/browser/notification_source.h" 66 #include "content/public/browser/notification_source.h"
65 #include "sql/connection.h" 67 #include "sql/connection.h"
66 #include "sql/statement.h" 68 #include "sql/statement.h"
67 #include "sync/api/attachments/attachment_id.h" 69 #include "sync/api/attachments/attachment_id.h"
68 #include "sync/api/fake_sync_change_processor.h" 70 #include "sync/api/fake_sync_change_processor.h"
69 #include "sync/api/sync_change.h" 71 #include "sync/api/sync_change.h"
70 #include "sync/api/sync_change_processor.h" 72 #include "sync/api/sync_change_processor.h"
71 #include "sync/api/sync_change_processor_wrapper_for_test.h" 73 #include "sync/api/sync_change_processor_wrapper_for_test.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ~HistoryBackendDBTest() override {} 128 ~HistoryBackendDBTest() override {}
127 129
128 protected: 130 protected:
129 friend class BackendDelegate; 131 friend class BackendDelegate;
130 132
131 // Creates the HistoryBackend and HistoryDatabase on the current thread, 133 // Creates the HistoryBackend and HistoryDatabase on the current thread,
132 // assigning the values to backend_ and db_. 134 // assigning the values to backend_ and db_.
133 void CreateBackendAndDatabase() { 135 void CreateBackendAndDatabase() {
134 backend_ = 136 backend_ =
135 new HistoryBackend(history_dir_, new BackendDelegate(this), NULL); 137 new HistoryBackend(history_dir_, new BackendDelegate(this), NULL);
136 backend_->Init(std::string(), false); 138 backend_->Init(std::string(), false,
139 TestHistoryDatabaseParamsForPath(history_dir_));
137 db_ = backend_->db_.get(); 140 db_ = backend_->db_.get();
138 DCHECK(in_mem_backend_) << "Mem backend should have been set by " 141 DCHECK(in_mem_backend_) << "Mem backend should have been set by "
139 "HistoryBackend::Init"; 142 "HistoryBackend::Init";
140 } 143 }
141 144
142 void CreateDBVersion(int version) { 145 void CreateDBVersion(int version) {
143 base::FilePath data_path; 146 base::FilePath data_path;
144 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path)); 147 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_path));
145 data_path = data_path.AppendASCII("History"); 148 data_path = data_path.AppendASCII("History");
146 data_path = 149 data_path =
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 } 999 }
997 1000
998 protected: 1001 protected:
999 friend class BackendDelegate; 1002 friend class BackendDelegate;
1000 1003
1001 // testing::Test 1004 // testing::Test
1002 void SetUp() override { 1005 void SetUp() override {
1003 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 1006 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
1004 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest"); 1007 history_dir_ = temp_dir_.path().AppendASCII("HistoryTest");
1005 ASSERT_TRUE(base::CreateDirectory(history_dir_)); 1008 ASSERT_TRUE(base::CreateDirectory(history_dir_));
1006 history_service_.reset(new HistoryService); 1009 if (!history_service_->Init(
1007 if (!history_service_->Init(history_dir_)) { 1010 TestHistoryDatabaseParamsForPath(history_dir_))) {
1008 history_service_.reset(); 1011 history_service_.reset();
1009 ADD_FAILURE(); 1012 ADD_FAILURE();
1010 } 1013 }
1011 } 1014 }
1012 1015
1013 void TearDown() override { 1016 void TearDown() override {
1014 if (history_service_) 1017 if (history_service_)
1015 CleanupHistoryService(); 1018 CleanupHistoryService();
1016 1019
1017 // Make sure we don't have any event pending that could disrupt the next 1020 // Make sure we don't have any event pending that could disrupt the next
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
1869 std::vector<PageUsageData*> results; 1872 std::vector<PageUsageData*> results;
1870 db_->QuerySegmentUsage(segment_time, 10, &results); 1873 db_->QuerySegmentUsage(segment_time, 10, &results);
1871 ASSERT_EQ(1u, results.size()); 1874 ASSERT_EQ(1u, results.size());
1872 EXPECT_EQ(url, results[0]->GetURL()); 1875 EXPECT_EQ(url, results[0]->GetURL());
1873 EXPECT_EQ(segment_id, results[0]->GetID()); 1876 EXPECT_EQ(segment_id, results[0]->GetID());
1874 EXPECT_EQ(title, results[0]->GetTitle()); 1877 EXPECT_EQ(title, results[0]->GetTitle());
1875 STLDeleteElements(&results); 1878 STLDeleteElements(&results);
1876 } 1879 }
1877 1880
1878 } // namespace history 1881 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698