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

Side by Side Diff: chrome/browser/history/android/android_provider_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
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/android/android_provider_backend.h" 5 #include "chrome/browser/history/android/android_provider_backend.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
16 #include "chrome/browser/chrome_notification_types.h" 16 #include "chrome/browser/chrome_notification_types.h"
17 #include "chrome/browser/history/chrome_history_client.h" 17 #include "chrome/browser/history/chrome_history_client.h"
18 #include "chrome/browser/history/chrome_history_client_factory.h" 18 #include "chrome/browser/history/chrome_history_client_factory.h"
19 #include "chrome/browser/history/history_backend.h" 19 #include "chrome/browser/history/history_backend.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/common/chrome_constants.h" 21 #include "chrome/common/chrome_constants.h"
22 #include "chrome/test/base/testing_browser_process.h" 22 #include "chrome/test/base/testing_browser_process.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "chrome/test/base/testing_profile_manager.h" 24 #include "chrome/test/base/testing_profile_manager.h"
25 #include "components/bookmarks/browser/bookmark_model.h" 25 #include "components/bookmarks/browser/bookmark_model.h"
26 #include "components/bookmarks/test/bookmark_test_helpers.h" 26 #include "components/bookmarks/test/bookmark_test_helpers.h"
27 #include "components/history/core/android/android_time.h" 27 #include "components/history/core/browser/android/android_time.h"
28 #include "components/history/core/browser/history_constants.h" 28 #include "components/history/core/browser/history_constants.h"
29 #include "components/history/core/browser/history_database_params.h"
29 #include "components/history/core/browser/keyword_search_term.h" 30 #include "components/history/core/browser/keyword_search_term.h"
31 #include "components/history/core/test/test_history_database.h"
30 #include "content/public/browser/browser_thread.h" 32 #include "content/public/browser/browser_thread.h"
31 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
32 #include "content/public/test/test_utils.h" 34 #include "content/public/test/test_utils.h"
33 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 36 #include "third_party/skia/include/core/SkBitmap.h"
35 37
36 using base::Time; 38 using base::Time;
37 using base::TimeDelta; 39 using base::TimeDelta;
38 using base::UTF8ToUTF16; 40 using base::UTF8ToUTF16;
39 using bookmarks::BookmarkModel; 41 using bookmarks::BookmarkModel;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 scoped_ptr<history::URLRows> modified_details_; 159 scoped_ptr<history::URLRows> modified_details_;
158 scoped_ptr<std::set<GURL>> favicon_changed_; 160 scoped_ptr<std::set<GURL>> favicon_changed_;
159 161
160 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendNotifier); 162 DISALLOW_COPY_AND_ASSIGN(AndroidProviderBackendNotifier);
161 }; 163 };
162 164
163 class AndroidProviderBackendTest : public testing::Test { 165 class AndroidProviderBackendTest : public testing::Test {
164 public: 166 public:
165 AndroidProviderBackendTest() 167 AndroidProviderBackendTest()
166 : thumbnail_db_(NULL), 168 : thumbnail_db_(NULL),
167 profile_manager_( 169 profile_manager_(TestingBrowserProcess::GetGlobal()),
168 TestingBrowserProcess::GetGlobal()),
169 bookmark_model_(NULL), 170 bookmark_model_(NULL),
170 ui_thread_(BrowserThread::UI, &message_loop_), 171 ui_thread_(BrowserThread::UI, &message_loop_),
171 file_thread_(BrowserThread::FILE, &message_loop_) { 172 file_thread_(BrowserThread::FILE, &message_loop_) {}
172 }
173 ~AndroidProviderBackendTest() override {} 173 ~AndroidProviderBackendTest() override {}
174 174
175 protected: 175 protected:
176 void SetUp() override { 176 void SetUp() override {
177 // Setup the testing profile, so the bookmark_model_sql_handler could 177 // Setup the testing profile, so the bookmark_model_sql_handler could
178 // get the bookmark model from it. 178 // get the bookmark model from it.
179 ASSERT_TRUE(profile_manager_.SetUp()); 179 ASSERT_TRUE(profile_manager_.SetUp());
180 // It seems that the name has to be chrome::kInitialProfile, so it 180 // It seems that the name has to be chrome::kInitialProfile, so it
181 // could be found by ProfileManager::GetLastUsedProfile(). 181 // could be found by ProfileManager::GetLastUsedProfile().
182 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile( 182 TestingProfile* testing_profile = profile_manager_.CreateTestingProfile(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 row.url_id_ = statement.ColumnInt64(2); 236 row.url_id_ = statement.ColumnInt64(2);
237 row.bookmark_ = statement.ColumnBool(3); 237 row.bookmark_ = statement.ColumnBool(3);
238 row.favicon_id_ = statement.ColumnInt64(4); 238 row.favicon_id_ = statement.ColumnInt64(4);
239 rows->push_back(row); 239 rows->push_back(row);
240 } 240 }
241 return true; 241 return true;
242 } 242 }
243 243
244 AndroidProviderBackendNotifier notifier_; 244 AndroidProviderBackendNotifier notifier_;
245 scoped_refptr<HistoryBackend> history_backend_; 245 scoped_refptr<HistoryBackend> history_backend_;
246 HistoryDatabase history_db_; 246 TestHistoryDatabase history_db_;
247 ThumbnailDatabase thumbnail_db_; 247 ThumbnailDatabase thumbnail_db_;
248 base::ScopedTempDir temp_dir_; 248 base::ScopedTempDir temp_dir_;
249 base::FilePath android_cache_db_name_; 249 base::FilePath android_cache_db_name_;
250 base::FilePath history_db_name_; 250 base::FilePath history_db_name_;
251 base::FilePath thumbnail_db_name_; 251 base::FilePath thumbnail_db_name_;
252 252
253 TestingProfileManager profile_manager_; 253 TestingProfileManager profile_manager_;
254 BookmarkModel* bookmark_model_; 254 BookmarkModel* bookmark_model_;
255 base::MessageLoopForUI message_loop_; 255 base::MessageLoopForUI message_loop_;
256 content::TestBrowserThread ui_thread_; 256 content::TestBrowserThread ui_thread_;
(...skipping 28 matching lines...) Expand all
285 GURL url3("http://www.bookmark.com"); 285 GURL url3("http://www.bookmark.com");
286 base::string16 title3(UTF8ToUTF16("bookmark")); 286 base::string16 title3(UTF8ToUTF16("bookmark"));
287 ASSERT_TRUE(bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(), 0, 287 ASSERT_TRUE(bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(), 0,
288 title3, url3)); 288 title3, url3));
289 // Only use the HistoryBackend to generate the test data. 289 // Only use the HistoryBackend to generate the test data.
290 // HistoryBackend will shutdown after that. 290 // HistoryBackend will shutdown after that.
291 { 291 {
292 scoped_refptr<HistoryBackend> history_backend; 292 scoped_refptr<HistoryBackend> history_backend;
293 history_backend = new HistoryBackend( 293 history_backend = new HistoryBackend(
294 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_); 294 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_);
295 history_backend->Init(std::string(), false); 295 history_backend->Init(std::string(), false,
296 TestHistoryDatabaseParamsForPath(temp_dir_.path()));
296 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 297 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
297 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 298 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
298 URLRow url_row; 299 URLRow url_row;
299 300
300 ASSERT_TRUE(history_backend->GetURL(url1, &url_row)); 301 ASSERT_TRUE(history_backend->GetURL(url1, &url_row));
301 url_id1 = url_row.id(); 302 url_id1 = url_row.id();
302 ASSERT_TRUE(history_backend->GetURL(url2, &url_row)); 303 ASSERT_TRUE(history_backend->GetURL(url2, &url_row));
303 url_id2 = url_row.id(); 304 url_id2 = url_row.id();
304 305
305 // Set favicon to url2. 306 // Set favicon to url2.
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5), 423 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5),
423 ui::PAGE_TRANSITION_LINK)); 424 ui::PAGE_TRANSITION_LINK));
424 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK)); 425 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK));
425 426
426 // Only use the HistoryBackend to generate the test data. 427 // Only use the HistoryBackend to generate the test data.
427 // HistoryBackend will shutdown after that. 428 // HistoryBackend will shutdown after that.
428 { 429 {
429 scoped_refptr<HistoryBackend> history_backend; 430 scoped_refptr<HistoryBackend> history_backend;
430 history_backend = new HistoryBackend( 431 history_backend = new HistoryBackend(
431 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_); 432 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_);
432 history_backend->Init(std::string(), false); 433 history_backend->Init(std::string(), false,
434 TestHistoryDatabaseParamsForPath(temp_dir_.path()));
433 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 435 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
434 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 436 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
435 437
436 history::URLRows url_rows(2u); 438 history::URLRows url_rows(2u);
437 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 439 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
438 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 440 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
439 url_rows[0].set_title(title1); 441 url_rows[0].set_title(title1);
440 url_rows[1].set_title(title2); 442 url_rows[1].set_title(title2);
441 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows)); 443 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows));
442 444
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5), 1860 visits2.push_back(VisitInfo(last_visited2 - TimeDelta::FromDays(5),
1859 ui::PAGE_TRANSITION_LINK)); 1861 ui::PAGE_TRANSITION_LINK));
1860 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK)); 1862 visits2.push_back(VisitInfo(last_visited2, ui::PAGE_TRANSITION_LINK));
1861 1863
1862 // Only use the HistoryBackend to generate the test data. 1864 // Only use the HistoryBackend to generate the test data.
1863 // HistoryBackend will shutdown after that. 1865 // HistoryBackend will shutdown after that.
1864 { 1866 {
1865 scoped_refptr<HistoryBackend> history_backend; 1867 scoped_refptr<HistoryBackend> history_backend;
1866 history_backend = new HistoryBackend( 1868 history_backend = new HistoryBackend(
1867 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_); 1869 temp_dir_.path(), new AndroidProviderBackendDelegate(), history_client_);
1868 history_backend->Init(std::string(), false); 1870 history_backend->Init(std::string(), false,
1871 TestHistoryDatabaseParamsForPath(temp_dir_.path()));
1869 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED); 1872 history_backend->AddVisits(url1, visits1, history::SOURCE_SYNCED);
1870 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED); 1873 history_backend->AddVisits(url2, visits2, history::SOURCE_SYNCED);
1871 URLRow url_row; 1874 URLRow url_row;
1872 1875
1873 history::URLRows url_rows(2u); 1876 history::URLRows url_rows(2u);
1874 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0])); 1877 ASSERT_TRUE(history_backend->GetURL(url1, &url_rows[0]));
1875 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1])); 1878 ASSERT_TRUE(history_backend->GetURL(url2, &url_rows[1]));
1876 url_rows[0].set_title(title1); 1879 url_rows[0].set_title(title1);
1877 url_rows[1].set_title(title2); 1880 url_rows[1].set_title(title2);
1878 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows)); 1881 ASSERT_EQ(2u, history_backend->UpdateURLs(url_rows));
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 row2.set_raw_url("http://www.example.com"); 2025 row2.set_raw_url("http://www.example.com");
2023 row2.set_url(GURL("http://www.example.com")); 2026 row2.set_url(GURL("http://www.example.com"));
2024 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10)); 2027 row2.set_last_visit_time(Time::Now() - TimeDelta::FromDays(10));
2025 row2.set_is_bookmark(false); 2028 row2.set_is_bookmark(false);
2026 row2.set_title(UTF8ToUTF16("example")); 2029 row2.set_title(UTF8ToUTF16("example"));
2027 std::vector<unsigned char> data; 2030 std::vector<unsigned char> data;
2028 data.push_back('1'); 2031 data.push_back('1');
2029 row2.set_favicon(base::RefCountedBytes::TakeVector(&data)); 2032 row2.set_favicon(base::RefCountedBytes::TakeVector(&data));
2030 2033
2031 { 2034 {
2032 HistoryDatabase history_db; 2035 TestHistoryDatabase history_db;
2033 ThumbnailDatabase thumbnail_db(NULL); 2036 ThumbnailDatabase thumbnail_db(NULL);
2034 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name_)); 2037 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name_));
2035 ASSERT_EQ(sql::INIT_OK, thumbnail_db.Init(thumbnail_db_name_)); 2038 ASSERT_EQ(sql::INIT_OK, thumbnail_db.Init(thumbnail_db_name_));
2036 2039
2037 scoped_ptr<AndroidProviderBackend> backend( 2040 scoped_ptr<AndroidProviderBackend> backend(
2038 new AndroidProviderBackend(android_cache_db_name_, 2041 new AndroidProviderBackend(android_cache_db_name_,
2039 &history_db, 2042 &history_db,
2040 &thumbnail_db, 2043 &thumbnail_db,
2041 history_client_, 2044 history_client_,
2042 &notifier_)); 2045 &notifier_));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2099 HistoryAndBookmarkRow row1; 2102 HistoryAndBookmarkRow row1;
2100 row1.set_raw_url("cnn.com"); 2103 row1.set_raw_url("cnn.com");
2101 row1.set_url(GURL("http://cnn.com")); 2104 row1.set_url(GURL("http://cnn.com"));
2102 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1)); 2105 row1.set_last_visit_time(Time::Now() - TimeDelta::FromDays(1));
2103 row1.set_created(Time::Now() - TimeDelta::FromDays(20)); 2106 row1.set_created(Time::Now() - TimeDelta::FromDays(20));
2104 row1.set_visit_count(10); 2107 row1.set_visit_count(10);
2105 row1.set_is_bookmark(true); 2108 row1.set_is_bookmark(true);
2106 row1.set_title(UTF8ToUTF16("cnn")); 2109 row1.set_title(UTF8ToUTF16("cnn"));
2107 2110
2108 { 2111 {
2109 HistoryDatabase history_db; 2112 TestHistoryDatabase history_db;
2110 ThumbnailDatabase thumbnail_db(NULL); 2113 ThumbnailDatabase thumbnail_db(NULL);
2111 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name_)); 2114 ASSERT_EQ(sql::INIT_OK, history_db.Init(history_db_name_));
2112 ASSERT_EQ(sql::INIT_OK, thumbnail_db.Init(thumbnail_db_name_)); 2115 ASSERT_EQ(sql::INIT_OK, thumbnail_db.Init(thumbnail_db_name_));
2113 scoped_ptr<AndroidProviderBackend> backend( 2116 scoped_ptr<AndroidProviderBackend> backend(
2114 new AndroidProviderBackend(android_cache_db_name_, 2117 new AndroidProviderBackend(android_cache_db_name_,
2115 &history_db, 2118 &history_db,
2116 &thumbnail_db, 2119 &thumbnail_db,
2117 history_client_, 2120 history_client_,
2118 &notifier_)); 2121 &notifier_));
2119 2122
(...skipping 26 matching lines...) Expand all
2146 update_args, &update_count)); 2149 update_args, &update_count));
2147 // Verify notifications. 2150 // Verify notifications.
2148 EXPECT_FALSE(notifier_.deleted_details()); 2151 EXPECT_FALSE(notifier_.deleted_details());
2149 ASSERT_TRUE(notifier_.modified_details()); 2152 ASSERT_TRUE(notifier_.modified_details());
2150 ASSERT_EQ(1u, notifier_.modified_details()->size()); 2153 ASSERT_EQ(1u, notifier_.modified_details()->size());
2151 // No favicon will be updated as thumbnail database is missing. 2154 // No favicon will be updated as thumbnail database is missing.
2152 EXPECT_FALSE(notifier_.favicon_changed()); 2155 EXPECT_FALSE(notifier_.favicon_changed());
2153 } 2156 }
2154 2157
2155 } // namespace history 2158 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698