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

Side by Side Diff: chrome/browser/webdata/web_database_migration_unittest.cc

Issue 7396024: Adding a sync_guid field to TemplateURL. Adding appropriate database migration changes and tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Lint fix. Created 9 years, 5 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/webdata/web_database.cc ('k') | chrome/test/data/web_database/version_38.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "app/sql/statement.h" 7 #include "app/sql/statement.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 179
180 // Assertion testing for migrating from version 27 and 28. 180 // Assertion testing for migrating from version 27 and 28.
181 void MigrateVersion28Assertions(); 181 void MigrateVersion28Assertions();
182 182
183 private: 183 private:
184 ScopedTempDir temp_dir_; 184 ScopedTempDir temp_dir_;
185 185
186 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest); 186 DISALLOW_COPY_AND_ASSIGN(WebDatabaseMigrationTest);
187 }; 187 };
188 188
189 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 38; 189 const int WebDatabaseMigrationTest::kCurrentTestedVersionNumber = 39;
190 190
191 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) { 191 void WebDatabaseMigrationTest::LoadDatabase(const FilePath::StringType& file) {
192 std::string contents; 192 std::string contents;
193 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents)); 193 ASSERT_TRUE(GetWebDatabaseData(FilePath(file), &contents));
194 194
195 sql::Connection connection; 195 sql::Connection connection;
196 ASSERT_TRUE(connection.Open(GetDatabasePath())); 196 ASSERT_TRUE(connection.Open(GetDatabasePath()));
197 ASSERT_TRUE(connection.Execute(contents.data())); 197 ASSERT_TRUE(connection.Execute(contents.data()));
198 } 198 }
199 199
(...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 ASSERT_TRUE(connection.Open(GetDatabasePath())); 1457 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1458 1458
1459 // Check version. 1459 // Check version.
1460 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection)); 1460 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1461 1461
1462 // |keywords| |last_modified| column should have been added. 1462 // |keywords| |last_modified| column should have been added.
1463 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id")); 1463 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
1464 EXPECT_TRUE(connection.DoesColumnExist("keywords", "last_modified")); 1464 EXPECT_TRUE(connection.DoesColumnExist("keywords", "last_modified"));
1465 } 1465 }
1466 } 1466 }
1467
1468 // Tests that the |keywords| |sync_guid| column gets added to the schema for
1469 // a version 38 database.
1470 TEST_F(WebDatabaseMigrationTest, MigrateVersion38ToCurrent) {
1471 // This schema is taken from a build prior to the addition of the |keywords|
1472 // |sync_guid| column.
1473 ASSERT_NO_FATAL_FAILURE(LoadDatabase(FILE_PATH_LITERAL("version_38.sql")));
1474
1475 // Verify pre-conditions. These are expectations for version 38 of the
1476 // database.
1477 {
1478 sql::Connection connection;
1479 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1480
1481 // Columns existing and not existing before current version.
1482 ASSERT_TRUE(connection.DoesColumnExist("keywords", "id"));
1483 ASSERT_FALSE(connection.DoesColumnExist("keywords", "sync_guid"));
1484 }
1485
1486 // Load the database via the WebDatabase class and migrate the database to
1487 // the current version.
1488 {
1489 WebDatabase db;
1490 ASSERT_EQ(sql::INIT_OK, db.Init(GetDatabasePath()));
1491 }
1492
1493 // Verify post-conditions. These are expectations for current version of the
1494 // database.
1495 {
1496 sql::Connection connection;
1497 ASSERT_TRUE(connection.Open(GetDatabasePath()));
1498
1499 // Check version.
1500 EXPECT_EQ(kCurrentTestedVersionNumber, VersionFromConnection(&connection));
1501
1502 // |keywords| |sync_guid| column should have been added.
1503 EXPECT_TRUE(connection.DoesColumnExist("keywords", "id"));
1504 EXPECT_TRUE(connection.DoesColumnExist("keywords", "sync_guid"));
1505 }
1506 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.cc ('k') | chrome/test/data/web_database/version_38.sql » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698