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

Side by Side Diff: components/history/core/browser/top_sites_database_unittest.cc

Issue 2727553006: [sql] Convert thumbnails and top-sites databases to auto-recovery. (Closed)
Patch Set: git-cl-format Created 3 years, 9 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Database is unusable at the SQLite level. 191 // Database is unusable at the SQLite level.
192 { 192 {
193 sql::test::ScopedErrorExpecter expecter; 193 sql::test::ScopedErrorExpecter expecter;
194 expecter.ExpectError(SQLITE_CORRUPT); 194 expecter.ExpectError(SQLITE_CORRUPT);
195 sql::Connection raw_db; 195 sql::Connection raw_db;
196 EXPECT_TRUE(raw_db.Open(file_name_)); 196 EXPECT_TRUE(raw_db.Open(file_name_));
197 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check")); 197 EXPECT_FALSE(raw_db.IsSQLValid("PRAGMA integrity_check"));
198 ASSERT_TRUE(expecter.SawExpectedErrors()); 198 ASSERT_TRUE(expecter.SawExpectedErrors());
199 } 199 }
200 200
201 // Corruption should be detected and recovered during Init(). After recovery, 201 // Corruption should be detected and recovered during Init().
202 // the Version2 checks should work.
203 { 202 {
204 sql::test::ScopedErrorExpecter expecter; 203 sql::test::ScopedErrorExpecter expecter;
205 expecter.ExpectError(SQLITE_CORRUPT); 204 expecter.ExpectError(SQLITE_CORRUPT);
206 205
207 TopSitesDatabase db; 206 TopSitesDatabase db;
208 ASSERT_TRUE(db.Init(file_name_)); 207 ASSERT_TRUE(db.Init(file_name_));
209
210 VerifyTablesAndColumns(db.db_.get()); 208 VerifyTablesAndColumns(db.db_.get());
211 209 VerifyDatabaseEmpty(db.db_.get());
212 // Basic operational check.
213 MostVisitedURLList urls;
214 std::map<GURL, Images> thumbnails;
215 db.GetPageThumbnails(&urls, &thumbnails);
216 ASSERT_EQ(3u, urls.size());
217 ASSERT_EQ(3u, thumbnails.size());
218 EXPECT_EQ(kUrl0, urls[0].url); // [0] because of url_rank.
219 // kGoogleThumbnail includes nul terminator.
220 ASSERT_EQ(sizeof(kGoogleThumbnail) - 1,
221 thumbnails[urls[0].url].thumbnail->size());
222 EXPECT_TRUE(!memcmp(thumbnails[urls[0].url].thumbnail->front(),
223 kGoogleThumbnail, sizeof(kGoogleThumbnail) - 1));
224 210
225 ASSERT_TRUE(expecter.SawExpectedErrors()); 211 ASSERT_TRUE(expecter.SawExpectedErrors());
226 } 212 }
227 } 213 }
228 214
229 TEST_F(TopSitesDatabaseTest, Recovery3) { 215 TEST_F(TopSitesDatabaseTest, Recovery3) {
230 // Recovery module only supports some platforms at this time. 216 // Recovery module only supports some platforms at this time.
231 if (!sql::Recovery::FullRecoverySupported()) 217 if (!sql::Recovery::FullRecoverySupported())
232 return; 218 return;
233 219
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 db.RemoveURL(url2); 446 db.RemoveURL(url2);
461 447
462 db.GetPageThumbnails(&urls, &thumbnails); 448 db.GetPageThumbnails(&urls, &thumbnails);
463 ASSERT_EQ(4u, urls.size()); 449 ASSERT_EQ(4u, urls.size());
464 ASSERT_EQ(4u, thumbnails.size()); 450 ASSERT_EQ(4u, thumbnails.size());
465 EXPECT_EQ(mapsUrl, urls[0].url); 451 EXPECT_EQ(mapsUrl, urls[0].url);
466 EXPECT_EQ(kUrl0, urls[1].url); 452 EXPECT_EQ(kUrl0, urls[1].url);
467 } 453 }
468 454
469 } // namespace history 455 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698