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 "base/files/scoped_temp_dir.h" | 5 #include "base/files/scoped_temp_dir.h" |
6 #include "base/format_macros.h" | 6 #include "base/format_macros.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { | 213 TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { |
214 AddAll(); | 214 AddAll(); |
215 ShortcutsDatabase::GuidToShortcutMap shortcuts; | 215 ShortcutsDatabase::GuidToShortcutMap shortcuts; |
216 db_->LoadShortcuts(&shortcuts); | 216 db_->LoadShortcuts(&shortcuts); |
217 EXPECT_EQ(arraysize(shortcut_test_db), shortcuts.size()); | 217 EXPECT_EQ(arraysize(shortcut_test_db), shortcuts.size()); |
218 EXPECT_TRUE(db_->DeleteAllShortcuts()); | 218 EXPECT_TRUE(db_->DeleteAllShortcuts()); |
219 db_->LoadShortcuts(&shortcuts); | 219 db_->LoadShortcuts(&shortcuts); |
220 EXPECT_EQ(0U, shortcuts.size()); | 220 EXPECT_EQ(0U, shortcuts.size()); |
221 } | 221 } |
222 | 222 |
223 TEST(ShortcutsDatabaseMigrationTest, MigrateV1ToV2) { | 223 TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) { |
224 // Open the v1 test file and use it to create a test database in a temp dir. | 224 // Use the pre-v0 test file to create a test database in a temp dir. |
225 base::FilePath sql_path; | 225 base::FilePath sql_path; |
226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); | 226 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); |
227 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v1.sql"); | 227 sql_path = sql_path.AppendASCII("History").AppendASCII( |
| 228 #if defined(OS_ANDROID) |
| 229 "Shortcuts.v1.sql"); |
| 230 #else |
| 231 "Shortcuts.no_fill_into_edit.sql"); |
| 232 #endif |
228 base::ScopedTempDir temp_dir; | 233 base::ScopedTempDir temp_dir; |
229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 234 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
230 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); | 235 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts1.db")); |
231 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | 236 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
232 | 237 |
233 CheckV2ColumnExistence(db_path, false); | 238 CheckV2ColumnExistence(db_path, false); |
234 | 239 |
235 // Create a ShortcutsDatabase from the test database, which will migrate the | 240 // Create a ShortcutsDatabase from the test database, which will migrate the |
236 // test database to the current version. | 241 // test database to the current version. |
237 { | 242 { |
238 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); | 243 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
239 db->Init(); | 244 db->Init(); |
240 } | 245 } |
(...skipping 12 matching lines...) Expand all Loading... |
253 EXPECT_EQ(statement.ColumnString(1), statement.ColumnString(0)); | 258 EXPECT_EQ(statement.ColumnString(1), statement.ColumnString(0)); |
254 | 259 |
255 // The other three columns have default values. | 260 // The other three columns have default values. |
256 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, | 261 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, |
257 static_cast<content::PageTransition>(statement.ColumnInt(2))); | 262 static_cast<content::PageTransition>(statement.ColumnInt(2))); |
258 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, | 263 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, |
259 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); | 264 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); |
260 EXPECT_TRUE(statement.ColumnString(4).empty()); | 265 EXPECT_TRUE(statement.ColumnString(4).empty()); |
261 } | 266 } |
262 EXPECT_TRUE(statement.Succeeded()); | 267 EXPECT_TRUE(statement.Succeeded()); |
| 268 #if !defined(OS_WIN) |
| 269 EXPECT_TRUE(temp_dir.Delete()); |
| 270 #endif |
| 271 } |
| 272 |
| 273 TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { |
| 274 // Use the v0 test file to create a test database in a temp dir. |
| 275 base::FilePath sql_path; |
| 276 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); |
| 277 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v0.sql"); |
| 278 base::ScopedTempDir temp_dir; |
| 279 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 280 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts2.db")); |
| 281 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
| 282 |
| 283 // Create a ShortcutsDatabase from the test database, which will migrate the |
| 284 // test database to the current version. |
| 285 { |
| 286 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
| 287 db->Init(); |
| 288 } |
| 289 |
| 290 // Check that all the old type values got converted to new values. |
| 291 sql::Connection connection; |
| 292 ASSERT_TRUE(connection.Open(db_path)); |
| 293 sql::Statement statement(connection.GetUniqueStatement( |
| 294 "SELECT count(1) FROM omni_box_shortcuts WHERE type in (9, 10, 11, 12)")); |
| 295 ASSERT_TRUE(statement.is_valid()); |
| 296 while (statement.Step()) |
| 297 EXPECT_EQ(0, statement.ColumnInt(0)); |
| 298 EXPECT_TRUE(statement.Succeeded()); |
| 299 #if !defined(OS_WIN) |
| 300 EXPECT_TRUE(temp_dir.Delete()); |
| 301 #endif |
263 } | 302 } |
264 | 303 |
265 } // namespace history | 304 } // namespace history |
OLD | NEW |