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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 // > .output version_nn.sql | 249 // > .output version_nn.sql |
250 // > .dump | 250 // > .dump |
251 void LoadDatabase(const base::FilePath::StringType& file); | 251 void LoadDatabase(const base::FilePath::StringType& file); |
252 | 252 |
253 private: | 253 private: |
254 base::ScopedTempDir temp_dir_; | 254 base::ScopedTempDir temp_dir_; |
255 | 255 |
256 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 256 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
257 }; | 257 }; |
258 | 258 |
259 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 56; | 259 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 57; |
260 | 260 |
261 void WebDatabaseMigrationTest::LoadDatabase( | 261 void WebDatabaseMigrationTest::LoadDatabase( |
262 const base::FilePath::StringType& file) { | 262 const base::FilePath::StringType& file) { |
263 std::string contents; | 263 std::string contents; |
264 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 264 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
265 | 265 |
266 sql::Connection connection; | 266 sql::Connection connection; |
267 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 267 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
268 ASSERT_TRUE(connection.Execute(contents.data())); | 268 ASSERT_TRUE(connection.Execute(contents.data())); |
269 } | 269 } |
(...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7)); | 2663 EXPECT_EQ(base::string16(), s_profiles.ColumnString16(7)); |
2664 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8)); | 2664 EXPECT_EQ(ASCIIToUTF16("US"), s_profiles.ColumnString16(8)); |
2665 EXPECT_EQ(1395948829, s_profiles.ColumnInt(9)); | 2665 EXPECT_EQ(1395948829, s_profiles.ColumnInt(9)); |
2666 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles.ColumnString16(10)); | 2666 EXPECT_EQ(ASCIIToUTF16("Chrome settings"), s_profiles.ColumnString16(10)); |
2667 EXPECT_EQ(std::string(), s_profiles.ColumnString(11)); | 2667 EXPECT_EQ(std::string(), s_profiles.ColumnString(11)); |
2668 | 2668 |
2669 // No more entries expected. | 2669 // No more entries expected. |
2670 ASSERT_FALSE(s_profiles.Step()); | 2670 ASSERT_FALSE(s_profiles.Step()); |
2671 } | 2671 } |
2672 } | 2672 } |
| 2673 |
| 2674 // Tests that migrating from version 56 to version 57 adds the full_name |
| 2675 // column to autofill_profile_names table. |
| 2676 TEST_F(WebDatabaseMigrationTest, MigrateVersion56ToCurrent) { |
| 2677 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_56.sql"))); |
| 2678 |
| 2679 // Verify pre-conditions. These are expectations for version 56 of the |
| 2680 // database. |
| 2681 { |
| 2682 sql::Connection connection; |
| 2683 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2684 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2685 |
| 2686 EXPECT_FALSE( |
| 2687 connection.DoesColumnExist("autofill_profile_names", "full_name")); |
| 2688 |
| 2689 // Verify the starting data. |
| 2690 sql::Statement s_names( |
| 2691 connection.GetUniqueStatement( |
| 2692 "SELECT guid, first_name, middle_name, last_name " |
| 2693 "FROM autofill_profile_names")); |
| 2694 ASSERT_TRUE(s_names.Step()); |
| 2695 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); |
| 2696 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); |
| 2697 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); |
| 2698 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); |
| 2699 } |
| 2700 |
| 2701 DoMigration(); |
| 2702 |
| 2703 // Verify post-conditions. These are expectations for current version of the |
| 2704 // database. |
| 2705 { |
| 2706 sql::Connection connection; |
| 2707 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2708 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2709 |
| 2710 // Check version. |
| 2711 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2712 |
| 2713 // The full_name column should have been added to autofill_profile_names |
| 2714 // table. |
| 2715 EXPECT_TRUE( |
| 2716 connection.DoesColumnExist("autofill_profile_names", "full_name")); |
| 2717 |
| 2718 // Data should have been preserved. Full name should have been set to the |
| 2719 // empty string. |
| 2720 sql::Statement s_names( |
| 2721 connection.GetUniqueStatement( |
| 2722 "SELECT guid, first_name, middle_name, last_name, full_name " |
| 2723 "FROM autofill_profile_names")); |
| 2724 |
| 2725 ASSERT_TRUE(s_names.Step()); |
| 2726 EXPECT_EQ("B41FE6E0-B13E-2A2A-BF0B-29FCE2C3ADBD", s_names.ColumnString(0)); |
| 2727 EXPECT_EQ(ASCIIToUTF16("Jon"), s_names.ColumnString16(1)); |
| 2728 EXPECT_EQ(base::string16(), s_names.ColumnString16(2)); |
| 2729 EXPECT_EQ(ASCIIToUTF16("Smith"), s_names.ColumnString16(3)); |
| 2730 EXPECT_EQ(base::string16(), s_names.ColumnString16(4)); |
| 2731 |
| 2732 // No more entries expected. |
| 2733 ASSERT_FALSE(s_names.Step()); |
| 2734 } |
| 2735 } |
OLD | NEW |