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 "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 // Open the v0 test file and use it to create a test database in a temp dir. |
|
Peter Kasting
2014/03/27 20:59:25
Nit: v0 -> pre-v0
Anuj
2014/03/27 21:46:10
Done.
| |
| 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 "Shortcuts.no_fill_into_edit.sql"); | |
| 228 base::ScopedTempDir temp_dir; | 229 base::ScopedTempDir temp_dir; |
| 229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 230 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 230 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); | 231 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts1.db")); |
|
Anuj
2014/03/27 01:56:40
The conflict in the db files created by two tests
Peter Kasting
2014/03/27 20:59:25
How is that possible? They're both running Create
Anuj
2014/03/27 21:46:10
I am not sure. But in my dev setup, the test faile
Peter Kasting
2014/03/27 21:55:28
:/ OK, I guess... I'd like to understand it now, b
Anuj
2014/03/27 22:19:05
So are you okay with this? Or do you want to block
| |
| 231 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | 232 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); |
| 232 | 233 |
| 233 CheckV2ColumnExistence(db_path, false); | 234 CheckV2ColumnExistence(db_path, false); |
| 234 | 235 |
| 235 // Create a ShortcutsDatabase from the test database, which will migrate the | 236 // Create a ShortcutsDatabase from the test database, which will migrate the |
| 236 // test database to the current version. | 237 // test database to the current version. |
| 237 { | 238 { |
| 238 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); | 239 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); |
| 239 db->Init(); | 240 db->Init(); |
| 240 } | 241 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 255 // The other three columns have default values. | 256 // The other three columns have default values. |
| 256 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, | 257 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, |
| 257 static_cast<content::PageTransition>(statement.ColumnInt(2))); | 258 static_cast<content::PageTransition>(statement.ColumnInt(2))); |
| 258 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, | 259 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, |
| 259 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); | 260 static_cast<AutocompleteMatchType::Type>(statement.ColumnInt(3))); |
| 260 EXPECT_TRUE(statement.ColumnString(4).empty()); | 261 EXPECT_TRUE(statement.ColumnString(4).empty()); |
| 261 } | 262 } |
| 262 EXPECT_TRUE(statement.Succeeded()); | 263 EXPECT_TRUE(statement.Succeeded()); |
| 263 } | 264 } |
| 264 | 265 |
| 266 TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) { | |
| 267 // Open the v1 test file and use it to create a test database in a temp dir. | |
|
Peter Kasting
2014/03/27 20:59:25
Nit: v1 -> v0
Anuj
2014/03/27 21:46:10
Done.
| |
| 268 base::FilePath sql_path; | |
| 269 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); | |
| 270 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v0.sql"); | |
| 271 base::ScopedTempDir temp_dir; | |
| 272 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 273 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts2.db")); | |
| 274 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); | |
| 275 | |
| 276 // Create a ShortcutsDatabase from the test database, which will migrate the | |
| 277 // test database to the current version. | |
| 278 { | |
| 279 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path)); | |
| 280 db->Init(); | |
| 281 } | |
| 282 | |
| 283 // Check that all the old type values got converted to new values. | |
| 284 sql::Connection connection; | |
| 285 ASSERT_TRUE(connection.Open(db_path)); | |
| 286 sql::Statement statement(connection.GetUniqueStatement( | |
| 287 "SELECT count(1) FROM omni_box_shortcuts WHERE type in (9, 10, 11, 12)")); | |
| 288 ASSERT_TRUE(statement.is_valid()); | |
| 289 while (statement.Step()) | |
| 290 EXPECT_EQ(0, statement.ColumnInt(0)); | |
| 291 EXPECT_TRUE(statement.Succeeded()); | |
| 292 } | |
| 293 | |
| 265 } // namespace history | 294 } // namespace history |
| OLD | NEW |