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/files/file_util.h" | 7 #include "base/files/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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // > .output version_nn.sql | 125 // > .output version_nn.sql |
126 // > .dump | 126 // > .dump |
127 void LoadDatabase(const base::FilePath::StringType& file); | 127 void LoadDatabase(const base::FilePath::StringType& file); |
128 | 128 |
129 private: | 129 private: |
130 base::ScopedTempDir temp_dir_; | 130 base::ScopedTempDir temp_dir_; |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 132 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
133 }; | 133 }; |
134 | 134 |
135 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 64; | 135 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 65; |
136 | 136 |
137 void WebDatabaseMigrationTest::LoadDatabase( | 137 void WebDatabaseMigrationTest::LoadDatabase( |
138 const base::FilePath::StringType& file) { | 138 const base::FilePath::StringType& file) { |
139 std::string contents; | 139 std::string contents; |
140 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 140 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
141 | 141 |
142 sql::Connection connection; | 142 sql::Connection connection; |
143 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 143 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
144 ASSERT_TRUE(connection.Execute(contents.data())); | 144 ASSERT_TRUE(connection.Execute(contents.data())); |
145 } | 145 } |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 | 927 |
928 // Check version. | 928 // Check version. |
929 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 929 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
930 | 930 |
931 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", | 931 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", |
932 "use_count")); | 932 "use_count")); |
933 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", | 933 EXPECT_TRUE(connection.DoesColumnExist("unmasked_credit_cards", |
934 "use_date")); | 934 "use_date")); |
935 } | 935 } |
936 } | 936 } |
| 937 |
| 938 // Tests addition of server metadata tables. |
| 939 TEST_F(WebDatabaseMigrationTest, MigrateVersion64ToCurrent) { |
| 940 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_64.sql"))); |
| 941 |
| 942 // Verify pre-conditions. |
| 943 { |
| 944 sql::Connection connection; |
| 945 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 946 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 947 |
| 948 sql::MetaTable meta_table; |
| 949 ASSERT_TRUE(meta_table.Init(&connection, 64, 64)); |
| 950 |
| 951 EXPECT_FALSE(connection.DoesTableExist("server_card_metadata")); |
| 952 EXPECT_FALSE(connection.DoesTableExist("server_address_metadata")); |
| 953 |
| 954 // Add a server address --- make sure it gets an ID. |
| 955 sql::Statement insert_profiles( |
| 956 connection.GetUniqueStatement( |
| 957 "INSERT INTO server_addresses(id, postal_code) " |
| 958 "VALUES ('', 90210)")); |
| 959 insert_profiles.Run(); |
| 960 } |
| 961 |
| 962 DoMigration(); |
| 963 |
| 964 // Verify post-conditions. |
| 965 { |
| 966 sql::Connection connection; |
| 967 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 968 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 969 |
| 970 // Check version. |
| 971 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 972 |
| 973 EXPECT_TRUE(connection.DoesTableExist("server_card_metadata")); |
| 974 EXPECT_TRUE(connection.DoesTableExist("server_address_metadata")); |
| 975 |
| 976 sql::Statement read_profiles( |
| 977 connection.GetUniqueStatement( |
| 978 "SELECT id, postal_code FROM server_addresses")); |
| 979 ASSERT_TRUE(read_profiles.Step()); |
| 980 EXPECT_FALSE(read_profiles.ColumnString(0).empty()); |
| 981 EXPECT_EQ("90210", read_profiles.ColumnString(1)); |
| 982 } |
| 983 } |
OLD | NEW |