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

Side by Side Diff: chrome/browser/history/shortcuts_database_unittest.cc

Issue 134853004: Migrate old Shortcuts DB data to conform to new type values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Trying to work around the copy as well as modification of v1.sql Created 6 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/shortcuts_database.cc ('k') | chrome/test/data/History/Shortcuts.v0.sql » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) { 250 TEST_F(ShortcutsDatabaseTest, DeleteAllShortcuts) {
251 AddAll(); 251 AddAll();
252 ShortcutsDatabase::GuidToShortcutMap shortcuts; 252 ShortcutsDatabase::GuidToShortcutMap shortcuts;
253 db_->LoadShortcuts(&shortcuts); 253 db_->LoadShortcuts(&shortcuts);
254 EXPECT_EQ(arraysize(shortcut_test_db), shortcuts.size()); 254 EXPECT_EQ(arraysize(shortcut_test_db), shortcuts.size());
255 EXPECT_TRUE(db_->DeleteAllShortcuts()); 255 EXPECT_TRUE(db_->DeleteAllShortcuts());
256 db_->LoadShortcuts(&shortcuts); 256 db_->LoadShortcuts(&shortcuts);
257 EXPECT_EQ(0U, shortcuts.size()); 257 EXPECT_EQ(0U, shortcuts.size());
258 } 258 }
259 259
260 TEST(ShortcutsDatabaseMigrationTest, MigrateV1ToV2) { 260 TEST(ShortcutsDatabaseMigrationTest, MigrateTableAddFillIntoEdit) {
261 // Open the v1 test file and use it to create a test database in a temp dir. 261 // Open the v0 test file and use it to create a test database in a temp dir.
262 base::FilePath sql_path; 262 base::FilePath sql_path;
263 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path)); 263 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path));
264 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v1.sql"); 264 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v0.sql");
265 base::ScopedTempDir temp_dir; 265 base::ScopedTempDir temp_dir;
266 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 266 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
267 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db")); 267 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db"));
268 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path)); 268 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path));
269 269
270 CheckV2ColumnExistence(db_path, false); 270 CheckV2ColumnExistence(db_path, false);
271 271
272 // Create a ShortcutsDatabase from the test database, which will migrate the 272 // Create a ShortcutsDatabase from the test database, which will migrate the
273 // test database to the current version. 273 // test database to the current version.
274 { 274 {
(...skipping 17 matching lines...) Expand all
292 // The other three columns have default values. 292 // The other three columns have default values.
293 EXPECT_EQ(content::PAGE_TRANSITION_TYPED, 293 EXPECT_EQ(content::PAGE_TRANSITION_TYPED,
294 static_cast<content::PageTransition>(statement.ColumnInt(2))); 294 static_cast<content::PageTransition>(statement.ColumnInt(2)));
295 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE, 295 EXPECT_EQ(AutocompleteMatchType::HISTORY_TITLE,
296 static_cast<AutocompleteMatch::Type>(statement.ColumnInt(3))); 296 static_cast<AutocompleteMatch::Type>(statement.ColumnInt(3)));
297 EXPECT_TRUE(statement.ColumnString(4).empty()); 297 EXPECT_TRUE(statement.ColumnString(4).empty());
298 } 298 }
299 EXPECT_TRUE(statement.Succeeded()); 299 EXPECT_TRUE(statement.Succeeded());
300 } 300 }
301 301
302 TEST(ShortcutsDatabaseMigrationTest, MigrateV0ToV1) {
303 // Open the v1 test file and use it to create a test database in a temp dir.
304 base::FilePath sql_path;
305 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &sql_path));
306 sql_path = sql_path.AppendASCII("History").AppendASCII("Shortcuts.v1.sql");
307 base::ScopedTempDir temp_dir;
308 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
309 base::FilePath db_path(temp_dir.path().AppendASCII("TestShortcuts.db"));
310 ASSERT_TRUE(sql::test::CreateDatabaseFromSQL(db_path, sql_path));
311
312 // Create a ShortcutsDatabase from the test database, which will migrate the
313 // test database to the current version.
314 {
315 scoped_refptr<ShortcutsDatabase> db(new ShortcutsDatabase(db_path));
316 db->Init();
317 }
318
319 // Check that all the old type values got converted to new values.
320 sql::Connection connection;
321 ASSERT_TRUE(connection.Open(db_path));
322 sql::Statement statement(connection.GetUniqueStatement(
323 "SELECT count(1) FROM omni_box_shortcuts WHERE type in (9, 10, 11, 12)"));
324 ASSERT_TRUE(statement.is_valid());
325 while (statement.Step())
326 EXPECT_EQ(0, statement.ColumnInt(0));
327 EXPECT_TRUE(statement.Succeeded());
328 }
329
302 } // namespace history 330 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/shortcuts_database.cc ('k') | chrome/test/data/History/Shortcuts.v0.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698