OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync/syncable/directory_backing_store.h" | 5 #include "components/sync/syncable/directory_backing_store.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 71 |
72 static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) { | 72 static bool LoadAndIgnoreReturnedData(DirectoryBackingStore *dbs) { |
73 Directory::MetahandlesMap tmp_handles_map; | 73 Directory::MetahandlesMap tmp_handles_map; |
74 JournalIndex delete_journals; | 74 JournalIndex delete_journals; |
75 MetahandleSet metahandles_to_purge; | 75 MetahandleSet metahandles_to_purge; |
76 Directory::KernelLoadInfo kernel_load_info; | 76 Directory::KernelLoadInfo kernel_load_info; |
77 return dbs->Load(&tmp_handles_map, &delete_journals, &metahandles_to_purge, | 77 return dbs->Load(&tmp_handles_map, &delete_journals, &metahandles_to_purge, |
78 &kernel_load_info) == OPENED; | 78 &kernel_load_info) == OPENED; |
79 } | 79 } |
80 | 80 |
| 81 void SetUpCorruptedRootDatabase(sql::Connection* connection); |
81 void SetUpVersion67Database(sql::Connection* connection); | 82 void SetUpVersion67Database(sql::Connection* connection); |
82 void SetUpVersion68Database(sql::Connection* connection); | 83 void SetUpVersion68Database(sql::Connection* connection); |
83 void SetUpVersion69Database(sql::Connection* connection); | 84 void SetUpVersion69Database(sql::Connection* connection); |
84 void SetUpVersion70Database(sql::Connection* connection); | 85 void SetUpVersion70Database(sql::Connection* connection); |
85 void SetUpVersion71Database(sql::Connection* connection); | 86 void SetUpVersion71Database(sql::Connection* connection); |
86 void SetUpVersion72Database(sql::Connection* connection); | 87 void SetUpVersion72Database(sql::Connection* connection); |
87 void SetUpVersion73Database(sql::Connection* connection); | 88 void SetUpVersion73Database(sql::Connection* connection); |
88 void SetUpVersion74Database(sql::Connection* connection); | 89 void SetUpVersion74Database(sql::Connection* connection); |
89 void SetUpVersion75Database(sql::Connection* connection); | 90 void SetUpVersion75Database(sql::Connection* connection); |
90 void SetUpVersion76Database(sql::Connection* connection); | 91 void SetUpVersion76Database(sql::Connection* connection); |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 if (it2 == expected_times.end()) { | 404 if (it2 == expected_times.end()) { |
404 ADD_FAILURE() << "Could not find expected time for " << meta_handle; | 405 ADD_FAILURE() << "Could not find expected time for " << meta_handle; |
405 continue; | 406 continue; |
406 } | 407 } |
407 ExpectTime(*it->second, it2->second); | 408 ExpectTime(*it->second, it2->second); |
408 } | 409 } |
409 } | 410 } |
410 | 411 |
411 } // namespace | 412 } // namespace |
412 | 413 |
| 414 void MigrationTest::SetUpCorruptedRootDatabase(sql::Connection* connection) { |
| 415 ASSERT_TRUE(connection->is_open()); |
| 416 ASSERT_TRUE(connection->BeginTransaction()); |
| 417 ASSERT_TRUE(connection->Execute( |
| 418 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), " |
| 419 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);" |
| 420 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL," |
| 421 "base_version bigint default -1,server_version bigint default 0," |
| 422 "mtime bigint default 0,server_mtime bigint default 0," |
| 423 "ctime bigint default 0,server_ctime bigint default 0," |
| 424 "server_position_in_parent bigint default 0," |
| 425 "local_external_id bigint default 0,id varchar(255) default 'r'," |
| 426 "parent_id varchar(255) default 'r'," |
| 427 "server_parent_id varchar(255) default 'r'," |
| 428 "prev_id varchar(255) default 'r',next_id varchar(255) default 'r'," |
| 429 "is_unsynced bit default 0,is_unapplied_update bit default 0," |
| 430 "is_del bit default 0,is_dir bit default 0," |
| 431 "is_bookmark_object bit default 0,server_is_dir bit default 0," |
| 432 "server_is_del bit default 0,server_is_bookmark_object bit default 0," |
| 433 "name varchar(255), " /* COLLATE PATHNAME, */ |
| 434 "unsanitized_name varchar(255)," /* COLLATE PATHNAME, */ |
| 435 "non_unique_name varchar," |
| 436 "server_name varchar(255)," /* COLLATE PATHNAME */ |
| 437 "server_non_unique_name varchar," |
| 438 "bookmark_url varchar,server_bookmark_url varchar," |
| 439 "singleton_tag varchar,bookmark_favicon blob," |
| 440 "server_bookmark_favicon blob);" |
| 441 "INSERT INTO metas VALUES(1,-1,0," LEGACY_PROTO_TIME_VALS( |
| 442 1) ",0,0,'r2','r2','r','r','r',0,0,0,1,0,0,0,0,NULL," |
| 443 "NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);" |
| 444 "CREATE TABLE share_info (id VARCHAR(128) primary key, " |
| 445 "last_sync_timestamp INT, name VARCHAR(128), " |
| 446 "initial_sync_ended BIT default 0, store_birthday VARCHAR(256), " |
| 447 "db_create_version VARCHAR(128), db_create_time int, " |
| 448 "next_id bigint default -2, cache_guid VARCHAR(32));" |
| 449 "INSERT INTO share_info VALUES('nick@chromium.org',694," |
| 450 "'nick@chromium.org',1,'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb'," |
| 451 "'Unknown',1263522064,-65542," |
| 452 "'9010788312004066376x-6609234393368420856x');" |
| 453 "CREATE TABLE share_version (id VARCHAR(128) primary key, data " |
| 454 "INT);" |
| 455 "INSERT INTO share_version VALUES('nick@chromium.org',68);")); |
| 456 ASSERT_TRUE(connection->CommitTransaction()); |
| 457 } |
| 458 |
413 void MigrationTest::SetUpVersion67Database(sql::Connection* connection) { | 459 void MigrationTest::SetUpVersion67Database(sql::Connection* connection) { |
414 // This is a version 67 database dump whose contents were backformed from | 460 // This is a version 67 database dump whose contents were backformed from |
415 // the contents of the version 68 database dump (the v68 migration was | 461 // the contents of the version 68 database dump (the v68 migration was |
416 // actually written first). | 462 // actually written first). |
417 ASSERT_TRUE(connection->is_open()); | 463 ASSERT_TRUE(connection->is_open()); |
418 ASSERT_TRUE(connection->BeginTransaction()); | 464 ASSERT_TRUE(connection->BeginTransaction()); |
419 ASSERT_TRUE(connection->Execute( | 465 ASSERT_TRUE(connection->Execute( |
420 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), " | 466 "CREATE TABLE extended_attributes(metahandle bigint, key varchar(127), " |
421 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);" | 467 "value blob, PRIMARY KEY(metahandle, key) ON CONFLICT REPLACE);" |
422 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL," | 468 "CREATE TABLE metas (metahandle bigint primary key ON CONFLICT FAIL," |
(...skipping 3140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3563 // Trying to unpack this entry should signal that the DB is corrupted. | 3609 // Trying to unpack this entry should signal that the DB is corrupted. |
3564 Directory::MetahandlesMap handles_map; | 3610 Directory::MetahandlesMap handles_map; |
3565 JournalIndex delete_journals; | 3611 JournalIndex delete_journals; |
3566 MetahandleSet metahandles_to_purge; | 3612 MetahandleSet metahandles_to_purge; |
3567 Directory::KernelLoadInfo kernel_load_info; | 3613 Directory::KernelLoadInfo kernel_load_info; |
3568 ASSERT_EQ(FAILED_DATABASE_CORRUPT, | 3614 ASSERT_EQ(FAILED_DATABASE_CORRUPT, |
3569 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge, | 3615 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge, |
3570 &kernel_load_info)); | 3616 &kernel_load_info)); |
3571 } | 3617 } |
3572 | 3618 |
| 3619 TEST_F(DirectoryBackingStoreTest, DetectCorruptedRoot) { |
| 3620 sql::Connection connection; |
| 3621 ASSERT_TRUE(connection.OpenInMemory()); |
| 3622 SetUpCorruptedRootDatabase(&connection); |
| 3623 |
| 3624 std::unique_ptr<TestDirectoryBackingStore> dbs( |
| 3625 new TestDirectoryBackingStore(GetUsername(), &connection)); |
| 3626 |
| 3627 Directory::MetahandlesMap handles_map; |
| 3628 JournalIndex delete_journals; |
| 3629 MetahandleSet metahandles_to_purge; |
| 3630 Directory::KernelLoadInfo kernel_load_info; |
| 3631 ASSERT_EQ(FAILED_DATABASE_CORRUPT, |
| 3632 dbs->Load(&handles_map, &delete_journals, &metahandles_to_purge, |
| 3633 &kernel_load_info)); |
| 3634 } |
| 3635 |
3573 TEST_P(MigrationTest, ToCurrentVersion) { | 3636 TEST_P(MigrationTest, ToCurrentVersion) { |
3574 sql::Connection connection; | 3637 sql::Connection connection; |
3575 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 3638 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
3576 // Assume all old versions have an old page size. | 3639 // Assume all old versions have an old page size. |
3577 connection.set_page_size(4096); | 3640 connection.set_page_size(4096); |
3578 switch (GetParam()) { | 3641 switch (GetParam()) { |
3579 case 67: | 3642 case 67: |
3580 SetUpVersion67Database(&connection); | 3643 SetUpVersion67Database(&connection); |
3581 break; | 3644 break; |
3582 case 68: | 3645 case 68: |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4254 ASSERT_FALSE(dbs->SaveChanges(snapshot)); | 4317 ASSERT_FALSE(dbs->SaveChanges(snapshot)); |
4255 // At this point the handler has been posted but not executed. | 4318 // At this point the handler has been posted but not executed. |
4256 ASSERT_FALSE(was_called); | 4319 ASSERT_FALSE(was_called); |
4257 // Pump the message loop and see that it is executed. | 4320 // Pump the message loop and see that it is executed. |
4258 base::RunLoop().RunUntilIdle(); | 4321 base::RunLoop().RunUntilIdle(); |
4259 ASSERT_TRUE(was_called); | 4322 ASSERT_TRUE(was_called); |
4260 } | 4323 } |
4261 | 4324 |
4262 } // namespace syncable | 4325 } // namespace syncable |
4263 } // namespace syncer | 4326 } // namespace syncer |
OLD | NEW |