Chromium Code Reviews| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 123 // > .output version_nn.sql | 123 // > .output version_nn.sql |
| 124 // > .dump | 124 // > .dump |
| 125 void LoadDatabase(const base::FilePath::StringType& file); | 125 void LoadDatabase(const base::FilePath::StringType& file); |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 base::ScopedTempDir temp_dir_; | 128 base::ScopedTempDir temp_dir_; |
| 129 | 129 |
| 130 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 130 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 65; | 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 66; |
| 134 | 134 |
| 135 void WebDatabaseMigrationTest::LoadDatabase( | 135 void WebDatabaseMigrationTest::LoadDatabase( |
| 136 const base::FilePath::StringType& file) { | 136 const base::FilePath::StringType& file) { |
| 137 std::string contents; | 137 std::string contents; |
| 138 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); | 138 ASSERT_TRUE(GetWebDatabaseData(base::FilePath(file), &contents)); |
| 139 | 139 |
| 140 sql::Connection connection; | 140 sql::Connection connection; |
| 141 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 141 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 142 ASSERT_TRUE(connection.Execute(contents.data())); | 142 ASSERT_TRUE(connection.Execute(contents.data())); |
| 143 } | 143 } |
| (...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 977 EXPECT_TRUE(connection.DoesTableExist("server_address_metadata")); | 977 EXPECT_TRUE(connection.DoesTableExist("server_address_metadata")); |
| 978 | 978 |
| 979 sql::Statement read_profiles( | 979 sql::Statement read_profiles( |
| 980 connection.GetUniqueStatement( | 980 connection.GetUniqueStatement( |
| 981 "SELECT id, postal_code FROM server_addresses")); | 981 "SELECT id, postal_code FROM server_addresses")); |
| 982 ASSERT_TRUE(read_profiles.Step()); | 982 ASSERT_TRUE(read_profiles.Step()); |
| 983 EXPECT_FALSE(read_profiles.ColumnString(0).empty()); | 983 EXPECT_FALSE(read_profiles.ColumnString(0).empty()); |
| 984 EXPECT_EQ("90210", read_profiles.ColumnString(1)); | 984 EXPECT_EQ("90210", read_profiles.ColumnString(1)); |
| 985 } | 985 } |
| 986 } | 986 } |
| 987 | |
| 988 // Tests addition of credit card billing address. | |
| 989 TEST_F(WebDatabaseMigrationTest, MigrateVersion65ToCurrent) { | |
| 990 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_65.sql"))); | |
| 991 | |
| 992 // Verify pre-conditions. | |
| 993 { | |
| 994 sql::Connection connection; | |
| 995 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
| 996 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
| 997 | |
| 998 sql::MetaTable meta_table; | |
| 999 ASSERT_TRUE(meta_table.Init(&connection, 65, 65)); | |
| 1000 | |
| 1001 EXPECT_FALSE(connection.DoesColumnExist("credit_cards", | |
| 1002 "billing_address_id")); | |
| 1003 | |
| 1004 sql::Statement(connection.GetUniqueStatement( | |
| 1005 "INSERT INTO credit_cards(guid, name_on_card) " | |
| 1006 "VALUES ('', 'Alice')")) | |
| 1007 .Run(); | |
|
Scott Hess - ex-Googler
2016/06/22 21:52:16
Maybe connection.Execute() instead?
please use gerrit instead
2016/06/23 01:26:58
Done.
| |
| 1008 } | |
| 1009 | |
| 1010 DoMigration(); | |
| 1011 | |
| 1012 // Verify post-conditions. | |
| 1013 { | |
| 1014 sql::Connection connection; | |
| 1015 ASSERT_TRUE(connection.Open(GetDatabasePath())); | |
| 1016 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | |
| 1017 | |
| 1018 // Check version. | |
| 1019 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | |
| 1020 | |
| 1021 EXPECT_TRUE(connection.DoesColumnExist("credit_cards", | |
| 1022 "billing_address_id")); | |
| 1023 | |
| 1024 sql::Statement read_credit_cards(connection.GetUniqueStatement( | |
| 1025 "SELECT name_on_card, billing_address_id FROM credit_cards")); | |
| 1026 ASSERT_TRUE(read_credit_cards.Step()); | |
| 1027 EXPECT_EQ("Alice", read_credit_cards.ColumnString(0)); | |
| 1028 EXPECT_TRUE(read_credit_cards.ColumnString(1).empty()); | |
| 1029 } | |
| 1030 } | |
| OLD | NEW |