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

Side by Side Diff: chrome/browser/importer/profile_writer_unittest.cc

Issue 306143003: Remove the BookmarkService interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@371825.2
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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/importer/profile_writer.h" 5 #include "chrome/browser/importer/profile_writer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 MakeURLRow("http://www.google.com", base::ASCIIToUTF16("Google"), 70 MakeURLRow("http://www.google.com", base::ASCIIToUTF16("Google"),
71 3, 10, 1)); 71 3, 10, 1));
72 history::URLRow row2( 72 history::URLRow row2(
73 MakeURLRow("http://www.yahoo.com", base::ASCIIToUTF16("Yahoo"), 73 MakeURLRow("http://www.yahoo.com", base::ASCIIToUTF16("Yahoo"),
74 3, 30, 10)); 74 3, 30, 10));
75 pages_.push_back(row1); 75 pages_.push_back(row1);
76 pages_.push_back(row2); 76 pages_.push_back(row2);
77 } 77 }
78 78
79 void VerifyBookmarksCount( 79 void VerifyBookmarksCount(
80 const std::vector<BookmarkService::URLAndTitle>& bookmarks_record, 80 const std::vector<BookmarkModel::URLAndTitle>& bookmarks_record,
81 BookmarkModel* bookmark_model, 81 BookmarkModel* bookmark_model,
82 size_t expected) { 82 size_t expected) {
83 std::vector<BookmarkMatch> matches; 83 std::vector<BookmarkMatch> matches;
84 for (size_t i = 0; i < bookmarks_record.size(); ++i) { 84 for (size_t i = 0; i < bookmarks_record.size(); ++i) {
85 bookmark_model->GetBookmarksMatching( 85 bookmark_model->GetBookmarksMatching(
86 bookmarks_record[i].title, 10, &matches); 86 bookmarks_record[i].title, 10, &matches);
87 EXPECT_EQ(expected, matches.size()); 87 EXPECT_EQ(expected, matches.size());
88 matches.clear(); 88 matches.clear();
89 } 89 }
90 } 90 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 CreateImportedBookmarksEntries(); 151 CreateImportedBookmarksEntries();
152 BookmarkModel* bookmark_model1 = 152 BookmarkModel* bookmark_model1 =
153 BookmarkModelFactory::GetForProfile(&profile1); 153 BookmarkModelFactory::GetForProfile(&profile1);
154 test::WaitForBookmarkModelToLoad(bookmark_model1); 154 test::WaitForBookmarkModelToLoad(bookmark_model1);
155 155
156 scoped_refptr<TestProfileWriter> profile_writer( 156 scoped_refptr<TestProfileWriter> profile_writer(
157 new TestProfileWriter(&profile1)); 157 new TestProfileWriter(&profile1));
158 profile_writer->AddBookmarks(bookmarks_, 158 profile_writer->AddBookmarks(bookmarks_,
159 base::ASCIIToUTF16("Imported from Firefox")); 159 base::ASCIIToUTF16("Imported from Firefox"));
160 160
161 std::vector<BookmarkService::URLAndTitle> url_record1; 161 std::vector<BookmarkModel::URLAndTitle> url_record1;
162 bookmark_model1->GetBookmarks(&url_record1); 162 bookmark_model1->GetBookmarks(&url_record1);
163 EXPECT_EQ(2u, url_record1.size()); 163 EXPECT_EQ(2u, url_record1.size());
164 164
165 std::vector<BookmarkService::URLAndTitle> url_record2; 165 std::vector<BookmarkModel::URLAndTitle> url_record2;
166 bookmark_model2->GetBookmarks(&url_record2); 166 bookmark_model2->GetBookmarks(&url_record2);
167 EXPECT_EQ(1u, url_record2.size()); 167 EXPECT_EQ(1u, url_record2.size());
168 } 168 }
169 169
170 // Verify that bookmarks are duplicated when added twice. 170 // Verify that bookmarks are duplicated when added twice.
171 TEST_F(ProfileWriterTest, CheckBookmarksAfterWritingDataTwice) { 171 TEST_F(ProfileWriterTest, CheckBookmarksAfterWritingDataTwice) {
172 TestingProfile profile; 172 TestingProfile profile;
173 profile.CreateBookmarkModel(true); 173 profile.CreateBookmarkModel(true);
174 174
175 CreateImportedBookmarksEntries(); 175 CreateImportedBookmarksEntries();
176 BookmarkModel* bookmark_model = 176 BookmarkModel* bookmark_model =
177 BookmarkModelFactory::GetForProfile(&profile); 177 BookmarkModelFactory::GetForProfile(&profile);
178 test::WaitForBookmarkModelToLoad(bookmark_model); 178 test::WaitForBookmarkModelToLoad(bookmark_model);
179 179
180 scoped_refptr<TestProfileWriter> profile_writer( 180 scoped_refptr<TestProfileWriter> profile_writer(
181 new TestProfileWriter(&profile)); 181 new TestProfileWriter(&profile));
182 profile_writer->AddBookmarks(bookmarks_, 182 profile_writer->AddBookmarks(bookmarks_,
183 base::ASCIIToUTF16("Imported from Firefox")); 183 base::ASCIIToUTF16("Imported from Firefox"));
184 std::vector<BookmarkService::URLAndTitle> bookmarks_record; 184 std::vector<BookmarkModel::URLAndTitle> bookmarks_record;
185 bookmark_model->GetBookmarks(&bookmarks_record); 185 bookmark_model->GetBookmarks(&bookmarks_record);
186 EXPECT_EQ(2u, bookmarks_record.size()); 186 EXPECT_EQ(2u, bookmarks_record.size());
187 187
188 VerifyBookmarksCount(bookmarks_record, bookmark_model, 1); 188 VerifyBookmarksCount(bookmarks_record, bookmark_model, 1);
189 189
190 profile_writer->AddBookmarks(bookmarks_, 190 profile_writer->AddBookmarks(bookmarks_,
191 base::ASCIIToUTF16("Imported from Firefox")); 191 base::ASCIIToUTF16("Imported from Firefox"));
192 // Verify that duplicate bookmarks exist. 192 // Verify that duplicate bookmarks exist.
193 VerifyBookmarksCount(bookmarks_record, bookmark_model, 2); 193 VerifyBookmarksCount(bookmarks_record, bookmark_model, 2);
194 } 194 }
195 195
196 // Verify that history entires are not duplicated when added twice. 196 // Verify that history entires are not duplicated when added twice.
197 TEST_F(ProfileWriterTest, CheckHistoryAfterWritingDataTwice) { 197 TEST_F(ProfileWriterTest, CheckHistoryAfterWritingDataTwice) {
198 TestingProfile profile; 198 TestingProfile profile;
199 ASSERT_TRUE(profile.CreateHistoryService(true, false)); 199 ASSERT_TRUE(profile.CreateHistoryService(true, false));
200 profile.BlockUntilHistoryProcessesPendingRequests(); 200 profile.BlockUntilHistoryProcessesPendingRequests();
201 201
202 CreateHistoryPageEntries(); 202 CreateHistoryPageEntries();
203 scoped_refptr<TestProfileWriter> profile_writer( 203 scoped_refptr<TestProfileWriter> profile_writer(
204 new TestProfileWriter(&profile)); 204 new TestProfileWriter(&profile));
205 profile_writer->AddHistoryPage(pages_, history::SOURCE_FIREFOX_IMPORTED); 205 profile_writer->AddHistoryPage(pages_, history::SOURCE_FIREFOX_IMPORTED);
206 VerifyHistoryCount(&profile); 206 VerifyHistoryCount(&profile);
207 size_t original_history_count = history_count_; 207 size_t original_history_count = history_count_;
208 history_count_ = 0; 208 history_count_ = 0;
209 209
210 profile_writer->AddHistoryPage(pages_, history::SOURCE_FIREFOX_IMPORTED); 210 profile_writer->AddHistoryPage(pages_, history::SOURCE_FIREFOX_IMPORTED);
211 VerifyHistoryCount(&profile); 211 VerifyHistoryCount(&profile);
212 EXPECT_EQ(original_history_count, history_count_); 212 EXPECT_EQ(original_history_count, history_count_);
213 } 213 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698