| OLD | NEW |
| 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 <list> | 5 #include <list> |
| 6 #include <map> | 6 #include <map> |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2035 return s.ColumnInt(0); | 2035 return s.ColumnInt(0); |
| 2036 } | 2036 } |
| 2037 | 2037 |
| 2038 // The sql files located in "chrome/test/data/web_database" were generated by | 2038 // The sql files located in "chrome/test/data/web_database" were generated by |
| 2039 // launching the Chromium application prior to schema change, then using the | 2039 // launching the Chromium application prior to schema change, then using the |
| 2040 // sqlite3 command-line application to dump the contents of the "Web Data" | 2040 // sqlite3 command-line application to dump the contents of the "Web Data" |
| 2041 // database. | 2041 // database. |
| 2042 // Like this: | 2042 // Like this: |
| 2043 // > .output version_nn.sql | 2043 // > .output version_nn.sql |
| 2044 // > .dump | 2044 // > .dump |
| 2045 void LoadDatabase(const FilePath& path); | 2045 void LoadDatabase(const FilePath::StringType& file); |
| 2046 | 2046 |
| 2047 // Assertion testing for migrating from version 27 and 28. | 2047 // Assertion testing for migrating from version 27 and 28. |
| 2048 void MigrateVersion28Assertions(); | 2048 void MigrateVersion28Assertions(); |
| 2049 | 2049 |
| 2050 private: | 2050 private: |
| 2051 ScopedTempDir temp_dir_; | 2051 ScopedTempDir temp_dir_; |
| 2052 | 2052 |
| 2053 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 2053 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
| 2054 }; | 2054 }; |
| 2055 | 2055 |
| 2056 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 32; | 2056 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 33; |
| 2057 | 2057 |
| 2058 void WebDatabaseMigrationTest::LoadDatabase(const FilePath& file) { | 2058 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { |
| 2059 std::string contents; | 2059 std::string contents; |
| 2060 ASSERT_TRUE(GetWebDatabaseData(file, &contents)); | 2060 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); |
| 2061 | 2061 |
| 2062 sql::Connection connection; | 2062 sql::Connection connection; |
| 2063 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2063 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2064 ASSERT_TRUE(connection.Execute(contents.data())); | 2064 ASSERT_TRUE(connection.Execute(contents.data())); |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 void WebDatabaseMigrationTest::MigrateVersion28Assertions() { | 2067 void WebDatabaseMigrationTest::MigrateVersion28Assertions() { |
| 2068 // Load the database via the WebDatabase class and migrate the database to | 2068 // Load the database via the WebDatabase class and migrate the database to |
| 2069 // the current version. | 2069 // the current version. |
| 2070 { | 2070 { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2155 EXPECT_TRUE(connection.DoesTableExist("token_service")); | 2155 EXPECT_TRUE(connection.DoesTableExist("token_service")); |
| 2156 } | 2156 } |
| 2157 } | 2157 } |
| 2158 | 2158 |
| 2159 // Tests that the |credit_card| table gets added to the schema for a version 22 | 2159 // Tests that the |credit_card| table gets added to the schema for a version 22 |
| 2160 // database. | 2160 // database. |
| 2161 TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) { | 2161 TEST_F(WebDatabaseMigrationTest, MigrateVersion22ToCurrent) { |
| 2162 // This schema is taken from a build prior to the addition of the | 2162 // This schema is taken from a build prior to the addition of the |
| 2163 // |credit_card| table. Version 22 of the schema. Contrast this with the | 2163 // |credit_card| table. Version 22 of the schema. Contrast this with the |
| 2164 // corrupt version below. | 2164 // corrupt version below. |
| 2165 ASSERT_NO_FATAL_FAILURE( | 2165 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_22.sql"))); |
| 2166 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_22.sql")))); | |
| 2167 | 2166 |
| 2168 // Verify pre-conditions. | 2167 // Verify pre-conditions. |
| 2169 { | 2168 { |
| 2170 sql::Connection connection; | 2169 sql::Connection connection; |
| 2171 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2170 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2172 | 2171 |
| 2173 // No |credit_card| table prior to version 23. | 2172 // No |credit_card| table prior to version 23. |
| 2174 ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "guid")); | 2173 ASSERT_FALSE(connection.DoesColumnExist("credit_cards", "guid")); |
| 2175 ASSERT_FALSE( | 2174 ASSERT_FALSE( |
| 2176 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); | 2175 connection.DoesColumnExist("credit_cards", "card_number_encrypted")); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2202 // Tests that the |credit_card| table gets added to the schema for a corrupt | 2201 // Tests that the |credit_card| table gets added to the schema for a corrupt |
| 2203 // version 22 database. The corruption is that the |credit_cards| table exists | 2202 // version 22 database. The corruption is that the |credit_cards| table exists |
| 2204 // but the schema version number was not set correctly to 23 or later. This | 2203 // but the schema version number was not set correctly to 23 or later. This |
| 2205 // test exercises code introduced to fix bug http://crbug.com/50699 that | 2204 // test exercises code introduced to fix bug http://crbug.com/50699 that |
| 2206 // resulted from the corruption. | 2205 // resulted from the corruption. |
| 2207 TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) { | 2206 TEST_F(WebDatabaseMigrationTest, MigrateVersion22CorruptedToCurrent) { |
| 2208 // This schema is taken from a build after the addition of the |credit_card| | 2207 // This schema is taken from a build after the addition of the |credit_card| |
| 2209 // table. Due to a bug in the migration logic the version is set incorrectly | 2208 // table. Due to a bug in the migration logic the version is set incorrectly |
| 2210 // to 22 (it should have been updated to 23 at least). | 2209 // to 22 (it should have been updated to 23 at least). |
| 2211 ASSERT_NO_FATAL_FAILURE( | 2210 ASSERT_NO_FATAL_FAILURE( |
| 2212 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_22_corrupt.sql")))); | 2211 LoadDatabase(FILE_PATH_LITERAL("version_22_corrupt.sql"))); |
| 2213 | 2212 |
| 2214 // Verify pre-conditions. These are expectations for corrupt version 22 of | 2213 // Verify pre-conditions. These are expectations for corrupt version 22 of |
| 2215 // the database. | 2214 // the database. |
| 2216 { | 2215 { |
| 2217 sql::Connection connection; | 2216 sql::Connection connection; |
| 2218 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2217 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2219 | 2218 |
| 2220 // Columns existing and not existing before current version. | 2219 // Columns existing and not existing before current version. |
| 2221 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); | 2220 ASSERT_TRUE(connection.DoesColumnExist("credit_cards", "unique_id")); |
| 2222 ASSERT_TRUE( | 2221 ASSERT_TRUE( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2250 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); | 2249 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 2251 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); | 2250 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); |
| 2252 } | 2251 } |
| 2253 } | 2252 } |
| 2254 | 2253 |
| 2255 // Tests that the |keywords| |logo_id| column gets added to the schema for a | 2254 // Tests that the |keywords| |logo_id| column gets added to the schema for a |
| 2256 // version 24 database. | 2255 // version 24 database. |
| 2257 TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) { | 2256 TEST_F(WebDatabaseMigrationTest, MigrateVersion24ToCurrent) { |
| 2258 // This schema is taken from a build prior to the addition of the |keywords| | 2257 // This schema is taken from a build prior to the addition of the |keywords| |
| 2259 // |logo_id| column. | 2258 // |logo_id| column. |
| 2260 ASSERT_NO_FATAL_FAILURE( | 2259 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_24.sql"))); |
| 2261 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_24.sql")))); | |
| 2262 | 2260 |
| 2263 // Verify pre-conditions. These are expectations for version 24 of the | 2261 // Verify pre-conditions. These are expectations for version 24 of the |
| 2264 // database. | 2262 // database. |
| 2265 { | 2263 { |
| 2266 sql::Connection connection; | 2264 sql::Connection connection; |
| 2267 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2265 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2268 | 2266 |
| 2269 // Columns existing and not existing before current version. | 2267 // Columns existing and not existing before current version. |
| 2270 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id")); | 2268 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 2271 ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); | 2269 ASSERT_FALSE(connection.DoesColumnExist("keywords", "logo_id")); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2291 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); | 2289 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); |
| 2292 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); | 2290 EXPECT_TRUE(connection.DoesColumnExist("keywords", "logo_id")); |
| 2293 } | 2291 } |
| 2294 } | 2292 } |
| 2295 | 2293 |
| 2296 // Tests that the |keywords| |created_by_policy| column gets added to the schema | 2294 // Tests that the |keywords| |created_by_policy| column gets added to the schema |
| 2297 // for a version 25 database. | 2295 // for a version 25 database. |
| 2298 TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) { | 2296 TEST_F(WebDatabaseMigrationTest, MigrateVersion25ToCurrent) { |
| 2299 // This schema is taken from a build prior to the addition of the |keywords| | 2297 // This schema is taken from a build prior to the addition of the |keywords| |
| 2300 // |created_by_policy| column. | 2298 // |created_by_policy| column. |
| 2301 ASSERT_NO_FATAL_FAILURE( | 2299 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_25.sql"))); |
| 2302 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_25.sql")))); | |
| 2303 | 2300 |
| 2304 // Verify pre-conditions. These are expectations for version 25 of the | 2301 // Verify pre-conditions. These are expectations for version 25 of the |
| 2305 // database. | 2302 // database. |
| 2306 { | 2303 { |
| 2307 sql::Connection connection; | 2304 sql::Connection connection; |
| 2308 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2305 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2309 } | 2306 } |
| 2310 | 2307 |
| 2311 // Load the database via the WebDatabase class and migrate the database to | 2308 // Load the database via the WebDatabase class and migrate the database to |
| 2312 // the current version. | 2309 // the current version. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2329 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy")); | 2326 EXPECT_TRUE(connection.DoesColumnExist("keywords", "created_by_policy")); |
| 2330 } | 2327 } |
| 2331 } | 2328 } |
| 2332 | 2329 |
| 2333 // Tests that the credit_cards.billing_address column is changed from a string | 2330 // Tests that the credit_cards.billing_address column is changed from a string |
| 2334 // to an int whilst preserving the associated billing address. This version of | 2331 // to an int whilst preserving the associated billing address. This version of |
| 2335 // the test makes sure a stored label is converted to an ID. | 2332 // the test makes sure a stored label is converted to an ID. |
| 2336 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) { | 2333 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringLabels) { |
| 2337 // This schema is taken from a build prior to the change of column type for | 2334 // This schema is taken from a build prior to the change of column type for |
| 2338 // credit_cards.billing_address from string to int. | 2335 // credit_cards.billing_address from string to int. |
| 2339 ASSERT_NO_FATAL_FAILURE( | 2336 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql"))); |
| 2340 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_26.sql")))); | |
| 2341 | 2337 |
| 2342 // Verify pre-conditions. These are expectations for version 26 of the | 2338 // Verify pre-conditions. These are expectations for version 26 of the |
| 2343 // database. | 2339 // database. |
| 2344 { | 2340 { |
| 2345 sql::Connection connection; | 2341 sql::Connection connection; |
| 2346 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2342 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2347 | 2343 |
| 2348 // Columns existing and not existing before current version. | 2344 // Columns existing and not existing before current version. |
| 2349 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); | 2345 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); |
| 2350 | 2346 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2403 // Column 6 is date_modified. | 2399 // Column 6 is date_modified. |
| 2404 } | 2400 } |
| 2405 } | 2401 } |
| 2406 | 2402 |
| 2407 // Tests that the credit_cards.billing_address column is changed from a string | 2403 // Tests that the credit_cards.billing_address column is changed from a string |
| 2408 // to an int whilst preserving the associated billing address. This version of | 2404 // to an int whilst preserving the associated billing address. This version of |
| 2409 // the test makes sure a stored string ID is converted to an integer ID. | 2405 // the test makes sure a stored string ID is converted to an integer ID. |
| 2410 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) { | 2406 TEST_F(WebDatabaseMigrationTest, MigrateVersion26ToCurrentStringIDs) { |
| 2411 // This schema is taken from a build prior to the change of column type for | 2407 // This schema is taken from a build prior to the change of column type for |
| 2412 // credit_cards.billing_address from string to int. | 2408 // credit_cards.billing_address from string to int. |
| 2413 ASSERT_NO_FATAL_FAILURE( | 2409 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_26.sql"))); |
| 2414 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_26.sql")))); | |
| 2415 | 2410 |
| 2416 // Verify pre-conditions. These are expectations for version 26 of the | 2411 // Verify pre-conditions. These are expectations for version 26 of the |
| 2417 // database. | 2412 // database. |
| 2418 { | 2413 { |
| 2419 sql::Connection connection; | 2414 sql::Connection connection; |
| 2420 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2415 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2421 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); | 2416 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", "billing_address")); |
| 2422 | 2417 |
| 2423 std::string stmt = "INSERT INTO autofill_profiles" | 2418 std::string stmt = "INSERT INTO autofill_profiles" |
| 2424 "(label, unique_id, first_name, middle_name, last_name, email," | 2419 "(label, unique_id, first_name, middle_name, last_name, email," |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 EXPECT_EQ(2012, s.ColumnInt(4)); | 2472 EXPECT_EQ(2012, s.ColumnInt(4)); |
| 2478 // Column 5 is encrypted credit card number blob. | 2473 // Column 5 is encrypted credit card number blob. |
| 2479 // Column 6 is date_modified. | 2474 // Column 6 is date_modified. |
| 2480 } | 2475 } |
| 2481 } | 2476 } |
| 2482 | 2477 |
| 2483 // Tests migration from 27->current. This test is now the same as 28->current | 2478 // Tests migration from 27->current. This test is now the same as 28->current |
| 2484 // as the column added in 28 was nuked in 29. | 2479 // as the column added in 28 was nuked in 29. |
| 2485 TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) { | 2480 TEST_F(WebDatabaseMigrationTest, MigrateVersion27ToCurrent) { |
| 2486 // Initialize the database. | 2481 // Initialize the database. |
| 2487 ASSERT_NO_FATAL_FAILURE( | 2482 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_27.sql"))); |
| 2488 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_27.sql")))); | |
| 2489 | 2483 |
| 2490 // Verify pre-conditions. These are expectations for version 28 of the | 2484 // Verify pre-conditions. These are expectations for version 28 of the |
| 2491 // database. | 2485 // database. |
| 2492 { | 2486 { |
| 2493 sql::Connection connection; | 2487 sql::Connection connection; |
| 2494 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2488 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2495 | 2489 |
| 2496 ASSERT_FALSE(connection.DoesColumnExist("keywords", "supports_instant")); | 2490 ASSERT_FALSE(connection.DoesColumnExist("keywords", "supports_instant")); |
| 2497 ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); | 2491 ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); |
| 2498 } | 2492 } |
| 2499 | 2493 |
| 2500 MigrateVersion28Assertions(); | 2494 MigrateVersion28Assertions(); |
| 2501 } | 2495 } |
| 2502 | 2496 |
| 2503 // Makes sure instant_url is added correctly to keywords. | 2497 // Makes sure instant_url is added correctly to keywords. |
| 2504 TEST_F(WebDatabaseMigrationTest, MigrateVersion28ToCurrent) { | 2498 TEST_F(WebDatabaseMigrationTest, MigrateVersion28ToCurrent) { |
| 2505 // Initialize the database. | 2499 // Initialize the database. |
| 2506 ASSERT_NO_FATAL_FAILURE( | 2500 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_28.sql"))); |
| 2507 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_28.sql")))); | |
| 2508 | 2501 |
| 2509 // Verify pre-conditions. These are expectations for version 28 of the | 2502 // Verify pre-conditions. These are expectations for version 28 of the |
| 2510 // database. | 2503 // database. |
| 2511 { | 2504 { |
| 2512 sql::Connection connection; | 2505 sql::Connection connection; |
| 2513 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2506 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2514 | 2507 |
| 2515 ASSERT_TRUE(connection.DoesColumnExist("keywords", "supports_instant")); | 2508 ASSERT_TRUE(connection.DoesColumnExist("keywords", "supports_instant")); |
| 2516 ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); | 2509 ASSERT_FALSE(connection.DoesColumnExist("keywords", "instant_url")); |
| 2517 } | 2510 } |
| 2518 | 2511 |
| 2519 MigrateVersion28Assertions(); | 2512 MigrateVersion28Assertions(); |
| 2520 } | 2513 } |
| 2521 | 2514 |
| 2522 // Makes sure date_modified is added correctly to autofill_profiles and | 2515 // Makes sure date_modified is added correctly to autofill_profiles and |
| 2523 // credit_cards. | 2516 // credit_cards. |
| 2524 TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) { | 2517 TEST_F(WebDatabaseMigrationTest, MigrateVersion29ToCurrent) { |
| 2525 // Initialize the database. | 2518 // Initialize the database. |
| 2526 ASSERT_NO_FATAL_FAILURE( | 2519 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_29.sql"))); |
| 2527 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_29.sql")))); | |
| 2528 | 2520 |
| 2529 // Verify pre-conditions. These are expectations for version 29 of the | 2521 // Verify pre-conditions. These are expectations for version 29 of the |
| 2530 // database. | 2522 // database. |
| 2531 { | 2523 { |
| 2532 sql::Connection connection; | 2524 sql::Connection connection; |
| 2533 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2525 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2534 | 2526 |
| 2535 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", | 2527 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", |
| 2536 "date_modified")); | 2528 "date_modified")); |
| 2537 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", | 2529 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2582 EXPECT_LE(s_credit_cards.ColumnInt64(0), | 2574 EXPECT_LE(s_credit_cards.ColumnInt64(0), |
| 2583 post_creation_time.ToTimeT()); | 2575 post_creation_time.ToTimeT()); |
| 2584 } | 2576 } |
| 2585 EXPECT_TRUE(s_credit_cards.Succeeded()); | 2577 EXPECT_TRUE(s_credit_cards.Succeeded()); |
| 2586 } | 2578 } |
| 2587 } | 2579 } |
| 2588 | 2580 |
| 2589 // Makes sure guids are added to autofill_profiles and credit_cards tables. | 2581 // Makes sure guids are added to autofill_profiles and credit_cards tables. |
| 2590 TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) { | 2582 TEST_F(WebDatabaseMigrationTest, MigrateVersion30ToCurrent) { |
| 2591 // Initialize the database. | 2583 // Initialize the database. |
| 2592 ASSERT_NO_FATAL_FAILURE( | 2584 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_30.sql"))); |
| 2593 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_30.sql")))); | |
| 2594 | 2585 |
| 2595 // Verify pre-conditions. These are expectations for version 29 of the | 2586 // Verify pre-conditions. These are expectations for version 29 of the |
| 2596 // database. | 2587 // database. |
| 2597 { | 2588 { |
| 2598 sql::Connection connection; | 2589 sql::Connection connection; |
| 2599 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2590 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2600 | 2591 |
| 2601 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "guid")); | 2592 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", "guid")); |
| 2602 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "guid")); | 2593 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", "guid")); |
| 2603 } | 2594 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2635 EXPECT_TRUE(guid::IsValidGUID(guid2)); | 2626 EXPECT_TRUE(guid::IsValidGUID(guid2)); |
| 2636 | 2627 |
| 2637 EXPECT_NE(guid1, guid2); | 2628 EXPECT_NE(guid1, guid2); |
| 2638 } | 2629 } |
| 2639 } | 2630 } |
| 2640 | 2631 |
| 2641 // Removes unique IDs and make GUIDs the primary key. Also removes unused | 2632 // Removes unique IDs and make GUIDs the primary key. Also removes unused |
| 2642 // columns. | 2633 // columns. |
| 2643 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { | 2634 TEST_F(WebDatabaseMigrationTest, MigrateVersion31ToCurrent) { |
| 2644 // Initialize the database. | 2635 // Initialize the database. |
| 2645 ASSERT_NO_FATAL_FAILURE( | 2636 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_31.sql"))); |
| 2646 LoadDatabase(FilePath(FILE_PATH_LITERAL("version_31.sql")))); | |
| 2647 | 2637 |
| 2648 // Verify pre-conditions. These are expectations for version 30 of the | 2638 // Verify pre-conditions. These are expectations for version 30 of the |
| 2649 // database. | 2639 // database. |
| 2650 AutoFillProfile profile; | 2640 AutoFillProfile profile; |
| 2651 string16 profile_label; | 2641 string16 profile_label; |
| 2652 int profile_unique_id = 0; | 2642 int profile_unique_id = 0; |
| 2653 int64 profile_date_modified = 0; | 2643 int64 profile_date_modified = 0; |
| 2654 CreditCard credit_card; | 2644 CreditCard credit_card; |
| 2655 string16 cc_label; | 2645 string16 cc_label; |
| 2656 int cc_unique_id = 0; | 2646 int cc_unique_id = 0; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2769 &credit_card_a, | 2759 &credit_card_a, |
| 2770 &cc_label_a, | 2760 &cc_label_a, |
| 2771 &cc_number_encrypted_a, | 2761 &cc_number_encrypted_a, |
| 2772 &cc_date_modified_a)); | 2762 &cc_date_modified_a)); |
| 2773 EXPECT_EQ(credit_card, credit_card_a); | 2763 EXPECT_EQ(credit_card, credit_card_a); |
| 2774 EXPECT_EQ(cc_label, cc_label_a); | 2764 EXPECT_EQ(cc_label, cc_label_a); |
| 2775 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); | 2765 EXPECT_EQ(cc_number_encrypted, cc_number_encrypted_a); |
| 2776 EXPECT_EQ(cc_date_modified, cc_date_modified_a); | 2766 EXPECT_EQ(cc_date_modified, cc_date_modified_a); |
| 2777 } | 2767 } |
| 2778 } | 2768 } |
| 2769 |
| 2770 // Adds a column for the autofill profile's country code. |
| 2771 TEST_F(WebDatabaseMigrationTest, MigrateVersion32ToCurrent) { |
| 2772 // Initialize the database. |
| 2773 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_32.sql"))); |
| 2774 |
| 2775 // Verify pre-conditions. These are expectations for version 32 of the |
| 2776 // database. |
| 2777 { |
| 2778 sql::Connection connection; |
| 2779 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2780 |
| 2781 EXPECT_FALSE(connection.DoesColumnExist("autofill_profiles", |
| 2782 "country_code")); |
| 2783 |
| 2784 // Check that the country value is the one we expect. |
| 2785 sql::Statement s( |
| 2786 connection.GetUniqueStatement("SELECT country FROM autofill_profiles")); |
| 2787 |
| 2788 ASSERT_TRUE(s.Step()); |
| 2789 std::string country = s.ColumnString(0); |
| 2790 EXPECT_EQ("United States", country); |
| 2791 } |
| 2792 |
| 2793 // Load the database via the WebDatabase class and migrate the database to |
| 2794 // the current version. |
| 2795 { |
| 2796 WebDatabase db; |
| 2797 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 2798 } |
| 2799 |
| 2800 // Verify post-conditions. These are expectations for current version of the |
| 2801 // database. |
| 2802 { |
| 2803 sql::Connection connection; |
| 2804 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2805 |
| 2806 // Check version. |
| 2807 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2808 |
| 2809 ASSERT_TRUE(connection.DoesColumnExist("autofill_profiles", |
| 2810 "country_code")); |
| 2811 |
| 2812 // Check that the country code is properly converted. |
| 2813 sql::Statement s(connection.GetUniqueStatement( |
| 2814 "SELECT country_code FROM autofill_profiles")); |
| 2815 |
| 2816 ASSERT_TRUE(s.Step()); |
| 2817 std::string country_code = s.ColumnString(0); |
| 2818 EXPECT_EQ("US", country_code); |
| 2819 } |
| 2820 } |
| 2821 |
| OLD | NEW |