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/guid.h" | 8 #include "base/guid.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 void LoadDatabase(const FilePath::StringType& file); | 188 void LoadDatabase(const FilePath::StringType& file); |
189 | 189 |
190 private: | 190 private: |
191 MessageLoopForUI message_loop_for_ui_; | 191 MessageLoopForUI message_loop_for_ui_; |
192 content::TestBrowserThread ui_thread_; | 192 content::TestBrowserThread ui_thread_; |
193 ScopedTempDir temp_dir_; | 193 ScopedTempDir temp_dir_; |
194 | 194 |
195 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); | 195 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); |
196 }; | 196 }; |
197 | 197 |
198 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 46; | 198 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 47; |
199 | 199 |
200 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { | 200 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { |
201 std::string contents; | 201 std::string contents; |
202 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); | 202 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); |
203 | 203 |
204 sql::Connection connection; | 204 sql::Connection connection; |
205 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 205 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
206 ASSERT_TRUE(connection.Execute(contents.data())); | 206 ASSERT_TRUE(connection.Execute(contents.data())); |
207 } | 207 } |
208 | 208 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 EXPECT_FALSE(connection.DoesColumnExist("keywords", "supports_instant")); | 551 EXPECT_FALSE(connection.DoesColumnExist("keywords", "supports_instant")); |
552 EXPECT_TRUE(connection.DoesColumnExist("keywords", "instant_url")); | 552 EXPECT_TRUE(connection.DoesColumnExist("keywords", "instant_url")); |
553 | 553 |
554 // Check that instant_url is empty. | 554 // Check that instant_url is empty. |
555 std::string stmt = "SELECT instant_url FROM keywords"; | 555 std::string stmt = "SELECT instant_url FROM keywords"; |
556 sql::Statement s(connection.GetUniqueStatement(stmt.c_str())); | 556 sql::Statement s(connection.GetUniqueStatement(stmt.c_str())); |
557 ASSERT_TRUE(s.Step()); | 557 ASSERT_TRUE(s.Step()); |
558 EXPECT_EQ(std::string(), s.ColumnString(0)); | 558 EXPECT_EQ(std::string(), s.ColumnString(0)); |
559 | 559 |
560 // Verify the data made it over. | 560 // Verify the data made it over. |
561 stmt = "SELECT " + std::string(KeywordTable::kKeywordColumns) + | 561 stmt = "SELECT " + KeywordTable::GetKeywordColumns() + " FROM keywords"; |
562 " FROM keywords"; | |
563 sql::Statement s2(connection.GetUniqueStatement(stmt.c_str())); | 562 sql::Statement s2(connection.GetUniqueStatement(stmt.c_str())); |
564 ASSERT_TRUE(s2.Step()); | 563 ASSERT_TRUE(s2.Step()); |
565 EXPECT_EQ(2, s2.ColumnInt(0)); | 564 EXPECT_EQ(2, s2.ColumnInt(0)); |
566 EXPECT_EQ("Google", s2.ColumnString(1)); | 565 EXPECT_EQ("Google", s2.ColumnString(1)); |
567 EXPECT_EQ("google.com", s2.ColumnString(2)); | 566 EXPECT_EQ("google.com", s2.ColumnString(2)); |
568 EXPECT_EQ("http://www.google.com/favicon.ico", s2.ColumnString(3)); | 567 EXPECT_EQ("http://www.google.com/favicon.ico", s2.ColumnString(3)); |
569 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"\ | 568 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}"\ |
570 "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"\ | 569 "{google:originalQueryForSuggestion}sourceid=chrome&ie={inputEncoding}"\ |
571 "&q={searchTerms}", | 570 "&q={searchTerms}", |
572 s2.ColumnString(4)); | 571 s2.ColumnString(4)); |
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, | 1775 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kDefaultSearchIDBackupKey, |
1777 &default_search_provider_id_backup)); | 1776 &default_search_provider_id_backup)); |
1778 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); | 1777 EXPECT_EQ(default_search_provider_id, default_search_provider_id_backup); |
1779 | 1778 |
1780 std::string default_search_provider_id_backup_signature; | 1779 std::string default_search_provider_id_backup_signature; |
1781 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, | 1780 EXPECT_TRUE(meta_table.GetValue(KeywordTable::kBackupSignatureKey, |
1782 &default_search_provider_id_backup_signature)); | 1781 &default_search_provider_id_backup_signature)); |
1783 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); | 1782 EXPECT_FALSE(default_search_provider_id_backup_signature.empty()); |
1784 | 1783 |
1785 EXPECT_TRUE(connection.DoesTableExist("keywords_backup")); | 1784 EXPECT_TRUE(connection.DoesTableExist("keywords_backup")); |
1786 std::string query("SELECT " + std::string(KeywordTable::kKeywordColumns) + | 1785 std::string query("SELECT " + KeywordTable::GetKeywordColumns() + |
1787 " FROM keywords_backup"); | 1786 " FROM keywords_backup"); |
1788 sql::Statement s(connection.GetUniqueStatement(query.c_str())); | 1787 sql::Statement s(connection.GetUniqueStatement(query.c_str())); |
1789 ASSERT_TRUE(s.Step()); | 1788 ASSERT_TRUE(s.Step()); |
1790 EXPECT_EQ(2, s.ColumnInt(0)); | 1789 EXPECT_EQ(2, s.ColumnInt(0)); |
1791 EXPECT_EQ("Google", s.ColumnString(1)); | 1790 EXPECT_EQ("Google", s.ColumnString(1)); |
1792 EXPECT_EQ("google.com", s.ColumnString(2)); | 1791 EXPECT_EQ("google.com", s.ColumnString(2)); |
1793 EXPECT_EQ("http://www.google.com/favicon.ico", s.ColumnString(3)); | 1792 EXPECT_EQ("http://www.google.com/favicon.ico", s.ColumnString(3)); |
1794 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" | 1793 EXPECT_EQ("{google:baseURL}search?{google:RLZ}{google:acceptedSuggestion}" |
1795 "{google:originalQueryForSuggestion}sourceid=chrome&" | 1794 "{google:originalQueryForSuggestion}sourceid=chrome&" |
1796 "ie={inputEncoding}&q={searchTerms}", | 1795 "ie={inputEncoding}&q={searchTerms}", |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2202 { | 2201 { |
2203 sql::Connection connection; | 2202 sql::Connection connection; |
2204 ASSERT_TRUE(connection.Open(GetDatabasePath())); | 2203 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
2205 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); | 2204 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
2206 | 2205 |
2207 // Check version. | 2206 // Check version. |
2208 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); | 2207 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
2209 EXPECT_LE(45, VersionFromConnection(&connection)); | 2208 EXPECT_LE(45, VersionFromConnection(&connection)); |
2210 } | 2209 } |
2211 } | 2210 } |
| 2211 |
| 2212 // Tests that the |alternate_urls| column is added to the keyword table schema |
| 2213 // for a version 45 database. |
| 2214 TEST_F(WebDatabaseMigrationTest, MigrateVersion46ToCurrent) { |
| 2215 ASSERT_NO_FATAL_FAILURE( |
| 2216 LoadDatabase(FILE_PATH_LITERAL("version_46.sql"))); |
| 2217 |
| 2218 // Verify pre-conditions. These are expectations for version 46 of the |
| 2219 // database. |
| 2220 { |
| 2221 sql::Connection connection; |
| 2222 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2223 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2224 |
| 2225 sql::MetaTable meta_table; |
| 2226 ASSERT_TRUE(meta_table.Init(&connection, 46, 46)); |
| 2227 |
| 2228 ASSERT_FALSE(connection.DoesColumnExist("keywords", "alternate_urls")); |
| 2229 ASSERT_FALSE(connection.DoesColumnExist("keywords_backup", |
| 2230 "alternate_urls")); |
| 2231 } |
| 2232 |
| 2233 // Load the database via the WebDatabase class and migrate the database to |
| 2234 // the current version. |
| 2235 { |
| 2236 WebDatabase db; |
| 2237 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath())); |
| 2238 ASSERT_FALSE(db.GetKeywordTable()->DidDefaultSearchProviderChange()); |
| 2239 } |
| 2240 |
| 2241 // Verify post-conditions. These are expectations for current version of the |
| 2242 // database. |
| 2243 { |
| 2244 sql::Connection connection; |
| 2245 ASSERT_TRUE(connection.Open(GetDatabasePath())); |
| 2246 ASSERT_TRUE(sql::MetaTable::DoesTableExist(&connection)); |
| 2247 |
| 2248 // Check version. |
| 2249 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); |
| 2250 |
| 2251 // A new column should have been created. |
| 2252 EXPECT_TRUE(connection.DoesColumnExist("keywords", "alternate_urls")); |
| 2253 ASSERT_TRUE(connection.DoesColumnExist("keywords_backup", |
| 2254 "alternate_urls")); |
| 2255 } |
| 2256 } |
OLD | NEW |