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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // > .output version_nn.sql | 250 // > .output version_nn.sql |
251 // > .dump | 251 // > .dump |
252 void LoadDatabase(const base::FilePath::StringType& file); | 252 void LoadDatabase(const base::FilePath::StringType& file); |
253 | 253 |
254 private: | 254 private: |
255 base::ScopedTempDir temp_dir_; | 255 base::ScopedTempDir temp_dir_; |
256 | 256 |
257 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 257 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
258 }; | 258 }; |
259 | 259 |
260 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 55; | 260 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 56; |
261 | 261 |
262 void WebDatabaseMigrationTest::LoadDatabase( | 262 void WebDatabaseMigrationTest::LoadDatabase( |
263 const base::FilePath::StringType& file) { | 263 const base::FilePath::StringType& file) { |
264 std::string contents; | 264 std::string contents; |
265 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 265 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
266 | 266 |
267 sql::Connection connection; | 267 sql::Connection connection; |
268 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 268 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
269 ASSERT_TRUE(connection.Execute(contents.data())); | 269 ASSERT_TRUE(connection.Execute(contents.data())); |
270 } | 270 } |
(...skipping 2330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(1)); | 2601 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(1)); |
2602 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2)); | 2602 EXPECT_EQ(ASCIIToUTF16("john doe"), s.ColumnString16(2)); |
2603 EXPECT_EQ(1384299200, s.ColumnInt64(3)); | 2603 EXPECT_EQ(1384299200, s.ColumnInt64(3)); |
2604 EXPECT_EQ(1384299200, s.ColumnInt64(4)); | 2604 EXPECT_EQ(1384299200, s.ColumnInt64(4)); |
2605 EXPECT_EQ(1, s.ColumnInt(5)); | 2605 EXPECT_EQ(1, s.ColumnInt(5)); |
2606 | 2606 |
2607 // No more entries expected. | 2607 // No more entries expected. |
2608 ASSERT_FALSE(s.Step()); | 2608 ASSERT_FALSE(s.Step()); |
2609 } | 2609 } |
2610 } | 2610 } |
| 2611 |
| 2612 // Tests that migrating from version 55 to version 56 adds the language_code |
| 2613 // column to autofill_profiles table. |
| 2614 TEST_F(WebDatabaseMigrationTest, MigrateVersion55ToCurrent) { |
| 2615 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_55.sql"))); |
| 2616 |
| 2617 // Verify pre-conditions. These are expectations for version 55 of the |
| 2618 // database. |
| 2619 { |
| 2620 sql::Connection connection; |
| 2621 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2622 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2623 |
| 2624 EXPECT_FALSE( |
| 2625 connection.DoesColumnExist("autofill_profiles", "language_code")); |
| 2626 } |
| 2627 |
| 2628 DoMigration(); |
| 2629 |
| 2630 // Verify post-conditions. These are expectations for current version of the |
| 2631 // database. |
| 2632 { |
| 2633 sql::Connection connection; |
| 2634 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2635 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2636 |
| 2637 // Check version. |
| 2638 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2639 |
| 2640 // The language_code column should have been added to autofill_profiles |
| 2641 // table. |
| 2642 EXPECT_TRUE( |
| 2643 connection.DoesColumnExist("autofill_profiles", "language_code")); |
| 2644 |
| 2645 // Data should have been preserved. Language code should have been set to |
| 2646 // empty string. |
| 2647 sql::Statement s_profiles( |
| 2648 connection.GetUniqueStatement( |
| 2649 "SELECT guid, company_name, street_address, dependent_locality," |
| 2650 " city, state, zipcode, sorting_code, country_code, date_modified," |
| 2651 " origin, language_code " |
| 2652 "FROM autofill_profiles")); |
| 2653 |
| 2654 ASSERT_TRUE(s_profiles.Step()); |
| 2655 EXPECT_EQ("00000000-0000-0000-0000-000000000001", |
| 2656 s_profiles.ColumnString(0)); |
| 2657 EXPECT_EQ(ASCIIToUTF16("Google Inc"), s_profiles.ColumnString16(1)); |
| 2658 EXPECT_EQ(ASCIIToUTF16("340 Main St"), |
| 2659 s_profiles.ColumnString16(2)); |
| 2660 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(3)); |
| 2661 EXPECT_EQ(ASCIIToUTF16("Los Angeles"), s_profiles.ColumnString16(4)); |
| 2662 EXPECT_EQ(ASCIIToUTF16("CA"), s_profiles.ColumnString16(5)); |
| 2663 EXPECT_EQ(ASCIIToUTF16("90291"), s_profiles.ColumnString16(6)); |
| 2664 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7)); |
| 2665 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8)); |
| 2666 EXPECT_EQ(1395948829, s_profiles.ColumnInt(9)); |
| 2667 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles.ColumnString16(10)); |
| 2668 EXPECT_EQ(std::string(), s_profiles.ColumnString(11)); |
| 2669 |
| 2670 // No more entries expected. |
| 2671 ASSERT_FALSE(s_profiles.Step()); |
| 2672 } |
| 2673 } |
OLD | NEW |