OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 void SetUpVersion72Database(sql::Connection* connection); | 59 void SetUpVersion72Database(sql::Connection* connection); |
60 void SetUpVersion73Database(sql::Connection* connection); | 60 void SetUpVersion73Database(sql::Connection* connection); |
61 void SetUpVersion74Database(sql::Connection* connection); | 61 void SetUpVersion74Database(sql::Connection* connection); |
62 void SetUpVersion75Database(sql::Connection* connection); | 62 void SetUpVersion75Database(sql::Connection* connection); |
63 void SetUpVersion76Database(sql::Connection* connection); | 63 void SetUpVersion76Database(sql::Connection* connection); |
64 void SetUpVersion77Database(sql::Connection* connection); | 64 void SetUpVersion77Database(sql::Connection* connection); |
65 void SetUpVersion78Database(sql::Connection* connection); | 65 void SetUpVersion78Database(sql::Connection* connection); |
66 void SetUpVersion79Database(sql::Connection* connection); | 66 void SetUpVersion79Database(sql::Connection* connection); |
67 void SetUpVersion80Database(sql::Connection* connection); | 67 void SetUpVersion80Database(sql::Connection* connection); |
68 void SetUpVersion81Database(sql::Connection* connection); | 68 void SetUpVersion81Database(sql::Connection* connection); |
| 69 void SetUpVersion82Database(sql::Connection* connection); |
69 | 70 |
70 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { | 71 void SetUpCurrentDatabaseAndCheckVersion(sql::Connection* connection) { |
71 SetUpVersion77Database(connection); // Prepopulates data. | 72 SetUpVersion77Database(connection); // Prepopulates data. |
72 scoped_ptr<TestDirectoryBackingStore> dbs( | 73 scoped_ptr<TestDirectoryBackingStore> dbs( |
73 new TestDirectoryBackingStore(GetUsername(), connection)); | 74 new TestDirectoryBackingStore(GetUsername(), connection)); |
74 | 75 |
75 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); | 76 ASSERT_TRUE(LoadAndIgnoreReturnedData(dbs.get())); |
76 ASSERT_FALSE(dbs->needs_column_refresh_); | 77 ASSERT_FALSE(dbs->needs_column_refresh_); |
77 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); | 78 ASSERT_EQ(kCurrentDBVersion, dbs->GetVersion()); |
78 } | 79 } |
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1954 for (int i = 0; i < V80_ROW_COUNT; i++) { | 1955 for (int i = 0; i < V80_ROW_COUNT; i++) { |
1955 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); | 1956 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); |
1956 std::string ord = V81_Ordinal(i); | 1957 std::string ord = V81_Ordinal(i); |
1957 s.BindBlob(0, ord.data(), ord.length()); | 1958 s.BindBlob(0, ord.data(), ord.length()); |
1958 ASSERT_TRUE(s.Run()); | 1959 ASSERT_TRUE(s.Run()); |
1959 s.Reset(true); | 1960 s.Reset(true); |
1960 } | 1961 } |
1961 ASSERT_TRUE(connection->CommitTransaction()); | 1962 ASSERT_TRUE(connection->CommitTransaction()); |
1962 } | 1963 } |
1963 | 1964 |
| 1965 void MigrationTest::SetUpVersion82Database(sql::Connection* connection) { |
| 1966 ASSERT_TRUE(connection->is_open()); |
| 1967 ASSERT_TRUE(connection->BeginTransaction()); |
| 1968 ASSERT_TRUE(connection->Execute( |
| 1969 "CREATE TABLE share_version (id VARCHAR(128) primary key, data INT);" |
| 1970 "INSERT INTO 'share_version' VALUES('nick@chromium.org',81);" |
| 1971 "CREATE TABLE models (model_id BLOB primary key, progress_marker BLOB, in" |
| 1972 "itial_sync_ended BOOLEAN default 0, transaction_version BIGINT " |
| 1973 "default 0);" |
| 1974 "INSERT INTO 'models' VALUES(X'C2881000',X'0888810218B605',1, 1);" |
| 1975 "CREATE TABLE 'metas'(metahandle bigint primary key ON CONFLICT FAIL,base" |
| 1976 "_version bigint default -1,server_version bigint default 0, " |
| 1977 "local_external_id bigint default 0" |
| 1978 ",mtime bigint default 0,server_mtime bigint default 0,ctime bigint d" |
| 1979 "efault 0,server_ctime bigint default 0,id varchar(255) default 'r',p" |
| 1980 "arent_id varchar(255) default 'r',server_parent_id varchar(255) defa" |
| 1981 "ult 'r',prev_id varchar(255) default 'r',next_id varchar(255) defaul" |
| 1982 "t 'r',is_unsynced bit default 0,is_unapplied_update bit default 0,is" |
| 1983 "_del bit default 0,is_dir bit default 0,server_is_dir bit default 0," |
| 1984 "server_is_del bit default 0,non_unique_name varchar,server_non_uniqu" |
| 1985 "e_name varchar(255),unique_server_tag varchar,unique_client_tag varc" |
| 1986 "har,specifics blob,server_specifics blob, base_server_specifics BLOB" |
| 1987 ", server_ordinal_in_parent blob);" |
| 1988 "CREATE TABLE 'share_info' (id TEXT primary key, name TEXT, store_birthda" |
| 1989 "y TEXT, db_create_version TEXT, db_create_time INT, next_id INT defa" |
| 1990 "ult -2, cache_guid TEXT , notification_state BLOB, bag_of_chips " |
| 1991 "blob);" |
| 1992 "INSERT INTO 'share_info' VALUES('nick@chromium.org','nick@chromium.org'," |
| 1993 "'c27e9f59-08ca-46f8-b0cc-f16a2ed778bb','Unknown',1263522064," |
| 1994 "-131078,'9010788312004066376x-6609234393368420856x',NULL, NULL);")); |
| 1995 |
| 1996 const char* insert_stmts[V80_ROW_COUNT] = { |
| 1997 "INSERT INTO 'metas' VALUES(1,-1,0,0," META_PROTO_TIMES_VALS(1) ",'r','" |
| 1998 "r','r','r','r',0,0,0,1,0,0,NULL,NULL,NULL,NULL,X'',X'',NULL,?);", |
| 1999 "INSERT INTO 'metas' VALUES(2,669,669,4," |
| 2000 META_PROTO_TIMES_VALS(2) ",'s_ID_2','s_ID_9','s_ID_9','s_ID_2','s_ID_" |
| 2001 "2',0,0,1,0,0,1,'Deleted Item','Deleted Item',NULL,NULL,X'C28810220A1" |
| 2002 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084141534741534741',X" |
| 2003 "'C28810260A17687474703A2F2F7777772E676F6F676C652E636F6D2F32120B41534" |
| 2004 "14447414447414447',NULL,?);", |
| 2005 "INSERT INTO 'metas' VALUES(4,681,681,3," |
| 2006 META_PROTO_TIMES_VALS(4) ",'s_ID_4','s_ID_9','s_ID_9','s_ID_4','s_ID_" |
| 2007 "4',0,0,1,0,0,1,'Welcome to Chromium','Welcome to Chromium',NULL,NULL" |
| 2008 ",X'C28810350A31687474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6" |
| 2009 "D652F696E746C2F656E2F77656C636F6D652E68746D6C1200',X'C28810350A31687" |
| 2010 "474703A2F2F7777772E676F6F676C652E636F6D2F6368726F6D652F696E746C2F656" |
| 2011 "E2F77656C636F6D652E68746D6C1200',NULL,?);", |
| 2012 "INSERT INTO 'metas' VALUES(5,677,677,7," |
| 2013 META_PROTO_TIMES_VALS(5) ",'s_ID_5','s_ID_9','s_ID_9','s_ID_5','s_ID_" |
| 2014 "5',0,0,1,0,0,1,'Google','Google',NULL,NULL,X'C28810220A16687474703A2" |
| 2015 "F2F7777772E676F6F676C652E636F6D2F12084147415347415347',X'C28810220A1" |
| 2016 "6687474703A2F2F7777772E676F6F676C652E636F6D2F12084147464447415347',N" |
| 2017 "ULL,?);", |
| 2018 "INSERT INTO 'metas' VALUES(6,694,694,6," |
| 2019 META_PROTO_TIMES_VALS(6) ",'s_ID_6','s_ID_9','s_ID_9','r','r',0,0,0,1" |
| 2020 ",1,0,'The Internet','The Internet',NULL,NULL,X'C2881000',X'C2881000'" |
| 2021 ",NULL,?);", |
| 2022 "INSERT INTO 'metas' VALUES(7,663,663,0," |
| 2023 META_PROTO_TIMES_VALS(7) ",'s_ID_7','r','r','r','r',0,0,0,1,1,0,'Goog" |
| 2024 "le Chrome','Google Chrome','google_chrome',NULL,NULL,NULL,NULL,?);", |
| 2025 "INSERT INTO 'metas' VALUES(8,664,664,0," |
| 2026 META_PROTO_TIMES_VALS(8) ",'s_ID_8','s_ID_7','s_ID_7','r','r',0,0,0,1" |
| 2027 ",1,0,'Bookmarks','Bookmarks','google_chrome_bookmarks',NULL,X'C28810" |
| 2028 "00',X'C2881000',NULL,?);", |
| 2029 "INSERT INTO 'metas' VALUES(9,665,665,1," |
| 2030 META_PROTO_TIMES_VALS(9) ",'s_ID_9','s_ID_8','s_ID_8','r','s_ID_10',0" |
| 2031 ",0,0,1,1,0,'Bookmark Bar','Bookmark Bar','bookmark_bar',NULL,X'C2881" |
| 2032 "000',X'C2881000',NULL,?);", |
| 2033 "INSERT INTO 'metas' VALUES(10,666,666,2," |
| 2034 META_PROTO_TIMES_VALS(10) ",'s_ID_10','s_ID_8','s_ID_8','s_ID_9','r'," |
| 2035 "0,0,0,1,1,0,'Other Bookmarks','Other Bookmarks','other_bookmarks',NU" |
| 2036 "LL,X'C2881000',X'C2881000',NULL,?);", |
| 2037 "INSERT INTO 'metas' VALUES(11,683,683,8," |
| 2038 META_PROTO_TIMES_VALS(11) ",'s_ID_11','s_ID_6','s_ID_6','r','s_ID_13'" |
| 2039 ",0,0,0,0,0,0,'Home (The Chromium Projects)','Home (The Chromium Proj" |
| 2040 "ects)',NULL,NULL,X'C28810220A18687474703A2F2F6465762E6368726F6D69756" |
| 2041 "D2E6F72672F1206414741545741',X'C28810290A1D687474703A2F2F6465762E636" |
| 2042 "8726F6D69756D2E6F72672F6F7468657212084146414756415346',NULL,?);", |
| 2043 "INSERT INTO 'metas' VALUES(12,685,685,9," |
| 2044 META_PROTO_TIMES_VALS(12) ",'s_ID_12','s_ID_6','s_ID_6','s_ID_13','s_" |
| 2045 "ID_14',0,0,0,1,1,0,'Extra Bookmarks','Extra Bookmarks',NULL,NULL,X'C" |
| 2046 "2881000',X'C2881000',NULL,?);", |
| 2047 "INSERT INTO 'metas' VALUES(13,687,687,10," |
| 2048 META_PROTO_TIMES_VALS(13) ",'s_ID_13','s_ID_6','s_ID_6','s_ID_11','s_" |
| 2049 "ID_12',0,0,0,0,0,0,'ICANN | Internet Corporation for Assigned Names " |
| 2050 "and Numbers','ICANN | Internet Corporation for Assigned Names and Nu" |
| 2051 "mbers',NULL,NULL,X'C28810240A15687474703A2F2F7777772E6963616E6E2E636" |
| 2052 "F6D2F120B504E474158463041414646',X'C28810200A15687474703A2F2F7777772" |
| 2053 "E6963616E6E2E636F6D2F120744414146415346',NULL,?);", |
| 2054 "INSERT INTO 'metas' VALUES(14,692,692,11," |
| 2055 META_PROTO_TIMES_VALS(14) ",'s_ID_14','s_ID_6','s_ID_6','s_ID_12','r'" |
| 2056 ",0,0,0,0,0,0,'The WebKit Open Source Project','The WebKit Open Sourc" |
| 2057 "e Project',NULL,NULL,X'C288101A0A12687474703A2F2F7765626B69742E6F726" |
| 2058 "72F1204504E4758',X'C288101C0A13687474703A2F2F7765626B69742E6F72672F7" |
| 2059 "81205504E473259',NULL,?);" }; |
| 2060 |
| 2061 for (int i = 0; i < V80_ROW_COUNT; i++) { |
| 2062 sql::Statement s(connection->GetUniqueStatement(insert_stmts[i])); |
| 2063 std::string ord = V81_Ordinal(i); |
| 2064 s.BindBlob(0, ord.data(), ord.length()); |
| 2065 ASSERT_TRUE(s.Run()); |
| 2066 s.Reset(true); |
| 2067 } |
| 2068 ASSERT_TRUE(connection->CommitTransaction()); |
| 2069 } |
| 2070 |
1964 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { | 2071 TEST_F(DirectoryBackingStoreTest, MigrateVersion67To68) { |
1965 sql::Connection connection; | 2072 sql::Connection connection; |
1966 ASSERT_TRUE(connection.OpenInMemory()); | 2073 ASSERT_TRUE(connection.OpenInMemory()); |
1967 | 2074 |
1968 SetUpVersion67Database(&connection); | 2075 SetUpVersion67Database(&connection); |
1969 | 2076 |
1970 // Columns existing before version 67. | 2077 // Columns existing before version 67. |
1971 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); | 2078 ASSERT_TRUE(connection.DoesColumnExist("metas", "name")); |
1972 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); | 2079 ASSERT_TRUE(connection.DoesColumnExist("metas", "unsanitized_name")); |
1973 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); | 2080 ASSERT_TRUE(connection.DoesColumnExist("metas", "server_name")); |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2381 scoped_ptr<TestDirectoryBackingStore> dbs( | 2488 scoped_ptr<TestDirectoryBackingStore> dbs( |
2382 new TestDirectoryBackingStore(GetUsername(), &connection)); | 2489 new TestDirectoryBackingStore(GetUsername(), &connection)); |
2383 ASSERT_FALSE(dbs->needs_column_refresh_); | 2490 ASSERT_FALSE(dbs->needs_column_refresh_); |
2384 ASSERT_TRUE(dbs->MigrateVersion81To82()); | 2491 ASSERT_TRUE(dbs->MigrateVersion81To82()); |
2385 ASSERT_EQ(82, dbs->GetVersion()); | 2492 ASSERT_EQ(82, dbs->GetVersion()); |
2386 ASSERT_FALSE(dbs->needs_column_refresh_); | 2493 ASSERT_FALSE(dbs->needs_column_refresh_); |
2387 | 2494 |
2388 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version")); | 2495 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version")); |
2389 } | 2496 } |
2390 | 2497 |
| 2498 TEST_F(DirectoryBackingStoreTest, MigrateVersion82To83) { |
| 2499 sql::Connection connection; |
| 2500 ASSERT_TRUE(connection.OpenInMemory()); |
| 2501 SetUpVersion82Database(&connection); |
| 2502 ASSERT_FALSE(connection.DoesColumnExist("metas", "transaction_version")); |
| 2503 |
| 2504 scoped_ptr<TestDirectoryBackingStore> dbs( |
| 2505 new TestDirectoryBackingStore(GetUsername(), &connection)); |
| 2506 ASSERT_TRUE(dbs->MigrateVersion82To83()); |
| 2507 ASSERT_EQ(83, dbs->GetVersion()); |
| 2508 |
| 2509 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version")); |
| 2510 } |
| 2511 |
2391 TEST_P(MigrationTest, ToCurrentVersion) { | 2512 TEST_P(MigrationTest, ToCurrentVersion) { |
2392 sql::Connection connection; | 2513 sql::Connection connection; |
2393 ASSERT_TRUE(connection.OpenInMemory()); | 2514 ASSERT_TRUE(connection.OpenInMemory()); |
2394 switch (GetParam()) { | 2515 switch (GetParam()) { |
2395 case 67: | 2516 case 67: |
2396 SetUpVersion67Database(&connection); | 2517 SetUpVersion67Database(&connection); |
2397 break; | 2518 break; |
2398 case 68: | 2519 case 68: |
2399 SetUpVersion68Database(&connection); | 2520 SetUpVersion68Database(&connection); |
2400 break; | 2521 break; |
(...skipping 29 matching lines...) Expand all Loading... |
2430 break; | 2551 break; |
2431 case 79: | 2552 case 79: |
2432 SetUpVersion79Database(&connection); | 2553 SetUpVersion79Database(&connection); |
2433 break; | 2554 break; |
2434 case 80: | 2555 case 80: |
2435 SetUpVersion80Database(&connection); | 2556 SetUpVersion80Database(&connection); |
2436 break; | 2557 break; |
2437 case 81: | 2558 case 81: |
2438 SetUpVersion81Database(&connection); | 2559 SetUpVersion81Database(&connection); |
2439 break; | 2560 break; |
| 2561 case 82: |
| 2562 SetUpVersion82Database(&connection); |
| 2563 break; |
2440 default: | 2564 default: |
2441 // If you see this error, it may mean that you've increased the | 2565 // If you see this error, it may mean that you've increased the |
2442 // database version number but you haven't finished adding unit tests | 2566 // database version number but you haven't finished adding unit tests |
2443 // for the database migration code. You need to need to supply a | 2567 // for the database migration code. You need to need to supply a |
2444 // SetUpVersionXXDatabase function with a dump of the test database | 2568 // SetUpVersionXXDatabase function with a dump of the test database |
2445 // at the old schema. Here's one way to do that: | 2569 // at the old schema. Here's one way to do that: |
2446 // 1. Start on a clean tree (with none of your pending schema changes). | 2570 // 1. Start on a clean tree (with none of your pending schema changes). |
2447 // 2. Set a breakpoint in this function and run the unit test. | 2571 // 2. Set a breakpoint in this function and run the unit test. |
2448 // 3. Allow this test to run to completion (step out of the call), | 2572 // 3. Allow this test to run to completion (step out of the call), |
2449 // without allowing ~MigrationTest to execute. | 2573 // without allowing ~MigrationTest to execute. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2512 "autofill_entries_added_during_migration")); | 2636 "autofill_entries_added_during_migration")); |
2513 ASSERT_FALSE(connection.DoesColumnExist("share_info", | 2637 ASSERT_FALSE(connection.DoesColumnExist("share_info", |
2514 "autofill_profiles_added_during_migration")); | 2638 "autofill_profiles_added_during_migration")); |
2515 | 2639 |
2516 // Column added in version 78. | 2640 // Column added in version 78. |
2517 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics")); | 2641 ASSERT_TRUE(connection.DoesColumnExist("metas", "base_server_specifics")); |
2518 | 2642 |
2519 // Column added in version 82. | 2643 // Column added in version 82. |
2520 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version")); | 2644 ASSERT_TRUE(connection.DoesColumnExist("models", "transaction_version")); |
2521 | 2645 |
| 2646 // Column added in version 83. |
| 2647 ASSERT_TRUE(connection.DoesColumnExist("metas", "transaction_version")); |
| 2648 |
2522 // Check download_progress state (v75 migration) | 2649 // Check download_progress state (v75 migration) |
2523 ASSERT_EQ(694, | 2650 ASSERT_EQ(694, |
2524 dir_info.kernel_info.download_progress[BOOKMARKS] | 2651 dir_info.kernel_info.download_progress[BOOKMARKS] |
2525 .timestamp_token_for_migration()); | 2652 .timestamp_token_for_migration()); |
2526 ASSERT_FALSE( | 2653 ASSERT_FALSE( |
2527 dir_info.kernel_info.download_progress[BOOKMARKS] | 2654 dir_info.kernel_info.download_progress[BOOKMARKS] |
2528 .has_token()); | 2655 .has_token()); |
2529 ASSERT_EQ(32904, | 2656 ASSERT_EQ(32904, |
2530 dir_info.kernel_info.download_progress[BOOKMARKS] | 2657 dir_info.kernel_info.download_progress[BOOKMARKS] |
2531 .data_type_id()); | 2658 .data_type_id()); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); | 2897 const std::string& guid2 = TestDirectoryBackingStore::GenerateCacheGUID(); |
2771 EXPECT_EQ(24U, guid1.size()); | 2898 EXPECT_EQ(24U, guid1.size()); |
2772 EXPECT_EQ(24U, guid2.size()); | 2899 EXPECT_EQ(24U, guid2.size()); |
2773 // In theory this test can fail, but it won't before the universe | 2900 // In theory this test can fail, but it won't before the universe |
2774 // dies of heat death. | 2901 // dies of heat death. |
2775 EXPECT_NE(guid1, guid2); | 2902 EXPECT_NE(guid1, guid2); |
2776 } | 2903 } |
2777 | 2904 |
2778 } // namespace syncable | 2905 } // namespace syncable |
2779 } // namespace syncer | 2906 } // namespace syncer |
OLD | NEW |