Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: components/webdata/common/web_database_migration_unittest.cc

Issue 2498053002: Add field to monitor last visited time for each search engine (Closed)
Patch Set: Add unit test for last_visited field. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 = 68; 133 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 69;
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 13 matching lines...) Expand all
157 // version_nn.sql file. 157 // version_nn.sql file.
158 if (i == 52) 158 if (i == 52)
159 continue; 159 continue;
160 160
161 connection.Raze(); 161 connection.Raze();
162 const base::FilePath& file_name = base::FilePath::FromUTF8Unsafe( 162 const base::FilePath& file_name = base::FilePath::FromUTF8Unsafe(
163 "version_" + base::IntToString(i) + ".sql"); 163 "version_" + base::IntToString(i) + ".sql");
164 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name.value())) 164 ASSERT_NO_FATAL_FAILURE(LoadDatabase(file_name.value()))
165 << "Failed to load " << file_name.MaybeAsASCII(); 165 << "Failed to load " << file_name.MaybeAsASCII();
166 DoMigration(); 166 DoMigration();
167
167 EXPECT_EQ(expected_schema, RemoveQuotes(connection.GetSchema())) 168 EXPECT_EQ(expected_schema, RemoveQuotes(connection.GetSchema()))
168 << "For version " << i; 169 << "For version " << i;
170
Peter Kasting 2016/11/21 03:35:08 Nit: Extra blank line
ltian 2016/11/28 22:08:02 Done.
169 } 171 }
170 } 172 }
171 173
172 // Tests that the all migrations from an empty database succeed. 174 // Tests that the all migrations from an empty database succeed.
173 TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) { 175 TEST_F(WebDatabaseMigrationTest, MigrateEmptyToCurrent) {
174 DoMigration(); 176 DoMigration();
175 177
176 // Verify post-conditions. These are expectations for current version of the 178 // Verify post-conditions. These are expectations for current version of the
177 // database. 179 // database.
178 { 180 {
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 "billing_address_id")); 1065 "billing_address_id"));
1064 1066
1065 sql::Statement read_masked(connection.GetUniqueStatement( 1067 sql::Statement read_masked(connection.GetUniqueStatement(
1066 "SELECT name_on_card, billing_address_id FROM masked_credit_cards")); 1068 "SELECT name_on_card, billing_address_id FROM masked_credit_cards"));
1067 ASSERT_TRUE(read_masked.Step()); 1069 ASSERT_TRUE(read_masked.Step());
1068 EXPECT_EQ("Alice", read_masked.ColumnString(0)); 1070 EXPECT_EQ("Alice", read_masked.ColumnString(0));
1069 EXPECT_TRUE(read_masked.ColumnString(1).empty()); 1071 EXPECT_TRUE(read_masked.ColumnString(1).empty());
1070 } 1072 }
1071 } 1073 }
1072 1074
1073 // Tests delete show_in_default_list column in keywords table. 1075 // Tests delete show_in_default_list column in keywords table.
Peter Kasting 2016/11/21 03:35:08 Nit: While here: delete -> deletion of (I missed
ltian 2016/11/28 22:08:02 Done.
1074 TEST_F(WebDatabaseMigrationTest, MigrateVersion67ToCurrent) { 1076 TEST_F(WebDatabaseMigrationTest, MigrateVersion67ToCurrent) {
1075 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_67.sql"))); 1077 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_67.sql")));
1076 1078
1077 // Verify pre-conditions. 1079 // Verify pre-conditions.
1078 { 1080 {
1079 sql::Connection connection; 1081 sql::Connection connection;
1080 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1082 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1081 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1083 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1082 1084
1083 sql::MetaTable meta_table; 1085 sql::MetaTable meta_table;
(...skipping 10 matching lines...) Expand all
1094 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1096 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1095 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); 1097 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1096 1098
1097 // Check version. 1099 // Check version.
1098 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1100 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1099 1101
1100 EXPECT_FALSE( 1102 EXPECT_FALSE(
1101 connection.DoesColumnExist("keywords", "show_in_default_list")); 1103 connection.DoesColumnExist("keywords", "show_in_default_list"));
1102 } 1104 }
1103 } 1105 }
1106
1107 // Tests add last_visited column in keywords table.
Peter Kasting 2016/11/21 03:35:08 Nit: add -> addition of
ltian 2016/11/28 22:08:02 Done.
1108 TEST_F(WebDatabaseMigrationTest, MigrateVersion68ToCurrent) {
1109 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_68.sql")));
1110
1111 // Verify pre-conditions.
1112 {
1113 sql::Connection connection;
1114 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1115 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1116
1117 sql::MetaTable meta_table;
1118 ASSERT_TRUE(meta_table.Init(&connection, 68, 68));
1119
1120 EXPECT_FALSE(connection.DoesColumnExist("keywords", "last_visited"));
1121 }
1122
1123 DoMigration();
1124
1125 // Verify post-conditions.
1126 {
1127 sql::Connection connection;
1128 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1129 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection));
1130
1131 // Check version.
1132 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1133
1134 EXPECT_TRUE(
1135 connection.DoesColumnExist("keywords", "last_visited"));
1136 }
1137 }
OLDNEW
« components/webdata/common/web_database.cc ('K') | « components/webdata/common/web_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698