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.h" | 10 #include "base/message_loop.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void LoadDatabase(const FilePath::StringType& file); | 206 void LoadDatabase(const FilePath::StringType& file); |
207 | 207 |
208 private: | 208 private: |
209 MessageLoopForUI message_loop_for_ui_; | 209 MessageLoopForUI message_loop_for_ui_; |
210 content::TestBrowserThread ui_thread_; | 210 content::TestBrowserThread ui_thread_; |
211 base::ScopedTempDir temp_dir_; | 211 base::ScopedTempDir temp_dir_; |
212 | 212 |
213 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 213 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
214 }; | 214 }; |
215 | 215 |
216 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 48; | 216 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 49; |
217 | 217 |
218 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { | 218 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { |
219 std::string contents; | 219 std::string contents; |
220 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); | 220 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); |
221 | 221 |
222 sql::Connection connection; | 222 sql::Connection connection; |
223 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 223 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
224 ASSERT_TRUE(connection.Execute(contents.data())); | 224 ASSERT_TRUE(connection.Execute(contents.data())); |
225 } | 225 } |
226 | 226 |
(...skipping 1822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2049 kCurrentTestedVersionNumber)); | 2049 kCurrentTestedVersionNumber)); |
2050 | 2050 |
2051 int64 default_search_provider_id = 0; | 2051 int64 default_search_provider_id = 0; |
2052 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, | 2052 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchProviderKey, |
2053 &default_search_provider_id)); | 2053 &default_search_provider_id)); |
2054 EXPECT_NE(0, default_search_provider_id); | 2054 EXPECT_NE(0, default_search_provider_id); |
2055 | 2055 |
2056 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); | 2056 EXPECT_NO_FATAL_FAILURE(CheckNoBackupData(connection, &meta_table)); |
2057 } | 2057 } |
2058 } | 2058 } |
| 2059 |
| 2060 // Tests that the |search_terms_replacement_key| column is added to the keyword |
| 2061 // table schema for a version 49 database. |
| 2062 TEST_F(WebDatabaseMigrationTest, MigrateVersion48ToCurrent) { |
| 2063 ASSERT_NO_FATAL_FAILURE( |
| 2064 LoadDatabase(FILE_PATH_LITERAL("version_48.sql"))); |
| 2065 |
| 2066 // Verify pre-conditions. These are expectations for version 48 of the |
| 2067 // database. |
| 2068 { |
| 2069 sql::Connection connection; |
| 2070 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2071 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2072 |
| 2073 sql::MetaTable meta_table; |
| 2074 ASSERT_TRUE(meta_table.Init(&connection, 48, 48)); |
| 2075 |
| 2076 ASSERT_FALSE(connection.DoesColumnExist("keywords", |
| 2077 "search_terms_replacement_key")); |
| 2078 } |
| 2079 |
| 2080 // Load the database via the WebDatabase class and migrate the database to |
| 2081 // the current version. |
| 2082 { |
| 2083 WebDatabase db; |
| 2084 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 2085 } |
| 2086 |
| 2087 // Verify post-conditions. These are expectations for current version of the |
| 2088 // database. |
| 2089 { |
| 2090 sql::Connection connection; |
| 2091 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2092 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2093 |
| 2094 // Check version. |
| 2095 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2096 |
| 2097 // A new column should have been created. |
| 2098 EXPECT_TRUE(connection.DoesColumnExist("keywords", |
| 2099 "search_terms_replacement_key")); |
| 2100 } |
| 2101 } |
OLD | NEW |