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

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

Issue 849323002: Componentize HistoryDatabase (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix android compilation 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
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_database.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 13 matching lines...) Expand all
24 #include "chrome/browser/chrome_notification_types.h" 24 #include "chrome/browser/chrome_notification_types.h"
25 #include "chrome/browser/history/history_notifications.h" 25 #include "chrome/browser/history/history_notifications.h"
26 #include "chrome/browser/history/history_service.h" 26 #include "chrome/browser/history/history_service.h"
27 #include "chrome/browser/history/history_service_factory.h" 27 #include "chrome/browser/history/history_service_factory.h"
28 #include "chrome/browser/history/in_memory_history_backend.h" 28 #include "chrome/browser/history/in_memory_history_backend.h"
29 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_paths.h" 30 #include "chrome/common/chrome_paths.h"
31 #include "chrome/common/importer/imported_favicon_usage.h" 31 #include "chrome/common/importer/imported_favicon_usage.h"
32 #include "chrome/test/base/testing_profile.h" 32 #include "chrome/test/base/testing_profile.h"
33 #include "components/history/core/browser/history_constants.h" 33 #include "components/history/core/browser/history_constants.h"
34 #include "components/history/core/browser/history_database_params.h"
34 #include "components/history/core/browser/in_memory_database.h" 35 #include "components/history/core/browser/in_memory_database.h"
35 #include "components/history/core/browser/keyword_search_term.h" 36 #include "components/history/core/browser/keyword_search_term.h"
36 #include "components/history/core/browser/visit_filter.h" 37 #include "components/history/core/browser/visit_filter.h"
37 #include "components/history/core/test/history_client_fake_bookmarks.h" 38 #include "components/history/core/test/history_client_fake_bookmarks.h"
39 #include "components/history/core/test/test_history_database.h"
38 #include "content/public/browser/notification_details.h" 40 #include "content/public/browser/notification_details.h"
39 #include "content/public/browser/notification_source.h" 41 #include "content/public/browser/notification_source.h"
40 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
41 #include "testing/gmock/include/gmock/gmock.h" 43 #include "testing/gmock/include/gmock/gmock.h"
42 #include "testing/gtest/include/gtest/gtest.h" 44 #include "testing/gtest/include/gtest/gtest.h"
43 #include "third_party/skia/include/core/SkBitmap.h" 45 #include "third_party/skia/include/core/SkBitmap.h"
44 #include "ui/gfx/codec/png_codec.h" 46 #include "ui/gfx/codec/png_codec.h"
45 #include "url/gurl.h" 47 #include "url/gurl.h"
46 48
47 using base::Time; 49 using base::Time;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 friend class HistoryBackendTestDelegate; 245 friend class HistoryBackendTestDelegate;
244 246
245 // testing::Test 247 // testing::Test
246 void SetUp() override { 248 void SetUp() override {
247 ClearFaviconChangedNotificationCounter(); 249 ClearFaviconChangedNotificationCounter();
248 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"), 250 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("BackendTest"),
249 &test_dir_)) 251 &test_dir_))
250 return; 252 return;
251 backend_ = new HistoryBackend( 253 backend_ = new HistoryBackend(
252 test_dir_, new HistoryBackendTestDelegate(this), &history_client_); 254 test_dir_, new HistoryBackendTestDelegate(this), &history_client_);
253 backend_->Init(std::string(), false); 255 backend_->Init(std::string(), false,
256 TestHistoryDatabaseParamsForPath(test_dir_));
254 } 257 }
255 258
256 void TearDown() override { 259 void TearDown() override {
257 if (backend_.get()) 260 if (backend_.get())
258 backend_->Closing(); 261 backend_->Closing();
259 backend_ = NULL; 262 backend_ = NULL;
260 mem_backend_.reset(); 263 mem_backend_.reset();
261 base::DeleteFile(test_dir_, true); 264 base::DeleteFile(test_dir_, true);
262 base::RunLoop().RunUntilIdle(); 265 base::RunLoop().RunUntilIdle();
263 history_client_.ClearAllBookmarks(); 266 history_client_.ClearAllBookmarks();
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 // Copy history database file to current directory so that it will be deleted 1562 // Copy history database file to current directory so that it will be deleted
1560 // in Teardown. 1563 // in Teardown.
1561 base::FilePath new_history_path(test_dir()); 1564 base::FilePath new_history_path(test_dir());
1562 base::DeleteFile(new_history_path, true); 1565 base::DeleteFile(new_history_path, true);
1563 base::CreateDirectory(new_history_path); 1566 base::CreateDirectory(new_history_path);
1564 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); 1567 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename);
1565 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file)); 1568 ASSERT_TRUE(base::CopyFile(old_history_path, new_history_file));
1566 1569
1567 backend_ = new HistoryBackend( 1570 backend_ = new HistoryBackend(
1568 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); 1571 new_history_path, new HistoryBackendTestDelegate(this), &history_client_);
1569 backend_->Init(std::string(), false); 1572 backend_->Init(std::string(), false,
1573 TestHistoryDatabaseParamsForPath(new_history_path));
1570 backend_->Closing(); 1574 backend_->Closing();
1571 backend_ = NULL; 1575 backend_ = NULL;
1572 1576
1573 // Now the database should already be migrated. 1577 // Now the database should already be migrated.
1574 // Check version first. 1578 // Check version first.
1575 int cur_version = HistoryDatabase::GetCurrentVersion(); 1579 int cur_version = HistoryDatabase::GetCurrentVersion();
1576 sql::Connection db; 1580 sql::Connection db;
1577 ASSERT_TRUE(db.Open(new_history_file)); 1581 ASSERT_TRUE(db.Open(new_history_file));
1578 sql::Statement s(db.GetUniqueStatement( 1582 sql::Statement s(db.GetUniqueStatement(
1579 "SELECT value FROM meta WHERE key = 'version'")); 1583 "SELECT value FROM meta WHERE key = 'version'"));
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
2811 // Copy history database file to current directory so that it will be deleted 2815 // Copy history database file to current directory so that it will be deleted
2812 // in Teardown. 2816 // in Teardown.
2813 base::FilePath new_history_path(test_dir()); 2817 base::FilePath new_history_path(test_dir());
2814 base::DeleteFile(new_history_path, true); 2818 base::DeleteFile(new_history_path, true);
2815 base::CreateDirectory(new_history_path); 2819 base::CreateDirectory(new_history_path);
2816 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename); 2820 base::FilePath new_history_file = new_history_path.Append(kHistoryFilename);
2817 ASSERT_TRUE(base::CopyFile(old_history, new_history_file)); 2821 ASSERT_TRUE(base::CopyFile(old_history, new_history_file));
2818 2822
2819 backend_ = new HistoryBackend( 2823 backend_ = new HistoryBackend(
2820 new_history_path, new HistoryBackendTestDelegate(this), &history_client_); 2824 new_history_path, new HistoryBackendTestDelegate(this), &history_client_);
2821 backend_->Init(std::string(), false); 2825 backend_->Init(std::string(), false,
2826 TestHistoryDatabaseParamsForPath(new_history_path));
2822 backend_->Closing(); 2827 backend_->Closing();
2823 backend_ = NULL; 2828 backend_ = NULL;
2824 2829
2825 // Now the history database should already be migrated. 2830 // Now the history database should already be migrated.
2826 2831
2827 // Check version in history database first. 2832 // Check version in history database first.
2828 int cur_version = HistoryDatabase::GetCurrentVersion(); 2833 int cur_version = HistoryDatabase::GetCurrentVersion();
2829 sql::Connection db; 2834 sql::Connection db;
2830 ASSERT_TRUE(db.Open(new_history_file)); 2835 ASSERT_TRUE(db.Open(new_history_file));
2831 sql::Statement s(db.GetUniqueStatement( 2836 sql::Statement s(db.GetUniqueStatement(
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 // History that block till bookmark bar model is loaded. 3040 // History that block till bookmark bar model is loaded.
3036 TEST_F(HistoryBackendTest, RemoveNotification) { 3041 TEST_F(HistoryBackendTest, RemoveNotification) {
3037 scoped_ptr<TestingProfile> profile(new TestingProfile()); 3042 scoped_ptr<TestingProfile> profile(new TestingProfile());
3038 3043
3039 // Add a URL. 3044 // Add a URL.
3040 GURL url("http://www.google.com"); 3045 GURL url("http://www.google.com");
3041 HistoryClientMock history_client; 3046 HistoryClientMock history_client;
3042 history_client.AddBookmark(url); 3047 history_client.AddBookmark(url);
3043 scoped_ptr<HistoryService> service( 3048 scoped_ptr<HistoryService> service(
3044 new HistoryService(&history_client, profile.get())); 3049 new HistoryService(&history_client, profile.get()));
3045 EXPECT_TRUE(service->Init(profile->GetPath())); 3050 EXPECT_TRUE(
3051 service->Init(TestHistoryDatabaseParamsForPath(profile->GetPath())));
3046 3052
3047 service->AddPage( 3053 service->AddPage(
3048 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(), 3054 url, base::Time::Now(), NULL, 1, GURL(), RedirectList(),
3049 ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false); 3055 ui::PAGE_TRANSITION_TYPED, SOURCE_BROWSED, false);
3050 3056
3051 // This won't actually delete the URL, rather it'll empty out the visits. 3057 // This won't actually delete the URL, rather it'll empty out the visits.
3052 // This triggers blocking on the BookmarkModel. 3058 // This triggers blocking on the BookmarkModel.
3053 EXPECT_CALL(history_client, BlockUntilBookmarksLoaded()); 3059 EXPECT_CALL(history_client, BlockUntilBookmarksLoaded());
3054 service->DeleteURL(url); 3060 service->DeleteURL(url);
3055 } 3061 }
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
3289 // Verify that the second term is no longer returned as result, and also check 3295 // Verify that the second term is no longer returned as result, and also check
3290 // at the low level that it is gone for good. The term corresponding to the 3296 // at the low level that it is gone for good. The term corresponding to the
3291 // first URLRow should not be affected. 3297 // first URLRow should not be affected.
3292 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1)); 3298 EXPECT_EQ(1u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term1));
3293 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2)); 3299 EXPECT_EQ(0u, GetNumberOfMatchingSearchTerms(kTestKeywordId, term2));
3294 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL)); 3300 EXPECT_TRUE(mem_backend_->db()->GetKeywordSearchTermRow(row1.id(), NULL));
3295 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL)); 3301 EXPECT_FALSE(mem_backend_->db()->GetKeywordSearchTermRow(row2.id(), NULL));
3296 } 3302 }
3297 3303
3298 } // namespace history 3304 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend.cc ('k') | chrome/browser/history/history_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698