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

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

Issue 285233012: Abstract history dependencies on bookmarks through HistoryClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 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 <algorithm> 5 #include <algorithm>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 11 matching lines...) Expand all
22 #include "chrome/browser/history/history_database.h" 22 #include "chrome/browser/history/history_database.h"
23 #include "chrome/browser/history/history_notifications.h" 23 #include "chrome/browser/history/history_notifications.h"
24 #include "chrome/browser/history/thumbnail_database.h" 24 #include "chrome/browser/history/thumbnail_database.h"
25 #include "chrome/browser/history/top_sites.h" 25 #include "chrome/browser/history/top_sites.h"
26 #include "chrome/common/thumbnail_score.h" 26 #include "chrome/common/thumbnail_score.h"
27 #include "chrome/test/base/testing_profile.h" 27 #include "chrome/test/base/testing_profile.h"
28 #include "chrome/tools/profiles/thumbnail-inl.h" 28 #include "chrome/tools/profiles/thumbnail-inl.h"
29 #include "components/bookmarks/browser/bookmark_model.h" 29 #include "components/bookmarks/browser/bookmark_model.h"
30 #include "components/bookmarks/browser/bookmark_utils.h" 30 #include "components/bookmarks/browser/bookmark_utils.h"
31 #include "components/bookmarks/test/test_bookmark_client.h" 31 #include "components/bookmarks/test/test_bookmark_client.h"
32 #include "components/history/core/test/history_client_fake_bookmarks.h"
32 #include "content/public/test/test_browser_thread.h" 33 #include "content/public/test/test_browser_thread.h"
33 #include "testing/gtest/include/gtest/gtest.h" 34 #include "testing/gtest/include/gtest/gtest.h"
34 #include "third_party/skia/include/core/SkBitmap.h" 35 #include "third_party/skia/include/core/SkBitmap.h"
35 #include "ui/gfx/codec/jpeg_codec.h" 36 #include "ui/gfx/codec/jpeg_codec.h"
36 37
37 using base::Time; 38 using base::Time;
38 using base::TimeDelta; 39 using base::TimeDelta;
39 using base::TimeTicks; 40 using base::TimeTicks;
40 using content::BrowserThread; 41 using content::BrowserThread;
41 42
42 // Filename constants. 43 // Filename constants.
43 static const base::FilePath::CharType kHistoryFile[] = 44 static const base::FilePath::CharType kHistoryFile[] =
44 FILE_PATH_LITERAL("History"); 45 FILE_PATH_LITERAL("History");
45 static const base::FilePath::CharType kArchivedHistoryFile[] = 46 static const base::FilePath::CharType kArchivedHistoryFile[] =
46 FILE_PATH_LITERAL("Archived History"); 47 FILE_PATH_LITERAL("Archived History");
47 static const base::FilePath::CharType kThumbnailFile[] = 48 static const base::FilePath::CharType kThumbnailFile[] =
48 FILE_PATH_LITERAL("Thumbnails"); 49 FILE_PATH_LITERAL("Thumbnails");
49 50
50 // The test must be in the history namespace for the gtest forward declarations 51 // The test must be in the history namespace for the gtest forward declarations
51 // to work. It also eliminates a bunch of ugly "history::". 52 // to work. It also eliminates a bunch of ugly "history::".
52 namespace history { 53 namespace history {
53 54
54 // ExpireHistoryTest ----------------------------------------------------------- 55 // ExpireHistoryTest -----------------------------------------------------------
55 56
56 class ExpireHistoryTest : public testing::Test, 57 class ExpireHistoryTest : public testing::Test,
57 public BroadcastNotificationDelegate { 58 public BroadcastNotificationDelegate {
58 public: 59 public:
59 ExpireHistoryTest() 60 ExpireHistoryTest()
60 : bookmark_model_(bookmark_client_.CreateModel(false)), 61 : ui_thread_(BrowserThread::UI, &message_loop_),
61 ui_thread_(BrowserThread::UI, &message_loop_),
62 db_thread_(BrowserThread::DB, &message_loop_), 62 db_thread_(BrowserThread::DB, &message_loop_),
63 expirer_(this, bookmark_model_.get()), 63 expirer_(this, &history_client_),
64 now_(Time::Now()) {} 64 now_(Time::Now()) {}
65 65
66 protected: 66 protected:
67 // Called by individual tests when they want data populated. 67 // Called by individual tests when they want data populated.
68 void AddExampleData(URLID url_ids[3], Time visit_times[4]); 68 void AddExampleData(URLID url_ids[3], Time visit_times[4]);
69 // Add visits with source information. 69 // Add visits with source information.
70 void AddExampleSourceData(const GURL& url, URLID* id); 70 void AddExampleSourceData(const GURL& url, URLID* id);
71 71
72 // Returns true if the given favicon/thumanil has an entry in the DB. 72 // Returns true if the given favicon/thumanil has an entry in the DB.
73 bool HasFavicon(favicon_base::FaviconID favicon_id); 73 bool HasFavicon(favicon_base::FaviconID favicon_id);
74 bool HasThumbnail(URLID url_id); 74 bool HasThumbnail(URLID url_id);
75 75
76 favicon_base::FaviconID GetFavicon(const GURL& page_url, 76 favicon_base::FaviconID GetFavicon(const GURL& page_url,
77 favicon_base::IconType icon_type); 77 favicon_base::IconType icon_type);
78 78
79 // EXPECTs that each URL-specific history thing (basically, everything but 79 // EXPECTs that each URL-specific history thing (basically, everything but
80 // favicons) is gone, the reason being either that it was |archived|, or 80 // favicons) is gone, the reason being either that it was |archived|, or
81 // manually deleted. 81 // manually deleted.
82 void EnsureURLInfoGone(const URLRow& row, bool archived); 82 void EnsureURLInfoGone(const URLRow& row, bool archived);
83 83
84 // Returns whether a NOTIFICATION_HISTORY_URLS_MODIFIED was sent for |url|. 84 // Returns whether a NOTIFICATION_HISTORY_URLS_MODIFIED was sent for |url|.
85 bool ModifiedNotificationSent(const GURL& url); 85 bool ModifiedNotificationSent(const GURL& url);
86 86
87 // Clears the list of notifications received. 87 // Clears the list of notifications received.
88 void ClearLastNotifications() { 88 void ClearLastNotifications() {
89 STLDeleteValues(&notifications_); 89 STLDeleteValues(&notifications_);
90 } 90 }
91 91
92 void StarURL(const GURL& url) { 92 void StarURL(const GURL& url) { history_client_.AddBookmark(url); }
93 bookmark_model_->AddURL(
94 bookmark_model_->bookmark_bar_node(), 0, base::string16(), url);
95 }
96 93
97 static bool IsStringInFile(const base::FilePath& filename, const char* str); 94 static bool IsStringInFile(const base::FilePath& filename, const char* str);
98 95
99 // Returns the path the db files are created in. 96 // Returns the path the db files are created in.
100 const base::FilePath& path() const { return tmp_dir_.path(); } 97 const base::FilePath& path() const { return tmp_dir_.path(); }
101 98
102 // This must be destroyed last. 99 // This must be destroyed last.
103 base::ScopedTempDir tmp_dir_; 100 base::ScopedTempDir tmp_dir_;
104 101
105 test::TestBookmarkClient bookmark_client_; 102 HistoryClientFakeBookmarks history_client_;
106 scoped_ptr<BookmarkModel> bookmark_model_;
107 103
108 base::MessageLoopForUI message_loop_; 104 base::MessageLoopForUI message_loop_;
109 content::TestBrowserThread ui_thread_; 105 content::TestBrowserThread ui_thread_;
110 content::TestBrowserThread db_thread_; 106 content::TestBrowserThread db_thread_;
111 107
112 ExpireHistoryBackend expirer_; 108 ExpireHistoryBackend expirer_;
113 109
114 scoped_ptr<HistoryDatabase> main_db_; 110 scoped_ptr<HistoryDatabase> main_db_;
115 scoped_ptr<ArchivedDatabase> archived_db_; 111 scoped_ptr<ArchivedDatabase> archived_db_;
116 scoped_ptr<ThumbnailDatabase> thumb_db_; 112 scoped_ptr<ThumbnailDatabase> thumb_db_;
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 // And no visits. 510 // And no visits.
515 VisitVector visits; 511 VisitVector visits;
516 main_db_->GetVisitsForURL(url_row.id(), &visits); 512 main_db_->GetVisitsForURL(url_row.id(), &visits);
517 ASSERT_EQ(0U, visits.size()); 513 ASSERT_EQ(0U, visits.size());
518 514
519 // Should still have the thumbnail. 515 // Should still have the thumbnail.
520 // TODO(sky): fix this, see comment in HasThumbnail. 516 // TODO(sky): fix this, see comment in HasThumbnail.
521 // ASSERT_TRUE(HasThumbnail(url_row.id())); 517 // ASSERT_TRUE(HasThumbnail(url_row.id()));
522 518
523 // Unstar the URL and delete again. 519 // Unstar the URL and delete again.
524 bookmark_utils::RemoveAllBookmarks(bookmark_model_.get(), url); 520 history_client_.ClearAllBookmarks();
525 ClearLastNotifications(); 521 ClearLastNotifications();
526 expirer_.DeleteURL(url); 522 expirer_.DeleteURL(url);
527 523
528 // Now it should be completely deleted. 524 // Now it should be completely deleted.
529 EnsureURLInfoGone(url_row, false); 525 EnsureURLInfoGone(url_row, false);
530 } 526 }
531 527
532 // Deletes multiple URLs at once. The favicon for the third one but 528 // Deletes multiple URLs at once. The favicon for the third one but
533 // not the first two should be deleted. 529 // not the first two should be deleted.
534 TEST_F(ExpireHistoryTest, DeleteURLs) { 530 TEST_F(ExpireHistoryTest, DeleteURLs) {
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 main_db_->GetVisitsForURL(url_id, &archived_visits); 947 main_db_->GetVisitsForURL(url_id, &archived_visits);
952 EXPECT_EQ(0U, archived_visits.size()); 948 EXPECT_EQ(0U, archived_visits.size());
953 } 949 }
954 950
955 // TODO(brettw) add some visits with no URL to make sure everything is updated 951 // TODO(brettw) add some visits with no URL to make sure everything is updated
956 // properly. Have the visits also refer to nonexistent FTS rows. 952 // properly. Have the visits also refer to nonexistent FTS rows.
957 // 953 //
958 // Maybe also refer to invalid favicons. 954 // Maybe also refer to invalid favicons.
959 955
960 } // namespace history 956 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698